Make pricing rule from Supplier and Customer Doc (#15533)
* Make pricing rule from Supplier and Customer Doc
* Make sure the "+" button also works the same way as the "Make" button
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
index 86694e6..c33ab62 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
@@ -116,6 +116,18 @@
};
},
+ onload: function(frm) {
+ if(frm.doc.__islocal && !frm.doc.applicable_for && (frm.doc.customer || frm.doc.supplier)) {
+ if(frm.doc.customer) {
+ frm.doc.applicable_for = "Customer";
+ frm.doc.selling = 1
+ } else {
+ frm.doc.applicable_for = "Supplier";
+ frm.doc.buying = 1
+ }
+ }
+ },
+
refresh: function(frm) {
var help_content =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index a44ac00..42f371b 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -384,3 +384,13 @@
args.transaction_type = "selling"
else:
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
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index f0236e0..be58df2 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -49,6 +49,10 @@
erpnext.utils.make_bank_account(frm.doc.doctype, frm.doc.name);
}, __("Make"));
+ frm.add_custom_button(__('Pricing Rule'), function () {
+ erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name);
+ }, __("Make"));
+
// indicators
erpnext.utils.set_party_dashboard_indicators(frm);
}
diff --git a/erpnext/buying/doctype/supplier/supplier_dashboard.py b/erpnext/buying/doctype/supplier/supplier_dashboard.py
index 4f01f58..f971776 100644
--- a/erpnext/buying/doctype/supplier/supplier_dashboard.py
+++ b/erpnext/buying/doctype/supplier/supplier_dashboard.py
@@ -13,6 +13,10 @@
{
'label': _('Orders'),
'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
+ },
+ {
+ 'label': _('Pricing'),
+ 'items': ['Pricing Rule']
}
]
}
\ No newline at end of file
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 8246790..baee68e 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -173,6 +173,20 @@
})
},
+ 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
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index fe3bedf..d687c85 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -106,6 +106,10 @@
frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name});
});
+ frm.add_custom_button(__('Pricing Rule'), function () {
+ erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name);
+ }, __("Make"));
+
// indicator
erpnext.utils.set_party_dashboard_indicators(frm);
diff --git a/erpnext/selling/doctype/customer/customer_dashboard.py b/erpnext/selling/doctype/customer/customer_dashboard.py
index 681b04a..9b905f8 100644
--- a/erpnext/selling/doctype/customer/customer_dashboard.py
+++ b/erpnext/selling/doctype/customer/customer_dashboard.py
@@ -21,6 +21,10 @@
{
'label': _('Projects'),
'items': ['Project']
+ },
+ {
+ 'label': _('Pricing'),
+ 'items': ['Pricing Rule']
}
]
}
\ No newline at end of file