[FIX] product_expiry: add sort_key for fefo strategy

Steps to reproduce:
- Enable product expiry
- Add two lots in stock:
  - lot_1 expired in 5 days
  - lot_2 expired in 2 days
- Enable the 'First Expiry First Out' removal strategy on its product
category
- Create a delivery using this product and mark is as todo

Issue:
lot_1 will be selected even though it will expire later.

Following 2151a34, _gather() can now use `self` to filter on itself
instead of performing a search() to save some time.
Problem is, no sort_key was defined for 'fefo' strategy.

Part-of: odoo/odoo#140175
This commit is contained in:
clesgow
2023-10-31 08:24:42 +00:00
parent 1f2f329421
commit 9200d3a5b2
@@ -16,3 +16,8 @@ class StockQuant(models.Model):
if removal_strategy == 'fefo':
return domain, 'removal_date, in_date, id'
return super()._get_removal_strategy_domain_order(domain, removal_strategy, qty)
def _get_removal_strategy_sort_key(self, removal_strategy):
if removal_strategy == 'fefo':
return lambda q: (q.removal_date, q.in_date, q.id), False
return super()._get_removal_strategy_sort_key(removal_strategy)