Skip to content

Commit

Permalink
[IMP] base_export_async: send mail using mail template
Browse files Browse the repository at this point in the history
module **base_export_async**: send mail using mail template for Asynchronous Export data
  • Loading branch information
paras-tsd committed Jul 19, 2023
1 parent 99387de commit f2ecfb1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
3 changes: 2 additions & 1 deletion base_export_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -20,6 +20,7 @@
'security/ir_rule.xml',
'data/config_parameter.xml',
'data/cron.xml',
'data/mail_template_data.xml',
],
'demo': [
],
Expand Down
24 changes: 24 additions & 0 deletions base_export_async/data/mail_template_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>
<odoo>
<data noupdate="1">
<!--Email template for Asynchronous Export of a file sent by email -->
<record id="email_template_delay_export" model="mail.template">
<field name="name">Asynchronous Export</field>
<field name="model_id" ref="base_export_async.model_delay_export" />
<field name="email_from">${object.env.ref('base.partner_root').email}</field>
<field name="reply_to">${object.env.ref('base.partner_root').email}</field>
<field name="subject">Export ${ctx.get('model_description')} ${datetime.datetime.now().strftime('%d/%m/%Y')}</field>
<field name="body_html">
<![CDATA[
<p>Your export is available <a href="${ctx.get('url')}">here</a>.</p>
<p>It will be automatically deleted on ${ctx.get('expiration_date')}.</p>
<p>&nbsp;</p>
<p><span style="color: #808080;">This is an automated message. Please do not reply.</span></p>
]]>
</field>
<field name="lang">${object.env.user.lang}</field>
<field name="user_signature" eval="False" />
<field name="auto_delete" eval="True" />
</record>
</data>
</odoo>
35 changes: 18 additions & 17 deletions base_export_async/models/delay_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,27 @@ 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': _("""
<p>Your export is available <a href="{}">here</a>.</p>
<p>It will be automatically deleted the {}.</p>
<p>&nbsp;</p>
<p><span style="color: #808080;">
This is an automated message please do not reply.
</span></p>
""").format(url, expiration_date),
'auto_delete': True,
})
mail_template = self.env.ref(
'base_export_async.email_template_delay_export'
)
if mail_template:
email_ctx = {
'url': url,
'model_description': model_description,
'email_from': email_from,
'expiration_date': expiration_date
}
email_values = {
'recipient_ids': [(6, 0, users.mapped('partner_id').ids)],
}
mail_template.with_context(**email_ctx).send_mail(
export_record.id,
force_send=False,
email_values=email_values
)

@api.model
def cron_delete(self):
Expand Down

0 comments on commit f2ecfb1

Please sign in to comment.