-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
base: 16.0
Are you sure you want to change the base?
Conversation
73f9b19
to
af7b05b
Compare
|
||
|
||
class ConfirmationMessageWizard(models.TransientModel): | ||
_name = "confirmation.message.wizard" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self, text, records, title=None, method=None, callback_params=None | |
self, message, records, title=None, method=None, callback_params=None |
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, | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(",")) |
There was a problem hiding this comment.
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}.") |
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!")) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required=True
9c83ede
to
d78f015
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality Tested LGTM
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 |
cebe087
to
7b9b96f
Compare
This PR has the |
bd8d75a
to
1babaf2
Compare
00f10b0
to
62467bd
Compare
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.