fix: not able to update default supplier from Supplier Quotation Comparison report
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 f7d0d94..9701e14 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 @@
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 @@
};
},
},
+ {
+ 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 684cd3a..085f30f 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 @@
<span class="indicator red">
Expires today / Already Expired
</span>"""
+
+
+@frappe.whitelist()
+def set_default_supplier(item_code, supplier, company):
+ frappe.db.set_value(
+ "Item Default",
+ {"parent": item_code, "company": company},
+ "default_supplier",
+ supplier,
+ )