chore: Code cleanup, reduce redundancy
This commit is contained in:
parent
be4dbad823
commit
359778e235
@ -363,38 +363,40 @@ erpnext.buying.link_to_mrs = function(frm) {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.buying.utils.get_linked_material_requests",
|
method: "erpnext.buying.utils.get_linked_material_requests",
|
||||||
args:{
|
args:{
|
||||||
items: frm.doc.items.map((item) => {return item.item_code;})
|
items: frm.doc.items.map((item) => item.item_code)
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.message || r.message.length == 0) {
|
if (!r.message || r.message.length == 0) {
|
||||||
frappe.throw({message: __("No pending Material Requests found to link for the given items."), title: __("Note")});
|
frappe.throw({
|
||||||
|
message: __("No pending Material Requests found to link for the given items."),
|
||||||
|
title: __("Note")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
var i = 0;
|
|
||||||
var item_length = frm.doc.items.length;
|
var item_length = frm.doc.items.length;
|
||||||
while (i < item_length) {
|
for (let item of frm.doc.items) {
|
||||||
var qty = frm.doc.items[i].qty;
|
var qty = item.qty;
|
||||||
(r.message[0] || []).forEach(function(d) {
|
(r.message[0] || []).forEach(function(d) {
|
||||||
if (d.qty > 0 && qty > 0 && frm.doc.items[i].item_code == d.item_code && !frm.doc.items[i].material_request_item)
|
if (d.qty > 0 && qty > 0 && item.item_code == d.item_code && !item.material_request_item)
|
||||||
{
|
{
|
||||||
frm.doc.items[i].material_request = d.mr_name;
|
item.material_request = d.mr_name;
|
||||||
frm.doc.items[i].material_request_item = d.mr_item;
|
item.material_request_item = d.mr_item;
|
||||||
var my_qty = Math.min(qty, d.qty);
|
var my_qty = Math.min(qty, d.qty);
|
||||||
qty = qty - my_qty;
|
qty = qty - my_qty;
|
||||||
d.qty = d.qty - my_qty;
|
d.qty = d.qty - my_qty;
|
||||||
frm.doc.items[i].stock_qty = my_qty*frm.doc.items[i].conversion_factor;
|
item.stock_qty = my_qty*item.conversion_factor;
|
||||||
frm.doc.items[i].qty = my_qty;
|
item.qty = my_qty;
|
||||||
|
|
||||||
frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + frm.doc.items[i].idx + ")");
|
frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")");
|
||||||
if (qty > 0)
|
if (qty > 0)
|
||||||
{
|
{
|
||||||
frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
|
frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
|
||||||
var newrow = frappe.model.add_child(frm.doc, frm.doc.items[i].doctype, "items");
|
var newrow = frappe.model.add_child(frm.doc, item.doctype, "items");
|
||||||
item_length++;
|
item_length++;
|
||||||
|
|
||||||
for (var key in frm.doc.items[i])
|
for (var key in item)
|
||||||
{
|
{
|
||||||
newrow[key] = frm.doc.items[i][key];
|
newrow[key] = item[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
newrow.idx = item_length;
|
newrow.idx = item_length;
|
||||||
@ -407,11 +409,9 @@ erpnext.buying.link_to_mrs = function(frm) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
refresh_field("items");
|
refresh_field("items");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user