[FIX] stock: scrap insufficient qty bypass UoM

Usecase to reproduce:
- Set 1 unit of product A in stock
- Scrap 1 dozen of product A

Warning message for Insufficient Quantity is not triggered.

It happens because there is no UoM conversion between scrap qty and
product quant quantity.

Fixes #30570

closes odoo/odoo#30589
This commit is contained in:
Arnold Moyaux
2019-01-28 13:13:21 +00:00
parent ae88e50928
commit 428546bc02
2 changed files with 20 additions and 1 deletions
+2 -1
View File
@@ -130,7 +130,8 @@ class StockScrap(models.Model):
self.package_id,
self.owner_id,
strict=True).mapped('quantity'))
if float_compare(available_qty, self.scrap_qty, precision_digits=precision) >= 0:
scrap_qty = self.product_uom_id._compute_quantity(self.scrap_qty, self.product_id.uom_id)
if float_compare(available_qty, scrap_qty, precision_digits=precision) >= 0:
return self.do_scrap()
else:
return {
+18
View File
@@ -3424,6 +3424,24 @@ class StockMove(TransactionCase):
self.assertEqual(scrap.state, 'done')
self.assertEqual(move1.reserved_availability, 0.25)
def test_scrap_6(self):
""" Check that scrap correctly handle UoM. """
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1)
scrap = self.env['stock.scrap'].create({
'product_id': self.product1.id,
'product_uom_id': self.uom_dozen.id,
'scrap_qty': 1,
})
warning_message = scrap.action_validate()
self.assertEqual(warning_message.get('res_model', 'Wrong Model'), 'stock.warn.insufficient.qty.scrap')
insufficient_qty_wizard = self.env['stock.warn.insufficient.qty.scrap'].create({
'product_id': self.product1.id,
'location_id': self.stock_location.id,
'scrap_id': scrap.id
})
insufficient_qty_wizard.action_done()
self.assertEqual(self.env['stock.quant']._gather(self.product1, self.stock_location).quantity, -11)
def test_in_date_1(self):
""" Check that moving a tracked quant keeps the incoming date.
"""