Skip to content

Commit

Permalink
[FIX] purchase_stock: ignore the receipt of returned qty
Browse files Browse the repository at this point in the history
In some cases, the received qty of the POL is incorrect

To reproduce the issue:
1. Create and confirm a PO
2. Receive the product
3. Return the product:
   - Update quantities on SO/PO: False
4. Receive again ("return the return"):
   - Update quantities on SO/PO: False
5. Open the PO

Error: The received qty of the POL is incorrect, it includes the
second receipt

The second receipt is processed as a classic receipt, so we simply
add the done qty of the SM to the received qty of the POL. We have
to improve the conditions.

OPW-3483449

closes odoo#139140

X-original-commit: 4067bd6
Signed-off-by: Tiffany Chang (tic) <[email protected]>
Signed-off-by: Adrien Widart (awt) <[email protected]>
  • Loading branch information
adwid committed Oct 19, 2023
1 parent 838ee8d commit e1c2876
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/purchase_stock/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def _compute_qty_received(self):
# receive the product physically in our stock. To avoid counting the
# quantity twice, we do nothing.
pass
elif move.origin_returned_move_id and move.origin_returned_move_id._is_purchase_return() and not move.to_refund:
pass
else:
total += move.product_uom._compute_quantity(move.quantity_done, line.product_uom, rounding_method='HALF-UP')
line._track_qty_received(total)
Expand Down
31 changes: 31 additions & 0 deletions addons/purchase_stock/tests/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,34 @@ def test_po_edit_after_receive(self):
]
})
self.assertEqual(len(po_2.picking_ids), 1)

def test_receive_returned_product_without_po_update(self):
"""
Receive again the returned qty, but with the option "Update PO" disabled
At the end, the received qty of the POL should be correct
"""
po = self.env['purchase.order'].create(self.po_vals)
po.button_confirm()

receipt01 = po.picking_ids
receipt01.move_ids.quantity_done = 5
receipt01.button_validate()

wizard = Form(self.env['stock.return.picking'].with_context(active_ids=receipt01.ids, active_id=receipt01.id, active_model='stock.picking')).save()
wizard.product_return_moves.to_refund = False
res = wizard.create_returns()

return_pick = self.env['stock.picking'].browse(res['res_id'])
return_pick.move_ids.quantity_done = 5
return_pick.button_validate()

wizard = Form(self.env['stock.return.picking'].with_context(active_ids=return_pick.ids, active_id=return_pick.id, active_model='stock.picking')).save()
wizard.product_return_moves.to_refund = False
res = wizard.create_returns()

receipt02 = self.env['stock.picking'].browse(res['res_id'])
receipt02.move_ids.quantity_done = 5
receipt02.button_validate()

self.assertEqual(po.order_line[0].qty_received, 5)
self.assertEqual(po.order_line[1].qty_received, 5)

0 comments on commit e1c2876

Please sign in to comment.