Skip to content

Commit

Permalink
[FIX] stock: round w/ precision_rounding
Browse files Browse the repository at this point in the history
Versions
--------
- 17.0+

Issue
-----
`precision_rounding` values were being passed incorrectly as
`precision_digits` parameters.

Solution
--------
Pass them as named `precision_rounding` parameters instead.

closes odoo#163182

Related: odoo/enterprise#61387
Signed-off-by: Tiffany Chang (tic) <tic@odoo.com>
  • Loading branch information
lvsz authored and willylohws committed May 3, 2024
1 parent 7c68dfd commit 7566d42
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion addons/stock/models/stock_move.py
Expand Up @@ -1815,7 +1815,7 @@ def _check_unlink_move_dest(self):
def _action_done(self, cancel_backorder=False):
moves = self.filtered(
lambda move: move.state == 'draft'
or float_is_zero(move.product_uom_qty, precision_digits=move.product_uom.rounding)
or float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding)
)._action_confirm(merge=False) # MRP allows scrapping draft moves
moves = (self | moves).exists().filtered(lambda x: x.state not in ('done', 'cancel'))
moves_ids_todo = OrderedSet()
Expand Down
2 changes: 1 addition & 1 deletion addons/stock/models/stock_move_line.py
Expand Up @@ -143,7 +143,7 @@ def _compute_quantity(self):
if not record.quant_id or record.quantity:
continue
origin_move = record.move_id._origin
if float_compare(record.move_id.product_qty, origin_move.quantity, record.move_id.product_uom.rounding) > 0:
if float_compare(record.move_id.product_qty, origin_move.quantity, precision_rounding=record.move_id.product_uom.rounding) > 0:
record.quantity = max(0, min(record.quant_id.available_quantity, record.move_id.product_qty - origin_move.quantity))
else:
record.quantity = max(0, record.quant_id.available_quantity)
Expand Down
23 changes: 23 additions & 0 deletions addons/stock/tests/test_move_lines.py
Expand Up @@ -110,3 +110,26 @@ def test_pick_from_4(self):
ml.quant_id = self.quant

self.assertEqual(move.move_line_ids.quantity, 0)

def test_pick_from_5(self):
""" check small quantities get handled correctly """
precision = self.env.ref('product.decimal_product_uom')
precision.digits = 6
self.product.uom_id = self.uom_kg
move = self.env['stock.move'].create({
'name': 'Test move',
'product_id': self.product.id,
'location_id': self.stock_location,
'location_dest_id': self.stock_location,
'product_uom_qty': 1e-5,
})
move_form = Form(move, view='stock.view_stock_move_operations')
with move_form.move_line_ids.new() as ml:
ml.quant_id = self.quant
move = move_form.save()
self.assertAlmostEqual(
move.move_line_ids.quantity,
1e-5,
delta=1e-6,
msg="Small line quantity should get detected",
)
14 changes: 7 additions & 7 deletions addons/stock/tests/test_multicompany.py
Expand Up @@ -461,13 +461,13 @@ def test_intercom_lot_push(self):
'location_dest_id': self.stock_location_a.id,
'product_id': product_lot.id,
'product_uom': product_lot.uom_id.id,
'product_uom_qty': 1.0,
'product_uom_qty': 0.1,
'picking_type_id': self.warehouse_a.in_type_id.id,
})
move_from_supplier._action_confirm()
move_line_1 = move_from_supplier.move_line_ids[0]
move_line_1.lot_name = 'lot 1'
move_line_1.quantity = 1.0
move_line_1.quantity = 0.1
move_from_supplier.picked = True
move_from_supplier._action_done()
lot_1 = move_line_1.lot_id
Expand All @@ -479,15 +479,15 @@ def test_intercom_lot_push(self):
'location_dest_id': intercom_location.id,
'product_id': product_lot.id,
'product_uom': product_lot.uom_id.id,
'product_uom_qty': 1.0,
'product_uom_qty': 0.1,
'picking_type_id': picking_type_to_transit.id,
'route_ids': [(4, route.id)],
})
move_to_transit.with_user(self.user_a)._action_confirm()
move_to_transit.with_user(self.user_a)._action_assign()
move_line_2 = move_to_transit.move_line_ids[0]
self.assertTrue(move_line_2.lot_id, move_line_1.lot_id)
move_line_2.quantity = 1.0
move_line_2.quantity = 0.1
move_to_transit.picked = True
move_to_transit.with_user(self.user_a)._action_done()

Expand All @@ -506,16 +506,16 @@ def test_intercom_lot_push(self):

move_line_3 = move_push.move_line_ids[0]
move_line_3.lot_name = 'lot 2'
move_line_3.quantity = 1.0
move_line_3.quantity = 0.1
picking_receipt.move_ids.picked = True
picking_receipt.button_validate()
lot_2 = move_line_3.lot_id
self.assertEqual(lot_1.company_id, self.company_a)
self.assertEqual(lot_1.name, 'lot 1')
self.assertEqual(self.env['stock.quant']._get_available_quantity(product_lot, intercom_location, lot_1), 1.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(product_lot, intercom_location, lot_1), 0.1)
self.assertEqual(lot_2.company_id, self.company_b)
self.assertEqual(lot_2.name, 'lot 2')
self.assertEqual(self.env['stock.quant']._get_available_quantity(product_lot, self.stock_location_b, lot_2), 1.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(product_lot, self.stock_location_b, lot_2), 0.1)

def test_intercom_lot_pull(self):
"""Use warehouse of comany a to resupply warehouse of company b. Check
Expand Down

0 comments on commit 7566d42

Please sign in to comment.