on_change_with of One2Many fields only supports returning a list of objects now.
This commit is contained in:
parent
a533bec384
commit
9c9a50ba22
18
bom.py
18
bom.py
|
@ -1,8 +1,6 @@
|
|||
from trytond.model import ModelSQL, ModelView, fields, Unique
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
__all__ = ['BOM', 'BOMDrawingLine']
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
|
||||
|
||||
class BOM(metaclass=PoolMeta):
|
||||
|
@ -18,17 +16,13 @@ class BOM(metaclass=PoolMeta):
|
|||
|
||||
@fields.depends('drawing', 'drawing_lines')
|
||||
def on_change_with_drawing_lines(self):
|
||||
DrawingLine = Pool().get('production.bom.drawing.line')
|
||||
if not self.drawing:
|
||||
to_remove = [x.id for x in self.drawing_lines]
|
||||
return {
|
||||
'remove': to_remove,
|
||||
}
|
||||
to_add = []
|
||||
return []
|
||||
res = []
|
||||
for position in self.drawing.positions:
|
||||
to_add.append((-1, {
|
||||
'position': position.id,
|
||||
}))
|
||||
return {'add': to_add}
|
||||
res.append(DrawingLine(position=position))
|
||||
return res
|
||||
|
||||
@fields.depends('drawing')
|
||||
def on_change_with_drawing_image(self, name=None):
|
||||
|
|
|
@ -28,18 +28,17 @@ class Production(metaclass=PoolMeta):
|
|||
|
||||
@fields.depends('bom', 'drawing', 'drawing_lines')
|
||||
def on_change_with_drawing_lines(self):
|
||||
Line = Pool().get('production.drawing.line')
|
||||
|
||||
if not self.bom or not self.bom.drawing and hasattr(self, 'drawing_lines'):
|
||||
to_remove = [x.id for x in getattr(self, 'drawing_lines', [])]
|
||||
return {
|
||||
'remove': to_remove,
|
||||
}
|
||||
to_add = []
|
||||
return []
|
||||
res = []
|
||||
for line in self.bom.drawing_lines:
|
||||
to_add.append((-1, {
|
||||
'position': line.position.id,
|
||||
'product': line.product.id if line.product else None,
|
||||
}))
|
||||
return {'add': to_add}
|
||||
res.append(Line(
|
||||
position=line.position,
|
||||
product=line.product,
|
||||
))
|
||||
return res
|
||||
|
||||
@fields.depends('bom')
|
||||
def on_change_with_drawing(self):
|
||||
|
|
Loading…
Reference in New Issue