From a7f3eb12ddc41a18df90a3d5519014c07c0e5d7b Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 9 Jun 2025 08:23:04 +0700 Subject: (andri) fix retry email marketing --- indoteknik_custom/models/mail_mail.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/mail_mail.py') diff --git a/indoteknik_custom/models/mail_mail.py b/indoteknik_custom/models/mail_mail.py index 82b1fcca..7ebd9293 100644 --- a/indoteknik_custom/models/mail_mail.py +++ b/indoteknik_custom/models/mail_mail.py @@ -1,12 +1,21 @@ from odoo import fields, models, api, _ +from datetime import timedelta class MailMail(models.Model): _inherit = 'mail.mail' + @api.model def retry_send_mail(self): - mails = self.env['mail.mail'].search([ + now = fields.Datetime.now() + seven_days_ago = now - timedelta(days=7) + + # Filter hanya email gagal dalam 7 hari terakhir + mails = self.search([ ('state', 'in', ['exception', 'cancel']), + ('create_date', '>=', seven_days_ago), + ('create_date', '<=', now), ], limit=250) + for mail in mails: - mail.state = 'outgoing' + mail.state = 'outgoing' -- cgit v1.2.3 From 114d17b3d8e21801a4020956c8e8eb80d33b1be6 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 9 Jun 2025 09:28:58 +0700 Subject: (andri) fix retry --- indoteknik_custom/models/mail_mail.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/mail_mail.py') diff --git a/indoteknik_custom/models/mail_mail.py b/indoteknik_custom/models/mail_mail.py index 7ebd9293..cbcd883a 100644 --- a/indoteknik_custom/models/mail_mail.py +++ b/indoteknik_custom/models/mail_mail.py @@ -1,6 +1,8 @@ from odoo import fields, models, api, _ from datetime import timedelta +import logging +_logger = logging.getLogger(__name__) class MailMail(models.Model): _inherit = 'mail.mail' @@ -12,10 +14,14 @@ class MailMail(models.Model): # Filter hanya email gagal dalam 7 hari terakhir mails = self.search([ - ('state', 'in', ['exception', 'cancel']), + ('state', 'in', 'exception'), ('create_date', '>=', seven_days_ago), ('create_date', '<=', now), ], limit=250) + _logger.info("Found %s failed emails in last 7 days to retry.", len(mails)) + for mail in mails: - mail.state = 'outgoing' + _logger.info("Retrying email ID %s - To: %s - Subject: %s", + mail.id, mail.email_to, mail.subject) + mail.state = 'outgoing' -- cgit v1.2.3 From b87f89b8af2731e02d6ab095c3e92e48b39b4f6c Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Sat, 14 Jun 2025 12:27:25 +0700 Subject: (andri) fix retry --- indoteknik_custom/models/mail_mail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/mail_mail.py') diff --git a/indoteknik_custom/models/mail_mail.py b/indoteknik_custom/models/mail_mail.py index cbcd883a..792b97b7 100644 --- a/indoteknik_custom/models/mail_mail.py +++ b/indoteknik_custom/models/mail_mail.py @@ -14,7 +14,7 @@ class MailMail(models.Model): # Filter hanya email gagal dalam 7 hari terakhir mails = self.search([ - ('state', 'in', 'exception'), + ('state', 'in', ['exception']), ('create_date', '>=', seven_days_ago), ('create_date', '<=', now), ], limit=250) -- cgit v1.2.3