Default Group By Expand Option In Odoo 17

CelineGeorge1 1,099 views 8 slides Aug 05, 2024
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

Default_group_by is an attribute used on Odoo xml. Usually it is used with the view tags such as , ,etc to specify the default field by which the records should be grouped by default.


Slide Content

d efault_group_by and expand Options In Odoo Enterprise

Introduction Enterprise default_group_by is an attribute used on Odoo xml. Usually it is used with the view tags such as <tree>, <kanban>,etc to specify the default field by which the records should be grouped by default. This parameter can be useful if we need to organize the records when it is loaded for the first time and hence the user experience can be enhanced.

Enterprise Here is an example of how default_group_by can be used in our code. For that, let’s create a simple model to store student details such as student_id, admission_date and state. class StudentDetails(models.Model): _name = 'student.details' _description = 'Student Card' student_id = fields.Many2one('res.partner', string="Student Name", required=True, domain=[("user_ids", "=", False)]) admission_date = fields.Date(string="Admission Date", default=fields.Date.today()) stage = fields.Selection([("applied", "Applied"), ('docs', "Documents Collected"), ('verify', 'Verification'), ('admit', 'Admitted')], string="Stage", default='applied')

Enterprise So, the normal tree view with these three fields will look like this

Enterprise Now, give the default_group_by parameter for the tree view as <tree string="Students List" default_group_by="stage"> <field name="admission_date"/> <field name="student_name_id"/> <field name="stage"/> </tree> This will result in showing the view like

Enterprise Now, let’s talk about expand parameter. It is used in the context of tree views to control how grouping behaves. Specifically, it determines whether the grouped items should be expanded by default when the view is loaded. We use expand=”1’” to use this. The full code for the previous <tree> tag will be as <tree string="Students List" default_group_by="stage" expand="1"> <field name="admission_date"/> <field name="student_name_id"/> <field name="stage"/> </tree>

Enterprise This will result to change the previous view like

For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com