Add launch_action helper function

This commit is contained in:
Nicolas Évrard
2025-03-07 19:06:04 +01:00
parent 1f414b20e5
commit 1e5fa01e63
3 changed files with 72 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add launch_action helper function
Version 7.4.0 - 2024-11-04
--------------------------
+22
View File
@@ -1312,6 +1312,28 @@ class Report(object):
return self._proxy.execute(ids, data, self._context)
def launch_action(xml_id, records, context=None, config=None):
if records:
assert len({type(x) for x in records}) == 1
if context is None:
context = {}
if isinstance(xml_id, str):
ModelData = Model.get('ir.model.data')
if not config:
config = proteus.config.get_config()
context = config.context
action_id = ModelData.get_id(*xml_id.split('.'), context)
elif isinstance(xml_id, int):
action_id = xml_id
Action = Model.get('ir.action')
action = Action.get_action_value(action_id, context)
return _convert_action(action, records, context=context, config=config)
def _convert_action(action, data=None, *, context=None, config=None):
if config is None:
config = proteus.config.get_config()
+49
View File
@@ -0,0 +1,49 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import unittest
try:
import pydot
except ImportError:
pydot = None
from proteus import Model, Wizard, launch_action
from .common import ProteusTestCase
class TestAction(ProteusTestCase):
def test_act_window(self):
IrModel = Model.get('ir.model')
actions = IrModel.find([
('name', '=', 'ir.action'),
])
model_access = launch_action(
'ir.act_model_access_form_relate_model', actions)
self.assertEqual(
{m.__class__.__name__ for m in model_access},
{'ir.model.access'})
def test_wizard(self):
IrModel = Model.get('ir.model')
actions = IrModel.find([
('name', '=', 'ir.action'),
])
wizard = launch_action('ir.print_model_graph', actions)
self.assertIsInstance(wizard, Wizard)
self.assertEqual(wizard.name, 'ir.model.print_model_graph')
@unittest.skipIf(not pydot, 'requires pydot')
def test_report(self):
IrModel = Model.get('ir.model')
actions = IrModel.find([
('name', '=', 'ir.action'),
])
ftype, data, direct_print, report_name = launch_action(
'ir.report_model_workflow_graph', actions)
self.assertIsInstance(ftype, str)
self.assertIsInstance(data, bytes)
self.assertIsInstance(direct_print, bool)
self.assertIsInstance(report_name, str)