fix: remove duplicate items validation
This commit is contained in:
parent
b62bf78814
commit
ee9f97ca7c
@ -70,51 +70,37 @@ frappe.ui.form.on("Packing Slip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
validate_calculate_item_details: (frm) => {
|
validate_calculate_item_details: (frm) => {
|
||||||
doc = locals[frm.doc.doctype][frm.doc.name];
|
frm.trigger("validate_items_qty");
|
||||||
var ps_detail = doc.items || [];
|
frm.trigger("calc_net_total_pkg");
|
||||||
|
|
||||||
frm.events.validate_duplicate_items(doc, ps_detail);
|
|
||||||
frm.events.calc_net_total_pkg(doc, ps_detail);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Do not allow duplicate items i.e. items with same item_code
|
validate_items_qty: (frm) => {
|
||||||
// Also check for 0 qty
|
frm.doc.items.forEach(item => {
|
||||||
validate_duplicate_items: (doc, ps_detail) => {
|
if (item.qty <= 0) {
|
||||||
for(var i=0; i<ps_detail.length; i++) {
|
frappe.msgprint(__("Invalid quantity specified for item {0}. Quantity should be greater than 0.", [item.item_code]));
|
||||||
for(var j=0; j<ps_detail.length; j++) {
|
|
||||||
if(i!=j && ps_detail[i].item_code && ps_detail[i].item_code == ps_detail[j].item_code) {
|
|
||||||
frappe.msgprint(__("You have entered duplicate items. Please rectify and try again."));
|
|
||||||
frappe.validated = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flt(ps_detail[i].qty) <= 0) {
|
|
||||||
frappe.msgprint(__("Invalid quantity specified for item {0}. Quantity should be greater than 0.", [ps_detail[i].item_code]));
|
|
||||||
frappe.validated = false;
|
frappe.validated = false;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Calculate Net Weight of Package
|
calc_net_total_pkg: (frm) => {
|
||||||
calc_net_total_pkg: (doc, ps_detail) => {
|
|
||||||
var net_weight_pkg = 0;
|
var net_weight_pkg = 0;
|
||||||
doc.net_weight_uom = (ps_detail && ps_detail.length) ? ps_detail[0].weight_uom : '';
|
var items = frm.doc.items || [];
|
||||||
doc.gross_weight_uom = doc.net_weight_uom;
|
frm.doc.net_weight_uom = (items && items.length) ? items[0].weight_uom : '';
|
||||||
|
frm.doc.gross_weight_uom = frm.doc.net_weight_uom;
|
||||||
|
|
||||||
for(var i=0; i<ps_detail.length; i++) {
|
items.forEach(item => {
|
||||||
var item = ps_detail[i];
|
if(item.weight_uom != frm.doc.net_weight_uom) {
|
||||||
if(item.weight_uom != doc.net_weight_uom) {
|
|
||||||
frappe.msgprint(__("Different UOM for items will lead to incorrect (Total) Net Weight value. Make sure that Net Weight of each item is in the same UOM."));
|
frappe.msgprint(__("Different UOM for items will lead to incorrect (Total) Net Weight value. Make sure that Net Weight of each item is in the same UOM."));
|
||||||
frappe.validated = false;
|
frappe.validated = false;
|
||||||
}
|
}
|
||||||
net_weight_pkg += flt(item.net_weight) * flt(item.qty);
|
net_weight_pkg += flt(item.net_weight) * flt(item.qty);
|
||||||
}
|
});
|
||||||
|
|
||||||
doc.net_weight_pkg = roundNumber(net_weight_pkg, 2);
|
frm.doc.net_weight_pkg = roundNumber(net_weight_pkg, 2);
|
||||||
|
|
||||||
if(!flt(doc.gross_weight_pkg)) {
|
if(!flt(frm.doc.gross_weight_pkg)) {
|
||||||
doc.gross_weight_pkg = doc.net_weight_pkg;
|
frm.doc.gross_weight_pkg = frm.doc.net_weight_pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_many(['net_weight_pkg', 'net_weight_uom', 'gross_weight_uom', 'gross_weight_pkg']);
|
refresh_many(['net_weight_pkg', 'net_weight_uom', 'gross_weight_uom', 'gross_weight_pkg']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user