Files
tryton/modules/production_routing/production.py
T

45 lines
1.5 KiB
Python
Raw Normal View History

2016-03-21 21:02:37 +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.
from trytond.model import fields
2021-12-11 17:58:43 +01:00
from trytond.pool import PoolMeta
2016-03-21 21:02:37 +01:00
from trytond.pyson import Eval
2018-06-26 19:11:49 +02:00
class Production(metaclass=PoolMeta):
2016-03-21 21:02:37 +01:00
__name__ = 'production'
routing = fields.Many2One('production.routing', 'Routing',
domain=[
('boms', '=', Eval('bom', 0)),
],
states={
'readonly': ~Eval('state').in_(['request', 'draft']),
'invisible': ~Eval('bom'),
})
2016-03-21 21:02:37 +01:00
@fields.depends('bom', 'routing')
def on_change_bom(self):
super(Production, self).on_change_bom()
if self.bom:
if self.routing:
if self.bom not in self.routing.boms:
self.routing = None
else:
self.routing = None
2016-06-24 09:24:46 +02:00
@fields.depends('routing')
def compute_lead_time(self, pattern=None):
pattern = pattern.copy() if pattern is not None else {}
2016-06-24 09:24:46 +02:00
pattern.setdefault(
'routing', self.routing.id if self.routing else None)
return super().compute_lead_time(pattern=pattern)
2016-06-24 09:24:46 +02:00
2016-03-21 21:02:37 +01:00
@classmethod
2020-05-01 00:19:33 +02:00
def compute_request(
cls, product, warehouse, quantity, date, company,
order_point=None):
2016-03-21 21:02:37 +01:00
production = super(Production, cls).compute_request(
2020-05-01 00:19:33 +02:00
product, warehouse, quantity, date, company,
order_point=order_point)
2016-03-21 21:02:37 +01:00
production.routing = product.boms[0].routing if product.boms else None
return production