diff --git a/crm/api/contact.py b/crm/api/contact.py new file mode 100644 index 00000000..5711f869 --- /dev/null +++ b/crm/api/contact.py @@ -0,0 +1,48 @@ +import frappe + + +@frappe.whitelist() +def create_new(contact, field, value): + """Create new email or phone for a contact""" + if not frappe.has_permission("Contact", "write", contact): + frappe.throw("Not permitted", frappe.PermissionError) + + contact = frappe.get_doc("Contact", contact) + + if field == "email": + contact.append("email_ids", {"email_id": value}) + elif field in ("mobile_no", "phone"): + contact.append("phone_nos", {"phone": value}) + else: + frappe.throw("Invalid field") + + contact.save() + return True + + +@frappe.whitelist() +def set_as_primary(contact, field, value): + """Set email or phone as primary for a contact""" + if not frappe.has_permission("Contact", "write", contact): + frappe.throw("Not permitted", frappe.PermissionError) + + contact = frappe.get_doc("Contact", contact) + + if field == "email": + for email in contact.email_ids: + if email.email_id == value: + email.is_primary = 1 + else: + email.is_primary = 0 + elif field in ("mobile_no", "phone"): + name = "is_primary_mobile_no" if field == "mobile_no" else "is_primary_phone" + for phone in contact.phone_nos: + if phone.phone == value: + phone.set(name, 1) + else: + phone.set(name, 0) + else: + frappe.throw("Invalid field") + + contact.save() + return True diff --git a/frontend/src/components/DropdownItem.vue b/frontend/src/components/DropdownItem.vue new file mode 100644 index 00000000..5460ff4b --- /dev/null +++ b/frontend/src/components/DropdownItem.vue @@ -0,0 +1,41 @@ + + + + diff --git a/frontend/src/pages/Contact.vue b/frontend/src/pages/Contact.vue index b64589f5..fe80f88b 100644 --- a/frontend/src/pages/Contact.vue +++ b/frontend/src/pages/Contact.vue @@ -95,14 +95,40 @@ {{ field.label }}