feat: add is process loss autoset and validation
This commit is contained in:
parent
b6dc0efa27
commit
984c97ed4e
@ -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."))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user