trytond-production_process/product.py

51 lines
1.7 KiB
Python
Raw Permalink Normal View History

2014-05-12 14:07:03 +02:00
#The COPYRIGHT file at the top level of this repository contains the full
#copyright notices and license terms.
from trytond.model import fields
from trytond.pyson import Eval, Get, If, Bool
from trytond.pool import Pool, PoolMeta
__all__ = ['ProductBom']
2014-05-12 14:07:03 +02:00
2018-10-29 00:04:47 +01:00
class ProductBom(metaclass=PoolMeta):
2014-05-12 14:07:03 +02:00
__name__ = 'product.product-production.bom'
process = fields.Many2One('production.process', 'Process',
domain=[
('output_products', '=', If(Bool(Eval('product')),
Eval('product', 0),
Get(Eval('_parent_product', {}), 'id', 0))),
],
2014-06-04 16:12:21 +02:00
depends=['product'])
@classmethod
def __setup__(cls):
super(ProductBom, cls).__setup__()
if not 'process' in cls.bom.depends:
cls.bom.states.update({
'readonly': Bool(Eval('process', 0)),
})
2022-05-03 16:13:23 +02:00
cls.bom.depends.add('process')
if not 'process' in cls.route.depends:
cls.route.states.update({
'readonly': Bool(Eval('process', 0)),
})
2022-05-03 16:13:23 +02:00
cls.route.depends.add('process')
2014-06-04 16:12:21 +02:00
@fields.depends('process', 'bom', 'route')
def on_change_process(self):
if self.process:
2016-07-05 13:24:17 +02:00
self.bom = self.process.bom
self.route = self.process.route
2014-05-12 14:07:03 +02:00
@classmethod
def create(cls, vlist):
pool = Pool()
Process = pool.get('production.process')
for values in vlist:
if values.get('process'):
process = Process(values['process'])
values['bom'] = process.bom.id
values['route'] = process.route.id
return super(ProductBom, cls).create(vlist)