From ea7565889fb9a833b3bcd9f36abca020285e17cc Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 13 Nov 2023 09:49:22 +0100 Subject: [PATCH] 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> --- erpnext/selling/doctype/customer/customer.js | 41 +++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 42932ad8bd..ddc7e2af8f 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -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({ - method: "erpnext.selling.doctype.customer.customer.make_quotation", - frm: cur_frm - }), - 'Opportunity': () => frappe.model.open_mapped_doc({ - method: "erpnext.selling.doctype.customer.customer.make_opportunity", - frm: cur_frm - }) - } + "Quotation": () => + frappe.model.open_mapped_doc({ + method: "erpnext.selling.doctype.customer.customer.make_quotation", + frm: frm, + }), + "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: 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");