blob: 5783b2c66111dfbbe4a9ce3448ce0bcfad17cfd8 [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
Ankush Menat494bd9e2022-03-28 18:52:46 +053012 primary_phones = [
13 phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone
14 ]
Rohan Bansal76825ab2020-04-28 16:08:52 +053015 if primary_phones:
16 phone = primary_phones[0]
17
18 # get the default mobile number
Ankush Menat494bd9e2022-03-28 18:52:46 +053019 primary_mobile_nos = [
20 phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no
21 ]
Rohan Bansal76825ab2020-04-28 16:08:52 +053022 if primary_mobile_nos:
23 mobile_no = primary_mobile_nos[0]
24
25 lead = frappe.get_doc("Lead", contact_lead)
Myuddin khatrifc0e45d2020-05-07 15:11:39 +053026 lead.db_set("phone", phone)
27 lead.db_set("mobile_no", mobile_no)
Anupam6eb77932021-11-19 10:13:05 +053028
Ankush Menat494bd9e2022-03-28 18:52:46 +053029
Anupam6eb77932021-11-19 10:13:05 +053030def copy_comments(doctype, docname, doc):
Ankush Menat494bd9e2022-03-28 18:52:46 +053031 comments = frappe.db.get_values(
32 "Comment",
33 filters={"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"},
34 fieldname="*",
35 )
Anupam6eb77932021-11-19 10:13:05 +053036 for comment in comments:
Ankush Menat494bd9e2022-03-28 18:52:46 +053037 comment = frappe.get_doc(comment.update({"doctype": "Comment"}))
Anupam6eb77932021-11-19 10:13:05 +053038 comment.name = None
39 comment.reference_doctype = doc.doctype
40 comment.reference_name = doc.name
41 comment.insert()
42
Ankush Menat494bd9e2022-03-28 18:52:46 +053043
Anupam6eb77932021-11-19 10:13:05 +053044def add_link_in_communication(doctype, docname, doc):
Anupam31ac1012021-12-17 19:21:08 +053045 communication_list = get_linked_communication_list(doctype, docname)
46
47 for communication in communication_list:
48 communication_doc = frappe.get_doc("Communication", communication)
49 communication_doc.add_link(doc.doctype, doc.name, autosave=True)
50
Ankush Menat494bd9e2022-03-28 18:52:46 +053051
Anupam31ac1012021-12-17 19:21:08 +053052def get_linked_communication_list(doctype, docname):
Ankush Menat494bd9e2022-03-28 18:52:46 +053053 communications = frappe.get_all(
54 "Communication", filters={"reference_doctype": doctype, "reference_name": docname}, pluck="name"
55 )
56 communication_links = frappe.get_all(
57 "Communication Link",
58 {"link_doctype": doctype, "link_name": docname, "parent": ("not in", communications)},
59 pluck="parent",
60 )
Anupam5b40d9e2021-12-18 20:12:57 +053061
Anupam31ac1012021-12-17 19:21:08 +053062 return communications + communication_links