diff options
| author | Jérome Maes <jem@openerp.com> | 2017-06-22 14:28:52 +0200 |
|---|---|---|
| committer | Jérome Maes <jem@openerp.com> | 2017-06-23 11:31:08 +0200 |
| commit | 39bf31ef75b7bd59ffb972402e236dd794dd7deb (patch) | |
| tree | af3d06e793174a2ddb4644886296caa6953a3fc5 /addons/lunch/models | |
| parent | 9d1744b797645ec1d301ded2156d1016adfc2462 (diff) | |
[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 !
Diffstat (limited to 'addons/lunch/models')
| -rw-r--r-- | addons/lunch/models/lunch.py | 11 |
1 files 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 |
