Rohan Bansal | 76825ab | 2020-04-28 16:08:52 +0530 | [diff] [blame] | 1 | import frappe |
| 2 | |
| 3 | |
| 4 | def 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 Bansal | 7835bf9 | 2020-04-29 13:09:16 +0530 | [diff] [blame] | 12 | primary_phones = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone] |
Rohan Bansal | 76825ab | 2020-04-28 16:08:52 +0530 | [diff] [blame] | 13 | if primary_phones: |
| 14 | phone = primary_phones[0] |
| 15 | |
| 16 | # get the default mobile number |
Rohan Bansal | 7835bf9 | 2020-04-29 13:09:16 +0530 | [diff] [blame] | 17 | primary_mobile_nos = [phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no] |
Rohan Bansal | 76825ab | 2020-04-28 16:08:52 +0530 | [diff] [blame] | 18 | if primary_mobile_nos: |
| 19 | mobile_no = primary_mobile_nos[0] |
| 20 | |
| 21 | lead = frappe.get_doc("Lead", contact_lead) |
Myuddin khatri | fc0e45d | 2020-05-07 15:11:39 +0530 | [diff] [blame] | 22 | lead.db_set("phone", phone) |
| 23 | lead.db_set("mobile_no", mobile_no) |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 24 | |
| 25 | def copy_comments(doctype, docname, doc): |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 26 | comments = frappe.db.get_values("Comment", filters={"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, fieldname="*") |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 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 | |
| 34 | def add_link_in_communication(doctype, docname, doc): |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 35 | 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 | |
| 41 | def get_linked_communication_list(doctype, docname): |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 42 | 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") |
Anupam | 5b40d9e | 2021-12-18 20:12:57 +0530 | [diff] [blame] | 49 | |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 50 | return communications + communication_links |