fix(Utils): Do not add duplicate item to items (#17895)

* fix: do not add duplicate item to items

* fix: compare warehouses, batch and qty for an item

* fix: code fixes

* Update utils.js

* fix: check required_date and delivery_date

* Update utils.js

* Update utils.js

* Update utils.js

* fix: mixed spaces and tabs
This commit is contained in:
Himanshu
2019-06-28 14:12:40 +05:30
committed by Nabin Hait
parent fdd1422d31
commit 5b5156356a

View File

@@ -587,6 +587,7 @@ erpnext.utils.map_current_doc = function(opts) {
if(!r.exc) {
var doc = frappe.model.sync(r.message);
cur_frm.dirty();
erpnext.utils.clear_duplicates();
cur_frm.refresh();
}
}
@@ -617,6 +618,27 @@ erpnext.utils.map_current_doc = function(opts) {
}
}
erpnext.utils.clear_duplicates = function() {
const unique_items = new Map();
/*
Create a Map of items with
item_code => [qty, warehouse, batch_no]
*/
let items = [];
for (let item of cur_frm.doc.items) {
if (!(unique_items.has(item.item_code) && unique_items.get(item.item_code)[0] === item.qty &&
unique_items.get(item.item_code)[1] === item.warehouse && unique_items.get(item.item_code)[2] === item.batch_no &&
unique_items.get(item.item_code)[3] === item.delivery_date && unique_items.get(item.item_code)[4] === item.required_date &&
unique_items.get(item.item_code)[5] === item.rate)) {
unique_items.set(item.item_code, [item.qty, item.warehouse, item.batch_no, item.delivery_date, item.required_date, item.rate]);
items.push(item);
}
}
cur_frm.doc.items = items;
}
frappe.form.link_formatters['Item'] = function(value, doc) {
if(doc && doc.item_name && doc.item_name !== value) {
return value? value + ': ' + doc.item_name: doc.item_name;