Merge pull request #34439 from frappe/fix/internal-communication

fix: consider sent or received for duplicate check
This commit is contained in:
Hussain Nagaria 2025-10-27 23:02:32 +05:30 committed by GitHub
commit 0b6ba2c709
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View file

@ -416,6 +416,13 @@ class Communication(Document, CommunicationEmailMixin):
# Timeline Links
def set_timeline_links(self):
# Skip timeline links if a "Sent" communication already exists
# else will create duplicate timeline entries
if self.sent_or_received == "Received" and self.find_one_by_filters(
message_id=self.message_id, sent_or_received="Sent"
):
return
contacts = []
create_contact_enabled = self.email_account and frappe.db.get_value(
"Email Account", self.email_account, "create_contact"

View file

@ -523,7 +523,7 @@ class TestInboundMail(IntegrationTestCase):
mail_content = self.get_test_mail(fname="incoming-1.raw")
message_id = Email(mail_content).message_id
# Create new communication record in DB
communication = self.new_communication(message_id=message_id)
communication = self.new_communication(message_id=message_id, sent_or_received="Received")
email_account = frappe.get_doc("Email Account", "_Test Email Account 1")
inbound_mail = InboundMail(mail_content, email_account, 12345, 1)

View file

@ -720,7 +720,9 @@ class InboundMail(Email):
if not self.message_id:
return
return Communication.find_one_by_filters(message_id=self.message_id, order_by="creation DESC")
return Communication.find_one_by_filters(
message_id=self.message_id, sent_or_received="Received", order_by="creation DESC"
)
def is_sender_same_as_receiver(self):
return self.from_email == self.email_account.email_id
@ -766,7 +768,9 @@ class InboundMail(Email):
if not self.is_reply():
return ""
communication = Communication.find_one_by_filters(message_id=self.in_reply_to)
communication = Communication.find_one_by_filters(
message_id=self.in_reply_to, order_by="creation DESC"
)
if not communication:
if self.parent_email_queue() and self.parent_email_queue().communication:
communication = Communication.find(self.parent_email_queue().communication, ignore_error=True)