@api.onchange('order_line')
def onchange_line(self):
copy_line = self.order_line.filtered(lambda x: x.copy)
if copy_line:
obj = self.env['od.stock.transfer.item'].new({
'product_id': copy_line.product_id.id,
'product_qty': copy_line.product_qty,
'product_uom': copy_line.product_uom.id,
'product_sub_qty': copy_line.product_sub_qty,
'product_sub_uom': copy_line.product_sub_uom.id,
'lot_id': copy_line.lot_id.id,
'remark': copy_line.remark,
'location_id': copy_line.location_id.id,
'location_dest_id': copy_line.location_dest_id.id,
'copy': False,
})
self.order_line |= obj
copy_line.copy = False
说明:
- order_line: 跟明细行关联的一个One2many字段
- copy:定义的复制字段