blob: 8ae991ff17111e4a9debd3f32149eb426bda0d93 [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):
26 comments = frappe.db.get_values("Comment", filters={"reference_doctype": doctype, "reference_name": docname}, fieldname="*")
27 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):
35 communications = frappe.get_all("Communication", filters={"reference_doctype": doctype, "reference_name": docname}, pluck='name')
36 communication_links = frappe.get_all('Communication Link',
37 {
38 "link_doctype": doctype,
39 "link_name": docname,
40 "parent": ("not in", communications)
41 }, pluck="parent")
Anupam6210f102021-11-19 10:32:04 +053042
Anupam6eb77932021-11-19 10:13:05 +053043 for communication in communications + communication_links:
44 communication_doc = frappe.get_doc("Communication", communication)
45 communication_doc.add_link(doc.doctype, doc.name, autosave=True)