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

[16.0][ADD] confirmation_wizard #942

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

geomer198
Copy link

@geomer198 geomer198 commented Aug 27, 2024

The module lets the developer trigger a confirmation wizard during any action in Odoo.
Based on data passed to the wizard and, based on user input, executes specified methods or close wizard.

@geomer198 geomer198 force-pushed the 16.0-t3893-confirmation_wizard-add branch 3 times, most recently from 73f9b19 to af7b05b Compare August 27, 2024 21:53


class ConfirmationMessageWizard(models.TransientModel):
_name = "confirmation.message.wizard"
Copy link
Member

Choose a reason for hiding this comment

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

The class name ConfirmationMessageWizard can be simplified to ConfirmationWizard. A shorter name improves readability without losing its meaning. And the same for _name = confirmation.wizard

_name = "confirmation.message.wizard"
_description = "Confirmation Wizard"

text = fields.Char(string="Confirm Message", required=True)
Copy link
Member

Choose a reason for hiding this comment

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

The field text should be renamed to message to make its purpose clearer, especially in the context of a confirmation dialog.

Comment on lines 28 to 35
def _prepare_action(self, title=None):
action = self.env["ir.actions.actions"]._for_xml_id(
"confirmation_wizard.confirmation_message_wizard_action"
)
if title:
action["name"] = title
action["context"] = self._context
return action
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _prepare_action(self, title=None):
action = self.env["ir.actions.actions"]._for_xml_id(
"confirmation_wizard.confirmation_message_wizard_action"
)
if title:
action["name"] = title
action["context"] = self._context
return action
def _prepare_action(self, title=None):
action = self.env["ir.actions.actions"]._for_xml_id(
"confirmation_wizard.confirmation_wizard_action"
)
action.update({
"name": title or _("Confirmation"),
"context": self._context,
})
return action


@api.model
def confirm_message(
self, text, records, title=None, method=None, callback_params=None
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self, text, records, title=None, method=None, callback_params=None
self, message, records, title=None, method=None, callback_params=None

Comment on lines 41 to 52
callback_params = callback_params or {}
res_ids = ",".join(map(str, records.ids))
wizard = self.create(
{
"text": text,
"res_ids": res_ids,
"return_type": "method",
"res_model": records._name,
"callback_method": method,
"callback_params": callback_params,
}
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
callback_params = callback_params or {}
res_ids = ",".join(map(str, records.ids))
wizard = self.create(
{
"text": text,
"res_ids": res_ids,
"return_type": "method",
"res_model": records._name,
"callback_method": method,
"callback_params": callback_params,
}
)
wizard = self.create(
{
"message": text,
"res_ids": repr(records.ids),
"return_type": "method",
"res_model": records._name,
"callback_method": method,
"callback_params": callback_params or {},
}
)


def _confirm_method(self):
if self.res_ids:
res_ids = map(int, self.res_ids.split(","))
Copy link
Member

Choose a reason for hiding this comment

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

use this way:

from ast import literal_eval

res_ids = literal_eval(self.res_ids) if self.record_ids else []

records = self.env[self.res_model].browse(res_ids)
if not records.exists():
raise models.UserError(
_(f"Records (IDS: {self.res_ids}) not found in model {self.res_model}.")
Copy link
Member

Choose a reason for hiding this comment

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

please, don't use f-string, translations may not work:

_("Records (IDS: '%(ids)s') not found in model '%(model)s'.")

raise models.UserError(
_(f"Records (IDS: {self.res_ids}) not found in model {self.res_model}.")
)
if not (records and hasattr(records, self.callback_method)):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if not (records and hasattr(records, self.callback_method)):
if not hasattr(records, self.callback_method):

_(f"Records (IDS: {self.res_ids}) not found in model {self.res_model}.")
)
if not (records and hasattr(records, self.callback_method)):
raise models.UserError(_(f"Method ({self.callback_method}) is not found!"))
Copy link
Member

Choose a reason for hiding this comment

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

don't use f-string

"Method '%(callback_method)s' is not found on model '%(res_model)s'."

("window_close", "Return Window Close Action"),
("method", "Return Method"),
],
default="window_close",
Copy link
Member

Choose a reason for hiding this comment

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

required=True

@geomer198 geomer198 force-pushed the 16.0-t3893-confirmation_wizard-add branch 2 times, most recently from 9c83ede to d78f015 Compare August 28, 2024 18:54
Copy link

@Bearnard21 Bearnard21 left a comment

Choose a reason for hiding this comment

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

Functionality Tested LGTM

@OCA-git-bot
Copy link
Contributor

Sorry @Bearnard21 you are not allowed to rebase.

To do so you must either have push permissions on the repository, or be a declared maintainer of all modified addons.

If you wish to adopt an addon and become it's maintainer, open a pull request to add your GitHub login to the maintainers key of its manifest.

@geomer198 geomer198 force-pushed the 16.0-t3893-confirmation_wizard-add branch 2 times, most recently from cebe087 to 7b9b96f Compare August 31, 2024 15:57
@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@geomer198 geomer198 force-pushed the 16.0-t3893-confirmation_wizard-add branch from bd8d75a to 1babaf2 Compare September 23, 2024 13:43
@geomer198 geomer198 force-pushed the 16.0-t3893-confirmation_wizard-add branch from 00f10b0 to 62467bd Compare October 21, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants