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
|
2024-12-16 18:28:21 +01:00
|
|
|
from trytond.pyson import Eval, If
|
2016-03-21 21:02:37 +01:00
|
|
|
|
|
|
|
|
|
2025-11-17 11:22:21 +01:00
|
|
|
class BOM(metaclass=PoolMeta):
|
|
|
|
|
__name__ = 'production.bom'
|
|
|
|
|
|
|
|
|
|
routings = fields.Many2Many(
|
|
|
|
|
'production.routing-production.bom', 'bom', 'routing', "Routings")
|
|
|
|
|
|
|
|
|
|
|
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=[
|
2024-12-16 18:28:21 +01:00
|
|
|
If(Eval('state').in_(['request', 'draft']),
|
|
|
|
|
('boms', '=', Eval('bom', 0)),
|
|
|
|
|
()),
|
2016-03-21 21:02:37 +01:00
|
|
|
],
|
|
|
|
|
states={
|
|
|
|
|
'readonly': ~Eval('state').in_(['request', 'draft']),
|
|
|
|
|
'invisible': ~Eval('bom'),
|
2022-04-08 19:07:13 +02:00
|
|
|
})
|
2016-03-21 21:02:37 +01:00
|
|
|
|
|
|
|
|
@fields.depends('bom', 'routing')
|
|
|
|
|
def on_change_bom(self):
|
2025-04-04 00:45:18 +02:00
|
|
|
super().on_change_bom()
|
2016-03-21 21:02:37 +01:00
|
|
|
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')
|
2023-07-22 18:55:46 +02:00
|
|
|
def compute_lead_time(self, pattern=None):
|
2023-07-22 18:53:50 +02:00
|
|
|
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)
|
2023-07-22 18:55:46 +02:00
|
|
|
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,
|
2024-09-07 11:20:52 +02:00
|
|
|
order_point=None, bom_pattern=None):
|
2025-04-04 00:45:18 +02:00
|
|
|
production = super().compute_request(
|
2020-05-01 00:19:33 +02:00
|
|
|
product, warehouse, quantity, date, company,
|
2024-09-07 11:20:52 +02:00
|
|
|
order_point=order_point, bom_pattern=bom_pattern)
|
|
|
|
|
if bom := product.get_bom(bom_pattern):
|
|
|
|
|
production.routing = bom.routing
|
2016-03-21 21:02:37 +01:00
|
|
|
return production
|