Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Sort on date field in QWEB report

By
Mario Gielissen | Openworx
on 10/27/15, 5:20 AM 1,040 views

Is it posible to sort on a date field in QWEB report?

<tr t-foreach="getLines(o)" t-as="line">
<td>
<span t-field="line.date"/> <===
</td>
<td>
1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/27/15, 5:42 AM

Hi,

One option is to inherit the model in your python file and add _order to sort the date in desc or asc. Then the report will be with sorted dates.

For eg:

class model_name(models.Model):
_inherit = 'model.name'
_order = 'date desc'

Another option is to modify the getLines() to return the records sorted by date field. For example, if you are having a recordset at the end of the function, sort it by date and then return.

For eg: (if you are working with new api)

def getLines(self,object):
moveline_obj = self.env['account.move.line']
movelines = moveline_obj.browse([self.id])
   recordset = movelines.sorted(key=lambda r: r.date)
   return recordset

Is it also possible to use python code in qweb? https://www.odoo.com/fr_FR/forum/help-1/question/qweb-report-sort-by-and-multi-lines-if-number-of-code-in-a-field-exceed-x-number-49722

Mario Gielissen | Openworx
on 10/27/15, 5:54 AM

Hi Mario, I modified the answer. please check

Akhil P Sivan
on 10/27/15, 6:30 AM

Hi Akhil, your solution with getlines () works, Many thanks!

Mario Gielissen | Openworx
on 10/27/15, 7:37 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/27/15, 5:20 AM
Seen: 1040 times
Last updated: 10/27/15, 10:07 AM