Browse Source

Merge PR #1917 into 12.0

Signed-off-by sebastienbeau
12.0-mig-module_prototyper_last
OCA-git-bot 4 years ago
parent
commit
236243b653
  1. 39
      attachment_synchronize/models/attachment_synchronize_task.py
  2. 2
      attachment_synchronize/tests/test_import.py
  3. 21
      attachment_synchronize/views/attachment_queue_views.xml
  4. 116
      attachment_synchronize/views/attachment_synchronize_task_views.xml

39
attachment_synchronize/models/attachment_synchronize_task.py

@ -89,7 +89,7 @@ class AttachmentSynchronizeTask(models.Model):
"\nFurther operations will be realized on these Attachments Queues depending " "\nFurther operations will be realized on these Attachments Queues depending "
"on their 'File Type' value.", "on their 'File Type' value.",
) )
enabled = fields.Boolean("Enabled", default=True)
active = fields.Boolean("Enabled", default=True, old="enabled")
avoid_duplicated_files = fields.Boolean( avoid_duplicated_files = fields.Boolean(
string="Avoid importing duplicated files", string="Avoid importing duplicated files",
help="If checked, a file will not be imported if an Attachment Queue with the " help="If checked, a file will not be imported if an Attachment Queue with the "
@ -101,6 +101,15 @@ class AttachmentSynchronizeTask(models.Model):
"related to this task.\nAn alert will be sent to these emails if any operation " "related to this task.\nAn alert will be sent to these emails if any operation "
"on these Attachment Queue's file type fails.", "on these Attachment Queue's file type fails.",
) )
count_attachment_failed = fields.Integer(compute="_compute_count_state")
count_attachment_pending = fields.Integer(compute="_compute_count_state")
count_attachment_done = fields.Integer(compute="_compute_count_state")
def _compute_count_state(self):
for record in self:
for state in ["failed", "pending", "done"]:
record["count_attachment_{}".format(state)] = \
len(record.attachment_ids.filtered(lambda r: r.state == state))
def _prepare_attachment_vals(self, data, filename): def _prepare_attachment_vals(self, data, filename):
self.ensure_one() self.ensure_one()
@ -139,11 +148,19 @@ class AttachmentSynchronizeTask(models.Model):
if domain is None: if domain is None:
domain = [] domain = []
domain = expression.AND( domain = expression.AND(
[domain, [("method_type", "=", "import"), ("enabled", "=", True)]]
[domain, [("method_type", "=", "import")]]
) )
for task in self.search(domain): for task in self.search(domain):
task.run_import() task.run_import()
def run(self):
for record in self:
method = "run_{}".format(record.method_type)
if not hasattr(self, method):
raise NotImplemented
else:
getattr(record, method)()
def run_import(self): def run_import(self):
self.ensure_one() self.ensure_one()
attach_obj = self.env["attachment.queue"] attach_obj = self.env["attachment.queue"]
@ -200,10 +217,16 @@ class AttachmentSynchronizeTask(models.Model):
for task in self: for task in self:
task.attachment_ids.filtered(lambda a: a.state == "pending").run() task.attachment_ids.filtered(lambda a: a.state == "pending").run()
def button_toogle_enabled(self):
for rec in self:
rec.enabled = not rec.enabled
def button_duplicate_record(self): def button_duplicate_record(self):
self.ensure_one()
self.copy({"enabled": False})
# due to orm limitation method call from ui should not have params
# so we need to define this method to be able to copy
# if we do not do this the context will be injected in default params
# in V14 maybe we can call copy directly
self.copy()
def copy(self, default=None):
if default is None:
default = {}
if "active" not in default:
default["active"] = False
return super().copy(default=default)

2
attachment_synchronize/tests/test_import.py

@ -78,6 +78,6 @@ class TestImport(SyncCommon):
self._check_attachment_created(count=1) self._check_attachment_created(count=1)
def test_running_cron_disable_task(self): def test_running_cron_disable_task(self):
self.task.write({"after_import": "delete", "enabled": False})
self.task.write({"after_import": "delete", "active": False})
self.env["attachment.synchronize.task"].run_task_import_scheduler() self.env["attachment.synchronize.task"].run_task_import_scheduler()
self._check_attachment_created(count=0) self._check_attachment_created(count=0)

21
attachment_synchronize/views/attachment_queue_views.xml

@ -32,4 +32,25 @@
</field> </field>
</record> </record>
<record id="attachment_queue_view_search" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="inherit_id" ref="attachment_queue.view_attachment_queue_search"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="task_id" filter_domain="[('task_id.name','ilike',self)]"/>
</field>
</field>
</record>
<record id="action_attachment_queue_related" model="ir.actions.act_window">
<field name="name">Attachments Queue</field>
<field name="type">ir.actions.act_window</field>
<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="domain">[('task_id', '=', active_id)]</field>
<field name="search_view_id" ref="attachment_queue.view_attachment_queue_search"/>
</record>
</odoo> </odoo>

116
attachment_synchronize/views/attachment_synchronize_task_views.xml

@ -5,16 +5,37 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<header> <header>
<button name="run_import" type="object" string="Run Import" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'import'), ('enabled','=', False)]}"/>
</header>
<header>
<button name="run_export" type="object" string="Run Export" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'export'), ('enabled','=', False)]}"/>
<button name="run" type="object" string="Run" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': [('active','=', False)]}"/>
</header> </header>
<sheet> <sheet>
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button name="button_toogle_enabled" type="object" class="oe_stat_button" icon="fa-archive">
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-thumbs-o-down" context="{'search_default_failed': 1}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_failed" widget="statinfo" nolabel="1"/>
</span>
<span class="o_stat_text">Fail</span>
</div>
</button>
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-spinner" context="{'search_default_pending': 1}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_pending" widget="statinfo" nolabel="1"/>
</span>
<span class="o_stat_text">Pending</span>
</div>
</button>
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-thumbs-o-up" context="{'search_default_done': 1}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_done" widget="statinfo" nolabel="1"/>
</span>
<span class="o_stat_text">Success</span>
</div>
</button>
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field <field
name="enabled"
name="active"
widget="boolean_button" widget="boolean_button"
options="{'terminology': { options="{'terminology': {
'string_true': 'Enabled', 'string_true': 'Enabled',
@ -44,56 +65,33 @@
<field name="after_import" /> <field name="after_import" />
<field name="move_path" colspan="4" attrs="{'invisible':[('after_import','!=','move'), ('after_import','!=','move_rename')]}"/> <field name="move_path" colspan="4" attrs="{'invisible':[('after_import','!=','move'), ('after_import','!=','move_rename')]}"/>
<field name="new_name" colspan="4" attrs="{'invisible': [('after_import','!=','rename'), ('after_import','!=','move_rename')]}"/> <field name="new_name" colspan="4" attrs="{'invisible': [('after_import','!=','rename'), ('after_import','!=','move_rename')]}"/>
<field name="file_type"/>
</group> </group>
<group string="Attachments">
<group>
<field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}" />
<group string="Notification">
<field name="failure_emails"/> <field name="failure_emails"/>
</group> </group>
<field name="attachment_ids" domain="[('task_id', '=', id)]" nolabel="1" attrs="{'invisible':[('method_type','!=','export')]}">
<tree>
<field name="name"/>
<field name="datas_fname"/>
<field name="file_type"/>
<field name="storage_backend_id"/>
<field name="type"/>
<field name="create_date"/>
<field name="state"/>
</tree>
</field>
</group>
</sheet> </sheet>
</form> </form>
</field> </field>
</record> </record>
<record id="view_attachment_import_task_tree" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<tree string="Tasks" decoration-muted="enabled == False">
<field name="name" select="1"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="pattern"/>
<field name="after_import"/>
<field name="move_path"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
</tree>
</field>
</record>
<record id="view_attachment_export_task_tree" model="ir.ui.view">
<record id="view_attachment_task_tree" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field> <field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Tasks" decoration-muted="enabled == False">
<tree string="Tasks" decoration-muted="active == False">
<field name="name" select="1"/> <field name="name" select="1"/>
<field name="backend_id"/> <field name="backend_id"/>
<field name="filepath"/> <field name="filepath"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
<field name="active" invisible="1"/>
<button name="run" type="object" string="Run" icon="fa-play-circle"/>
<field name="count_attachment_failed" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-thumbs-o-down" context="{'search_default_failed': 1}"/>
<field name="count_attachment_pending" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-spinner" context="{'search_default_pending': 1}"/>
<field name="count_attachment_done" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-thumbs-o-up" context="{'search_default_done': 1}"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone" invisible="not context.get('show_duplicate_button')"/>
<button name="toggle_active" type="object" string="Active/Inactive" icon="fa-archive" invisible="not context.get('show_toggle_active_button')"/>
</tree> </tree>
</field> </field>
</record> </record>
@ -120,21 +118,7 @@
<field name="view_id" eval="False"/> <field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_attachment_task_search"/> <field name="search_view_id" ref="view_attachment_task_search"/>
<field name="domain">[('method_type', '=', 'import')]</field> <field name="domain">[('method_type', '=', 'import')]</field>
<field name="context">{'default_method_type': 'import'}</field>
</record>
<record id="act_open_attachment_import_task_view_tree" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_attachment_import_task_tree"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
<record id="act_open_attachment_import_task_view_form" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_task_form"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
<field name="context">{'default_method_type': 'import', "active_test": False}</field>
</record> </record>
<menuitem id="menu_attachment_import_task" <menuitem id="menu_attachment_import_task"
@ -152,21 +136,7 @@
<field name="view_id" eval="False"/> <field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_attachment_task_search"/> <field name="search_view_id" ref="view_attachment_task_search"/>
<field name="domain">[('method_type', '=', 'export')]</field> <field name="domain">[('method_type', '=', 'export')]</field>
<field name="context">{'default_method_type': 'export'}</field>
</record>
<record id="act_open_attachment_export_task_view_tree" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_attachment_export_task_tree"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
</record>
<record id="act_open_attachment_export_task_view_form" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_task_form"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
<field name="context">{'default_method_type': 'export', "active_test": False}</field>
</record> </record>
<menuitem id="menu_attachment_export_task" <menuitem id="menu_attachment_export_task"

Loading…
Cancel
Save