File: model.py

package info (click to toggle)
tryton-server 7.0.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,760 kB
  • sloc: python: 53,744; xml: 5,194; sh: 803; sql: 217; makefile: 28
file content (184 lines) | stat: -rw-r--r-- 4,442 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# 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 (
    ModelSingleton, ModelSQL, UnionMixin, fields, sequence_ordered)
from trytond.pool import Pool
from trytond.pyson import Eval


class Model(ModelSQL):
    'Model'
    __name__ = 'test.model'
    name = fields.Char('Name')


class ModelParent(Model):
    "Model Parent"
    __name__ = 'test.model_parent'
    name = fields.Char("Name")
    children = fields.One2Many('test.model_child', 'parent', "Children")


class ModelChild(Model):
    "Model Child"
    __name__ = 'test.model_child'
    name = fields.Char("Name")
    parent = fields.Many2One('test.model_parent', "Parent")


class ModelChildChild(Model):
    "Model Child Child"
    __name__ = 'test.model_child_child'
    name = fields.Char("Name")
    parent = fields.Many2One('test.model_child', "Parent")


class ModelContext(Model):
    "Model with contextual field"
    __name__ = 'test.model_context'
    name = fields.Char("Name")
    target = fields.Many2One(
        'test.model', "Target",
        context={
            'name': Eval('name'),
            })


class ModelContextParent(Model):
    "Model with contextual field from _parent"
    __name__ = 'test.model_context_parent'
    parent = fields.Many2One('test.model', "Parent")
    target = fields.Many2One(
        'test.model', "Target",
        context={
            'name': Eval('_parent_parent', {}).get('name'),
            })


class ModelDefault(Model):
    "Model with default"
    __name__ = 'test.model.default'

    name = fields.Char("Name")
    description = fields.Char("Description")
    target = fields.Many2One('test.model', "Target")

    @classmethod
    def default_description(cls):
        return "Test"


class Singleton(ModelSingleton, ModelSQL):
    'Singleton'
    __name__ = 'test.singleton'
    name = fields.Char('Name')

    @staticmethod
    def default_name():
        return 'test'


class URLObject(ModelSQL):
    'URLObject'
    __name__ = 'test.urlobject'
    name = fields.Char('Name')


class Model4Union1(ModelSQL):
    'Model for union 1'
    __name__ = 'test.model.union1'
    name = fields.Char('Name')
    optional = fields.Char('Optional')


class Model4Union2(ModelSQL):
    'Model for union 2'
    __name__ = 'test.model.union2'
    name = fields.Char('Name')


class Model4Union3(ModelSQL):
    'Model for union 3'
    __name__ = 'test.model.union3'
    name = fields.Char('Name')


class Model4Union4(ModelSQL):
    'Model for union 4'
    __name__ = 'test.model.union4'
    name = fields.Char('Name')


class Union(UnionMixin, ModelSQL):
    'Union'
    __name__ = 'test.union'
    name = fields.Char('Name')
    optional = fields.Char('Optional')

    @staticmethod
    def union_models():
        return ['test.model.union%s' % i for i in range(1, 4)]


class UnionUnion(UnionMixin, ModelSQL):
    'Union of union'
    __name__ = 'test.union.union'
    name = fields.Char('Name')

    @staticmethod
    def union_models():
        return ['test.union', 'test.model.union4']


class Model4UnionTree1(ModelSQL):
    'Model for union tree 1'
    __name__ = 'test.model.union.tree1'
    name = fields.Char('Name')


class Model4UnionTree2(ModelSQL):
    'Model for union tree 2'
    __name__ = 'test.model.union.tree2'
    name = fields.Char('Name')
    parent = fields.Many2One('test.model.union.tree1', 'Parent')


class UnionTree(UnionMixin, ModelSQL):
    'Union tree'
    __name__ = 'test.union.tree'
    name = fields.Char('Name')
    parent = fields.Many2One('test.union.tree', 'Parent')
    childs = fields.One2Many('test.union.tree', 'parent', 'Childs')

    @staticmethod
    def union_models():
        return ['test.model.union.tree1', 'test.model.union.tree2']


class SequenceOrderedModel(sequence_ordered(), ModelSQL):
    'Sequence Ordered Model'
    __name__ = 'test.order.sequence'


def register(module):
    Pool.register(
        Model,
        ModelParent,
        ModelChild,
        ModelChildChild,
        ModelContext,
        ModelContextParent,
        ModelDefault,
        Singleton,
        URLObject,
        Model4Union1,
        Model4Union2,
        Model4Union3,
        Model4Union4,
        Union,
        UnionUnion,
        Model4UnionTree1,
        Model4UnionTree2,
        UnionTree,
        SequenceOrderedModel,
        module=module, type_='model')