fix: set contact as primary backend logic
This commit is contained in:
parent
d297f045c5
commit
36f4ddee20
@ -12,7 +12,8 @@
|
|||||||
"column_break_uvny",
|
"column_break_uvny",
|
||||||
"gender",
|
"gender",
|
||||||
"mobile_no",
|
"mobile_no",
|
||||||
"phone"
|
"phone",
|
||||||
|
"is_primary"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -55,7 +56,6 @@
|
|||||||
"fetch_from": "contact.phone",
|
"fetch_from": "contact.phone",
|
||||||
"fieldname": "phone",
|
"fieldname": "phone",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Phone",
|
"label": "Phone",
|
||||||
"options": "Phone",
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
@ -64,16 +64,22 @@
|
|||||||
"fetch_from": "contact.gender",
|
"fetch_from": "contact.gender",
|
||||||
"fieldname": "gender",
|
"fieldname": "gender",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Gender",
|
"label": "Gender",
|
||||||
"options": "Gender",
|
"options": "Gender",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "is_primary",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Is Primary"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-08-25 19:19:27.813526",
|
"modified": "2023-11-12 14:58:18.846919",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Contacts",
|
"name": "CRM Contacts",
|
||||||
|
|||||||
@ -7,6 +7,44 @@ from frappe.model.document import Document
|
|||||||
|
|
||||||
|
|
||||||
class CRMDeal(Document):
|
class CRMDeal(Document):
|
||||||
|
def validate(self):
|
||||||
|
self.set_primary_contact()
|
||||||
|
self.set_primary_email_mobile_no()
|
||||||
|
|
||||||
|
def set_primary_contact(self, contact=None):
|
||||||
|
if not self.contacts:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not contact and len(self.contacts) == 1:
|
||||||
|
self.contacts[0].is_primary = 1
|
||||||
|
elif contact:
|
||||||
|
for d in self.contacts:
|
||||||
|
if d.contact == contact:
|
||||||
|
d.is_primary = 1
|
||||||
|
else:
|
||||||
|
d.is_primary = 0
|
||||||
|
|
||||||
|
def set_primary_email_mobile_no(self):
|
||||||
|
if not self.contacts:
|
||||||
|
self.email = ""
|
||||||
|
self.mobile_no = ""
|
||||||
|
return
|
||||||
|
|
||||||
|
if len([contact for contact in self.contacts if contact.is_primary]) > 1:
|
||||||
|
frappe.throw(_("Only one {0} can be set as primary.").format(frappe.bold("Contact")))
|
||||||
|
|
||||||
|
primary_contact_exists = False
|
||||||
|
for d in self.contacts:
|
||||||
|
if d.is_primary == 1:
|
||||||
|
primary_contact_exists = True
|
||||||
|
self.email = d.email.strip()
|
||||||
|
self.mobile_no = d.mobile_no.strip()
|
||||||
|
break
|
||||||
|
|
||||||
|
if not primary_contact_exists:
|
||||||
|
self.email = ""
|
||||||
|
self.mobile_no = ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sort_options():
|
def sort_options():
|
||||||
return [
|
return [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user