[FIX] stock: picking: do_unreserve

When a scrapped move is part of an open picking, it was not possible to
unreserve the picking. A scrapped move is done and scrapped ; this
combination should be allowed.

opw-1835186
This commit is contained in:
Simon Lejeune
2018-04-25 14:03:32 +02:00
parent 9e5c1f68a5
commit c812122d5e
+13 -3
View File
@@ -486,9 +486,19 @@ class StockMove(models.Model):
}
def _do_unreserve(self):
if any(move.state in ('done', 'cancel') for move in self):
raise UserError(_('Cannot unreserve a done move'))
self.mapped('move_line_ids').unlink()
moves_to_unreserve = self.env['stock.move']
for move in self:
if move.state == 'cancel':
# We may have cancelled move in an open picking in a "propagate_cancel" scenario.
continue
if move.state == 'done':
if move.scrapped:
# We may have done move in an open picking in a scrap scenario.
continue
else:
raise UserError(_('Cannot unreserve a done move'))
moves_to_unreserve |= move
moves_to_unreserve.mapped('move_line_ids').unlink()
return True
def _push_apply(self):