Merge branch 'develop' into fix/scr/return
diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py
index 04a0dfa..0054edb 100644
--- a/erpnext/controllers/sales_and_purchase_return.py
+++ b/erpnext/controllers/sales_and_purchase_return.py
@@ -503,7 +503,7 @@
doctype
+ " Item": {
"doctype": doctype + " Item",
- "field_map": {"serial_no": "serial_no", "batch_no": "batch_no"},
+ "field_map": {"serial_no": "serial_no", "batch_no": "batch_no", "bom": "bom"},
"postprocess": update_item,
},
"Payment Schedule": {"doctype": "Payment Schedule", "postprocess": update_terms},
diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py
index aa4468c..8d67e30 100644
--- a/erpnext/controllers/subcontracting_controller.py
+++ b/erpnext/controllers/subcontracting_controller.py
@@ -89,6 +89,9 @@
if bom.item != item.item_code:
msg = f"Please select an valid BOM for Item {item.item_name}."
frappe.throw(_(msg))
+ else:
+ msg = f"Please select a BOM for Item {item.item_name}."
+ frappe.throw(_(msg))
def __get_data_before_save(self):
item_dict = {}
diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py
index 8490d14..0e6fe95 100644
--- a/erpnext/controllers/tests/test_subcontracting_controller.py
+++ b/erpnext/controllers/tests/test_subcontracting_controller.py
@@ -815,6 +815,7 @@
"item_name",
"qty",
"uom",
+ "bom",
"warehouse",
"stock_uom",
"subcontracting_order",
diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py
index cd05b74..bce5360 100644
--- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py
+++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py
@@ -57,6 +57,7 @@
def before_validate(self):
super(SubcontractingReceipt, self).before_validate()
+ self.set_items_bom()
self.set_items_cost_center()
self.set_items_expense_account()
@@ -193,6 +194,24 @@
).format(item.idx)
)
+ def set_items_bom(self):
+ if self.is_return:
+ for item in self.items:
+ if not item.bom:
+ item.bom = frappe.db.get_value(
+ "Subcontracting Receipt Item",
+ {"name": item.subcontracting_receipt_item, "parent": self.return_against},
+ "bom",
+ )
+ else:
+ for item in self.items:
+ if not item.bom:
+ item.bom = frappe.db.get_value(
+ "Subcontracting Order Item",
+ {"name": item.subcontracting_order_item, "parent": item.subcontracting_order},
+ "bom",
+ )
+
def set_items_cost_center(self):
if self.company:
cost_center = frappe.get_cached_value("Company", self.company, "cost_center")
diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py
index 090f145..34e7842 100644
--- a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py
+++ b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py
@@ -327,7 +327,7 @@
for row in scr.supplied_items:
self.assertEqual(transferred_batch.get(row.batch_no), row.consumed_qty)
- def test_subcontracting_order_partial_return(self):
+ def test_subcontracting_receipt_partial_return(self):
sco = get_subcontracting_order()
rm_items = get_rm_items(sco.supplied_items)
itemwise_details = make_stock_in_entry(rm_items=rm_items)
@@ -343,15 +343,17 @@
scr1_return = make_return_subcontracting_receipt(scr_name=scr1.name, qty=-3)
scr1.load_from_db()
self.assertEqual(scr1_return.status, "Return")
+ self.assertIsNotNone(scr1_return.items[0].bom)
self.assertEqual(scr1.items[0].returned_qty, 3)
scr2_return = make_return_subcontracting_receipt(scr_name=scr1.name, qty=-7)
scr1.load_from_db()
self.assertEqual(scr2_return.status, "Return")
+ self.assertIsNotNone(scr2_return.items[0].bom)
self.assertEqual(scr1.status, "Return Issued")
self.assertEqual(scr1.items[0].returned_qty, 10)
- def test_subcontracting_order_over_return(self):
+ def test_subcontracting_receipt_over_return(self):
sco = get_subcontracting_order()
rm_items = get_rm_items(sco.supplied_items)
itemwise_details = make_stock_in_entry(rm_items=rm_items)
@@ -402,8 +404,8 @@
"stock_value_difference",
)
- # Service Cost(100 * 10) + Raw Materials Cost(50 * 10) + Additional Costs(100) = 1600
- self.assertEqual(stock_value_difference, 1600)
+ # Service Cost(100 * 10) + Raw Materials Cost(100 * 10) + Additional Costs(10 * 10) = 2100
+ self.assertEqual(stock_value_difference, 2100)
self.assertFalse(get_gl_entries("Subcontracting Receipt", scr.name))
def test_subcontracting_receipt_gl_entry(self):