Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
779 Tampilan

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

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Penulis

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.

Post Terkait Replies Tampilan Aktivitas
1
Jun 25
959
1
Jul 25
661
3
Jul 25
1046
1
Jun 25
701
1
Jul 25
826