From 04ee39f3e5da53a54d482e189852cd3744161c5a Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 17 Jul 2018 08:09:03 +0200 Subject: [PATCH] [IMP] replace python sort with SQL --- stock_cycle_count/models/stock_location.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stock_cycle_count/models/stock_location.py b/stock_cycle_count/models/stock_location.py index 2dc9c94d0..93886b082 100644 --- a/stock_cycle_count/models/stock_location.py +++ b/stock_cycle_count/models/stock_location.py @@ -23,9 +23,12 @@ class StockLocation(models.Model): @api.multi def _compute_loc_accuracy(self): for rec in self: - history = self.env['stock.inventory'].search([ - ('location_id', '=', rec.id), ('state', '=', 'done')]) - history = history.sorted(key=lambda r: r.write_date, reverse=True) + history = self.env['stock.inventory'].search( + [('location_id', '=', rec.id), + ('state', '=', 'done'), + ], + order='write_date DESC' + ) if history: wh_id = rec.get_warehouse(rec) wh = self.env['stock.warehouse'].browse(wh_id)