fix: Fixes related to customer/lead merging (#18075)

This commit is contained in:
Nabin Hait
2019-06-28 12:36:27 +05:30
committed by GitHub
parent 42e62bd1b4
commit b059c6f630
7 changed files with 26 additions and 12 deletions

View File

@@ -55,14 +55,28 @@ class SellingController(StockController):
self.set_price_list_and_item_details(for_validate=for_validate)
def set_missing_lead_customer_details(self):
customer, lead = None, None
if getattr(self, "customer", None):
customer = self.customer
elif self.doctype == "Opportunity" and self.party_name:
if self.opportunity_from == "Customer":
customer = self.party_name
else:
lead = self.party_name
elif self.doctype == "Quotation" and self.party_name:
if self.quotation_to == "Customer":
customer = self.party_name
else:
lead = self.party_name
if customer:
from erpnext.accounts.party import _get_party_details
fetch_payment_terms_template = False
if (self.get("__islocal") or
self.company != frappe.db.get_value(self.doctype, self.name, 'company')):
fetch_payment_terms_template = True
party_details = _get_party_details(self.customer,
party_details = _get_party_details(customer,
ignore_permissions=self.flags.ignore_permissions,
doctype=self.doctype, company=self.company,
fetch_payment_terms_template=fetch_payment_terms_template,
@@ -71,10 +85,9 @@ class SellingController(StockController):
party_details.pop("sales_team")
self.update_if_missing(party_details)
elif getattr(self, "lead", None):
elif lead:
from erpnext.crm.doctype.lead.lead import get_lead_details
self.update_if_missing(get_lead_details(
self.lead,
self.update_if_missing(get_lead_details(lead,
posting_date=self.get('transaction_date') or self.get('posting_date'),
company=self.company))

View File

@@ -43,7 +43,7 @@ class TestMapper(unittest.TestCase):
qtn = frappe.get_doc({
"doctype": "Quotation",
"quotation_to": "Customer",
"customer": customer,
"party_name": customer,
"order_type": "Sales",
"transaction_date" : nowdate(),
"valid_till" : add_months(nowdate(), 1)

View File

@@ -320,11 +320,11 @@ def make_opportunity_from_communication(communication, ignore_communication_link
if not lead:
lead = make_lead_from_communication(communication, ignore_communication_links=True)
enquiry_from = "Lead"
opportunity_from = "Lead"
opportunity = frappe.get_doc({
"doctype": "Opportunity",
"enquiry_from": enquiry_from,
"opportunity_from": opportunity_from,
"lead": lead
}).insert(ignore_permissions=True)

View File

@@ -99,7 +99,7 @@ def make_quotation(domain):
"creation": frappe.flags.current_date,
"doctype": "Quotation",
"quotation_to": "Customer",
"customer": customer,
"party_name": customer,
"currency": party_account_currency or company_currency,
"conversion_rate": exchange_rate,
"order_type": "Sales",

View File

@@ -1,6 +1,7 @@
import frappe
def execute():
frappe.reload_doctype("Quotation")
# update customer_name from Customer document if quotation_to is set to Customer
frappe.db.sql('''
update tabQuotation, tabCustomer

View File

@@ -34,7 +34,7 @@ def make_opportunity(items, customer):
b = frappe.get_doc({
"doctype": "Opportunity",
"opportunity_from": "Customer",
"customer": customer,
"party_name": customer,
"opportunity_type": _("Sales"),
"with_items": 1
})

View File

@@ -36,11 +36,11 @@ def send_message(subject="Website Query", message="", sender="", status="Open"):
))
if customer:
opportunity.customer = customer[0][0]
opportunity.party_name = customer[0][0]
elif lead:
opportunity.lead = lead
opportunity.party_name = lead
else:
opportunity.lead = new_lead.name
opportunity.party_name = new_lead.name
opportunity.insert(ignore_permissions=True)