Skip to content

[17.0][FIX] rma: fixed inconsistencies with delivery quantities #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _compute_out_shipment_count(self):
pickings = line._get_out_pickings()
line.out_shipment_count = len(pickings)

def _get_rma_move_qty(self, states, direction="in"):
def _get_rma_move_qty(self, states, direction="in", use_demand_qty=True):
for rec in self:
product_obj = self.env["uom.uom"]
qty = 0.0
Expand All @@ -122,7 +122,12 @@ def _get_rma_move_qty(self, states, direction="in"):
continue
elif direction == "in" and move.move_dest_ids:
continue
qty += product_obj._compute_quantity(move.product_uom_qty, rec.uom_id)
if use_demand_qty:
qty += product_obj._compute_quantity(
move.product_uom_qty, rec.uom_id
)
else:
qty += product_obj._compute_quantity(move.quantity, rec.uom_id)
return qty

@api.depends(
Expand Down Expand Up @@ -159,9 +164,13 @@ def _compute_qty_to_deliver(self):
for rec in self:
rec.qty_to_deliver = 0.0
if rec.delivery_policy == "ordered":
rec.qty_to_deliver = rec.product_qty - rec.qty_delivered
rec.qty_to_deliver = max(
rec.product_qty - rec.qty_outgoing - rec.qty_delivered, 0
)
elif rec.delivery_policy == "received":
rec.qty_to_deliver = rec.qty_received - rec.qty_delivered
rec.qty_to_deliver = max(
rec.qty_received - rec.qty_outgoing - rec.qty_delivered, 0
)

@api.depends("move_ids", "move_ids.state", "type")
def _compute_qty_incoming(self):
Expand All @@ -188,7 +197,7 @@ def _compute_qty_outgoing(self):
@api.depends("move_ids", "move_ids.state", "type")
def _compute_qty_delivered(self):
for rec in self:
qty = rec._get_rma_move_qty("done", direction="out")
qty = rec._get_rma_move_qty("done", direction="out", use_demand_qty=False)
rec.qty_delivered = qty

@api.model
Expand Down
12 changes: 6 additions & 6 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def test_02_customer_rma(self):
# product specific
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_1).qty_to_deliver,
3,
0,
"Wrong qty to_deliver",
)
self._check_equal_quantity(
Expand All @@ -689,7 +689,7 @@ def test_02_customer_rma(self):
)
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_2).qty_to_deliver,
5,
0,
"Wrong qty to_deliver",
)
self._check_equal_quantity(
Expand All @@ -699,7 +699,7 @@ def test_02_customer_rma(self):
)
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_3).qty_to_deliver,
2,
0,
"Wrong qty to_deliver",
)
self._check_equal_quantity(
Expand Down Expand Up @@ -912,7 +912,7 @@ def test_04_supplier_rma(self):
)
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_1).qty_to_deliver,
3,
0,
"Wrong qty_to_deliver",
)
self._check_equal_quantity(
Expand All @@ -922,7 +922,7 @@ def test_04_supplier_rma(self):
)
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_2).qty_to_deliver,
5,
0,
"Wrong qty_to_deliver",
)
self._check_equal_quantity(
Expand All @@ -932,7 +932,7 @@ def test_04_supplier_rma(self):
)
self._check_equal_quantity(
lines.filtered(lambda x: x.product_id == self.product_3).qty_to_deliver,
2,
0,
"Wrong qty_to_deliver",
)
self.assertEqual(
Expand Down