diff --git a/base_export_async/__manifest__.py b/base_export_async/__manifest__.py index 9dba8ddd5e..3f6611d192 100644 --- a/base_export_async/__manifest__.py +++ b/base_export_async/__manifest__.py @@ -6,7 +6,7 @@ 'summary': """ Asynchronous export with job queue """, - 'version': '12.0.1.1.0', + 'version': '12.0.1.1.1', 'license': 'AGPL-3', 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/queue', @@ -20,6 +20,7 @@ 'security/ir_rule.xml', 'data/config_parameter.xml', 'data/cron.xml', + 'data/mail_template_data.xml', ], 'demo': [ ], diff --git a/base_export_async/data/mail_template_data.xml b/base_export_async/data/mail_template_data.xml new file mode 100644 index 0000000000..e1f8904e8b --- /dev/null +++ b/base_export_async/data/mail_template_data.xml @@ -0,0 +1,19 @@ + + + + Delay Export + Export ${object.model_description} ${datetime.date.today()} + + + +

Your export is available here.

+

It will be automatically deleted the ${object.expiration_date}.

+
+

This is an automated message please do not reply.

+
+
+
diff --git a/base_export_async/models/delay_export.py b/base_export_async/models/delay_export.py index 7246768185..60dd3f9ef0 100644 --- a/base_export_async/models/delay_export.py +++ b/base_export_async/models/delay_export.py @@ -21,6 +21,9 @@ class DelayExport(models.Model): _description = 'Asynchronous Export' user_ids = fields.Many2many('res.users', string='Users', index=True) + model_description = fields.Char() + url = fields.Char() + expiration_date = fields.Date() @api.model def delay_export(self, data): @@ -116,26 +119,30 @@ def export(self, params): expiration_date = fields.Date.to_string( date_today + relativedelta(days=+int(time_to_live))) - # TODO : move to email template odoo_bot = self.sudo().env.ref("base.partner_root") email_from = odoo_bot.email model_description = self.env[model_name]._description - self.env['mail.mail'].create({ - 'email_from': email_from, - 'reply_to': email_from, - 'recipient_ids': [(6, 0, users.mapped('partner_id').ids)], - 'subject': _("Export {} {}").format( - model_description, fields.Date.to_string(fields.Date.today())), - 'body_html': _(""" -

Your export is available here.

-

It will be automatically deleted the {}.

-

 

-

- This is an automated message please do not reply. -

- """).format(url, expiration_date), - 'auto_delete': True, - }) + mail_template = self.env.ref( + 'base_export_async.delay_export_mail_template', + raise_if_not_found=False + ) + if mail_template: + export_record.write( + { + "url": url, + "expiration_date": expiration_date, + "model_description": model_description, + } + ) + mail_template.send_mail( + export_record.id, + force_send=False, + email_values={ + "email_from": email_from, + "reply_to": email_from, + "recipient_ids": [(6, 0, users.mapped("partner_id").ids)], + }, + ) @api.model def cron_delete(self):