fix: prevent over riding scrap table values, name kwargs, set currency

This commit is contained in:
18alantom
2021-08-26 13:15:57 +05:30
parent 466ff46045
commit f7f573b11b
2 changed files with 8 additions and 6 deletions

View File

@@ -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()

View File

@@ -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():