From f7f573b11bd902b9bcf3f13e456fb7ef91a4f7e7 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 26 Aug 2021 13:15:57 +0530 Subject: [PATCH] fix: prevent over riding scrap table values, name kwargs, set currency --- erpnext/manufacturing/doctype/bom/bom.py | 2 +- erpnext/manufacturing/doctype/bom/test_bom.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index b9647e9c613..70237f9147f 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -232,7 +232,7 @@ class BOM(WebsiteGenerator): } ret = self.get_bom_material_detail(args) for key, value in ret.items(): - if not item.get(key): + if item.get(key) is None: item.set(key, value) @frappe.whitelist() diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 8b9820c7bb5..6a81ac33679 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -232,30 +232,30 @@ class TestBOM(unittest.TestCase): if not frappe.db.exists("BOM", f"BOM-{fg_item_non_whole.item_code}-001"): bom_doc = create_bom_with_process_loss_item( - fg_item_non_whole, bom_item, 0.25, 0, 1 + fg_item_non_whole, bom_item, scrap_qty=0.25, scrap_rate=0, fg_qty=1 ) bom_doc.submit() bom_doc = create_bom_with_process_loss_item( - fg_item_non_whole, bom_item, 2, 0 + fg_item_non_whole, bom_item, scrap_qty=2, scrap_rate=0 ) # PL Item qty can't be >= FG Item qty self.assertRaises(frappe.ValidationError, bom_doc.submit) bom_doc = create_bom_with_process_loss_item( - fg_item_non_whole, bom_item, 1, 100 + fg_item_non_whole, bom_item, scrap_qty=1, scrap_rate=100 ) # PL Item rate has to be 0 self.assertRaises(frappe.ValidationError, bom_doc.submit) bom_doc = create_bom_with_process_loss_item( - fg_item_whole, bom_item, 0.25, 0 + fg_item_whole, bom_item, scrap_qty=0.25, scrap_rate=0 ) # Items with whole UOMs can't be PL Items self.assertRaises(frappe.ValidationError, bom_doc.submit) bom_doc = create_bom_with_process_loss_item( - fg_item_non_whole, bom_item, 0.25, 0, is_process_loss=0 + fg_item_non_whole, bom_item, scrap_qty=0.25, scrap_rate=0, is_process_loss=0 ) # FG Items in Scrap/Loss Table should have Is Process Loss set self.assertRaises(frappe.ValidationError, bom_doc.submit) @@ -330,6 +330,7 @@ def create_nested_bom(tree, prefix="_Test bom "): bom = frappe.get_doc(doctype="BOM", item=bom_item_code) for child_item in child_items.keys(): bom.append("items", {"item_code": prefix + child_item}) + bom.currency = "INR" bom.insert() bom.submit() @@ -373,6 +374,7 @@ def create_bom_with_process_loss_item( "rate": scrap_rate, "is_process_loss": is_process_loss }) + bom_doc.currency = "INR" return bom_doc def create_process_loss_bom_items():