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

Hello, I have Odoo 8.

I need to add a "group by" button in a report. I know that the XML code is like this:

<filter name="groupby_name" context="{'group_by': 'field''}" string="Description" />

But I have a model A on where I do the group by and this model has a many2one relation with a model B. The attribute of the many2one relation is named "rel". If I need to group by over any field of model B, how can I do? If I write

<filter name="groupby_name" context="{'group_by': 'rel.name_field''}" string="Description" />

But when I press the button to grupo by I get: TypeError: this.fields[field] is undefined

How can I do this groupby? Thanks!

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

Hello Jose,

Related field field by default it will not store in the Database, so you have to pass store=True argument while declare the field on python, after that you can able to do group by.

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

take related field:

e.g.

rel = fields,many2one('modelB')

field_use_in_filter = fields.field_type(related='rel.field_name')

and then use it in a filter 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
7
thg 5 20
6407
0
thg 4 16
3074
2
thg 4 15
5962
11
thg 9 21
32158
2
thg 3 25
8455