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: