m0r7y
m0r7y

Reputation: 720

Qweb : How can I use method sort() or function sorted() on Qweb?


I try to call sort() method and sorted() function but it doesn't work.
Calling sorted() function :

<t t-set='data' t-value="{4: 'd', 3: 'c', 'b': 2, 'a': 1}"/>
<t t-set="list_key" t-value="sorted(list(data.keys()))"/>
<t t-esc="list_key"/>

But it gives me error like :

Error to render compiling AST TypeError: 'NoneType' object is not callable

Calling sort() method:

<t t-set='data' t-value="{4: 'd', 3: 'c', 'b': 2, 'a': 1}"/>
<t t-set="list_key" t-value="list(data.keys()).sort()"/>
<t t-esc="list_key"/>

It gives no error but when i try to access one element of list_key, i get this error :

Error to render compiling AST TypeError: 'NoneType' object is not subscriptable

Can you help me? Thanky you.

Upvotes: 0

Views: 1541

Answers (1)

arryph
arryph

Reputation: 2825

I don't know why you needed to create sort method inside your model definition, as sorted method is already provided to be applied on a recordset, can also be used inside qweb. For example, this line is taken from odoo community code:

<t t-foreach="move.move_line_ids.sorted(key=lambda ml: ml.location_id.id)" t-as="ml">

For more information on odoo ORM sorted method, you can read the official documentation.

Upvotes: 1

Related Questions