Skip to content

Commit

Permalink
fix: duplicate IM
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Nov 18, 2024
1 parent cc494a0 commit 55d6823
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@
"ignore_xss_filter": 1,
"label": "In Reply To (Message ID)",
"length": 255,
"read_only": 1
"read_only": 1,
"search_index": 1
},
{
"fieldname": "column_break_pxhn",
Expand Down Expand Up @@ -430,7 +431,8 @@
"fieldtype": "Data",
"label": "Incoming Mail Log",
"no_copy": 1,
"read_only": 1
"read_only": 1,
"search_index": 1
},
{
"fieldname": "section_break_vtax",
Expand All @@ -441,7 +443,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-11-18 13:33:53.161839",
"modified": "2024-11-18 14:12:48.953159",
"modified_by": "Administrator",
"module": "Mail Client",
"name": "Incoming Mail",
Expand Down
29 changes: 21 additions & 8 deletions mail_client/mail_client/doctype/incoming_mail/incoming_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,22 @@ def create_incoming_mail(

if not do_not_save:
doc.flags.ignore_links = True
doc.save(ignore_permissions=True)
if not do_not_submit:
try:

try:
doc.insert(ignore_permissions=True)

if not do_not_submit:
doc.submit()
except Exception:
frappe.log_error(
title="Submit Incoming Mail",
message=frappe.get_traceback(with_context=True),
)
except frappe.UniqueValidationError:
frappe.log_error(
title="Duplicate Incoming Mail",
message=frappe.get_traceback(with_context=True),
)
except Exception:
frappe.log_error(
title="Create Incoming Mail",
message=frappe.get_traceback(with_context=True),
)

return doc

Expand Down Expand Up @@ -353,3 +360,9 @@ def fetch_emails_from_mail_server() -> None:
except Exception:
error_log = frappe.get_traceback(with_context=False)
frappe.log_error(title="Fetch Emails from Mail Server", message=error_log)


def on_doctype_update() -> None:
frappe.db.add_unique(
"Incoming Mail", ["receiver", "incoming_mail_log"], constraint_name="unique_receiver_mail_log"
)

0 comments on commit 55d6823

Please sign in to comment.