Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] excel_import_export: allow selection of all related templates for export action #3095

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions excel_import_export/models/xlsx_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,31 +429,53 @@ def _compute_output_instruction(self):
inst_dict[itype] = rec.post_import_hook
rec.instruction = inst_dict

def add_export_action(self):
self.ensure_one()
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",
"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'),
('fname', '=', '%s'),
('gname', '=', False)]}
('export_action_id', '!=', False),
('gname', '=', False)]}
"""
% (self.res_model, self.fname),
% (self.res_model),
}
action = self.env["ir.actions.act_window"].create(vals)
self.export_action_id = action
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be a bit more concise:

    def remove_export_action(self):
        self.ensure_one()
        self.is_available = False
        if not self.search(
            [("res_model", "=", self.res_model), ("is_available", "=", True)]
        ):
            self.export_action_id.unlink()
        self.export_action_id = False

self.ensure_one()
if self.export_action_id:
self.export_action_id.unlink()
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()
Expand Down
Loading