feat(customer): add button to quick-create sales order and quotation (#37320)

* feat(customer): add button to quick-create sales order and quotation

* fix: create buttons in customer

* refactor: don't repeat yourself

---------

Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
This commit is contained in:
David Arnold 2023-11-13 09:49:22 +01:00 committed by GitHub
parent 4a111f7362
commit ea7565889f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,17 +3,32 @@
frappe.ui.form.on("Customer", {
setup: function(frm) {
frm.custom_make_buttons = {
"Opportunity": "Opportunity",
"Quotation": "Quotation",
"Sales Order": "Sales Order",
"Pricing Rule": "Pricing Rule",
};
frm.make_methods = {
'Quotation': () => frappe.model.open_mapped_doc({
"Quotation": () =>
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.customer.customer.make_quotation",
frm: cur_frm
frm: frm,
}),
'Opportunity': () => frappe.model.open_mapped_doc({
"Sales Order": () =>
frappe.model.with_doctype("Sales Order", function () {
var so = frappe.model.get_new_doc("Sales Order");
so.customer = frm.doc.name; // Set the current customer as the SO customer
frappe.set_route("Form", "Sales Order", so.name);
}),
"Opportunity": () =>
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.customer.customer.make_opportunity",
frm: cur_frm
})
}
frm: frm,
}),
"Pricing Rule": () =>
erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name),
};
frm.add_fetch('lead_name', 'company_name', 'customer_name');
frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
@ -146,9 +161,9 @@ frappe.ui.form.on("Customer", {
{party_type: 'Customer', party: frm.doc.name, party_name: frm.doc.customer_name});
}, __('View'));
frm.add_custom_button(__('Pricing Rule'), function () {
erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name);
}, __('Create'));
for (const doctype in frm.make_methods) {
frm.add_custom_button(__(doctype), frm.make_methods[doctype], __("Create"));
}
frm.add_custom_button(__('Get Customer Group Details'), function () {
frm.trigger("get_customer_group_details");