تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
8 الردود
21942 أدوات العرض

Hi:

I'm using Odoo 12 Enterprise. I was wondering if it's posible to add a group by filter by more than 1 field, something like this:

<filter string="My Filter" name="my_filter" context="{'group_by':['field_1','field_2']}"/>

I tried it this way and it did not work, Odoo Views Documentation refers in the filter section:

context

a Python dictionary, merged into the action’s domain to generate the search domain

The key group_by can be used to define a groupby available in the ‘Group By’ menu. The ‘group_by’ value can be a valid field name or a list of field names.

الصورة الرمزية
إهمال

Idea:
1- You can create a computed field and concatenate two or more fields and return to that computed field.
2- Make that computed field store=True

أفضل إجابة

You can Add filter to Favorites like this by code or just add from front-end:- 

<record id="filter_invoice_refund" model="ir.filters">

<field name="name">By Credit Note</field>

<field name="model_id">account.invoice.report</field>

<field name="domain">[('move_type', '=', 'out_refund')]</field>

<field name="user_id" eval="False"/>

<field name="context">{'group_by': ['invoice_date:month', 'invoice_user_id']}</field>

</record>



الصورة الرمزية
إهمال
أفضل إجابة


الصورة الرمزية
إهمال
أفضل إجابة

this kinda of solution by using same name for filters and enable them by default you can get the result of group by state>customer  or you can swap filter order in code to get customer>state 

you can do in search tag it like this example 

<search>
<group string="Group By">
​<filter string="State" name="customer" context="{'group_by': 'state'}"/>
​<filter string="Customer" name="customer" context="{'group_by': 'customer_id'}"/>
group> </search>

and in model="ir.actions.act_window" enable both on them :

<record id="model_name_action" model="ir.actions.act_window">
​#rest of code
​<field name="context">{'search_default_customer': 1}field>
record>



الصورة الرمزية
إهمال
أفضل إجابة

Hi Daniel Almaguer

Check this answer:
https://www.odoo.com/forum/help-1/search-filter-group-by-for-more-than-1-field-148380

I hope it will help you.

Thank You

الصورة الرمزية
إهمال
أفضل إجابة

many years after, maybe it is usefull for some one...solution working  on  ver14 enterprise

 
conceptos liquidados nomina

hr\.payslip\.line
\ \ \ \ \ \ \ \ pivot\ \-\->
\ \ \{'search_default_day':1,
\ \ \ \ \ \ \ \ \ \ 'search_default_concepto':\ 1,
\ \ \ \ \ \ \ \ \ \ 'search_default_dif0':\ 1,
\ \ \}

\ \ \ \ \ \


\ "\ rel="ugc">ir\.ui\.view">
\ \ \ \ hr.payslip.line





 







الصورة الرمزية
إهمال
أفضل إجابة

in Odoo 14 it's not working as well.
It seems still not fixed now, or no plan to fix it. because the error text is : ""group_by" value must be a string" for 

context="{'group_by':['field_1','field_2']}"

الصورة الرمزية
إهمال
أفضل إجابة

Hello @Daniel,

You can not add a group by filter by adding more than one field in single filter.


you have to add two different filters for two different fields like this:


<filter string="My Filter1" name="myfilter1" context="{'group_by': 'field1'}"/>

<filter string="My Filter2" name="myfilter2" context="{'group_by': 'field2'}"/>

الصورة الرمزية
إهمال
أفضل إجابة

Hi Daniel, you are right. It should be possible to use group_by like that. I tested this way in Odoo 11 Enterprise and it was working perfectly.

But in Odoo 12 Enterprise, it throws me "Uncaught TypeError: Cannot read property 'type' of undefined". Not sure, it could be a bug.

الصورة الرمزية
إهمال