diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index ed0531e6dd..26fd52d114 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -45,6 +45,7 @@ class StockController(AccountsController): for sle in sle_list: if warehouse_account.get(sle.warehouse): # from warehouse account + self.check_expense_account(detail) gl_list.append(self.get_gl_dict({ @@ -230,10 +231,10 @@ class StockController(AccountsController): make_gl_entries(gl_entries) def check_expense_account(self, item): - if item.meta.get_field("expense_account") and not item.expense_account: + if not item.get("expense_account"): frappe.throw(_("Expense or Difference account is mandatory for Item {0} as there is difference in value").format(item.item_code)) - if getattr(item, "expense_account", None) and not item.cost_center: + if item.get("expense_account") and not item.cost_center: frappe.throw(_("""Cost Center is mandatory for Item {0}""").format(item.item_code)) def get_sl_entries(self, d, args): diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 496d57707c..626c3fcbe1 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -112,7 +112,7 @@ class ProductionOrder(Document): produced_qty = flt(produced_qty[0][0]) if produced_qty else 0 if produced_qty > self.qty: - frappe.throw(_("Manufactured quantity {0} cannot be greater than planned quanitity {1} in Production Order {2}").format(produced_qty, self.qty, self.name, StockOverProductionError)) + frappe.throw(_("Manufactured quantity {0} cannot be greater than planned quanitity {1} in Production Order {2}").format(produced_qty, self.qty, self.name), StockOverProductionError) self.db_set("produced_qty", produced_qty) diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py index 4c563e6499..2736be4efc 100644 --- a/erpnext/manufacturing/doctype/production_order/test_production_order.py +++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py @@ -7,40 +7,21 @@ import unittest import frappe from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.manufacturing.doctype.production_order.production_order import make_stock_entry - +from erpnext.stock.doctype.stock_entry import test_stock_entry class TestProductionOrder(unittest.TestCase): def test_planned_qty(self): set_perpetual_inventory(0) + + planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0 + pro_doc = frappe.copy_doc(test_records[0]) pro_doc.insert() pro_doc.submit() # add raw materials to stores - s = frappe.new_doc("Stock Entry") - s.purpose = "Material Receipt" - s.company = "_Test Company" - s.append("mtn_details", { - "item_code": "_Test Item", - "t_warehouse": "Stores - _TC", - "qty": 100, - "incoming_rate": 5000 - }) - s.insert() - s.submit() - - # add raw materials to stores - s = frappe.new_doc("Stock Entry") - s.purpose = "Material Receipt" - s.company = "_Test Company" - s.append("mtn_details", { - "item_code": "_Test Item Home Desktop 100", - "t_warehouse": "Stores - _TC", - "qty": 100, - "incoming_rate": 1000 - }) - s.insert() - s.submit() + test_stock_entry.make_stock_entry("_Test Item", None, "Stores - _TC", 100, 100) + test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "Stores - _TC", 100, 100) # from stores to wip s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4)) @@ -56,8 +37,8 @@ class TestProductionOrder(unittest.TestCase): self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name, "produced_qty"), 4) - self.assertEqual(frappe.db.get_value("Bin", {"item_code": "_Test FG Item", - "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty"), 6) + planned1 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") + self.assertEqual(planned1 - planned0, 6) return pro_doc @@ -65,11 +46,8 @@ class TestProductionOrder(unittest.TestCase): from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError pro_doc = self.test_planned_qty() - s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 7)) - for d in s.get("mtn_details"): - d.s_warehouse = "Stores - _TC" - s.insert() - s.submit() + test_stock_entry.make_stock_entry("_Test Item", None, "_Test Warehouse - _TC", 100, 100) + test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "_Test Warehouse - _TC", 100, 100) s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture/Repack", 7)) s.insert() diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index f5fd08cfb4..3480f2c63a 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -824,3 +824,23 @@ def make_serialized_item(): return se test_records = frappe.get_test_records('Stock Entry') + +def make_stock_entry(item, source, target, qty, incoming_rate=None): + s = frappe.new_doc("Stock Entry") + if source and target: + s.purpose = "Material Transfer" + elif source: + s.purpose = "Material Issue" + else: + s.purpose = "Material Receipt" + s.company = "_Test Company" + s.append("mtn_details", { + "item_code": item, + "s_warehouse": source, + "t_warehouse": target, + "qty": qty, + "incoming_rate": incoming_rate + }) + s.insert() + s.submit() + return s