feat: add is process loss autoset and validation

This commit is contained in:
18alantom
2021-06-23 15:06:00 +05:30
parent 867ed3a1e4
commit 025f4b21de
2 changed files with 25 additions and 0 deletions

View File

@@ -360,6 +360,14 @@ frappe.ui.form.on("BOM", {
}
});
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."))
}
}
erpnext.bom.BomController = erpnext.TransactionController.extend({
conversion_rate: function(doc) {
if(this.frm.doc.currency === this.get_company_currency()) {
@@ -380,6 +388,9 @@ erpnext.bom.BomController = erpnext.TransactionController.extend({
child.bom_no = '';
}
if (scrap_items) {
set_is_process_loss(doc, cdt, cdn)
}
get_bom_material_detail(doc, cdt, cdn, scrap_items);
},
@@ -447,6 +458,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");

View File

@@ -81,6 +81,7 @@ class BOM(WebsiteGenerator):
self.validate_operations()
self.calculate_cost()
self.update_stock_qty()
self.validate_scrap_items()
self.update_cost(update_parent=False, from_child_bom=True, save=False)
def get_context(self, context):
@@ -585,6 +586,15 @@ class BOM(WebsiteGenerator):
if not d.batch_size or d.batch_size <= 0:
d.batch_size = 1
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)