Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions erpnext/crm/doctype/lead/lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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
Expand Down Expand Up @@ -251,6 +253,13 @@ def set_missing_values(source, target):

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,
Expand Down
5 changes: 5 additions & 0 deletions erpnext/selling/doctype/customer/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def create_primary_contact(self):
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
Expand All @@ -196,6 +198,8 @@ def create_primary_address(self):

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"
Expand Down Expand Up @@ -312,6 +316,7 @@ def create_contact(contact, party_type, party, email):
"doctype": "Contact",
"first_name": contact[0],
"last_name": len(contact) > 1 and contact[1] or "",
"is_primary_contact": 1,
}
)
contact.append("email_ids", dict(email_id=email, is_primary=1))
Expand Down
Loading