콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
8401 화면

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]))

아바타
취소