Files
tryton/ir.py
T
Cédric Krier 81814eea17 Fix flake8 errors and warnings
We add the flake8 configuration used so we ensure everyone uses the same.
We remove the usage of __all__ for non public API.
When possible, we rationalize the class name according to its __name__ and module.

issue9082
review297061002
2020-03-01 12:33:52 +01:00

49 lines
1.7 KiB
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
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,
},
depends=['action_function', 'action_model_name'])
action_model_name = fields.Function(
fields.Char("Action Model Name"), 'on_change_with_action_model_name')
del _required
@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('notification_email', '_parent_notification_email.model')
def on_change_notification_email(self):
pool = Pool()
Model = pool.get('ir.model')
if self.notification_email:
try:
trigger_model, = Model.search([
('model', '=', self.notification_email.model),
])
except ValueError:
pass
else:
self.model = trigger_model
notification_model, = Model.search([
('model', '=', 'notification.email'),
])
self.action_model = notification_model
self.action_function = 'trigger'