Files
tryton/modules/production/stock.py
T

168 lines
5.8 KiB
Python
Raw Normal View History

2014-12-02 12:55:39 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2022-03-20 01:27:59 +01:00
from sql import Null
from trytond.model import Check, fields
2022-03-19 22:44:15 +01:00
from trytond.pool import Pool, PoolMeta
2021-12-11 17:58:43 +01:00
from trytond.pyson import Eval
2012-05-13 23:00:54 +02:00
2018-06-26 19:11:49 +02:00
class Location(metaclass=PoolMeta):
2012-09-24 22:12:50 +02:00
__name__ = 'stock.location'
2012-05-13 23:00:54 +02:00
production_location = fields.Many2One('stock.location', 'Production',
states={
'invisible': Eval('type') != 'warehouse',
'required': Eval('type') == 'warehouse',
},
domain=[
('type', '=', 'production'),
])
2020-10-12 19:32:02 +02:00
production_picking_location = fields.Many2One(
'stock.location', "Production Picking",
states={
'invisible': Eval('type') != 'warehouse',
},
domain=[
('type', '=', 'storage'),
2021-10-03 13:45:32 +02:00
('parent', 'child_of', [Eval('id', -1)]),
2020-10-12 19:32:02 +02:00
],
help="Where the production components are picked from.\n"
"Leave empty to use the warehouse storage location.")
production_output_location = fields.Many2One(
2020-10-15 00:21:20 +02:00
'stock.location', "Production Output",
2020-10-12 19:32:02 +02:00
states={
'invisible': Eval('type') != 'warehouse',
},
domain=[
('type', '=', 'storage'),
2021-10-03 13:45:32 +02:00
('parent', 'child_of', [Eval('id', -1)]),
2020-10-12 19:32:02 +02:00
],
help="Where the produced goods are stored.\n"
"Leave empty to use the warehouse storage location.")
2012-05-13 23:00:54 +02:00
2018-06-26 19:11:49 +02:00
class Move(metaclass=PoolMeta):
2012-09-24 22:12:50 +02:00
__name__ = 'stock.move'
production_input = fields.Many2One(
'production', "Production Input", readonly=True, ondelete='CASCADE',
2012-05-13 23:00:54 +02:00
domain=[('company', '=', Eval('company'))],
2022-03-20 01:27:59 +01:00
states={
'invisible': ~Eval('production_input'),
})
production_output = fields.Many2One(
'production', "Production Output", readonly=True, ondelete='CASCADE',
2012-05-13 23:00:54 +02:00
domain=[('company', '=', Eval('company'))],
2022-03-20 01:27:59 +01:00
states={
'invisible': ~Eval('production_output'),
})
2022-03-20 01:27:59 +01:00
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'),
})
2022-03-20 01:27:59 +01:00
@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:
2023-03-26 09:49:00 +02:00
return self.production_input
2022-03-20 01:27:59 +01:00
elif self.production_output:
2023-03-26 09:49:00 +02:00
return self.production_output
2022-03-20 01:27:59 +01:00
def set_effective_date(self):
if not self.effective_date and self.production_input:
2016-06-24 09:22:52 +02:00
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
2022-03-19 22:44:15 +01:00
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