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 6
/
stock.py
167 lines (146 loc) · 5.82 KB
/
stock.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
# 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 sql import Null
from trytond.model import Check, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
class Location(metaclass=PoolMeta):
__name__ = 'stock.location'
production_location = fields.Many2One('stock.location', 'Production',
states={
'invisible': Eval('type') != 'warehouse',
'required': Eval('type') == 'warehouse',
},
domain=[
('type', '=', 'production'),
])
production_picking_location = fields.Many2One(
'stock.location', "Production Picking",
states={
'invisible': Eval('type') != 'warehouse',
},
domain=[
('type', '=', 'storage'),
('parent', 'child_of', [Eval('id', -1)]),
],
help="Where the production components are picked from.\n"
"Leave empty to use the warehouse storage location.")
production_output_location = fields.Many2One(
'stock.location', "Production Output",
states={
'invisible': Eval('type') != 'warehouse',
},
domain=[
('type', '=', 'storage'),
('parent', 'child_of', [Eval('id', -1)]),
],
help="Where the produced goods are stored.\n"
"Leave empty to use the warehouse storage location.")
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
production_input = fields.Many2One(
'production', "Production Input", readonly=True, ondelete='CASCADE',
domain=[('company', '=', Eval('company'))],
states={
'invisible': ~Eval('production_input'),
})
production_output = fields.Many2One(
'production', "Production Output", readonly=True, ondelete='CASCADE',
domain=[('company', '=', Eval('company'))],
states={
'invisible': ~Eval('production_output'),
})
production = fields.Function(fields.Many2One(
'production', "Production",
states={
'invisible': ~Eval('production'),
}),
'on_change_with_production')
production_cost_price_updated = fields.Boolean(
"Cost Price Updated", readonly=True,
states={
'invisible': ~Eval('production_input') & (Eval('state') == 'done'),
})
@classmethod
def __setup__(cls):
super().__setup__()
t = cls.__table__()
cls._sql_constraints += [
('production_single', Check(t, (
(t.production_input == Null)
| (t.production_output == Null))),
'production.msg_stock_move_production_single'),
]
@fields.depends(
'production_input', '_parent_production_input.id',
'production_output', '_parent_production_output.id')
def on_change_with_production(self, name=None):
if self.production_input:
return self.production_input.id
elif self.production_output:
return self.production_output.id
def set_effective_date(self):
if not self.effective_date and self.production_input:
self.effective_date = self.production_input.effective_start_date
if not self.effective_date and self.production_output:
self.effective_date = self.production_output.effective_date
super(Move, self).set_effective_date()
@classmethod
def write(cls, *args):
super().write(*args)
cost_price_update = []
actions = iter(args)
for moves, values in zip(actions, actions):
for move in moves:
if (move.state == 'done'
and move.production_input
and 'cost_price' in values):
cost_price_update.append(move)
if cost_price_update:
cls.write(
cost_price_update, {'production_cost_price_updated': True})
class ProductQuantitiesByWarehouseMove(metaclass=PoolMeta):
__name__ = 'stock.product_quantities_warehouse.move'
@classmethod
def _get_document_models(cls):
return super()._get_document_models() + ['production']
def get_document(self, name):
document = super().get_document(name)
if self.move.production_input:
document = str(self.move.production_input)
if self.move.production_output:
document = str(self.move.production_output)
return document
class LotTrace(metaclass=PoolMeta):
__name__ = 'stock.lot.trace'
production_input = fields.Many2One('production', "Production Input")
production_output = fields.Many2One('production', "Production Output")
@classmethod
def _columns(cls, move):
return super()._columns(move) + [
move.production_input.as_('production_input'),
move.production_output.as_('production_output'),
]
@classmethod
def get_documents(cls):
pool = Pool()
Model = pool.get('ir.model')
return super().get_documents() + [
('production', Model.get_name('production'))]
def get_document(self, name):
document = super().get_document(name)
if self.production_input:
document = str(self.production_input)
elif self.production_output:
document = str(self.production_output)
return document
def _get_upward_traces(self):
traces = super()._get_upward_traces()
if self.production_input:
traces.update(self.production_input.outputs)
return traces
def _get_downward_traces(self):
traces = super()._get_downward_traces()
if self.production_output:
traces.update(self.production_output.inputs)
return traces