Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
472 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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.

Powiązane posty Odpowiedzi Widoki Czynność
1
cze 25
646
1
lip 25
374
3
lip 25
724
1
cze 25
475
1
lip 25
507