|
|
for production in self:
if production.state != 'draft' or self.env.context.get('skip_compute_move_raw_ids'):
continue
list_move_raw = [Command.link(move.id) for move in production.move_raw_ids.filtered(lambda m: not m.bom_line_id)]
if not production.bom_id and not production._origin.product_id:
production.move_raw_ids = list_move_raw
if any(move.bom_line_id.bom_id != production.bom_id or move.bom_line_id._skip_bom_line(production.product_id)\
for move in production.move_raw_ids if move.bom_line_id):
production.move_raw_ids = [Command.clear()]
if production.bom_id and production.product_id and production.product_qty > 0:
# keep manual entries
moves_raw_values = production._get_moves_raw_values()
move_raw_dict = {move.bom_line_id.id: move for move in production.move_raw_ids.filtered(lambda m: m.bom_line_id)}
for move_raw_values in moves_raw_values:
if move_raw_values['bom_line_id'] in move_raw_dict:
# update existing entries
list_move_raw += [Command.update(move_raw_dict[move_raw_values['bom_line_id']].id, move_raw_values)]
else:
# add new entries
list_move_raw += [Command.create(move_raw_values)]
production.move_raw_ids = list_move_raw
else:
production.move_raw_ids = [Command.delete(move.id) for move in production.move_raw_ids.filtered(lambda m: m.bom_line_id)]
|
|