blob: a4576a287e188cf7d16e83592856ffc1a2b3311c [file] [log] [blame]
Rohan Bansal76825ab2020-04-28 16:08:52 +05301import frappe
2
3
4def update_lead_phone_numbers(contact, method):
5 if contact.phone_nos:
6 contact_lead = contact.get_link_for("Lead")
7 if contact_lead:
8 phone = mobile_no = contact.phone_nos[0].phone
9
10 if len(contact.phone_nos) > 1:
11 # get the default phone number
Rohan Bansal7835bf92020-04-29 13:09:16 +053012 primary_phones = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone]
Rohan Bansal76825ab2020-04-28 16:08:52 +053013 if primary_phones:
14 phone = primary_phones[0]
15
16 # get the default mobile number
Rohan Bansal7835bf92020-04-29 13:09:16 +053017 primary_mobile_nos = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no]
Rohan Bansal76825ab2020-04-28 16:08:52 +053018 if primary_mobile_nos:
19 mobile_no = primary_mobile_nos[0]
20
21 lead = frappe.get_doc("Lead", contact_lead)
Myuddin khatrifc0e45d2020-05-07 15:11:39 +053022 lead.db_set("phone", phone)
23 lead.db_set("mobile_no", mobile_no)
Anupam6eb77932021-11-19 10:13:05 +053024
25def copy_comments(doctype, docname, doc):
Anupam31ac1012021-12-17 19:21:08 +053026 comments = frappe.db.get_values("Comment", filters={"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, fieldname="*")
Anupam6eb77932021-11-19 10:13:05 +053027 for comment in comments:
28 comment = frappe.get_doc(comment.update({"doctype":"Comment"}))
29 comment.name = None
30 comment.reference_doctype = doc.doctype
31 comment.reference_name = doc.name
32 comment.insert()
33
34def add_link_in_communication(doctype, docname, doc):
Anupam31ac1012021-12-17 19:21:08 +053035 communication_list = get_linked_communication_list(doctype, docname)
36
37 for communication in communication_list:
38 communication_doc = frappe.get_doc("Communication", communication)
39 communication_doc.add_link(doc.doctype, doc.name, autosave=True)
40
41def get_linked_communication_list(doctype, docname):
Anupam6eb77932021-11-19 10:13:05 +053042 communications = frappe.get_all("Communication", filters={"reference_doctype": doctype, "reference_name": docname}, pluck='name')
43 communication_links = frappe.get_all('Communication Link',
44 {
45 "link_doctype": doctype,
46 "link_name": docname,
47 "parent": ("not in", communications)
48 }, pluck="parent")
Anupam5b40d9e2021-12-18 20:12:57 +053049
Anupam31ac1012021-12-17 19:21:08 +053050 return communications + communication_links