From 033e82510d8898c452259c8f7903e6520f2d8faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Fri, 23 Oct 2020 22:29:27 +0200 Subject: [PATCH] [REF] make menu more consistent In normal tree view duplicate and archive can be done throught the action menu. So we only need to show this button when this tree view are included in a form using a o2m or m2m. So this visibility can be activated by passing value in the context Also make the copy consitent whatever way you do it --- .../models/attachment_synchronize_task.py | 15 ++++++++++++--- .../views/attachment_synchronize_task_views.xml | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/attachment_synchronize/models/attachment_synchronize_task.py b/attachment_synchronize/models/attachment_synchronize_task.py index a7f03edc3..96a16fb6e 100644 --- a/attachment_synchronize/models/attachment_synchronize_task.py +++ b/attachment_synchronize/models/attachment_synchronize_task.py @@ -111,7 +111,6 @@ class AttachmentSynchronizeTask(models.Model): record["count_attachment_{}".format(state)] = \ len(record.attachment_ids.filtered(lambda r: r.state == state)) - def _prepare_attachment_vals(self, data, filename): self.ensure_one() vals = { @@ -219,5 +218,15 @@ class AttachmentSynchronizeTask(models.Model): task.attachment_ids.filtered(lambda a: a.state == "pending").run() def button_duplicate_record(self): - self.ensure_one() - self.copy({"active": 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) diff --git a/attachment_synchronize/views/attachment_synchronize_task_views.xml b/attachment_synchronize/views/attachment_synchronize_task_views.xml index e25082bdd..76a4ed76d 100644 --- a/attachment_synchronize/views/attachment_synchronize_task_views.xml +++ b/attachment_synchronize/views/attachment_synchronize_task_views.xml @@ -90,8 +90,8 @@