[fix] connect customer to Quotation, Opportunity if created from lead, fixes #6051
This commit is contained in:
parent
cf7a36ac26
commit
e35dbca01b
@ -328,3 +328,4 @@ erpnext.patches.v7_0.update_conversion_factor_in_supplier_quotation_item
|
||||
erpnext.patches.v7_1.move_sales_invoice_from_parent_to_child_timesheet
|
||||
execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null")
|
||||
erpnext.patches.v7_1.update_lead_source
|
||||
erpnext.patches.v7_1.fix_link_for_customer_from_lead
|
6
erpnext/patches/v7_1/fix_link_for_customer_from_lead.py
Normal file
6
erpnext/patches/v7_1/fix_link_for_customer_from_lead.py
Normal file
@ -0,0 +1,6 @@
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
for c in frappe.db.sql('select name from tabCustomer where ifnull(lead_name,"")!=""'):
|
||||
customer = frappe.get_doc('Customer', c[0])
|
||||
customer.update_lead_status()
|
@ -40,14 +40,24 @@ class Customer(TransactionBase):
|
||||
|
||||
return self.customer_name
|
||||
|
||||
def after_insert(self):
|
||||
'''If customer created from Lead, update customer id in quotations, opportunities'''
|
||||
self.update_lead_status()
|
||||
|
||||
def validate(self):
|
||||
self.flags.is_new_doc = self.is_new()
|
||||
validate_party_accounts(self)
|
||||
self.status = get_party_status(self)
|
||||
|
||||
def update_lead_status(self):
|
||||
'''If Customer created from Lead, update lead status to "Converted"
|
||||
update Customer link in Quotation, Opportunity'''
|
||||
if self.lead_name:
|
||||
frappe.db.sql("update `tabLead` set status='Converted' where name = %s", self.lead_name)
|
||||
frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False)
|
||||
|
||||
for doctype in ('Opportunity', 'Quotation'):
|
||||
for d in frappe.get_all(doctype, {'lead': self.lead_name}):
|
||||
frappe.db.set_value(doctype, d.name, 'customer', self.name, update_modified=False)
|
||||
|
||||
def update_address(self):
|
||||
frappe.db.sql("""update `tabAddress` set customer_name=%s, modified=NOW()
|
||||
@ -81,7 +91,6 @@ class Customer(TransactionBase):
|
||||
def on_update(self):
|
||||
self.validate_name_with_customer_group()
|
||||
|
||||
self.update_lead_status()
|
||||
self.update_address()
|
||||
self.update_contact()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user