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

Hi Everyone!

I need to sort the data by Next Activity Deadline in CRM which is relational field. By default in Odoo, we don't have right to sort any relational field.

Any idea how to do sorting of this relational field?

อวตาร
ละทิ้ง

specifically which relation field many2one, x2many? field name?

คำตอบที่ดีที่สุด

Hi. Do you tested storing the field? Odoo needs stored field to do a sort.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I had a similar problem and I solved it by creating a second computed field and use this where required.

Example to get the idea:

@api.multi
def _compute_sorted_related_records(self):
for record in self:
record.sorted_related_records = record.related_records.sorted(
key=lambda r: r.my_sort_field
).ids

sorted_related_records = fields.Many2many(
'related.model',
compute=_compute_sorted_related_records,
)
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Ravi Gadhia

I need to sort activity_date_deadline field in CRM which is datetime type field and that field is not stored in database

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can add '_order' comment to sort record while listing out in list view. In that you can assign your field name and sorting method.


อวตาร
ละทิ้ง
ผู้เขียน

Relational field is not working in _order method

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 25
1339
0
ม.ค. 25
1152
Field service upgrade แก้ไขแล้ว
1
ธ.ค. 24
1498
1
มิ.ย. 22
5642
Field __last_update แก้ไขแล้ว
1
ก.พ. 19
4999