How to use the trytond.model.fields.One2Many 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
from import Report
from import exec_command_pipe
from trytond.backend import TableHandler
import expr
import base64

class Workflow(ModelSQL, ModelView):
    _name = "workflow"
    _table = "wkf"
    _description = __doc__
    name = fields.Char('Name', required=True, translate=True)
    model = fields.Char('Resource Model', required=True, select=1)
    on_create = fields.Boolean('On Create', select=2)
    activities = fields.One2Many('workflow.activity', 'workflow',

    def __init__(self):
        super(Workflow, self).__init__()
            'no_workflow_defined': 'No workflow defined!',

    def init(self, cursor, module_name):
        super(Workflow, self).init(cursor, module_name)
        table = TableHandler(cursor, self, module_name)

        # Migration from 1.2 rename osv into model
        if table.column_exist('osv'):
            cursor.execute('UPDATE "' + self._table + '" ' \
                    'SET model = osv')
github tryton / trytond / trytond / workflow / View on Github external

class WorkflowInstance(ModelSQL, ModelView):
    "Workflow instance"
    _table = "wkf_instance"
    _name = "workflow.instance"
    _rec_name = 'res_type'
    _description = __doc__
    workflow = fields.Many2One('workflow', 'Workflow', ondelete="RESTRICT",
    uid = fields.Integer('User ID')
    res_id = fields.Integer('Resource ID', required=True, select=1)
    res_type = fields.Char('Resource Model', required=True, select=1)
    state = fields.Char('State', required=True, select=1)
    overflows = fields.One2Many('workflow.workitem', 'subflow',
    transitions = fields.Many2Many('workflow.transition-workflow.instance',
            'inst_id', 'trans_id')
    workitems = fields.One2Many('workflow.workitem', 'instance', 'Workitems')

    def __init__(self):
        super(WorkflowInstance, self).__init__()
            'no_instance_defined': 'No workflow instance defined!',
        for i in ('create', 'write', 'delete', 'copy'):
            del self._rpc[i]
        #TODO add a constraint to have only one active instance by resource

    def init(self, cursor, module_name):
        super(WorkflowInstance, self).init(cursor, module_name)
github tryton / trytond / trytond / ir / View on Github external
        def wrapper(cls, modules):
            modules = [m for m in modules if m.state == state]
            return func(cls, modules)
        return wrapper
    return filter

class Module(ModelSQL, ModelView):
    __name__ = "ir.module"
    name = fields.Char("Name", readonly=True, required=True)
    version = fields.Function(fields.Char('Version'), 'get_version')
    dependencies = fields.One2Many('ir.module.dependency',
        'module', 'Dependencies', readonly=True)
    parents = fields.Function(fields.One2Many('ir.module', None, 'Parents'),
    childs = fields.Function(fields.One2Many('ir.module', None, 'Childs'),
    state = fields.Selection([
        ('not activated', 'Not Activated'),
        ('activated', 'Activated'),
        ('to upgrade', 'To be upgraded'),
        ('to remove', 'To be removed'),
        ('to activate', 'To be activated'),
        ], string='State', readonly=True)

    def __setup__(cls):
        super(Module, cls).__setup__()
        table = cls.__table__()
        cls._sql_constraints = [
github openlabs / nereid-project / View on Github external
'Participants', states={'invisible': Eval('type') != 'task'},

    #: Tags for tasks.
    tags = fields.Many2Many(
        '', 'task', 'tag',
        'Tags', depends=['type'],
            'invisible': Eval('type') != 'task',
            'readonly': Eval('type') != 'task',

    all_participants = fields.Function(
            'nereid.user', None,
            'All Participants', depends=['company']
        ), 'get_all_participants'
    assigned_to = fields.Many2One(
        'nereid.user', 'Assigned to', depends=['all_participants'],
        domain=[('id', 'in', Eval('all_participants'))],
            'invisible': Eval('type') != 'task',
            'readonly': Eval('type') != 'task',

    progress_state = fields.Selection(
        PROGRESS_STATES, 'Progress State',
        depends=['state', 'type'], select=True,
github tryton / trytond / trytond / ir / View on Github external

class RuleGroup(ModelSQL, ModelView):
    "Rule group"
    __name__ = ''
    name = fields.Char(
        "Name", select=True, translate=True, required=True,
        help="Displayed to users when access error is raised for this rule.")
    model = fields.Many2One('ir.model', 'Model', select=True,
        required=True, ondelete='CASCADE')
    global_p = fields.Boolean('Global', select=True,
        help="Make the rule global \nso every users must follow this rule.")
    default_p = fields.Boolean('Default', select=True,
        help="Add this rule to all users by default.")
    rules = fields.One2Many('ir.rule', 'rule_group', 'Tests',
        help="The rule is satisfied if at least one test is True.")
    groups = fields.Many2Many('',
        'rule_group', 'group', 'Groups')
    perm_read = fields.Boolean('Read Access')
    perm_write = fields.Boolean('Write Access')
    perm_create = fields.Boolean('Create Access')
    perm_delete = fields.Boolean('Delete Access')

    def __setup__(cls):
        super(RuleGroup, cls).__setup__()
        cls._order.insert(0, ('model', 'ASC'))
        cls._order.insert(1, ('global_p', 'ASC'))
        cls._order.insert(2, ('default_p', 'ASC'))

        t = cls.__table__()
github tryton / trytond / trytond / webdav / View on Github external
('key', '=', key),
        if not shares:
            return None
        for share in shares:
            if cls.match(share, command, path):
        return None

class Attachment(ModelSQL, ModelView):
    __name__ = 'ir.attachment'

    path = fields.Function(fields.Char('Path'), 'get_path')
    url = fields.Function(fields.Char('URL'), 'get_url')
    shares = fields.Function(fields.One2Many('webdav.share', None, 'Shares',
                ('path', '=', Eval('path')),
            depends=['path']), 'get_shares', 'set_shares')

    def __setup__(cls):
        super(Attachment, cls).__setup__()
                'collection_attachment_name': ('You can not create an '
                    'attachment named "%(attachment)s" in collection '
                    '"%(collection)s" because there is already a collection '
                    'with that name.')

github tryton / trytond / trytond / ir / View on Github external
args = args[2:]
        super(ActionReport, cls).write(reports, values, *args)

class ActionActWindow(ActionMixin, ModelSQL, ModelView):
    "Action act window"
    __name__ = 'ir.action.act_window'
    domain = fields.Char('Domain Value')
    context = fields.Char('Context Value')
    order = fields.Char('Order Value')
    res_model = fields.Char('Model')
    context_model = fields.Char('Context Model')
    context_domain = fields.Char(
        "Context Domain",
        help="Part of the domain that will be evaluated on each refresh.")
    act_window_views = fields.One2Many('ir.action.act_window.view',
            'act_window', 'Views')
    views = fields.Function(fields.Binary('Views'), 'get_views')
    act_window_domains = fields.One2Many('ir.action.act_window.domain',
        'act_window', 'Domains')
    domains = fields.Function(fields.Binary('Domains'), 'get_domains')
    limit = fields.Integer('Limit', help='Default limit for the list view.')
    action = fields.Many2One('ir.action', 'Action', required=True,
    search_value = fields.Char('Search Criteria',
            help='Default search criteria for the list view.')
    pyson_domain = fields.Function(fields.Char('PySON Domain'), 'get_pyson')
    pyson_context = fields.Function(fields.Char('PySON Context'),
    pyson_order = fields.Function(fields.Char('PySON Order'), 'get_pyson')
    pyson_search_value = fields.Function(fields.Char(
        'PySON Search Criteria'), 'get_pyson')
github tryton / trytond / trytond / model / View on Github external
ref = field.model_name.replace('.','_')
                        ref = self.pool.get(field.model_name)._table
                    table.add_fk(field_name, ref, field.ondelete)

                        field_name, and 'add' or 'remove')

                required = field.required
                if isinstance(field, (fields.Integer, fields.Float,
                    required = True
                    field_name, action=required and 'add' or 'remove')

            elif not isinstance(field, (fields.One2Many, fields.Function,
                raise Exception('Unknow field type !')

        for field_name, field in self._columns.iteritems():
            if isinstance(field, fields.Many2One) \
                    and field.model_name == self._name \
                    and field.left and field.right:
                self._rebuild_tree(cursor, 0, field_name, False, 0)

        for ident, constraint, msg in self._sql_constraints:
            table.add_constraint(ident, constraint)

        if self._history:
            cursor.execute('SELECT id FROM "' + self._table + '"')
            if cursor.rowcount:
github tryton / trytond / trytond / res / View on Github external
for sub_ids in grouped_slice(menu_ids):
                            ('id', 'in', sub_ids),
        menu_ids = set(chain(*test_ids))
        for group_id, ids in res.items():
            res[group_id] = tuple(id_ for id_ in ids if id_ in menu_ids)
        return res

class Group(DeactivableMixin, ModelSQL, ModelView):
    __name__ = ""
    name = fields.Char('Name', required=True, select=True, translate=True)
    users = fields.Many2Many('', 'group', 'user', 'Users')
    model_access = fields.One2Many('ir.model.access', 'group',
       'Access Model')
    field_access = fields.One2Many('ir.model.field.access', 'group',
        'Access Field')
    buttons = fields.Many2Many(
        '', 'group', 'button', "Buttons")
    rule_groups = fields.Many2Many('',
       'group', 'rule_group', 'Rules',
       domain=[('global_p', '!=', True), ('default_p', '!=', True)])
    menu_access = MenuMany2Many('',
       'group', 'menu', 'Access Menu')

    def __setup__(cls):
        super(Group, cls).__setup__()
        table = cls.__table__()
        cls._sql_constraints += [
github openlabs / nereid-project / View on Github external
__all__ = ['NereidUser']
__metaclass__ = PoolMeta

class NereidUser:
    Add employee
    __name__ = "nereid.user"

    #: Allow the nereid user to be connected to an internal employee. This
    #: indicates that the user is an employee and not a regular participant
    employee = fields.Many2One('company.employee', 'Employee', select=True)

    member_of_projects = fields.One2Many(
        "", "user", "Member of Projects"

    def serialize(self, purpose=None):
        Serialize NereidUser and return a dictonary.
        result = super(NereidUser, self).serialize(purpose)
        result['image'] = {
            'url': self.get_profile_picture(size=20),
        result['email'] =
        result['employee'] = self.employee and or None
        result['permissions'] = [p.value for p in self.permissions]
        return result