Browse Source

Add possibility to notify by mail in case of attachment processing failure

12.0-mig-module_prototyper_last
Florian da Costa 5 years ago
committed by David Beal
parent
commit
7bff12e874
  1. 1
      base_attachment_queue/__manifest__.py
  2. 16
      base_attachment_queue/data/mail_template.xml
  3. 19
      base_attachment_queue/models/attachment.py

1
base_attachment_queue/__manifest__.py

@ -19,6 +19,7 @@
'security/ir.model.access.csv',
'data/cron.xml',
'data/ir_config_parameter.xml',
'data/mail_template.xml',
],
'demo': [
'demo/attachment_metadata_demo.xml'

16
base_attachment_queue/data/mail_template.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="attachment_failure_notification" model="mail.template">
<field name="email_to">${object.failure_emails}</field>
<field name="name">Attachment Failure notification</field>
<field name="subject">The attachment ${object.name} has failed</field>
<field name="model_id" ref="base_attachment_queue.model_ir_attachment_metadata"/>
<field name="body_html"><![CDATA[
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">Hello,<br><br></p>
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">The attachment ${object.name} has failed with the following error message : <br>${object.state_message}<br></p><p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;"></p>
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;">Regards,<br></p>
]]></field>
</record>
</odoo>

19
base_attachment_queue/models/attachment.py

@ -26,6 +26,20 @@ class IrAttachmentMetadata(models.Model):
('done', 'Done'),
], readonly=False, required=True, default='pending')
state_message = fields.Text()
failure_emails = fields.Char(
compute='_compute_failure_emails',
string="Failure Emails",
help="list of email (separated by comma) which should be notified in "
"case of failure")
def _compute_failure_emails(self):
for attach in self:
attach.failure_emails = attach._get_failure_emails()
def _get_failure_emails(self):
# to be overriden in submodules implementing the file_type
self.ensure_one()
return ""
@api.model
def run_attachment_metadata_scheduler(self, domain=None):
@ -47,6 +61,8 @@ class IrAttachmentMetadata(models.Model):
"""
Run the process for each attachment metadata
"""
failure_tmpl = self.env.ref(
'base_attachment_queue.attachment_failure_notification')
for attachment in self:
with api.Environment.manage():
with registry(self.env.cr.dbname).cursor() as new_cr:
@ -63,6 +79,9 @@ class IrAttachmentMetadata(models.Model):
'state': 'failed',
'state_message': str(e),
})
emails = attach.failure_emails
if emails:
failure_tmpl.send_mail(attach.id)
attach.env.cr.commit()
else:
vals = {

Loading…
Cancel
Save