From 184cd4ed03e2189566c17e5515882fc527b3c1e3 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 9 Oct 2024 09:52:40 +0000 Subject: [PATCH 1/3] [IMP] excel_import_export: remove fname check from domain for export to allow all templates selectable --- excel_import_export/models/xlsx_template.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/excel_import_export/models/xlsx_template.py b/excel_import_export/models/xlsx_template.py index ffddf14..da9f17b 100644 --- a/excel_import_export/models/xlsx_template.py +++ b/excel_import_export/models/xlsx_template.py @@ -442,10 +442,9 @@ def add_export_action(self): "view_mode": "form", "context": """ {'template_domain': [('res_model', '=', '%s'), - ('fname', '=', '%s'), ('gname', '=', False)]} """ - % (self.res_model, self.fname), + % (self.res_model), } action = self.env["ir.actions.act_window"].create(vals) self.export_action_id = action From 926709b1b8f999afd0fa1d80008ca88dcb2c4013 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Fri, 25 Oct 2024 10:38:16 +0000 Subject: [PATCH 2/3] adj --- excel_import_export/models/xlsx_template.py | 36 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/excel_import_export/models/xlsx_template.py b/excel_import_export/models/xlsx_template.py index da9f17b..ff1a030 100644 --- a/excel_import_export/models/xlsx_template.py +++ b/excel_import_export/models/xlsx_template.py @@ -122,6 +122,9 @@ class XLSXTemplate(models.Model): comodel_name="ir.actions.report", string="Report Action", ) + is_display = fields.Boolean( + help="Technical field to control template visibility in server actions." + ) def _compute_result_field(self): for rec in self: @@ -431,28 +434,51 @@ def _compute_output_instruction(self): def add_export_action(self): self.ensure_one() + model = self.env["ir.model"].search([("model", "=", self.res_model)], limit=1) + # Check if an action already exists for this binding_model_id + existing_action = self.env["ir.actions.act_window"].search( + [ + ("binding_model_id", "=", model.id), + ("res_model", "=", "export.xlsx.wizard"), + ("name", "=", "Export Excel"), + ], + limit=1, + ) + if existing_action: + self.export_action_id = existing_action + self.is_display = True + return vals = { "name": "Export Excel", "res_model": "export.xlsx.wizard", - "binding_model_id": self.env["ir.model"] - .search([("model", "=", self.res_model)]) - .id, + "binding_model_id": model.id, "binding_type": "action", "target": "new", "view_mode": "form", "context": """ {'template_domain': [('res_model', '=', '%s'), - ('gname', '=', False)]} + ('is_display', '=', True), + ('gname', '=', False)]} """ % (self.res_model), } action = self.env["ir.actions.act_window"].create(vals) self.export_action_id = action + self.is_display = True def remove_export_action(self): self.ensure_one() if self.export_action_id: - self.export_action_id.unlink() + self.is_display = False + other_template = self.search( + [ + ("export_action_id", "=", self.export_action_id.id), + ("id", "!=", self.id), + ] + ) + if not other_template: + self.export_action_id.unlink() + self.export_action_id = False def add_import_action(self): self.ensure_one() From 35c2f440674762b58bd13aa6f6a01e85c7347bf1 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Tue, 29 Oct 2024 04:16:43 +0000 Subject: [PATCH 3/3] upd --- excel_import_export/models/xlsx_template.py | 65 ++++++++++----------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/excel_import_export/models/xlsx_template.py b/excel_import_export/models/xlsx_template.py index ff1a030..74dc463 100644 --- a/excel_import_export/models/xlsx_template.py +++ b/excel_import_export/models/xlsx_template.py @@ -122,9 +122,6 @@ class XLSXTemplate(models.Model): comodel_name="ir.actions.report", string="Report Action", ) - is_display = fields.Boolean( - help="Technical field to control template visibility in server actions." - ) def _compute_result_field(self): for rec in self: @@ -432,22 +429,18 @@ def _compute_output_instruction(self): inst_dict[itype] = rec.post_import_hook rec.instruction = inst_dict - def add_export_action(self): - self.ensure_one() - model = self.env["ir.model"].search([("model", "=", self.res_model)], limit=1) - # Check if an action already exists for this binding_model_id - existing_action = self.env["ir.actions.act_window"].search( - [ - ("binding_model_id", "=", model.id), - ("res_model", "=", "export.xlsx.wizard"), - ("name", "=", "Export Excel"), - ], - limit=1, - ) - if existing_action: - self.export_action_id = existing_action - self.is_display = True - return + def _get_export_action_domain(self, model): + return [ + ("binding_model_id", "=", model.id), + ("res_model", "=", "export.xlsx.wizard"), + ("name", "=", "Export Excel"), + ] + + def _get_export_action(self, model): + export_action_domain = self._get_export_action_domain(model) + return self.env["ir.actions.act_window"].search(export_action_domain, limit=1) + + def _create_export_action(self, model): vals = { "name": "Export Excel", "res_model": "export.xlsx.wizard", @@ -457,28 +450,32 @@ def add_export_action(self): "view_mode": "form", "context": """ {'template_domain': [('res_model', '=', '%s'), - ('is_display', '=', True), + ('export_action_id', '!=', False), ('gname', '=', False)]} """ % (self.res_model), } - action = self.env["ir.actions.act_window"].create(vals) - self.export_action_id = action - self.is_display = True + return self.env["ir.actions.act_window"].create(vals) + + def add_export_action(self): + self.ensure_one() + model = self.env["ir.model"].search([("model", "=", self.res_model)], limit=1) + export_action = self._get_export_action(model) + if not export_action: + export_action = self._create_export_action(model) + self.export_action_id = export_action def remove_export_action(self): self.ensure_one() - if self.export_action_id: - self.is_display = False - other_template = self.search( - [ - ("export_action_id", "=", self.export_action_id.id), - ("id", "!=", self.id), - ] - ) - if not other_template: - self.export_action_id.unlink() - self.export_action_id = False + export_action = self.export_action_id + self.export_action_id = False + if not self.search( + [ + ("res_model", "=", self.res_model), + ("export_action_id", "=", export_action.id), + ] + ): + export_action.unlink() def add_import_action(self): self.ensure_one()