Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
11142 มุมมอง

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>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

Hi Mario, I modified the answer. please check

ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
1670
1
พ.ค. 25
1659
QWeb: use t-if to check birthday date แก้ไขแล้ว
1
เม.ย. 25
2253
1
ก.พ. 25
1544
0
ต.ค. 24
1300