Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class WorkflowTransition(ModelSQL, ModelView):
"Workflow transition"
_table = "wkf_transition"
_name = "workflow.transition"
_rec_name = 'signal'
_description = __doc__
trigger_model = fields.Char('Trigger Type')
trigger_expr_id = fields.Char('Trigger Expr ID')
signal = fields.Char('Signal (button Name)')
group = fields.Many2One('res.group', 'Group Required')
condition = fields.Char('Condition', required=True)
act_from = fields.Many2One('workflow.activity', 'Source Activity',
required=True, select=1, ondelete='CASCADE')
act_to = fields.Many2One('workflow.activity', 'Destination Activity',
required=True, select=1, ondelete='CASCADE')
instances = fields.Many2Many('workflow.transition-workflow.instance',
'trans_id', 'inst_id')
def default_condition(self, cursor, user, context=None):
return 'True'
WorkflowTransition()
class WorkflowInstance(ModelSQL, ModelView):
"Workflow instance"
_table = "wkf_instance"
_name = "workflow.instance"
_rec_name = 'res_type'
_description = __doc__
:license: GPLv3, see LICENSE for more details.
"""
from trytond.pool import PoolMeta, Pool
from trytond.model import ModelSQL, fields
__all__ = ['Company', 'CompanyProjectAdmins']
__metaclass__ = PoolMeta
class Company:
"""
Add project admins to company
"""
__name__ = "company.company"
project_admins = fields.Function(
fields.One2Many("nereid.user", None, "Project Admins"),
'get_admins'
)
project_managers = fields.Function(
fields.One2Many("nereid.user", None, "Project Managers"),
'get_admins'
)
def get_admins(self, name):
"""
Returns all the nereid users who are admin for this company
"""
NereidUser = Pool().get('nereid.user')
assert name in ('project_admins', 'project_managers')
def is_leaf(expression):
return (isinstance(expression, (list, tuple))
and len(expression) > 2
and isinstance(expression[1], str)
and expression[1] in OPERATORS) # TODO remove OPERATORS test
class ModelStorage(Model):
"""
Define a model with storage capability in Tryton.
"""
__slots__ = ('_transaction', '_user', '_context', '_ids',
'_transaction_cache', '_local_cache')
create_uid = fields.Many2One(
'res.user', lazy_gettext('ir.msg_created_by'), readonly=True)
create_date = fields.Timestamp(
lazy_gettext('ir.msg_created_by'), readonly=True)
write_uid = fields.Many2One(
'res.user', lazy_gettext('ir.msg_edited_by'), readonly=True)
write_date = fields.Timestamp(
lazy_gettext('ir.msg_edited_at'), readonly=True)
rec_name = fields.Function(
fields.Char(lazy_gettext('ir.msg_record_name')), 'get_rec_name',
searcher='search_rec_name')
@classmethod
def __setup__(cls):
super(ModelStorage, cls).__setup__()
if issubclass(cls, ModelView):
cls.__rpc__.update({
from trytond.tools import grouped_slice, reduce_ids
from trytond.transaction import Transaction
from .resource import ResourceMixin, resource_copy
__all__ = ['NoteCopyMixin']
class Note(ResourceMixin, ModelSQL, ModelView):
"Note"
__name__ = 'ir.note'
message = fields.Text('Message', states={
'readonly': Eval('id', 0) > 0,
})
message_wrapped = fields.Function(fields.Text('Message'),
'on_change_with_message_wrapped')
unread = fields.Function(fields.Boolean('Unread'), 'get_unread',
searcher='search_unread', setter='set_unread')
@staticmethod
def default_unread():
return False
@classmethod
def get_wrapper(cls):
return TextWrapper(width=79)
@fields.depends('message')
def on_change_with_message_wrapped(self, name=None):
wrapper = self.get_wrapper()
message = self.message or ''
return '\n'.join(map(wrapper.fill, message.splitlines()))
# Restart the cache on the get_triggers method of ir.trigger
cls._get_triggers_cache.clear()
@classmethod
def delete(cls, records):
super(Trigger, cls).delete(records)
# Restart the cache on the get_triggers method of ir.trigger
cls._get_triggers_cache.clear()
class TriggerLog(ModelSQL):
'Trigger Log'
__name__ = 'ir.trigger.log'
trigger = fields.Many2One(
'ir.trigger', 'Trigger', required=True, ondelete='CASCADE')
record_id = fields.Integer('Record ID', required=True)
@classmethod
def __register__(cls, module_name):
super(TriggerLog, cls).__register__(module_name)
table = cls.__table_handler__(module_name)
table.index_action(['trigger', 'record_id'], 'add')
domain = [('code', '=', code)] + cls.language.domain
try:
lang, = Lang.search(domain, limit=1)
return lang.id
except ValueError:
return None
class TranslationExportResult(ModelView):
"Export translation"
__name__ = 'ir.translation.export.result'
language = fields.Many2One('ir.lang', 'Language', readonly=True)
module = fields.Many2One('ir.module', 'Module', readonly=True)
file = fields.Binary('File', readonly=True, filename='filename')
filename = fields.Char('Filename')
class TranslationExport(Wizard):
"Export translation"
__name__ = "ir.translation.export"
start = StateView('ir.translation.export.start',
'ir.translation_export_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Export', 'export', 'tryton-ok', default=True),
])
export = StateTransition()
result = StateView('ir.translation.export.result',
'ir.translation_export_result_view_form', [
Button('Close', 'end', 'tryton-close'),
])
@staticmethod
def current_user_privilege_set(uri, cache=None):
return ['create', 'read', 'write', 'delete']
class Share(ModelSQL, ModelView):
"Share"
__name__ = 'webdav.share'
_rec_name = 'key'
path = fields.Char('Path', required=True, select=True)
key = fields.Char('Key', required=True, select=True,
states={
'readonly': True,
})
user = fields.Many2One('res.user', 'User', required=True)
expiration_date = fields.Date('Expiration Date', required=True)
note = fields.Text('Note')
url = fields.Function(fields.Char('URL'), 'get_url')
@staticmethod
def default_key():
return uuid.uuid4().hex
@staticmethod
def default_user():
return Transaction().user
@staticmethod
def default_expiration_date():
return datetime.date.today() + relativedelta(months=1)
return self.get_action_values(
self.type, [self.get_action_id(self.id)])[0]
class ActionKeyword(ModelSQL, ModelView):
"Action keyword"
__name__ = 'ir.action.keyword'
keyword = fields.Selection([
('tree_open', 'Open tree'),
('form_print', 'Print form'),
('form_action', 'Action form'),
('form_relate', 'Form relate'),
('graph_open', 'Open Graph'),
], string='Keyword', required=True)
model = fields.Reference('Model', selection='models_get')
action = fields.Many2One('ir.action', 'Action',
ondelete='CASCADE', select=True)
groups = fields.Function(fields.One2Many('res.group', None, 'Groups'),
'get_groups', searcher='search_groups')
_get_keyword_cache = Cache('ir_action_keyword.get_keyword')
@classmethod
def __setup__(cls):
super(ActionKeyword, cls).__setup__()
cls.__rpc__.update({
'get_keyword': RPC(cache=dict(days=1)),
})
@classmethod
def __register__(cls, module_name):
super(ActionKeyword, cls).__register__(module_name)
def search_out_of_sync(cls, name, clause):
table = cls.__table__()
name, operator, value = clause
Operator = fields.SQL_OPERATORS[operator]
query = table.select(table.id,
where=Operator(
(table.fs_values != table.values) & (table.fs_values != Null),
value))
return [('id', 'in', query)]