Skip to content
Snippets Groups Projects
Commit 39bf31ef authored by Jérome Maes's avatar Jérome Maes
Browse files

[FIX] lunch: don't break lunch widget

In order to sort lunch order by date desc, the commit
9ab9da23 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 !
parent 9d1744b7
Branches
Tags
No related merge requests found
# -*- 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment