From 39bf31ef75b7bd59ffb972402e236dd794dd7deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Thu, 22 Jun 2017 14:28:52 +0200 Subject: [PATCH] [FIX] lunch: don't break lunch widget In order to sort lunch order by date desc, the commit 9ab9da235f94552a917002804b054cbb916367ea modified the json structure (dict to array) of serialized 'previous_order' field, without changing js code. The previous order field should respect the new order, so using OrderedDict does the job ! --- addons/lunch/models/lunch.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/lunch/models/lunch.py b/addons/lunch/models/lunch.py index a3ec3e7f51b..e4c634a1649 100644 --- a/addons/lunch/models/lunch.py +++ b/addons/lunch/models/lunch.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from operator import itemgetter +from collections import OrderedDict import json import datetime @@ -92,9 +92,9 @@ class LunchOrder(models.Model): }.values() if self.previous_order_ids: - lunch_data = [] + lunch_data = {} for line in self.previous_order_ids: - lunch_data.append({ + lunch_data[line.id] = { 'line_id': line.id, 'product_id': line.product_id.id, 'product_name': line.product_id.name, @@ -103,8 +103,9 @@ class LunchOrder(models.Model): 'price': line.price, 'date': line.date, 'currency_id': line.currency_id.id, - }) - lunch_data.sort(key=itemgetter('date', 'line_id'), reverse=True) + } + # sort the old lunch orders by (date, id) + lunch_data = OrderedDict(sorted(lunch_data.items(), key=lambda t: (t[1]['date'], t[0]), reverse=True)) self.previous_order_widget = json.dumps(lunch_data) @api.one