Browse Source

[REF] refactor code, rename enabled to active, and simplifie run code

12.0-mig-module_prototyper_last
Sébastien BEAU 4 years ago
parent
commit
77fb6956dc
  1. 18
      attachment_synchronize/models/attachment_synchronize_task.py
  2. 2
      attachment_synchronize/tests/test_import.py
  3. 26
      attachment_synchronize/views/attachment_synchronize_task_views.xml

18
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 "
@ -139,11 +139,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 +208,6 @@ 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.ensure_one()
self.copy({"enabled": False})
self.copy({"active": False})

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)

26
attachment_synchronize/views/attachment_synchronize_task_views.xml

@ -5,16 +5,13 @@
<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="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',
@ -70,16 +67,17 @@
<record id="view_attachment_import_task_tree" model="ir.ui.view"> <record id="view_attachment_import_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="pattern"/> <field name="pattern"/>
<field name="after_import"/> <field name="after_import"/>
<field name="move_path"/> <field name="move_path"/>
<field name="enabled" invisible="1"/>
<field name="active" invisible="1"/>
<button name="run" type="object" string="Run" icon="fa-play-circle"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/> <button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
<button name="toggle_active" type="object" string="Active/Inactive" icon="fa-archive"/>
</tree> </tree>
</field> </field>
</record> </record>
@ -87,13 +85,13 @@
<record id="view_attachment_export_task_tree" model="ir.ui.view"> <record id="view_attachment_export_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"/>
<field name="active" invisible="1"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/> <button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
<button name="toggle_active" type="object" string="Enable" icon="fa-archive"/>
</tree> </tree>
</field> </field>
</record> </record>
@ -120,7 +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>
<field name="context">{'default_method_type': 'import', "active_test": False}</field>
</record> </record>
<record id="act_open_attachment_import_task_view_tree" model="ir.actions.act_window.view"> <record id="act_open_attachment_import_task_view_tree" model="ir.actions.act_window.view">
@ -152,7 +150,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>
<field name="context">{'default_method_type': 'export', "active_test": False}</field>
</record> </record>
<record id="act_open_attachment_export_task_view_tree" model="ir.actions.act_window.view"> <record id="act_open_attachment_export_task_view_tree" model="ir.actions.act_window.view">

Loading…
Cancel
Save