How to use the trytond.model.fields function in trytond

To help you get started, we’ve selected a few trytond examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tryton / trytond / trytond / workflow / View on Github external
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('', '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'


class WorkflowInstance(ModelSQL, ModelView):
    "Workflow instance"
    _table = "wkf_instance"
    _name = "workflow.instance"
    _rec_name = 'res_type'
    _description = __doc__
github openlabs / nereid-project / View on Github external
: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__ = ""

    project_admins = fields.Function(
        fields.One2Many("nereid.user", None, "Project Admins"),

    project_managers = fields.Function(
        fields.One2Many("nereid.user", None, "Project Managers"),

    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')
github tryton / trytond / trytond / model / View on Github external
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',

    def __setup__(cls):
        super(ModelStorage, cls).__setup__()
        if issubclass(cls, ModelView):
github tryton / trytond / trytond / ir / View on Github external
from import grouped_slice, reduce_ids
from trytond.transaction import Transaction
from .resource import ResourceMixin, resource_copy

__all__ = ['NoteCopyMixin']

class Note(ResourceMixin, ModelSQL, ModelView):
    __name__ = 'ir.note'
    message = fields.Text('Message', states={
            'readonly': Eval('id', 0) > 0,
    message_wrapped = fields.Function(fields.Text('Message'),
    unread = fields.Function(fields.Boolean('Unread'), 'get_unread',
        searcher='search_unread', setter='set_unread')

    def default_unread():
        return False

    def get_wrapper(cls):
        return TextWrapper(width=79)

    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()))
github tryton / trytond / trytond / ir / View on Github external
# Restart the cache on the get_triggers method of ir.trigger

    def delete(cls, records):
        super(Trigger, cls).delete(records)
        # Restart the cache on the get_triggers method of ir.trigger

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)

    def __register__(cls, module_name):
        super(TriggerLog, cls).__register__(module_name)

        table = cls.__table_handler__(module_name)
        table.index_action(['trigger', 'record_id'], 'add')
github tryton / trytond / trytond / ir / View on Github external
domain = [('code', '=', code)] + cls.language.domain
            lang, =, limit=1)
        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'),
github tryton / trytond / trytond / webdav / View on Github external
    def current_user_privilege_set(uri, cache=None):
        return ['create', 'read', 'write', 'delete']

class Share(ModelSQL, ModelView):
    __name__ = 'webdav.share'
    _rec_name = 'key'

    path = fields.Char('Path', required=True, select=True)
    key = fields.Char('Key', required=True, select=True,
            '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')

    def default_key():
        return uuid.uuid4().hex

    def default_user():
        return Transaction().user

    def default_expiration_date():
        return + relativedelta(months=1)
github tryton / trytond / trytond / ir / View on Github external
return self.get_action_values(
            self.type, [self.get_action_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('', None, 'Groups'),
        'get_groups', searcher='search_groups')
    _get_keyword_cache = Cache('ir_action_keyword.get_keyword')

    def __setup__(cls):
        super(ActionKeyword, cls).__setup__()
                'get_keyword': RPC(cache=dict(days=1)),

    def __register__(cls, module_name):
        super(ActionKeyword, cls).__register__(module_name)
github tryton / trytond / trytond / ir / View on Github external
def search_out_of_sync(cls, name, clause):
        table = cls.__table__()
        name, operator, value = clause
        Operator = fields.SQL_OPERATORS[operator]
        query =,
                (table.fs_values != table.values) & (table.fs_values != Null),
        return [('id', 'in', query)]