Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
9476 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ

specifically which relation field many2one, x2many? field name?

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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,
)
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Tác giả

Relational field is not working in _order method

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 25
1316
0
thg 1 25
1138
1
thg 12 24
1466
1
thg 6 22
5603
Field __last_update Đã xử lý
1
thg 2 19
4982