From ad8e189c2630244f5423d1f26bf442b5e636d9c2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 19 Apr 2024 15:34:26 +0530 Subject: [PATCH] fix: not able to update default supplier from Supplier Quotation Comparison report --- .../supplier_quotation_comparison.js | 31 ++++++++++++++++--- .../supplier_quotation_comparison.py | 10 ++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js index f7d0d947b619..9701e147f057 100644 --- a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js +++ b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.js @@ -133,6 +133,13 @@ frappe.query_reports["Supplier Quotation Comparison"] = { return row.supplier_name; }); + let items = []; + report.data.forEach((d) => { + if (!items.includes(d.item_code)) { + items.push(d.item_code); + } + }); + // Create a dialog window for the user to pick their supplier let dialog = new frappe.ui.Dialog({ title: __("Select Default Supplier"), @@ -151,20 +158,34 @@ frappe.query_reports["Supplier Quotation Comparison"] = { }; }, }, + { + reqd: 1, + label: "Item", + fieldtype: "Link", + options: "Item", + fieldname: "item_code", + get_query: () => { + return { + filters: { + name: ["in", items], + }, + }; + }, + }, ], }); dialog.set_primary_action(__("Set Default Supplier"), () => { let values = dialog.get_values(); + if (values) { // Set the default_supplier field of the appropriate Item to the selected supplier frappe.call({ - method: "frappe.client.set_value", + method: "erpnext.buying.report.supplier_quotation_comparison.supplier_quotation_comparison.set_default_supplier", args: { - doctype: "Item", - name: item_code, - fieldname: "default_supplier", - value: values.supplier, + item_code: values.item_code, + supplier: values.supplier, + company: filters.company, }, freeze: true, callback: (r) => { diff --git a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.py b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.py index 684cd3a0f9ee..085f30f84d9f 100644 --- a/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.py +++ b/erpnext/buying/report/supplier_quotation_comparison/supplier_quotation_comparison.py @@ -292,3 +292,13 @@ def get_message(): Expires today / Already Expired """ + + +@frappe.whitelist() +def set_default_supplier(item_code, supplier, company): + frappe.db.set_value( + "Item Default", + {"parent": item_code, "company": company}, + "default_supplier", + supplier, + )