Simplify trigger action
We use now a selection field to choose the action to trigger. It is safer and more user friendly. issue9096 review272961003
This commit is contained in:
@@ -8,25 +8,27 @@ from trytond.pyson import Eval
|
||||
class Trigger(metaclass=PoolMeta):
|
||||
__name__ = 'ir.trigger'
|
||||
|
||||
_required = ((Eval('action_function') == 'trigger')
|
||||
& (Eval('action_model_name') == 'notification.email'))
|
||||
|
||||
notification_email = fields.Many2One(
|
||||
'notification.email', "Email Notification", readonly=True,
|
||||
states={
|
||||
'required': _required,
|
||||
'invisible': ~_required,
|
||||
'required': Eval('notification_email_required', False),
|
||||
'invisible': ~Eval('notification_email_required', False),
|
||||
},
|
||||
depends=['action_function', 'action_model_name'])
|
||||
action_model_name = fields.Function(
|
||||
fields.Char("Action Model Name"), 'on_change_with_action_model_name')
|
||||
depends=['notification_email_required'])
|
||||
notification_email_required = fields.Function(
|
||||
fields.Boolean("Notification Email Required"),
|
||||
'on_change_with_notification_email_required')
|
||||
|
||||
del _required
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.action.selection.append(
|
||||
('notification.email|trigger', "Email Notification"),
|
||||
)
|
||||
|
||||
@fields.depends('action_model')
|
||||
def on_change_with_action_model_name(self, name=None):
|
||||
if self.action_model:
|
||||
return self.action_model.model
|
||||
@fields.depends('action')
|
||||
def on_change_with_notification_email_required(self, name=None):
|
||||
return self.action == 'notification.email|trigger'
|
||||
|
||||
@fields.depends('notification_email', '_parent_notification_email.model')
|
||||
def on_change_notification_email(self):
|
||||
@@ -41,8 +43,4 @@ class Trigger(metaclass=PoolMeta):
|
||||
pass
|
||||
else:
|
||||
self.model = trigger_model
|
||||
notification_model, = Model.search([
|
||||
('model', '=', 'notification.email'),
|
||||
])
|
||||
self.action_model = notification_model
|
||||
self.action_function = 'trigger'
|
||||
self.action = 'notification.email|trigger'
|
||||
|
||||
@@ -38,9 +38,6 @@ class NotificationEmailTestCase(ModuleTestCase):
|
||||
model, = Model.search([
|
||||
('model', '=', User.__name__),
|
||||
])
|
||||
action_model, = Model.search([
|
||||
('model', '=', 'notification.email'),
|
||||
])
|
||||
|
||||
action = Action(name="Notification Email", type='ir.action.report')
|
||||
action.save()
|
||||
@@ -91,17 +88,13 @@ class NotificationEmailTestCase(ModuleTestCase):
|
||||
model, = Model.search([
|
||||
('model', '=', User.__name__),
|
||||
])
|
||||
action_model, = Model.search([
|
||||
('model', '=', 'notification.email'),
|
||||
])
|
||||
Trigger.create([{
|
||||
'name': 'Test creation',
|
||||
'model': model.id,
|
||||
'on_create': True,
|
||||
'condition': 'true',
|
||||
'notification_email': notification_email.id,
|
||||
'action_model': action_model.id,
|
||||
'action_function': 'trigger',
|
||||
'action': 'notification.email|trigger',
|
||||
}])
|
||||
|
||||
with patch.object(
|
||||
@@ -141,9 +134,6 @@ class NotificationEmailTestCase(ModuleTestCase):
|
||||
model, = Model.search([
|
||||
('model', '=', User.__name__),
|
||||
])
|
||||
action_model, = Model.search([
|
||||
('model', '=', 'notification.email'),
|
||||
])
|
||||
en, = Language.search([('code', '=', 'en')])
|
||||
|
||||
attachment = Report()
|
||||
@@ -205,17 +195,13 @@ class NotificationEmailTestCase(ModuleTestCase):
|
||||
model, = Model.search([
|
||||
('model', '=', User.__name__),
|
||||
])
|
||||
action_model, = Model.search([
|
||||
('model', '=', 'notification.email'),
|
||||
])
|
||||
Trigger.create([{
|
||||
'name': 'Test creation',
|
||||
'model': model.id,
|
||||
'on_create': True,
|
||||
'condition': 'true',
|
||||
'notification_email': notification_email.id,
|
||||
'action_model': action_model.id,
|
||||
'action_function': 'trigger',
|
||||
'action': 'notification.email|trigger',
|
||||
}])
|
||||
|
||||
with patch.object(
|
||||
|
||||
Reference in New Issue
Block a user