This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
configuration.py
235 lines (212 loc) · 9.31 KB
/
configuration.py
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# 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 import backend
from trytond.model import (
ModelSingleton, ModelSQL, ModelView, ValueMixin, fields)
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.pool import Pool
from trytond.pyson import Eval, Id
from trytond.tools.multivalue import migrate_property
sequences = ['shipment_in_sequence', 'shipment_in_return_sequence',
'shipment_out_sequence', 'shipment_out_return_sequence',
'shipment_internal_sequence', 'inventory_sequence']
shipment_internal_transit = fields.Many2One(
'stock.location', "Internal Shipment Transit", required=True,
domain=[
('type', '=', 'storage'),
],
help="The default location used for stock that is in transit between "
"warehouses.")
def default_func(field_name):
@classmethod
def default(cls, **pattern):
return getattr(
cls.multivalue_model(field_name),
'default_%s' % field_name, lambda: None)()
return default
def default_sequence(name):
@classmethod
def default(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('stock', name)
except KeyError:
return None
return default
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
'Stock Configuration'
__name__ = 'stock.configuration'
shipment_in_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Supplier Shipment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_in')),
],
help="Used to generate the number given to supplier shipments."))
shipment_in_return_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Supplier Return Shipment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_in_return')),
],
help="Used to generate the number given to supplier return "
"shipments."))
shipment_out_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Customer Shipment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_out')),
],
help="Used to generate the number given to customer "
"shipments."))
shipment_out_return_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Customer Return Shipment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_out_return')),
],
help="Used to generate the number given to customer return "
"shipments."))
shipment_internal_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Internal Shipment Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_internal')),
],
help="Used to generate the number given to internal "
"shipments."))
inventory_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Inventory Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_inventory')),
],
help="Used to generate the number given to inventories."))
shipment_internal_transit = fields.MultiValue(shipment_internal_transit)
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field in sequences:
return pool.get('stock.configuration.sequence')
if field == 'shipment_internal_transit':
return pool.get('stock.configuration.location')
return super(Configuration, cls).multivalue_model(field)
default_shipment_in_sequence = default_func('shipment_in_sequence')
default_shipment_in_return_sequence = default_func(
'shipment_in_return_sequence')
default_shipment_out_sequence = default_func('shipment_out_sequence')
default_shipment_out_return_sequence = default_func(
'shipment_out_return_sequence')
default_shipment_internal_sequence = default_func(
'shipment_internal_sequence')
default_inventory_sequence = default_func('inventory_sequence')
default_shipment_internal_transit = default_func(
'shipment_internal_transit')
class ConfigurationSequence(ModelSQL, CompanyValueMixin):
"Stock Configuration Sequence"
__name__ = 'stock.configuration.sequence'
shipment_in_sequence = fields.Many2One(
'ir.sequence', "Supplier Shipment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_in')),
])
shipment_in_return_sequence = fields.Many2One(
'ir.sequence', "Supplier Return Shipment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_in_return')),
])
shipment_out_sequence = fields.Many2One(
'ir.sequence', "Customer Shipment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_out')),
])
shipment_out_return_sequence = fields.Many2One(
'ir.sequence', "Customer Return Shipment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_out_return')),
])
shipment_internal_sequence = fields.Many2One(
'ir.sequence', "Internal Shipment Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_shipment_internal')),
])
inventory_sequence = fields.Many2One(
'ir.sequence', "Inventory Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('stock', 'sequence_type_inventory')),
])
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(ConfigurationSequence, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.extend(sequences)
value_names.extend(sequences)
fields.append('company')
migrate_property(
'stock.configuration', field_names, cls, value_names,
fields=fields)
default_shipment_in_sequence = default_sequence('sequence_shipment_in')
default_shipment_in_return_sequence = default_sequence(
'sequence_shipment_in_return')
default_shipment_out_sequence = default_sequence('sequence_shipment_out')
default_shipment_out_return_sequence = default_sequence(
'sequence_shipment_out_return')
default_shipment_internal_sequence = default_sequence(
'sequence_shipment_internal')
default_inventory_sequence = default_sequence('sequence_inventory')
class ConfigurationLocation(ModelSQL, ValueMixin):
"Stock Configuration Location"
__name__ = 'stock.configuration.location'
shipment_internal_transit = shipment_internal_transit
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
super(ConfigurationLocation, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('shipment_internal_transit')
value_names.append('shipment_internal_transit')
migrate_property(
'stock.configuration', field_names, cls, value_names,
fields=fields)
@classmethod
def default_shipment_internal_transit(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('stock', 'location_transit')
except KeyError:
return None