diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py index a9975c1e6f..8a0dbe1e65 100644 --- a/erpnext/manufacturing/doctype/production_order/test_production_order.py +++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py @@ -54,4 +54,4 @@ class TestProductionOrder(unittest.TestCase): self.assertRaises(StockOverProductionError, s.submit) -test_records = frappe.get_test_records('Production Order') \ No newline at end of file +test_records = frappe.get_test_records('Production Order') diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json index 531f1a72f6..eb0d7c9daa 100644 --- a/erpnext/stock/doctype/item/test_records.json +++ b/erpnext/stock/doctype/item/test_records.json @@ -83,7 +83,7 @@ "tax_type": "_Test Account Excise Duty - _TC" } ], - "stock_uom": "_Test UOM" + "stock_uom": "_Test UOM 1" }, { "default_warehouse": "_Test Warehouse - _TC", diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index fb4493a37c..5562e5a141 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -479,23 +479,34 @@ class StockEntry(StockController): self.production_order = None if self.bom_no: - if self.purpose in ["Material Issue", "Material Transfer", "Manufacture", "Repack", - "Subcontract"]: - if self.production_order and self.purpose == "Material Transfer": - item_dict = self.get_pending_raw_materials(pro_obj) + if self.purpose in ("Material Issue", "Material Transfer", "Manufacture", + "Repack", "Subcontract"): + + if self.production_order: + # production: stores -> wip + if self.purpose == "Material Transfer": + item_dict = self.get_pending_raw_materials(pro_obj) + for item in item_dict.values(): + item["to_warehouse"] = pro_obj.wip_warehouse + + # production: wip -> finished goods + elif self.purpose == "Manufacture": + item_dict = self.get_bom_raw_materials(self.fg_completed_qty) + for item in item_dict.values(): + item["from_warehouse"] = pro_obj.wip_warehouse + + else: + frappe.throw(_("Stock Entry against Production Order must be for 'Material Transfer' or 'Manufacture'")) else: if not self.fg_completed_qty: frappe.throw(_("Manufacturing Quantity is mandatory")) item_dict = self.get_bom_raw_materials(self.fg_completed_qty) - for item in item_dict.values(): - if pro_obj: - item["from_warehouse"] = pro_obj.wip_warehouse - item["to_warehouse"] = "" # add raw materials to Stock Entry Detail table self.add_to_stock_entry_detail(item_dict) - if self.bom_no: + # add finished goods item + if self.purpose in ("Manufacture", "Repack"): if self.production_order: item_code = pro_obj.production_item to_warehouse = pro_obj.fg_warehouse @@ -529,6 +540,7 @@ class StockEntry(StockController): for item in item_dict.values(): item.from_warehouse = item.default_warehouse + item.to_warehouse = "" return item_dict @@ -585,8 +597,8 @@ class StockEntry(StockController): for d in item_dict: se_child = self.append('mtn_details') - se_child.s_warehouse = item_dict[d].get("from_warehouse", self.from_warehouse) - se_child.t_warehouse = item_dict[d].get("to_warehouse", self.to_warehouse) + se_child.s_warehouse = item_dict[d].get("from_warehouse") + se_child.t_warehouse = item_dict[d].get("to_warehouse") se_child.item_code = cstr(d) se_child.item_name = item_dict[d]["item_name"] se_child.description = item_dict[d]["description"] @@ -596,6 +608,11 @@ class StockEntry(StockController): se_child.expense_account = item_dict[d]["expense_account"] or expense_account se_child.cost_center = item_dict[d]["cost_center"] or cost_center + if se_child.s_warehouse==None: + se_child.s_warehouse = self.from_warehouse + if se_child.t_warehouse==None: + se_child.t_warehouse = self.to_warehouse + # in stock uom se_child.transfer_qty = flt(item_dict[d]["qty"]) se_child.conversion_factor = 1.00