Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
671 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 25
836
1
thg 7 25
549
3
thg 7 25
945
1
thg 6 25
648
1
thg 7 25
710