fix(crm): ensure primary address and contact follows customer setting (#37710)

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
(cherry picked from commit a74e1f1600)

# Conflicts:
#	erpnext/selling/doctype/customer/customer.py
This commit is contained in:
David Arnold
2023-11-11 15:50:21 +01:00
committed by Mergify
parent b8a773e3e1
commit 2912e22c37
2 changed files with 18 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ from frappe.contacts.address_and_contact import (
delete_contact_and_address,
load_address_and_contact,
)
from frappe.contacts.doctype.address.address import get_default_address
from frappe.contacts.doctype.contact.contact import get_default_contact
from frappe.email.inbox import link_communication_to_document
from frappe.model.mapper import get_mapped_doc
from frappe.utils import comma_and, get_link_to_form, has_gravatar, validate_email_address
@@ -325,6 +327,13 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False):
target.customer_group = frappe.db.get_default("Customer Group")
address = get_default_address("Lead", source.name)
contact = get_default_contact("Lead", source.name)
if address:
target.customer_primary_address = address
if contact:
target.customer_primary_contact = contact
doclist = get_mapped_doc(
"Lead",
source_name,

View File

@@ -253,6 +253,8 @@ class Customer(TransactionBase):
self.db_set("customer_primary_contact", contact.name)
self.db_set("mobile_no", self.mobile_no)
self.db_set("email_id", self.email_id)
elif self.customer_primary_contact:
frappe.set_value("Contact", self.customer_primary_contact, "is_primary_contact", 1) # ensure
def create_primary_address(self):
from frappe.contacts.doctype.address.address import get_address_display
@@ -263,6 +265,8 @@ class Customer(TransactionBase):
self.db_set("customer_primary_address", address.name)
self.db_set("primary_address", address_display)
elif self.customer_primary_address:
frappe.set_value("Address", self.customer_primary_address, "is_primary_address", 1) # ensure
def update_lead_status(self):
"""If Customer created from Lead, update lead status to "Converted"
@@ -386,9 +390,14 @@ def create_contact(contact, party_type, party, email):
doc = frappe.get_doc(
{
"doctype": "Contact",
<<<<<<< HEAD
"first_name": first,
"middle_name": middle,
"last_name": last,
=======
"first_name": contact[0],
"last_name": len(contact) > 1 and contact[1] or "",
>>>>>>> a74e1f1600 (fix(crm): ensure primary address and contact follows customer setting (#37710))
"is_primary_contact": 1,
}
)