[IMP] attachment_queue: pre-commit
parent
dbcffb06fa
commit
5d5d277e3d
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record model="ir.cron" id="cronjob_run_attachment_queue">
|
||||
|
@ -8,7 +8,7 @@
|
|||
<field name="numbercall">-1</field>
|
||||
<field name="active">False</field>
|
||||
<field name="doall" eval="False" />
|
||||
<field name="model_id" ref="model_attachment_queue"/>
|
||||
<field name="model_id" ref="model_attachment_queue" />
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.run_attachment_queue_scheduler()</field>
|
||||
</record>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo noupdate="1">
|
||||
<record id="attachment_queue_cron_batch_limit" model="ir.config_parameter">
|
||||
<field name="key">attachment_queue_cron_batch_limit</field>
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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="attachment_queue.model_attachment_queue"/>
|
||||
<field name="body_html"><![CDATA[
|
||||
<field name="model_id" ref="attachment_queue.model_attachment_queue" />
|
||||
<field
|
||||
name="body_html"
|
||||
><![CDATA[
|
||||
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:"Lucida Grande", Helvetica, Verdana, Arial, sans-serif;">Hello,<br><br></p>
|
||||
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:"Lucida Grande", 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:"Lucida Grande", Helvetica, Verdana, Arial, sans-serif;"></p>
|
||||
<p style="margin:0px 0px 10px 0px;font-size:13px;font-family:"Lucida Grande", Helvetica, Verdana, Arial, sans-serif;">Regards,<br></p>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" ?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="attachment_queue_demo" model="attachment.queue">
|
||||
|
|
|
@ -35,7 +35,7 @@ class AttachmentQueue(models.Model):
|
|||
compute="_compute_failure_emails",
|
||||
string="Failure Emails",
|
||||
help="Comma-separated list of email addresses to be notified in case of"
|
||||
"failure",
|
||||
"failure",
|
||||
)
|
||||
|
||||
def _compute_failure_emails(self):
|
||||
|
@ -67,15 +67,11 @@ class AttachmentQueue(models.Model):
|
|||
"""
|
||||
Run the process for each attachment queue
|
||||
"""
|
||||
failure_tmpl = self.env.ref(
|
||||
"attachment_queue.attachment_failure_notification"
|
||||
)
|
||||
failure_tmpl = self.env.ref("attachment_queue.attachment_failure_notification")
|
||||
for attachment in self:
|
||||
with api.Environment.manage():
|
||||
with registry(self.env.cr.dbname).cursor() as new_cr:
|
||||
new_env = api.Environment(
|
||||
new_cr, self.env.uid, self.env.context
|
||||
)
|
||||
new_env = api.Environment(new_cr, self.env.uid, self.env.context)
|
||||
attach = attachment.with_env(new_env)
|
||||
try:
|
||||
attach._run()
|
||||
|
@ -83,9 +79,7 @@ class AttachmentQueue(models.Model):
|
|||
except Exception as e:
|
||||
attach.env.cr.rollback()
|
||||
_logger.exception(str(e))
|
||||
attach.write(
|
||||
{"state": "failed", "state_message": str(e)}
|
||||
)
|
||||
attach.write({"state": "failed", "state_message": str(e)})
|
||||
emails = attach.failure_emails
|
||||
if emails:
|
||||
failure_tmpl.send_mail(attach.id)
|
||||
|
|
|
@ -14,4 +14,3 @@ This module can be used in combination with attachment_synchronize to control fi
|
|||
|
||||
|
||||
image:: ../static/description/form.png
|
||||
|
||||
|
|
|
@ -12,17 +12,14 @@ class TestAttachmentBaseQueue(TransactionCase):
|
|||
self.env = api.Environment(
|
||||
self.registry.test_cr, self.env.uid, self.env.context
|
||||
)
|
||||
self.attachment = self.env.ref(
|
||||
"attachment_queue.attachment_queue_demo"
|
||||
)
|
||||
self.attachment = self.env.ref("attachment_queue.attachment_queue_demo")
|
||||
|
||||
def tearDown(self):
|
||||
self.registry.leave_test_mode()
|
||||
super().tearDown()
|
||||
|
||||
def test_attachment_queue(self):
|
||||
"""Test run_attachment_queue_scheduler to ensure set state to done
|
||||
"""
|
||||
"""Test run_attachment_queue_scheduler to ensure set state to done"""
|
||||
self.assertEqual(self.attachment.state, "pending")
|
||||
self.env["attachment.queue"].run_attachment_queue_scheduler()
|
||||
self.env.cache.invalidate()
|
||||
|
@ -32,8 +29,7 @@ class TestAttachmentBaseQueue(TransactionCase):
|
|||
self.assertEqual(attach.state, "done")
|
||||
|
||||
def test_set_done(self):
|
||||
"""Test set_done manually
|
||||
"""
|
||||
"""Test set_done manually"""
|
||||
self.assertEqual(self.attachment.state, "pending")
|
||||
self.attachment.set_done()
|
||||
self.assertEqual(self.attachment.state, "done")
|
||||
|
|
|
@ -1,27 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_attachment_queue_form" model="ir.ui.view">
|
||||
<field name="model">attachment.queue</field>
|
||||
<field name="inherit_id" ref="base.view_attachment_form"/>
|
||||
<field name="inherit_id" ref="base.view_attachment_form" />
|
||||
<field name="mode">primary</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/*" position="before">
|
||||
<header>
|
||||
<button name="run" states="pending,failed"
|
||||
string="Run" type="object" class="oe_highlight"/>
|
||||
<button name="set_done" states="pending,failed"
|
||||
string="Set to Done" type="object"/>
|
||||
<button
|
||||
name="run"
|
||||
states="pending,failed"
|
||||
string="Run"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
<button
|
||||
name="set_done"
|
||||
states="pending,failed"
|
||||
string="Set to Done"
|
||||
type="object"
|
||||
/>
|
||||
</header>
|
||||
</xpath>
|
||||
<field name="url" position="after">
|
||||
<field name="date_done"/>
|
||||
<field name="state"/>
|
||||
<field name="file_type"/>
|
||||
<field name="date_done" />
|
||||
<field name="state" />
|
||||
<field name="file_type" />
|
||||
</field>
|
||||
<group name="description_group">
|
||||
<group name="state_message" string="Error" colspan="4">
|
||||
<field name="state_message" nolabel="1"/>
|
||||
<field name="state_message" nolabel="1" />
|
||||
</group>
|
||||
</group>
|
||||
</field>
|
||||
|
@ -31,12 +40,12 @@
|
|||
<field name="model">attachment.queue</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree default_order='create_date desc'>
|
||||
<field name="name"/>
|
||||
<field name="datas_fname"/>
|
||||
<field name="file_type"/>
|
||||
<field name="type"/>
|
||||
<field name="create_date"/>
|
||||
<field name="state"/>
|
||||
<field name="name" />
|
||||
<field name="datas_fname" />
|
||||
<field name="file_type" />
|
||||
<field name="type" />
|
||||
<field name="create_date" />
|
||||
<field name="state" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -45,31 +54,69 @@
|
|||
<field name="model">attachment.queue</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Attachments">
|
||||
<field name="name" filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]" string="Attachment"/>
|
||||
<field name="create_date"/>
|
||||
<filter name="url"
|
||||
string="URL"
|
||||
domain="[('type','=','url')]"/>
|
||||
<filter name="binary"
|
||||
string="Binary"
|
||||
domain="[('type','=','binary')]"/>
|
||||
<separator/>
|
||||
<filter name="my_documents_filter"
|
||||
string="My Document(s)"
|
||||
domain="[('create_uid','=',uid)]"
|
||||
help="Filter on my documents"/>
|
||||
<field name="create_uid"/>
|
||||
<field name="type"/>
|
||||
<filter string="Pending" name="pending" domain="[('state', '=', 'pending')]"/>
|
||||
<filter string="Failed" name="failed" domain="[('state', '=', 'failed')]"/>
|
||||
<filter string="Done" name="done" domain="[('state', '=', 'done')]"/>
|
||||
<field
|
||||
name="name"
|
||||
filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]"
|
||||
string="Attachment"
|
||||
/>
|
||||
<field name="create_date" />
|
||||
<filter name="url" string="URL" domain="[('type','=','url')]" />
|
||||
<filter name="binary" string="Binary" domain="[('type','=','binary')]" />
|
||||
<separator />
|
||||
<filter
|
||||
name="my_documents_filter"
|
||||
string="My Document(s)"
|
||||
domain="[('create_uid','=',uid)]"
|
||||
help="Filter on my documents"
|
||||
/>
|
||||
<field name="create_uid" />
|
||||
<field name="type" />
|
||||
<filter
|
||||
string="Pending"
|
||||
name="pending"
|
||||
domain="[('state', '=', 'pending')]"
|
||||
/>
|
||||
<filter string="Failed" name="failed" domain="[('state', '=', 'failed')]" />
|
||||
<filter string="Done" name="done" domain="[('state', '=', 'done')]" />
|
||||
<group expand="0" string="Group By">
|
||||
<filter string="Owner" name="owner" domain="[]" context="{'group_by':'create_uid'}"/>
|
||||
<filter string="Type" name="type" domain="[]" context="{'group_by':'type'}" groups="base.group_no_one"/>
|
||||
<filter string="Company" name="company" domain="[]" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
|
||||
<filter string="Creation Month" name="creation_month" domain="[]" context="{'group_by':'create_date'}"/>
|
||||
<filter string="State" name="state" domain="[]" context="{'group_by': 'state'}"/>
|
||||
<filter string="File type" name="file_type" domain="[]" context="{'group_by': 'file_type'}"/>
|
||||
<filter
|
||||
string="Owner"
|
||||
name="owner"
|
||||
domain="[]"
|
||||
context="{'group_by':'create_uid'}"
|
||||
/>
|
||||
<filter
|
||||
string="Type"
|
||||
name="type"
|
||||
domain="[]"
|
||||
context="{'group_by':'type'}"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<filter
|
||||
string="Company"
|
||||
name="company"
|
||||
domain="[]"
|
||||
context="{'group_by':'company_id'}"
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
<filter
|
||||
string="Creation Month"
|
||||
name="creation_month"
|
||||
domain="[]"
|
||||
context="{'group_by':'create_date'}"
|
||||
/>
|
||||
<filter
|
||||
string="State"
|
||||
name="state"
|
||||
domain="[]"
|
||||
context="{'group_by': 'state'}"
|
||||
/>
|
||||
<filter
|
||||
string="File type"
|
||||
name="file_type"
|
||||
domain="[]"
|
||||
context="{'group_by': 'file_type'}"
|
||||
/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
|
@ -81,27 +128,29 @@
|
|||
<field name="res_model">attachment.queue</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" eval="False"/>
|
||||
<field name="search_view_id" ref="view_attachment_queue_search"/>
|
||||
<field name="view_id" eval="False" />
|
||||
<field name="search_view_id" ref="view_attachment_queue_search" />
|
||||
</record>
|
||||
|
||||
<record id="act_open_attachment_que_view_tree" model="ir.actions.act_window.view">
|
||||
<field eval="10" name="sequence"/>
|
||||
<field eval="10" name="sequence" />
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_id" ref="view_attachment_queue_tree"/>
|
||||
<field name="act_window_id" ref="action_attachment_queue"/>
|
||||
<field name="view_id" ref="view_attachment_queue_tree" />
|
||||
<field name="act_window_id" ref="action_attachment_queue" />
|
||||
</record>
|
||||
|
||||
<record id="act_open_attachment_que_view_form" model="ir.actions.act_window.view">
|
||||
<field eval="10" name="sequence"/>
|
||||
<field eval="10" name="sequence" />
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_attachment_queue_form"/>
|
||||
<field name="act_window_id" ref="action_attachment_queue"/>
|
||||
<field name="view_id" ref="view_attachment_queue_form" />
|
||||
<field name="act_window_id" ref="action_attachment_queue" />
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_attachment_queue"
|
||||
parent="base.next_id_9"
|
||||
sequence="20"
|
||||
action="action_attachment_queue"/>
|
||||
<menuitem
|
||||
id="menu_attachment_queue"
|
||||
parent="base.next_id_9"
|
||||
sequence="20"
|
||||
action="action_attachment_queue"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue