-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Hi @OCA/server-environment-maintainers, any chances to have this reviewed and merged? |
62467bd
to
c7d0a9f
Compare
@ivs-cetmix @GabbasovDinar People might have different opinions, but mine is that such a simple tool might get a broader adoption if licensed under LGPL rather than AGPL. Many companies would simply replicate the feature without adopting it if licensed as AGPL. In a word, my opinion is simple framework tools are better licensed under LGPL. But of course the choice is yours and this won't impact for merging the contrib. |
Sounds reasonable, we will change the license to "LGPL-3". |
697a715
to
420be3b
Compare
7a90287
to
efe6033
Compare
confirmation_wizard/readme/USAGE.rst
Outdated
# Confirmation wizard | ||
return ( | ||
self.env["confirmation.wizard"] | ||
.with_context(skip_confirm=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.
I don't see how skip_confirm
is being implemented, do I miss anything?
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.
I don't see how
skip_confirm
is being implemented, do I miss anything?
if not self._context("skip_confirm", False):
This line is before confirm_message
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.
I understand, but it means the developer who is using this confirmation wizard need to implement a context checking, e.g skip_confirm, every time we invoke the wizard. This seems redundant to me
Confirm message with close window return type | ||
:param message: confirmation message | ||
:param title: wizard title | ||
:return dict: ir actions act window dict |
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.
You should include invisible_cancel
as a special context here and how it works. I think it should be show_cancel
is False to hide it, default to True, or hide_cancel
is True to hide the Cancel button. invisible_cancel
isn't a proper word in english
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.
You should include
invisible_cancel
as a special context here and how it works. I think it should beshow_cancel
is False to hide it, default to True, orhide_cancel
is True to hide the Cancel button.invisible_cancel
isn't a proper word in english
This context key used as special configuration and use to all methods where confirmation wizard call. This functional is describe in USAGE.rst file.
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.
even it's already been in the documentation, it's a good thing to put that context in this docstring as well as they are closely used together
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.
Code LGTM
@@ -0,0 +1,122 @@ | |||
# Copyright (C) 2024 Cetmix OÜ | |||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
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.
@ivs-cetmix seems you guys ended up changing the license for LGPL in the manifest file but kept AGPL in the file headers, making the whole inconsistent. Pick the one you want but it should be consistent... cc @geomer198
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.