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

Conversation

AungKoKoLin1997
Copy link
Contributor

Before this PR, when two templates exist for the same model, clicking ADD EXPORT ACTION for each template
creates separate server actions for each. As a result, if multiple templates are created for the same model,
numerous server actions with the label Export Excel will accumulate for that model.

With this PR, if two templates exist for the same model and ADD EXPORT ACTION is clicked for each,
they will now share a single server action. Users can then select templates from within the Export Excel wizard.
Clicking REMOVE EXPORT ACTION on a template will remove only that template from the Export Excel selection.
The server action itself will be deleted only when no templates use it for export.

@qrtl QT4815

@AungKoKoLin1997 AungKoKoLin1997 changed the title [15.0][IMP] excel_import_export: excel_import_export: allow selection of all related templates for export action [15.0][IMP] excel_import_export: allow selection of all related templates for export action Oct 26, 2024
Comment on lines 125 to 127
is_display = fields.Boolean(
help="Technical field to control template visibility in server actions."
)
Copy link
Member

Choose a reason for hiding this comment

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

I think is_available may make a better name.

Copy link
Member

Choose a reason for hiding this comment

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

On second thought, we can actually remove this field. Just adjust template_domain of the export action context to use export_action_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer second option to avoid adding new field.

@@ -431,29 +434,51 @@ def _compute_output_instruction(self):

def add_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.

I think this method can be restructured in the following manner for better readability:

    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
        self.is_available = True

}
action = self.env["ir.actions.act_window"].create(vals)
self.export_action_id = action
self.is_display = True

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

@OCA-git-bot
Copy link
Contributor

Hi @kittiu,
some modules you are maintaining are being modified, check this out!

Comment on lines 470 to 478
if not self.search(
[
("res_model", "=", self.res_model),
("export_action_id", "!=", False),
("id", "!=", self.id),
]
):
self.export_action_id.unlink()
self.export_action_id = False
Copy link
Member

Choose a reason for hiding this comment

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

The condition ("export_action_id", "!=", False) is probably not optimal, considering there could be cases where multiple export actions exist for a model.

Suggested change
if not self.search(
[
("res_model", "=", self.res_model),
("export_action_id", "!=", False),
("id", "!=", self.id),
]
):
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()

…l related templates for export action

Before this commit, when two templates exist for the same model, clicking "ADD EXPORT ACTION" for each template
creates separate server actions for each. As a result, if multiple templates are created for the same model,
numerous server actions with the label "Export Excel" will accumulate for that model.
With this commit, if two templates exist for the same model and "ADD EXPORT ACTION" is clicked for each,
they will now share a single server action. Users can then select templates from within the "Export Excel" wizard.
Clicking "REMOVE EXPORT ACTION" on a template will remove only that template from the "Export Excel" selection.
The server action itself will be deleted only when no templates use it for export.
Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

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

Code review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants