From 984c97ed4ee80c72edf8f12776ab3a8d99605424 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 23 Jun 2021 15:06:00 +0530 Subject: [PATCH] feat: add is process loss autoset and validation --- erpnext/manufacturing/doctype/bom/bom.js | 15 +++++++++++++++ erpnext/manufacturing/doctype/bom/bom.py | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 3f50b41be1..a5ce8c6195 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -379,6 +379,9 @@ erpnext.bom.BomController = class BomController extends erpnext.TransactionContr 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 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) { }, 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 @@ frappe.ui.form.on("BOM", "with_operations", function(frm) { 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 6bd2a985e2..de0c521cf5 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -155,6 +155,7 @@ class BOM(WebsiteGenerator): 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 @@ class BOM(WebsiteGenerator): 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)