From 831dfc8f6d0b88a2be2df57ae195ebe990568015 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Fri, 22 Aug 2025 19:39:52 +0200 Subject: [PATCH 1/2] perf: create Pricing Rule from Customer and Supplier --- erpnext/buying/doctype/supplier/supplier.js | 11 +++++++++-- erpnext/selling/doctype/customer/customer.js | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index f26292789cc..6649dec36c8 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -67,7 +67,7 @@ frappe.ui.form.on("Supplier", { frm.make_methods = { "Bank Account": () => erpnext.utils.make_bank_account(frm.doc.doctype, frm.doc.name), - "Pricing Rule": () => erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name), + "Pricing Rule": () => frm.trigger("make_pricing_rule"), }; }, @@ -120,7 +120,7 @@ frappe.ui.form.on("Supplier", { frm.add_custom_button( __("Pricing Rule"), function () { - erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); + frm.trigger("make_pricing_rule"); }, __("Create") ); @@ -230,4 +230,11 @@ frappe.ui.form.on("Supplier", { }); dialog.show(); }, + make_pricing_rule: function (frm) { + frappe.new_doc("Pricing Rule", { + applicable_for: "Supplier", + supplier: frm.doc.name, + buying: 1, + }); + }, }); diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index d314c878cc2..b04eb8eb60d 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -32,7 +32,7 @@ frappe.ui.form.on("Customer", { method: "erpnext.selling.doctype.customer.customer.make_payment_entry", frm: frm, }), - "Pricing Rule": () => erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name), + "Pricing Rule": () => frm.trigger("make_pricing_rule"), "Bank Account": () => erpnext.utils.make_bank_account(frm.doc.doctype, frm.doc.name), }; @@ -264,4 +264,11 @@ frappe.ui.form.on("Customer", { }); dialog.show(); }, + make_pricing_rule: function (frm) { + frappe.new_doc("Pricing Rule", { + applicable_for: "Customer", + customer: frm.doc.name, + selling: 1, + }); + }, }); From 7bc508004be0fb8e3ac82b608704e2e444d5949b Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Fri, 22 Aug 2025 19:40:31 +0200 Subject: [PATCH 2/2] chore!: remove unused utils --- .../accounts/doctype/pricing_rule/pricing_rule.py | 11 ----------- erpnext/public/js/utils.js | 14 -------------- 2 files changed, 25 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 398149968b9..5ccb614f1b5 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -702,17 +702,6 @@ def set_transaction_type(args): args.transaction_type = "buying" -@frappe.whitelist() -def make_pricing_rule(doctype, docname): - doc = frappe.new_doc("Pricing Rule") - doc.applicable_for = doctype - doc.set(frappe.scrub(doctype), docname) - doc.selling = 1 if doctype == "Customer" else 0 - doc.buying = 1 if doctype == "Supplier" else 0 - - return doc - - @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def get_item_uoms(doctype, txt, searchfield, start, page_len, filters): diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index eb02cbce4c7..e27eac9ee6b 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -293,20 +293,6 @@ $.extend(erpnext.utils, { }); }, - make_pricing_rule: function (doctype, docname) { - frappe.call({ - method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.make_pricing_rule", - args: { - doctype: doctype, - docname: docname, - }, - callback: function (r) { - var doclist = frappe.model.sync(r.message); - frappe.set_route("Form", doclist[0].doctype, doclist[0].name); - }, - }); - }, - /** * Checks if the first row of a given child table is empty * @param child_table - Child table Doctype