Skip to content

Commit

Permalink
[FIX] stock_account: Correct order in candidates_receipt search for F…
Browse files Browse the repository at this point in the history
…IFO valuation

When decreasing `qty_done` in an outgoing stock move,
the search query for `candidates_receipt` was ordering by `date` in ascending order,
resulting in the selection of the oldest record instead of the most recent one.

This commit changes the order to `date desc, id desc`
to ensure the most recent record is selected,
as intended by the comments in the write method.
  • Loading branch information
kanda999 committed May 16, 2024
1 parent 978b2cf commit 02fb389
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion addons/stock_account/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def write(self, vals):
# no need to adapt `remaining_qty` and `remaining_value` as `_run_fifo` took care of it
move_vals['value'] = move_id.value - correction_value
elif move_id._is_out() and qty_difference < 0:
candidates_receipt = self.env['stock.move'].search(move_id._get_in_domain(), order='date, id desc', limit=1)
candidates_receipt = self.env['stock.move'].search(move_id._get_in_domain(), order='date desc, id desc', limit=1)
if candidates_receipt:
candidates_receipt.write({
'remaining_qty': candidates_receipt.remaining_qty + -qty_difference,
Expand Down

0 comments on commit 02fb389

Please sign in to comment.