Skip to content

Commit

Permalink
Merge pull request #367 from shariquerik/update-deal-on-contact-update
Browse files Browse the repository at this point in the history
fix: Sync Contact & Deal primary contact's email/mobile_no
  • Loading branch information
shariquerik authored Sep 23, 2024
2 parents 29c709e + 9313868 commit 257e9b2
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit 257e9b2

Please sign in to comment.