Skip to Content
Menu
This question has been flagged
1 Reply
4566 Views

I have a one2many field inside form, in this field i want to group by two field so i do some search i found that in odoo we can't group by fields in tree view inside a form, so i decided to add button that return tree view of model (one2many field), but until now i con't return tree view with group by fields any advices.

my code :

def display_offers(self):
search_view_id = self.env.ref('module_name.eligibility_result_filter').id
tree_view_id = self.env.ref('module_name.eligibility_result_tree').ids
form_view_id = self.env.ref('module_name.eligibility_result_form').ids
return {
'name': _('Display offers'),
'view_mode': 'tree',
'res_model': 'model.model',
'domain': str([('id', 'in', self.one2many_field.ids)]),
'context': {'search_default_operator': 1, 'search_default_technology': 1},
'search_view_id': search_view_id,
'views': [[tree_view_id, 'tree'], [form_view_id, 'form']],
'type': 'ir.actions.act_window',
'target': 'current',

} 


<record id="eligibility_result_filter" model="ir.ui.view">
<
field name="name">model.model.filter</field>
<
field name="model">model.model</field>
<
field name="arch" type="xml">
<
search string="offers">
<
group expand="1" string="Group By...">
<
filter name="Oper" string="Operator" domain="[]" context="{'group_by':'operator'}"/>
<
filter name="tech" string="Technology" domain="[]" context="{'group_by':'technology'}"/>
</
group>
</
search>
</
field>
</record>
Avatar
Discard
Author Best Answer

solution:

def display_offers(self):
search_view_id = self.env.ref('module_name.eligibility_result_filter').id
tree_view_id = self.env.ref('module_name.eligibility_result_tree').ids
form_view_id = self.env.ref('module_name.eligibility_result_form').ids
return {
'name': _('Display offers'),
'view_mode': 'tree',
'res_model': 'model.model',
'domain': str([('id', 'in', self.one2many_field.ids)]),
'context': 'context': {'group_by': ['operator', 'technology']},,
'search_view_id': search_view_id,
'views': [[tree_view_id, 'tree'], [form_view_id, 'form']],
'type': 'ir.actions.act_window',
'target': 'current',

Avatar
Discard

I loved this array in the grouping .. many thanks for your answer.

Related Posts Replies Views Activity
8
Apr 23
34141
4
Jan 18
2355
1
Nov 17
18612
1
Oct 22
3155
1
Jul 20
6741