[FIX] stock: validate a picking with only scrap

Usecase:
- Create a planned transfer
- Add line with initial demand
- Create a scrap
- Click on button validate

The wizard asking for a backorder or not is diplayed. The UserError
that prevent to validate a picking without quantity done or reserved
should have been raised. The scrap moves are directly processed once
the user validates his scrap order. Validate a picking with only done
moves, will not have any effect.

closes odoo/odoo#31076
This commit is contained in:
Arnold Moyaux
2019-02-20 09:17:10 +00:00
parent 86cb78740b
commit 443b810e09
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -708,7 +708,7 @@ class Picking(models.Model):
# If no lots when needed, raise error
picking_type = self.picking_type_id
precision_digits = self.env['decimal.precision'].precision_get('Product Unit of Measure')
no_quantities_done = all(float_is_zero(move_line.qty_done, precision_digits=precision_digits) for move_line in self.move_line_ids)
no_quantities_done = all(float_is_zero(move_line.qty_done, precision_digits=precision_digits) for move_line in self.move_line_ids.filtered(lambda m: m.state not in ('done', 'cancel')))
no_reserved_quantities = all(float_is_zero(move_line.product_qty, precision_rounding=move_line.product_uom_id.rounding) for move_line in self.move_line_ids)
if no_reserved_quantities and no_quantities_done:
raise UserError(_('You cannot validate a transfer if you have not processed any quantity. You should rather cancel the transfer.'))
+9
View File
@@ -3233,6 +3233,15 @@ class StockMove(TransactionCase):
})
picking.action_confirm()
picking.action_assign()
scrap = self.env['stock.scrap'].create({
'picking_id': picking.id,
'product_id': self.product1.id,
'product_uom_id': self.uom_unit.id,
'scrap_qty': 5.0,
})
scrap.do_scrap()
# No products are reserved on the move of 10, click on `button_validate`.
with self.assertRaises(UserError):
picking.button_validate()