Skip to content

Commit

Permalink
Make pricing rule from Supplier and Customer Doc (#15533)
Browse files Browse the repository at this point in the history
* Make pricing rule from Supplier and Customer Doc

* Make sure the "+" button also works the same way as the "Make" button
  • Loading branch information
SaiFi0102 authored and rmehta committed Sep 30, 2018
1 parent 6ecb255 commit 90cf2dd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/pricing_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
Expand Down
10 changes: 10 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions erpnext/buying/doctype/supplier/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions erpnext/buying/doctype/supplier/supplier_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def get_data():
{
'label': _('Orders'),
'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
},
{
'label': _('Pricing'),
'items': ['Pricing Rule']
}
]
}
14 changes: 14 additions & 0 deletions erpnext/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions erpnext/selling/doctype/customer/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions erpnext/selling/doctype/customer/customer_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def get_data():
{
'label': _('Projects'),
'items': ['Project']
},
{
'label': _('Pricing'),
'items': ['Pricing Rule']
}
]
}

0 comments on commit 90cf2dd

Please sign in to comment.