跳至内容
菜单
此问题已终结
1 回复
556 查看

How can I modify the pivot view to do the following:

  1. Restrict the groupable fields in the rows and columns i.e. I want certain fields in the rows only and certain fields in the columns only
  2. Hide the None group in the table

Odoo v18 Community Edition

形象
丢弃
最佳答案

Hi,


1- Restricting Groupable Fields in Rows/Columns

       <record id="view_model_my_pivot" model="ir.ui.view">

  <field name="name">my.model.pivot.restricted</field>
<field name="model">my.model</field>
<field name="arch" type="xml">
<pivot string="Custom Analysis" default_group_by="[['category']]" >
<field name="category" type="row"/>
<field name="user_id" type="col"/>
<field name="amount" type="measure"/>
<field name="count" type="measure"/>
</pivot>
</field>
</record>


      - <field name="category" type="row"/> :-  This field will be used for rows in the pivot table. It implies that the pivot table will group data based on the "category" field of the model.


      - <field name="user_id" type="col"/> :- This field will be used for columns in the pivot table. It implies that the pivot table will organize data horizontally based on the "user_id" field of the model.



2. Removing Unwanted Options from ‘Group By’ & Hiding “None”


        - To hide the “None” group in a pivot view in Odoo 18 Community Edition, you need to ensure that the fields used for grouping (rows or columns) never have null/False values in the dataset being visualized. Odoo shows "None" automatically when grouped fields are empty.


*  Add a domain to exclude nulls:-

      Edit you action as,

             <record id="action_my_model_pivot" model="ir.actions.act_window">

                     <field name="name">My Pivot</field>

                     <field name="res_model">my.model</field>

                     <field name="view_mode">pivot</field>

                     <field name="domain">[('my_group_field', '!=', False)]</field>

            </record>


Hope it helps

形象
丢弃
编写者

1. The code you've given sets the default row and col, but users can still change the fields to group by. This doesn't enforce the restriction of fields that I want.
2. The nature of my model and data is such that all records will have certain fields False.

相关帖文 回复 查看 活动
1
6月 25
700
1
7月 25
416
3
7月 25
791
1
6月 25
556
1
7月 25
598