From 1417c7e828b91e142220f2f6a8fd6f43552c27f0 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 2 May 2019 14:12:10 +0530 Subject: [PATCH 1/3] fix: data pulling based on quotation_to and party_name --- erpnext/public/js/utils/party.js | 5 ++++- erpnext/selling/doctype/quotation/quotation.js | 14 ++++++++++++-- erpnext/selling/doctype/quotation/quotation.json | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js index eab04006c21..5869c4da4c2 100644 --- a/erpnext/public/js/utils/party.js +++ b/erpnext/public/js/utils/party.js @@ -103,7 +103,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field, erpnext.utils.set_taxes = function(frm, address_field, display_field, is_your_company_address) { if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) { if(!erpnext.utils.validate_mandatory(frm, "Lead/Customer/Supplier", - frm.doc.customer || frm.doc.supplier || frm.doc.lead, address_field)) { + frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name , address_field)) { return; } @@ -125,6 +125,9 @@ erpnext.utils.set_taxes = function(frm, address_field, display_field, is_your_co } else if (frm.doc.supplier) { party_type = 'Supplier'; party = frm.doc.supplier; + } else if (frm.doc.quotation_to){ + party_type = frm.doc.quotation_to; + party = frm.doc.party_name; } frappe.call({ diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 3116e65b686..397c853097b 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -127,14 +127,24 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ // to overwrite the customer_filter trigger from queries.js this.frm.toggle_reqd("party_name", this.frm.doc.quotation_to); - this.frm.set_query('customer_address', erpnext.queries.address_query); - this.frm.set_query('shipping_address_name', erpnext.queries.address_query); + this.frm.set_query('customer_address', this.address_query); + this.frm.set_query('shipping_address_name', this.address_query); }, tc_name: function() { this.get_terms(); }, + address_query: function(doc) { + return { + query: 'frappe.contacts.doctype.address.address.address_query', + filters: { + link_doctype: frappe.dynamic_link.doctype, + link_name: doc.party_name + } + }; + }, + validate_company_and_party: function(party_field) { if(!this.frm.doc.quotation_to) { frappe.msgprint(__("Please select a value for {0} quotation_to {1}", [this.frm.doc.doctype, this.frm.doc.name])); diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index 4b247075451..bbb84e2e33e 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -441,7 +441,7 @@ "collapsible": 1, "collapsible_depends_on": "", "columns": 0, - "depends_on": "eval:(doc.customer || doc.lead)", + "depends_on": "eval:doc.party_name", "fetch_if_empty": 0, "fieldname": "contact_section", "fieldtype": "Section Break", @@ -542,7 +542,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:doc.customer", + "depends_on": "eval:doc.quotaion_to=='Customer' && doc.party_name", "fetch_if_empty": 0, "fieldname": "contact_person", "fieldtype": "Link", @@ -3224,7 +3224,7 @@ "istable": 0, "max_attachments": 1, "menu_index": 0, - "modified": "2019-04-25 15:26:21.983298", + "modified": "2019-05-02 14:10:43.355616", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", From 625191d20a2c02eb564f1ffdfb324b9465654c26 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 2 May 2019 15:50:01 +0530 Subject: [PATCH 2/3] fix: provision to setup customer name on quotation save and patch for the same --- erpnext/patches.txt | 1 + .../v11_1/set_missing_title_for_quotation.py | 27 +++++++++++++++++++ .../selling/doctype/quotation/quotation.json | 4 +-- .../selling/doctype/quotation/quotation.py | 8 ++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v11_1/set_missing_title_for_quotation.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d7d22722e26..3ddc069331b 100755 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -595,3 +595,4 @@ erpnext.patches.v11_1.woocommerce_set_creation_user erpnext.patches.v11_1.delete_bom_browser erpnext.patches.v11_1.set_salary_details_submittable erpnext.patches.v11_1.rename_depends_on_lwp +erpnext.patches.v11_1.set_missing_title_for_quotation \ No newline at end of file diff --git a/erpnext/patches/v11_1/set_missing_title_for_quotation.py b/erpnext/patches/v11_1/set_missing_title_for_quotation.py new file mode 100644 index 00000000000..659edabc365 --- /dev/null +++ b/erpnext/patches/v11_1/set_missing_title_for_quotation.py @@ -0,0 +1,27 @@ +import frappe + +def execute(): + '''update customer_name from Customer document if quotation_to is set to Customer ''' + frappe.db.sql(''' + update tabQuotation, tabCustomer + set + tabQuotation.customer_name = tabCustomer.customer_name, + tabQuotation.title = tabCustomer.customer_name + where + tabQuotation.customer_name is null + and tabQuotation.party_name = tabCustomer.name + and tabQuotation.quotation_to = 'Customer' + ''') + + '''update customer_name from Lead document if quotation_to is set to Lead ''' + + frappe.db.sql(''' + update tabQuotation, tabLead + set + tabQuotation.customer_name = case when ifnull(tabLead.company_name, '') != '' then tabLead.company_name else tabLead.lead_name end, + tabQuotation.title = case when ifnull(tabLead.company_name, '') != '' then tabLead.company_name else tabLead.lead_name end + where + tabQuotation.customer_name is null + and tabQuotation.party_name = tabLead.name + and tabQuotation.quotation_to = 'Lead' + ''') diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index bbb84e2e33e..abafbbf6a16 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -195,7 +195,7 @@ "bold": 1, "collapsible": 0, "columns": 0, - "fetch_from": "customer.customer_name", + "fetch_from": "", "fetch_if_empty": 0, "fieldname": "customer_name", "fieldtype": "Data", @@ -3224,7 +3224,7 @@ "istable": 0, "max_attachments": 1, "menu_index": 0, - "modified": "2019-05-02 14:10:43.355616", + "modified": "2019-05-02 15:16:37.394455", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 42b68728ad2..3ba8adc3c8e 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -29,6 +29,7 @@ class Quotation(SellingController): self.validate_order_type() self.validate_uom_is_integer("stock_uom", "qty") self.validate_valid_till() + self.set_customer_name() if self.items: self.with_items = 1 @@ -46,6 +47,13 @@ class Quotation(SellingController): if self.quotation_to == "Lead" and self.party_name: frappe.get_doc("Lead", self.party_name).set_status(update=True) + def set_customer_name(self): + if self.party_name and self.quotation_to == 'Customer': + self.customer_name = frappe.db.get_value("Customer", self.party_name, "customer_name") + elif self.party_name and self.quotation_to == 'Lead': + lead_name, company_name = frappe.db.get_value("Lead", self.party_name, ["lead_name", "company_name"]) + self.customer_name = company_name or lead_name + def update_opportunity(self): for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])): if opportunity: From 75b63c5b4c8587d9832d5a5baf52b602b84236f5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 2 May 2019 16:00:49 +0530 Subject: [PATCH 3/3] Update set_missing_title_for_quotation.py --- erpnext/patches/v11_1/set_missing_title_for_quotation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v11_1/set_missing_title_for_quotation.py b/erpnext/patches/v11_1/set_missing_title_for_quotation.py index 659edabc365..e86b8320c31 100644 --- a/erpnext/patches/v11_1/set_missing_title_for_quotation.py +++ b/erpnext/patches/v11_1/set_missing_title_for_quotation.py @@ -1,7 +1,7 @@ import frappe def execute(): - '''update customer_name from Customer document if quotation_to is set to Customer ''' + # update customer_name from Customer document if quotation_to is set to Customer frappe.db.sql(''' update tabQuotation, tabCustomer set @@ -13,7 +13,7 @@ def execute(): and tabQuotation.quotation_to = 'Customer' ''') - '''update customer_name from Lead document if quotation_to is set to Lead ''' + # update customer_name from Lead document if quotation_to is set to Lead frappe.db.sql(''' update tabQuotation, tabLead