feat: move to newer contacts structure

This commit is contained in:
Himanshu Warekar 2019-08-08 23:49:53 +05:30
parent 365da10718
commit fa662e1732
5 changed files with 29 additions and 18 deletions

View file

@ -82,7 +82,7 @@ class Contact(Document):
if (link.link_doctype, link.link_name) in reference_links:
return True
def add_email_address(self, email_id, autosave=False):
def add_email(self, email_id, autosave=False):
self.append("email_ids", {
"email_id": email_id
})
@ -90,7 +90,7 @@ class Contact(Document):
if autosave:
self.save(ignore_permissions=True)
def add_phone_number(self, phone_number, autosave=False):
def add_phone(self, phone_number, autosave=False):
self.append("phone_numbers", {
"phone": phone_number
})

View file

@ -74,13 +74,13 @@ def create_linked_contact(link_list):
contact = frappe.get_doc({
"doctype": "Contact",
"salutation": "Mr",
"email_id": "test_contact@example.com",
"first_name": "_Test First Name",
"last_name": "_Test Last Name",
"is_primary_contact": 1,
"phone": "+91 0000000000",
"status": "Open"
})
contact.add_email("test_contact@example.com")
contact.add_phone("+91 0000000000")
for name in link_list:
contact.append("links",{

View file

@ -339,10 +339,11 @@ def get_contacts(email_strings):
if not contact_name:
contact = frappe.get_doc({
"doctype": "Contact",
"first_name": frappe.unscrub(email.split("@")[0]),
"email_id": email
}).insert(ignore_permissions=True)
"doctype": "Contact",
"first_name": frappe.unscrub(email.split("@")[0]),
})
contact.add_email(email)
contact.insert(ignore_permissions=True)
contact_name = contact.name
contacts.append(contact_name)

View file

@ -101,20 +101,23 @@ class TestCommunication(unittest.TestCase):
contact_sender = frappe.get_doc({
"doctype": "Contact",
"first_name": frappe.generate_hash(length=10),
"email_id": "comm_sender@example.com"
}).insert(ignore_permissions=True)
})
contact_sender.add_email("comm_sender@example.com")
contact_sender.insert(ignore_permissions=True)
contact_recipient = frappe.get_doc({
"doctype": "Contact",
"first_name": frappe.generate_hash(length=10),
"email_id": "comm_recipient@example.com"
}).insert(ignore_permissions=True)
contact_recipient.add_email("comm_recipient@example.com")
contact_recipient.insert(ignore_permissions=True)
contact_cc = frappe.get_doc({
"doctype": "Contact",
"first_name": frappe.generate_hash(length=10),
"email_id": "comm_cc@example.com"
}).insert(ignore_permissions=True)
})
contact_cc.add_email("comm_cc@example.com")
contact_cc.insert(ignore_permissions=True)
comm = frappe.get_doc({
"doctype": "Communication",

View file

@ -1068,16 +1068,23 @@ def create_contact(user, ignore_links=False, ignore_mandatory=False):
if user.name in ["Administrator", "Guest"]: return
if not frappe.db.get_value("Contact", {"email_id": user.email}):
frappe.get_doc({
d = frappe.get_doc({
"doctype": "Contact",
"first_name": user.first_name,
"last_name": user.last_name,
"email_id": user.email,
"user": user.name,
"gender": user.gender,
"phone": user.phone,
"mobile_no": user.mobile_no
}).insert(ignore_permissions=True, ignore_links=ignore_links, ignore_mandatory=ignore_mandatory)
})
if user.email:
d.add_email(user.email)
if user.phone:
d.add_phone(user.phone)
if user.mobile_no:
d.add_phone(user.mobile_no)
d.insert(ignore_permissions=True, ignore_links=ignore_links, ignore_mandatory=ignore_mandatory)
@frappe.whitelist()