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: Sync Contact & Deal primary contact's email/mobile_no #367

Merged
Merged
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
16 changes: 16 additions & 0 deletions crm/api/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def validate(doc, method):
set_primary_mobile_no(doc)
doc.set_primary_email()
doc.set_primary("mobile_no")
update_deals_email_mobile_no(doc)


def set_primary_email(doc):
Expand All @@ -25,6 +26,21 @@ def set_primary_mobile_no(doc):
doc.phone_nos[0].is_primary_mobile_no = 1


def update_deals_email_mobile_no(doc):
linked_deals = frappe.get_all(
"CRM Contacts",
filters={"contact": doc.name, "is_primary": 1},
fields=["parent"],
)

for linked_deal in linked_deals:
deal = frappe.get_cached_doc("CRM Deal", linked_deal.parent)
if deal.email != doc.email_id or deal.mobile_no != doc.mobile_no:
deal.email = doc.email_id
deal.mobile_no = doc.mobile_no
deal.save(ignore_permissions=True)


@frappe.whitelist()
def get_contact(name):
Contact = frappe.qb.DocType("Contact")
Expand Down
Loading