Skip to content

Commit

Permalink
[FIX] confirmation_wizard: docstrings are added and _prepare_action m…
Browse files Browse the repository at this point in the history
…ethod is fixed
  • Loading branch information
geomer198 committed Aug 31, 2024
1 parent a2fdca1 commit cebe087
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion confirmation_wizard/wizard/confirmation_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class ConfirmationWizard(models.TransientModel):

@api.model
def _prepare_action(self, title=None):
action = self.env["ir.actions.actions"]._for_xml_id(
"""
Prepare confirmation wizard
:param title: wizard title
"""
action = self.env["ir.actions.act_window"]._for_xml_id(
"confirmation_wizard.confirmation_wizard_action"
)
action.update(
Expand All @@ -43,6 +47,15 @@ def _prepare_action(self, title=None):
def confirm_message(
self, message, records, title=None, method=None, callback_params=None
):
"""
Confirm message with method return type
:param message: confirmation message
:param records: record set
:param title: wizard title
:param method: triggered method
:param callback_params: method arguments
:return dict: ir actions act window dict
"""
wizard = self.create(
{
"message": message,
Expand All @@ -57,6 +70,12 @@ def confirm_message(

@api.model
def confirm_no_action_message(self, message, title=None):
"""
Confirm message with close window return type
:param message: confirmation message
:param title: wizard title
:return dict: ir actions act window dict
"""
wizard = self.create(
{
"message": message,
Expand All @@ -66,9 +85,11 @@ def confirm_no_action_message(self, message, title=None):
return wizard._prepare_action(title)

def _confirm_window_close(self):
"""Action confirm for return type window close"""
return {"type": "ir.actions.act_window_close"}

def _confirm_method(self):
"""Action confirm for return type method"""
res_ids = literal_eval(self.res_ids) if self.res_ids else []
records = self.env[self.res_model].browse(res_ids)
if not records.exists():
Expand All @@ -84,5 +105,6 @@ def _confirm_method(self):
return getattr(records, self.callback_method)(**self.callback_params)

def action_confirm(self):
"""Action confirm wizard"""
method = getattr(self, f"_confirm_{self.return_type}", None)
return method()

0 comments on commit cebe087

Please sign in to comment.