feat: add is process loss autoset and validation
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index 3f50b41..a5ce8c6 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -379,6 +379,9 @@
child.bom_no = '';
}
+ if (scrap_items) {
+ set_is_process_loss(doc, cdt, cdn)
+ }
get_bom_material_detail(doc, cdt, cdn, scrap_items);
}
@@ -446,6 +449,10 @@
},
callback: function(r) {
d = locals[cdt][cdn];
+ if (d.is_process_loss) {
+ r.message.rate = 0
+ r.message.base_rate = 0
+ }
$.extend(d, r.message);
refresh_field("items");
refresh_field("scrap_items");
@@ -655,3 +662,11 @@
frm.set_value("operations", []);
}
});
+
+function set_is_process_loss(doc, cdt, cdn) {
+ const row = locals[cdt][cdn]
+ if (row.item_code === doc.item) {
+ row.is_process_loss = 1
+ frappe.msgprint(__("Item:") + ` ${row.item_code} ` + __("set as process loss."))
+ }
+}
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 6bd2a98..de0c521 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -155,6 +155,7 @@
self.update_stock_qty()
self.update_cost(update_parent=False, from_child_bom=True, update_hour_rate = False, save=False)
self.set_bom_level()
+ self.validate_scrap_items()
def get_context(self, context):
context.parents = [{'name': 'boms', 'title': _('All BOMs') }]
@@ -691,6 +692,15 @@
if update:
self.db_set("bom_level", self.bom_level)
+ def validate_scrap_items(self):
+ for item in self.scrap_items:
+ if item.item_code == self.item and not item.is_process_loss:
+ frappe.throw(_('Item:') + f' {item.item_code} ' +\
+ _('in Scrap/Loss Items table should have Is Process Loss checked.'))
+ elif item.item_code != self.item and item.is_process_loss:
+ frappe.throw(_('Item:') + f' {item.item_code} ' +\
+ _('in Scrap/Loss Items table should not have Is Process Loss checked.'))
+
def get_bom_item_rate(args, bom_doc):
if bom_doc.rm_cost_as_per == 'Valuation Rate':
rate = get_valuation_rate(args) * (args.get("conversion_factor") or 1)