تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
8386 أدوات العرض

Hi,

how can i order by key 'date' an array like this in qweb report? Odoo v11

[{'id':'1', 'date':'2019-05-01'},{'id':'2', 'date':'2018-01-01'},{'id':'3', 'date':'2019-01-01'}]

الصورة الرمزية
إهمال

Odoo Tips, Hope this will helps: https://old.reddit.com/r/learnopenerp/

أفضل إجابة

Hello

please try with below code:

from operator import itemgetter
list_to_be_sorted = [{'id':'1', 'date':'2019-05-01'},{'id':'2', 'date':'2018-01-01'},{'id':'3', 'date':'2019-01-01'}]
newlist = sorted(list_to_be_sorted, key=itemgetter('date'))
print newlist
الصورة الرمزية
إهمال

for qweb, <t t-foreach="sorted(list_to_be_sorted, key=itemgetter('date'))" t-as="record">

...

</t>

أفضل إجابة

In QWeb Report you can order them like in Python code:

 <tr t-foreach="docs.sorted(key=lambda x: x.date)" t-as="item">

    ...

</tr>

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

With expression:
OrderedDict(sorted(Lines[o.id][currency].items(), key=lambda t: t[0]))

The error is:
AttributeError: 'list' object has no attribute 'items'


With expression:
Lines[o.id][currency].sorted(key=lambda b: b[0])

The error is:
AttributeError: 'list' object has no attribute 'sorted'

الصورة الرمزية
إهمال
أفضل إجابة

Try this:


ordered = OrderedDict(sorted(mydict.items(), key=lambda t: t[0]))

الصورة الرمزية
إهمال