fix: added hooks to validate contact before save

This commit is contained in:
Shariq Ansari 2023-11-13 17:49:08 +05:30
parent 61fa0eb616
commit f5e3b81be8
2 changed files with 59 additions and 40 deletions

View File

@ -1,6 +1,27 @@
import frappe import frappe
def validate(doc, method):
set_primary_email(doc)
set_primary_mobile_no(doc)
doc.set_primary_email()
doc.set_primary("mobile_no")
def set_primary_email(doc):
if not doc.email_ids:
return
if len(doc.email_ids) == 1:
doc.email_ids[0].is_primary = 1
def set_primary_mobile_no(doc):
if not doc.phone_nos:
return
if len(doc.phone_nos) == 1:
doc.phone_nos[0].is_primary_mobile_no = 1
@frappe.whitelist() @frappe.whitelist()
def create_new(contact, field, value): def create_new(contact, field, value):
"""Create new email or phone for a contact""" """Create new email or phone for a contact"""

View File

@ -125,13 +125,11 @@ website_route_rules = [
# --------------- # ---------------
# Hook on document methods and events # Hook on document methods and events
# doc_events = { doc_events = {
# "*": { "Contact": {
# "on_update": "method", "validate": ["crm.api.contact.validate"],
# "on_cancel": "method", },
# "on_trash": "method" }
# }
# }
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------