Skip to content

Commit

Permalink
Merge PR #29 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed May 23, 2024
2 parents d430853 + 384c006 commit 634f974
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
11 changes: 9 additions & 2 deletions stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,23 @@ def _compute_qty(self):
done_qty = abs(other_qty - incoming_qty)
open_qty = sum(request.allocation_ids.mapped("open_product_qty"))
uom = request.product_id.uom_id
request.qty_done = uom._compute_quantity(done_qty, request.product_uom_id)
request.qty_done = uom._compute_quantity(
done_qty,
request.product_uom_id,
rounding_method="HALF-UP",
)
request.qty_in_progress = uom._compute_quantity(
open_qty, request.product_uom_id
open_qty,
request.product_uom_id,
rounding_method="HALF-UP",
)
request.qty_cancelled = (
max(
0,
uom._compute_quantity(
request.product_qty - done_qty - open_qty,
request.product_uom_id,
rounding_method="HALF-UP",
),
)
if request.allocation_ids
Expand Down
4 changes: 3 additions & 1 deletion stock_request/models/stock_request_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def default_get(self, fields):
def _compute_product_qty(self):
for rec in self:
rec.product_qty = rec.product_uom_id._compute_quantity(
rec.product_uom_qty, rec.product_id.product_tmpl_id.uom_id
rec.product_uom_qty,
rec.product_id.product_tmpl_id.uom_id,
rounding_method="HALF-UP",
)

name = fields.Char(copy=False, required=True, readonly=True, default="/")
Expand Down
4 changes: 3 additions & 1 deletion stock_request/models/stock_request_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class StockRequestAllocation(models.Model):
def _compute_requested_product_qty(self):
for rec in self:
rec.requested_product_qty = rec.product_uom_id._compute_quantity(
rec.requested_product_uom_qty, rec.product_id.uom_id
rec.requested_product_uom_qty,
rec.product_id.uom_id,
rounding_method="HALF-UP",
)

@api.depends(
Expand Down
42 changes: 42 additions & 0 deletions stock_request/tests/test_stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,3 +1341,45 @@ def test_stock_request_order_state_04(self):
self.assertEqual(self.request_a.state, "cancel")
self.assertEqual(self.request_b.state, "done")
self.assertEqual(self.order.state, "done")

def test_rounding_half_up_in_progress_01(self):
product_half_up = self._create_product(
"HALFUP", "HalfUp Product", self.main_company.id
)
product_half_up.uom_id.rounding = 1.0
vals = {
"product_id": product_half_up.id,
"product_uom_id": product_half_up.uom_id.id,
"product_uom_qty": 0.5,
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.virtual_loc.id,
}
stock_request = self.stock_request.create(vals)
stock_request.action_confirm()
self.assertEqual(
stock_request.qty_in_progress,
1,
"Quantity in progress should be the rounded up after confirmation",
)

def test_rounding_half_up_in_progress_02(self):
product_half_up = self._create_product(
"HALFUP", "HalfUp Product", self.main_company.id
)
product_half_up.uom_id.rounding = 1.0
vals = {
"product_id": product_half_up.id,
"product_uom_id": product_half_up.uom_id.id,
"product_uom_qty": 1.49,
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.virtual_loc.id,
}
stock_request = self.stock_request.create(vals)
stock_request.action_confirm()
self.assertEqual(
stock_request.qty_in_progress,
1,
"Quantity in progress should be the rounded down after confirmation",
)

0 comments on commit 634f974

Please sign in to comment.