From a119688e32f0a56ae546d75cdd047b2190308fa7 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 24 Sep 2020 15:22:46 +0530 Subject: [PATCH 1/3] fix: (RFQ/SQ) Link to Material Requests in Tools section --- .../request_for_quotation.js | 5 + .../request_for_quotation.json | 9 +- .../supplier_quotation/supplier_quotation.js | 6 + .../supplier_quotation.json | 10 +- erpnext/public/js/controllers/buying.js | 125 +++++++++--------- 5 files changed, 76 insertions(+), 79 deletions(-) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 4a937f7f0d..660af96505 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -326,6 +326,11 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e d.show(); }, __("Get items from")); + //Link Material Requests + this.frm.add_custom_button(__('Link to Material Requests'), + function() { + erpnext.buying.link_to_mrs(me.frm); + }, __("Tools")); } }, diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json index 5cd8e6f4fa..6994ef72f0 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json @@ -17,7 +17,6 @@ "get_suppliers_button", "items_section", "items", - "link_to_mrs", "supplier_response_section", "email_template", "message_for_supplier", @@ -119,12 +118,6 @@ "options": "Request for Quotation Item", "reqd": 1 }, - { - "depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)", - "fieldname": "link_to_mrs", - "fieldtype": "Button", - "label": "Link to Material Requests" - }, { "fieldname": "supplier_response_section", "fieldtype": "Section Break" @@ -235,7 +228,7 @@ "icon": "fa fa-shopping-cart", "is_submittable": 1, "links": [], - "modified": "2020-06-25 14:37:21.140194", + "modified": "2020-09-24 13:53:56.066616", "modified_by": "Administrator", "module": "Buying", "name": "Request for Quotation", diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index 1b8b40459f..c146f13dfe 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -54,6 +54,12 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext } }) }, __("Get items from")); + + //Link Material Requests + this.frm.add_custom_button(__('Link to Material Requests'), + function() { + erpnext.buying.link_to_mrs(me.frm); + }, __("Tools")); } }, diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json index 660dcff34b..0ffaa44a0d 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json @@ -34,7 +34,6 @@ "ignore_pricing_rule", "items_section", "items", - "link_to_mrs", "pricing_rule_details", "pricing_rules", "section_break_22", @@ -320,12 +319,6 @@ "options": "Supplier Quotation Item", "reqd": 1 }, - { - "depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)", - "fieldname": "link_to_mrs", - "fieldtype": "Button", - "label": "Link to material requests" - }, { "fieldname": "pricing_rule_details", "fieldtype": "Section Break", @@ -803,9 +796,10 @@ ], "icon": "fa fa-shopping-cart", "idx": 29, + "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-07-18 05:10:45.556792", + "modified": "2020-09-24 15:18:29.073368", "modified_by": "Administrator", "module": "Buying", "name": "Supplier Quotation", diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index cb76c87b62..fb904e7d66 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -294,69 +294,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ this.get_terms(); }, - link_to_mrs: function() { - var my_items = []; - for (var i in cur_frm.doc.items) { - if(!cur_frm.doc.items[i].material_request){ - my_items.push(cur_frm.doc.items[i].item_code); - } - } - frappe.call({ - method: "erpnext.buying.utils.get_linked_material_requests", - args:{ - items: my_items - }, - callback: function(r) { - if(!r.message || r.message.length == 0) { - frappe.throw(__("No pending Material Requests found to link for the given items.")) - } - else { - var i = 0; - var item_length = cur_frm.doc.items.length; - while (i < item_length) { - var qty = cur_frm.doc.items[i].qty; - (r.message[0] || []).forEach(function(d) { - if (d.qty > 0 && qty > 0 && cur_frm.doc.items[i].item_code == d.item_code && !cur_frm.doc.items[i].material_request_item) - { - cur_frm.doc.items[i].material_request = d.mr_name; - cur_frm.doc.items[i].material_request_item = d.mr_item; - var my_qty = Math.min(qty, d.qty); - qty = qty - my_qty; - d.qty = d.qty - my_qty; - cur_frm.doc.items[i].stock_qty = my_qty*cur_frm.doc.items[i].conversion_factor; - cur_frm.doc.items[i].qty = my_qty; - - frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + cur_frm.doc.items[i].idx + ")"); - if (qty > 0) - { - frappe.msgprint("Splitting " + qty + " units of " + d.item_code); - var newrow = frappe.model.add_child(cur_frm.doc, cur_frm.doc.items[i].doctype, "items"); - item_length++; - - for (var key in cur_frm.doc.items[i]) - { - newrow[key] = cur_frm.doc.items[i][key]; - } - - newrow.idx = item_length; - newrow["stock_qty"] = newrow.conversion_factor*qty; - newrow["qty"] = qty; - - newrow["material_request"] = ""; - newrow["material_request_item"] = ""; - - } - } - }); - i++; - } - refresh_field("items"); - //cur_frm.save(); - } - } - }); - }, - update_auto_repeat_reference: function(doc) { if (doc.auto_repeat) { frappe.call({ @@ -422,6 +359,68 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ cur_frm.add_fetch('project', 'cost_center', 'cost_center'); +erpnext.buying.link_to_mrs = function(frm) { + var my_items = []; + for (var i in frm.doc.items) { + if(!frm.doc.items[i].material_request){ + my_items.push(frm.doc.items[i].item_code); + } + } + frappe.call({ + method: "erpnext.buying.utils.get_linked_material_requests", + args:{ + items: my_items + }, + callback: function(r) { + if(!r.message || r.message.length == 0) { + frappe.throw(__("No pending Material Requests found to link for the given items.")) + } + else { + var i = 0; + var item_length = frm.doc.items.length; + while (i < item_length) { + var qty = frm.doc.items[i].qty; + (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) + { + frm.doc.items[i].material_request = d.mr_name; + frm.doc.items[i].material_request_item = d.mr_item; + var my_qty = Math.min(qty, d.qty); + qty = qty - my_qty; + d.qty = d.qty - my_qty; + frm.doc.items[i].stock_qty = my_qty*frm.doc.items[i].conversion_factor; + frm.doc.items[i].qty = my_qty; + + frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + frm.doc.items[i].idx + ")"); + if (qty > 0) + { + frappe.msgprint("Splitting " + qty + " units of " + d.item_code); + var newrow = frappe.model.add_child(frm.doc, frm.doc.items[i].doctype, "items"); + item_length++; + + for (var key in frm.doc.items[i]) + { + newrow[key] = frm.doc.items[i][key]; + } + + newrow.idx = item_length; + newrow["stock_qty"] = newrow.conversion_factor*qty; + newrow["qty"] = qty; + + newrow["material_request"] = ""; + newrow["material_request_item"] = ""; + + } + } + }); + i++; + } + refresh_field("items"); + } + } + }); +} + erpnext.buying.get_default_bom = function(frm) { $.each(frm.doc["items"] || [], function(i, d) { if (d.item_code && d.bom === "") { From be4dbad823ecba34fbedccca84f351fb08ccf2fa Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 24 Sep 2020 16:43:25 +0530 Subject: [PATCH 2/3] style: (minor) Reduce loc --- erpnext/public/js/controllers/buying.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index fb904e7d66..62da7f5c5b 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -360,20 +360,14 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ cur_frm.add_fetch('project', 'cost_center', 'cost_center'); erpnext.buying.link_to_mrs = function(frm) { - var my_items = []; - for (var i in frm.doc.items) { - if(!frm.doc.items[i].material_request){ - my_items.push(frm.doc.items[i].item_code); - } - } frappe.call({ method: "erpnext.buying.utils.get_linked_material_requests", args:{ - items: my_items + items: frm.doc.items.map((item) => {return item.item_code;}) }, callback: function(r) { if(!r.message || r.message.length == 0) { - frappe.throw(__("No pending Material Requests found to link for the given items.")) + frappe.throw({message: __("No pending Material Requests found to link for the given items."), title: __("Note")}); } else { var i = 0; From 359778e2357997aaeac126c37bdcb34e8efa7ed3 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 16 Oct 2020 16:47:23 +0530 Subject: [PATCH 3/3] chore: Code cleanup, reduce redundancy --- .../request_for_quotation.js | 2 +- .../supplier_quotation/supplier_quotation.js | 2 +- erpnext/public/js/controllers/buying.js | 78 +++++++++---------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 660af96505..1ebd21a17b 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -326,7 +326,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e d.show(); }, __("Get items from")); - //Link Material Requests + // Link Material Requests this.frm.add_custom_button(__('Link to Material Requests'), function() { erpnext.buying.link_to_mrs(me.frm); diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index c146f13dfe..934d71c3b3 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -55,7 +55,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext }) }, __("Get items from")); - //Link Material Requests + // Link Material Requests this.frm.add_custom_button(__('Link to Material Requests'), function() { erpnext.buying.link_to_mrs(me.frm); diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 62da7f5c5b..8cae7a5b3d 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -363,54 +363,54 @@ erpnext.buying.link_to_mrs = function(frm) { frappe.call({ method: "erpnext.buying.utils.get_linked_material_requests", args:{ - items: frm.doc.items.map((item) => {return item.item_code;}) + items: frm.doc.items.map((item) => item.item_code) }, callback: function(r) { - if(!r.message || r.message.length == 0) { - frappe.throw({message: __("No pending Material Requests found to link for the given items."), title: __("Note")}); + if (!r.message || r.message.length == 0) { + 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; - while (i < item_length) { - var qty = frm.doc.items[i].qty; - (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) + + var item_length = frm.doc.items.length; + for (let item of frm.doc.items) { + var qty = item.qty; + (r.message[0] || []).forEach(function(d) { + if (d.qty > 0 && qty > 0 && item.item_code == d.item_code && !item.material_request_item) + { + item.material_request = d.mr_name; + item.material_request_item = d.mr_item; + var my_qty = Math.min(qty, d.qty); + qty = qty - my_qty; + d.qty = d.qty - my_qty; + item.stock_qty = my_qty*item.conversion_factor; + item.qty = my_qty; + + frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + item.idx + ")"); + if (qty > 0) { - frm.doc.items[i].material_request = d.mr_name; - frm.doc.items[i].material_request_item = d.mr_item; - var my_qty = Math.min(qty, d.qty); - qty = qty - my_qty; - d.qty = d.qty - my_qty; - frm.doc.items[i].stock_qty = my_qty*frm.doc.items[i].conversion_factor; - frm.doc.items[i].qty = my_qty; + frappe.msgprint("Splitting " + qty + " units of " + d.item_code); + var newrow = frappe.model.add_child(frm.doc, item.doctype, "items"); + item_length++; - frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + frm.doc.items[i].idx + ")"); - if (qty > 0) + for (var key in item) { - frappe.msgprint("Splitting " + qty + " units of " + d.item_code); - var newrow = frappe.model.add_child(frm.doc, frm.doc.items[i].doctype, "items"); - item_length++; - - for (var key in frm.doc.items[i]) - { - newrow[key] = frm.doc.items[i][key]; - } - - newrow.idx = item_length; - newrow["stock_qty"] = newrow.conversion_factor*qty; - newrow["qty"] = qty; - - newrow["material_request"] = ""; - newrow["material_request_item"] = ""; - + newrow[key] = item[key]; } + + newrow.idx = item_length; + newrow["stock_qty"] = newrow.conversion_factor*qty; + newrow["qty"] = qty; + + newrow["material_request"] = ""; + newrow["material_request_item"] = ""; + } - }); - i++; - } - refresh_field("items"); + } + }); } + refresh_field("items"); } }); }