From 9200d3a5b2ea2ac6c3d0bbf88982e225f9027a86 Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 27 Oct 2023 16:02:27 +0200 Subject: [PATCH] [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 --- addons/product_expiry/models/stock_quant.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/product_expiry/models/stock_quant.py b/addons/product_expiry/models/stock_quant.py index 2fef651f80c..69f1c40c3f7 100644 --- a/addons/product_expiry/models/stock_quant.py +++ b/addons/product_expiry/models/stock_quant.py @@ -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)