Skip to content

Commit

Permalink
fix: remove duplicate items validation
Browse files Browse the repository at this point in the history
(cherry picked from commit ee9f97c)
  • Loading branch information
s-aga-r authored and mergify[bot] committed May 25, 2023
1 parent 0c7efae commit c7628c9
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions erpnext/stock/doctype/packing_slip/packing_slip.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,37 @@ frappe.ui.form.on("Packing Slip", {
},

validate_calculate_item_details: (frm) => {
doc = locals[frm.doc.doctype][frm.doc.name];
var ps_detail = doc.items || [];

frm.events.validate_duplicate_items(doc, ps_detail);
frm.events.calc_net_total_pkg(doc, ps_detail);
frm.trigger("validate_items_qty");
frm.trigger("calc_net_total_pkg");
},

// Do not allow duplicate items i.e. items with same item_code
// Also check for 0 qty
validate_duplicate_items: (doc, ps_detail) => {
for(var i=0; i<ps_detail.length; i++) {
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]));
validate_items_qty: (frm) => {
frm.doc.items.forEach(item => {
if (item.qty <= 0) {
frappe.msgprint(__("Invalid quantity specified for item {0}. Quantity should be greater than 0.", [item.item_code]));
frappe.validated = false;
}
}
});
},

// Calculate Net Weight of Package
calc_net_total_pkg: (doc, ps_detail) => {
calc_net_total_pkg: (frm) => {
var net_weight_pkg = 0;
doc.net_weight_uom = (ps_detail && ps_detail.length) ? ps_detail[0].weight_uom : '';
doc.gross_weight_uom = doc.net_weight_uom;
var items = frm.doc.items || [];
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++) {
var item = ps_detail[i];
if(item.weight_uom != doc.net_weight_uom) {
items.forEach(item => {
if(item.weight_uom != frm.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.validated = false;
}
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)) {
doc.gross_weight_pkg = doc.net_weight_pkg;
if(!flt(frm.doc.gross_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']);
Expand Down

0 comments on commit c7628c9

Please sign in to comment.