Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def firstline(description):
try:
return next((x for x in description.splitlines() if x.strip()))
except StopIteration:
return ''
if config.getboolean('attachment', 'filestore', default=True):
file_id = 'file_id'
store_prefix = config.get('attachment', 'store_prefix', default=None)
else:
file_id = None
store_prefix = None
class Attachment(ResourceMixin, ModelSQL, ModelView):
"Attachment"
__name__ = 'ir.attachment'
name = fields.Char('Name', required=True)
type = fields.Selection([
('data', 'Data'),
('link', 'Link'),
], 'Type', required=True)
description = fields.Text('Description')
summary = fields.Function(fields.Char('Summary'), 'on_change_with_summary')
link = fields.Char('Link', states={
'invisible': Eval('type') != 'link',
}, depends=['type'])
data = fields.Binary('Data', filename='name',
file_id=file_id, store_prefix=store_prefix,
states={
'invisible': Eval('type') != 'data',
update=RPC(instantiate=0, readonly=False))
@classmethod
def update(cls, exports, fields):
pool = Pool()
Line = pool.get('ir.export.line')
to_delete = []
to_save = []
for export in exports:
to_delete.extend(export.export_fields)
to_save.extend(Line(export=export, name=f) for f in fields)
Line.delete(to_delete)
Line.save(to_save)
class ExportLine(_ClearCache, ModelSQL, ModelView):
"Export line"
__name__ = 'ir.export.line'
name = fields.Char('Name')
export = fields.Many2One('ir.export', 'Export', select=True, required=True,
ondelete='CASCADE')
def create(cls, vlist):
ModelView._view_toolbar_get_cache.clear()
return super().create(vlist)
@classmethod
def write(cls, *args):
ModelView._view_toolbar_get_cache.clear()
super().write(*args)
@classmethod
def delete(cls, records):
ModelView._view_toolbar_get_cache.clear()
super().delete(records)
class Export(_ClearCache, ModelSQL, ModelView):
"Export"
__name__ = "ir.export"
name = fields.Char('Name')
resource = fields.Char('Resource')
export_fields = fields.One2Many('ir.export.line', 'export',
'Fields')
@classmethod
def __setup__(cls):
super().__setup__()
cls.__rpc__.update(
update=RPC(instantiate=0, readonly=False))
@classmethod
def update(cls, exports, fields):
pool = Pool()
# 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 ModelSQL, fields
class Cache(ModelSQL):
"Cache"
__name__ = 'ir.cache'
name = fields.Char('Name', required=True)
timestamp = fields.DateTime('Timestamp')
('create_uid', 'in', users),
domain or [],
])
cls.delete(sessions)
@classmethod
def create(cls, vlist):
vlist = [v.copy() for v in vlist]
for values in vlist:
# Ensure to get a different key for each record
# default methods are called only once
values.setdefault('key', cls.default_key())
return super(Session, cls).create(vlist)
class SessionWizard(ModelSQL):
"Session Wizard"
__name__ = 'ir.session.wizard'
data = fields.Text('Data')
@classmethod
def __setup__(cls):
super(SessionWizard, cls).__setup__()
cls.__rpc__ = {}
@staticmethod
def default_data():
return json.dumps({})
" Contact your project admin for the same."
)
return redirect(request.referrer)
if request.method == 'POST' and request.is_xhr:
self.delete([self])
return jsonify({
'success': True,
})
flash("Could not delete tag! Try again.")
return redirect(request.referrer)
class TaskTags(ModelSQL):
'Task Tags'
__name__ = 'project.work-project.work.tag'
task = fields.Many2One(
'project.work', 'Project',
ondelete='CASCADE', select=1, required=True,
domain=[('type', '=', 'task')]
)
tag = fields.Many2One(
'project.work.tag', 'Tag', select=1, required=True, ondelete='CASCADE',
)
@classmethod
def __register__(cls, module_name):
'''
'tryton-refresh',
'tryton-remove',
'tryton-save',
'tryton-search',
'tryton-star-border',
'tryton-star',
'tryton-switch',
'tryton-translate',
'tryton-unarchive',
'tryton-undo',
'tryton-warning',
]]
class UIMenu(DeactivableMixin, sequence_ordered(), tree(separator=' / '),
ModelSQL, ModelView):
"UI menu"
__name__ = 'ir.ui.menu'
name = fields.Char('Menu', required=True, translate=True)
childs = fields.One2Many('ir.ui.menu', 'parent', 'Children')
parent = fields.Many2One('ir.ui.menu', 'Parent Menu', select=True,
ondelete='CASCADE')
groups = fields.Many2Many('ir.ui.menu-res.group',
'menu', 'group', 'Groups')
complete_name = fields.Function(fields.Char('Complete Name'),
'get_rec_name', searcher='search_rec_name')
icon = fields.Selection('list_icons', 'Icon', translate=False)
action = fields.Function(fields.Reference('Action',
selection=[
('', ''),
('ir.action.report', 'ir.action.report'),
('subflow', '=', instance.id),
], context=context)
workitem_obj.write(cursor, 0, workitem_ids, {
'state': 'complete',
}, context=context)
for workitem in workitem_obj.browse(cursor, user,
workitem_ids, context=context):
for act_name in act_names:
self.validate(cursor, user, workitem.instance,
signal='subflow.' + act_name, context=context)
return res
WorkflowInstance()
class WorkflowTransitionInstance(ModelSQL):
"Workflow Transition - Instance"
_name = 'workflow.transition-workflow.instance'
_table = 'wkf_witm_trans'
_description = __doc__
trans_id = fields.Many2One('workflow.transition', 'Transition',
ondelete='CASCADE', select=1, required=True)
inst_id = fields.Many2One('workflow.instance', 'Instance',
ondelete='CASCADE', select=1, required=True)
def fields_get(self, cursor, user, fields_names=None, context=None):
res = super(WorkflowTransitionInstance, self).fields_get(cursor, user,
fields_names=fields_names, context=context)
for field in res:
res[field]['readonly'] = True
return res
_PRIORITIES = [
('0', 'Low'),
('1', 'Normal'),
('2', 'High'),
]
_READONLY = If(Eval('state').in_(['waiting', 'closed']),
True,
If(Eval('state') == 'chatting',
Eval('act_from') != Eval('_user'),
False))
_DEPENDS = ['state', 'act_from']
class Request(ModelSQL, ModelView):
"Request"
__name__ = 'res.request'
name = fields.Char('Subject', states={
'readonly': _READONLY,
}, required=True, depends=_DEPENDS)
active = fields.Boolean('Active')
priority = fields.Selection(_PRIORITIES, 'Priority', states={
'readonly': _READONLY,
}, required=True, order_field='priority', depends=_DEPENDS)
act_from = fields.Many2One('res.user', 'From', required=True,
readonly=True)
act_to = fields.Many2One('res.user', 'To', required=True,
domain=[('active', '=', True)],
states={
'readonly': _READONLY,
}, depends=_DEPENDS)
pass
class LastTimestampError(ValidationError):
pass
class SequenceType(ModelSQL, ModelView):
"Sequence type"
__name__ = 'ir.sequence.type'
name = fields.Char('Sequence Name', required=True, translate=True)
code = fields.Char('Sequence Code', required=True)
class Sequence(DeactivableMixin, ModelSQL, ModelView):
"Sequence"
__name__ = 'ir.sequence'
_strict = False
name = fields.Char('Sequence Name', required=True, translate=True)
code = fields.Selection('code_get', 'Sequence Code', required=True,
states={
'readonly': Eval('context', {}).contains('code'),
})
prefix = fields.Char('Prefix')
suffix = fields.Char('Suffix')
type = fields.Selection([
('incremental', 'Incremental'),
('decimal timestamp', 'Decimal Timestamp'),
('hexadecimal timestamp', 'Hexadecimal Timestamp'),
], 'Type')