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 |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 12 | primary_phones = [ |
| 13 | phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone |
| 14 | ] |
Rohan Bansal | 76825ab | 2020-04-28 16:08:52 +0530 | [diff] [blame] | 15 | if primary_phones: |
| 16 | phone = primary_phones[0] |
| 17 | |
| 18 | # get the default mobile number |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 19 | primary_mobile_nos = [ |
| 20 | phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no |
| 21 | ] |
Rohan Bansal | 76825ab | 2020-04-28 16:08:52 +0530 | [diff] [blame] | 22 | if primary_mobile_nos: |
| 23 | mobile_no = primary_mobile_nos[0] |
| 24 | |
| 25 | lead = frappe.get_doc("Lead", contact_lead) |
Myuddin khatri | fc0e45d | 2020-05-07 15:11:39 +0530 | [diff] [blame] | 26 | lead.db_set("phone", phone) |
| 27 | lead.db_set("mobile_no", mobile_no) |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 28 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 29 | |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 30 | def copy_comments(doctype, docname, doc): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 31 | comments = frappe.db.get_values( |
| 32 | "Comment", |
| 33 | filters={"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, |
| 34 | fieldname="*", |
| 35 | ) |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 36 | for comment in comments: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 37 | comment = frappe.get_doc(comment.update({"doctype": "Comment"})) |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 38 | comment.name = None |
| 39 | comment.reference_doctype = doc.doctype |
| 40 | comment.reference_name = doc.name |
| 41 | comment.insert() |
| 42 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 43 | |
Anupam | 6eb7793 | 2021-11-19 10:13:05 +0530 | [diff] [blame] | 44 | def add_link_in_communication(doctype, docname, doc): |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 45 | 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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 51 | |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 52 | def get_linked_communication_list(doctype, docname): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 53 | 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 | ) |
Anupam | 5b40d9e | 2021-12-18 20:12:57 +0530 | [diff] [blame] | 61 | |
Anupam | 31ac101 | 2021-12-17 19:21:08 +0530 | [diff] [blame] | 62 | return communications + communication_links |