refactor: shift auto entry of is process loss check, update validations
This commit is contained in:
parent
3df8d0cdf0
commit
7433b97106
@ -379,9 +379,6 @@ erpnext.bom.BomController = class BomController extends erpnext.TransactionContr
|
|||||||
child.bom_no = '';
|
child.bom_no = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrap_items) {
|
|
||||||
set_is_process_loss(doc, cdt, cdn)
|
|
||||||
}
|
|
||||||
get_bom_material_detail(doc, cdt, cdn, scrap_items);
|
get_bom_material_detail(doc, cdt, cdn, scrap_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,9 +447,10 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) {
|
|||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
d = locals[cdt][cdn];
|
d = locals[cdt][cdn];
|
||||||
if (d.is_process_loss) {
|
if (d.is_process_loss) {
|
||||||
r.message.rate = 0
|
r.message.rate = 0;
|
||||||
r.message.base_rate = 0
|
r.message.base_rate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.extend(d, r.message);
|
$.extend(d, r.message);
|
||||||
refresh_field("items");
|
refresh_field("items");
|
||||||
refresh_field("scrap_items");
|
refresh_field("scrap_items");
|
||||||
@ -661,12 +659,37 @@ frappe.ui.form.on("BOM", "with_operations", function(frm) {
|
|||||||
if(!cint(frm.doc.with_operations)) {
|
if(!cint(frm.doc.with_operations)) {
|
||||||
frm.set_value("operations", []);
|
frm.set_value("operations", []);
|
||||||
}
|
}
|
||||||
|
toggle_operations(frm);
|
||||||
});
|
});
|
||||||
|
|
||||||
function set_is_process_loss(doc, cdt, cdn) {
|
frappe.ui.form.on("BOM Scrap Item", {
|
||||||
const row = locals[cdt][cdn]
|
item_code(frm, cdt, cdn) {
|
||||||
if (row.item_code === doc.item) {
|
const { item_code } = locals[cdt][cdn];
|
||||||
row.is_process_loss = 1
|
if (item_code === frm.doc.item) {
|
||||||
frappe.msgprint(__("Item:") + ` ${row.item_code} ` + __("set as process loss."))
|
locals[cdt][cdn].is_process_loss = 1;
|
||||||
|
trigger_process_loss_qty_prompt(frm, cdt, cdn, item_code)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function trigger_process_loss_qty_prompt(frm, cdt, cdn, item_code) {
|
||||||
|
frappe.prompt(
|
||||||
|
{
|
||||||
|
fieldname: "percent",
|
||||||
|
fieldtype: "Percent",
|
||||||
|
label: __("% Finished Item Quantity"),
|
||||||
|
description:
|
||||||
|
__("Set quantity of process loss item:") +
|
||||||
|
` ${item_code} ` +
|
||||||
|
__("as a percentage of finished item quantity"),
|
||||||
|
},
|
||||||
|
(data) => {
|
||||||
|
const row = locals[cdt][cdn];
|
||||||
|
row.stock_qty = (frm.doc.quantity * data.percent) / 100;
|
||||||
|
row.qty = row.stock_qty / (row.conversion_factor ?? 1);
|
||||||
|
refresh_field("scrap_items");
|
||||||
|
},
|
||||||
|
__("Set Process Loss Item Quantity"),
|
||||||
|
__("Set Quantity")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -695,11 +695,25 @@ class BOM(WebsiteGenerator):
|
|||||||
def validate_scrap_items(self):
|
def validate_scrap_items(self):
|
||||||
for item in self.scrap_items:
|
for item in self.scrap_items:
|
||||||
if item.item_code == self.item and not item.is_process_loss:
|
if item.item_code == self.item and not item.is_process_loss:
|
||||||
frappe.throw(_('Item:') + f' {item.item_code} ' +\
|
frappe.throw(_('Scrap/Loss Item:') + f' {frappe.bold(item.item_code)} ' +\
|
||||||
_('in Scrap/Loss Items table should have Is Process Loss checked.'))
|
_('should have') + ' ' + frappe.bold(_('Is Process Loss')) + ' ' + ('checked.'))
|
||||||
elif item.item_code != self.item and item.is_process_loss:
|
elif item.item_code != self.item and item.is_process_loss:
|
||||||
frappe.throw(_('Item:') + f' {item.item_code} ' +\
|
frappe.throw(_('Scrap/Loss Item:') + f' {frappe.bold(item.item_code)} ' +\
|
||||||
_('in Scrap/Loss Items table should not have Is Process Loss checked.'))
|
_('should not have') + ' ' + frappe.bold(_('Is Process Loss')) + ' ' + ('checked.'))
|
||||||
|
|
||||||
|
stock_uom = item.stock_uom
|
||||||
|
must_be_whole_number = frappe.get_value("UOM", stock_uom, "must_be_whole_number")
|
||||||
|
if item.is_process_loss and must_be_whole_number:
|
||||||
|
frappe.throw(_('Item:') + f' {frappe.bold(item.item_code)} ' +\
|
||||||
|
_('with Stock UOM:') + f' {frappe.bold(stock_uom)} '+\
|
||||||
|
_('cannot be a Scrap/Loss Item.'))
|
||||||
|
|
||||||
|
if item.is_process_loss and (item.stock_qty >= self.quantity):
|
||||||
|
frappe.throw(_('Scrap/Loss Item:') + f' {item.item_code} ' +\
|
||||||
|
_('should have') +' '+frappe.bold(_('Qty')) +\
|
||||||
|
' ' + _('less than finished goods') + ' ' +\
|
||||||
|
frappe.bold(_('Quantity.')))
|
||||||
|
|
||||||
|
|
||||||
def get_bom_item_rate(args, bom_doc):
|
def get_bom_item_rate(args, bom_doc):
|
||||||
if bom_doc.rm_cost_as_per == 'Valuation Rate':
|
if bom_doc.rm_cost_as_per == 'Valuation Rate':
|
||||||
|
Loading…
Reference in New Issue
Block a user