Browse Source

[IMP] Add smart button to related Tasks from Storage Backend

12.0-mig-module_prototyper_last
clementmbr 5 years ago
committed by David Beal
parent
commit
71dc6fc205
  1. 56
      attachment_synchronize/models/storage_backend.py
  2. 27
      attachment_synchronize/views/storage_backend_views.xml

56
attachment_synchronize/models/storage_backend.py

@ -9,3 +9,59 @@ class StorageBackend(models.Model):
synchronize_task_ids = fields.One2many(
"attachment.synchronize.task", "backend_id", string="Tasks"
)
import_task_count = fields.Integer(
"Import Tasks", compute="_compute_import_task_count"
)
export_task_count = fields.Integer(
"Export Tasks", compute="_compute_export_task_count"
)
def _compute_import_task_count(self):
for rec in self:
rec.import_task_count = len(
rec.synchronize_task_ids.filtered(lambda t: t.method_type == "import")
)
def _compute_export_task_count(self):
for rec in self:
rec.export_task_count = len(
rec.synchronize_task_ids.filtered(lambda t: t.method_type == "export")
)
def action_related_import_task(self):
self.ensure_one()
act_window_xml_id = "attachment_synchronize.action_attachment_import_task"
act_window = self.env.ref(act_window_xml_id).read()[0]
domain = [
("id", "in", self.synchronize_task_ids.ids),
("method_type", "=", "import"),
]
act_window["domain"] = domain
if self.import_task_count == 1:
form = self.env.ref("attachment_synchronize.view_attachment_task_form")
act_window["views"] = [(form.id, "form")]
act_window["res_id"] = (
self.env["attachment.synchronize.task"].search(domain).id
)
return act_window
def action_related_export_task(self):
self.ensure_one()
act_window_xml_id = "attachment_synchronize.action_attachment_export_task"
act_window = self.env.ref(act_window_xml_id).read()[0]
domain = [
("id", "in", self.synchronize_task_ids.ids),
("method_type", "=", "export"),
]
act_window["domain"] = domain
if self.export_task_count == 1:
form = self.env.ref("attachment_synchronize.view_attachment_task_form")
act_window["views"] = [(form.id, "form")]
act_window["res_id"] = (
self.env["attachment.synchronize.task"].search(domain).id
)
return act_window

27
attachment_synchronize/views/storage_backend_views.xml

@ -6,12 +6,27 @@
<field name="inherit_id" ref="storage_backend.storage_backend_view_form" />
<field name="priority" eval="250"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='config']" position="after">
<notebook>
<page string="Tasks">
<field name="synchronize_task_ids" domain="[('backend_id', '=', id)]" context="{'default_backend_id': id}"/>
</page>
</notebook>
<xpath expr="//div[hasclass('oe_title')]" position="before">
<div class="oe_button_box" name="button_box">
<button
class="oe_stat_button"
type="object"
attrs="{'invisible': [('import_task_count', '&lt;', 1)]}"
name="action_related_import_task"
icon="fa-download"
>
<field name="import_task_count" widget="statinfo" />
</button>
<button
class="oe_stat_button"
type="object"
attrs="{'invisible': [('export_task_count', '&lt;', 1)]}"
name="action_related_export_task"
icon="fa-upload"
>
<field name="export_task_count" widget="statinfo" />
</button>
</div>
</xpath>
</field>
</record>

Loading…
Cancel
Save