From 90cf2ddc01ad3b3b825b3f78b3a1925de8285714 Mon Sep 17 00:00:00 2001 From: Saif Date: Sun, 30 Sep 2018 21:46:31 +0500 Subject: [PATCH] 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 --- .../accounts/doctype/pricing_rule/pricing_rule.js | 12 ++++++++++++ .../accounts/doctype/pricing_rule/pricing_rule.py | 10 ++++++++++ erpnext/buying/doctype/supplier/supplier.js | 4 ++++ .../buying/doctype/supplier/supplier_dashboard.py | 4 ++++ erpnext/public/js/utils.js | 14 ++++++++++++++ erpnext/selling/doctype/customer/customer.js | 4 ++++ .../selling/doctype/customer/customer_dashboard.py | 4 ++++ 7 files changed, 52 insertions(+) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js index 86694e6bab..c33ab62140 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js @@ -116,6 +116,18 @@ frappe.ui.form.on('Pricing Rule', { }; }, + 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 = ` diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index a44ac00f5b..42f371bddd 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -384,3 +384,13 @@ def set_transaction_type(args): 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 f0236e0be9..be58df25ca 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -49,6 +49,10 @@ frappe.ui.form.on("Supplier", { 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 4f01f58691..f971776948 100644 --- a/erpnext/buying/doctype/supplier/supplier_dashboard.py +++ b/erpnext/buying/doctype/supplier/supplier_dashboard.py @@ -13,6 +13,10 @@ def get_data(): { '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 8246790abc..baee68e6be 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -173,6 +173,20 @@ $.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 diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index fe3bedfe38..d687c85e3a 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -106,6 +106,10 @@ frappe.ui.form.on("Customer", { 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 681b04a247..9b905f8512 100644 --- a/erpnext/selling/doctype/customer/customer_dashboard.py +++ b/erpnext/selling/doctype/customer/customer_dashboard.py @@ -21,6 +21,10 @@ def get_data(): { 'label': _('Projects'), 'items': ['Project'] + }, + { + 'label': _('Pricing'), + 'items': ['Pricing Rule'] } ] } \ No newline at end of file