Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes

CelineGeorge1 327 views 7 slides May 02, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Mixin classes are helpful for developers to extend the models. Using these classes helps to modify fields, methods and other functionalities of models without directly changing the base models. This slide will show how to extend models using mixin classes in odoo 17.


Slide Content

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes Enterprise

Introduction Enterpr ise Mixin classes are helpful for developers to extend the models. Using these classes helps to modify fields, methods and other functionalities of models without directly changing the base models. This slide will show how to extend models using mixin classes in odoo 17.

Enterprise Define a Mixin Class: Define a new python class for the mixin. A mixin class typically contains methods or fields that we can add to other models if we want. First, create a mixin class with some fields. Those fields can be used in the model that is inherited.

Enterprise class ClassMixin(models.AbstractModel): _name = 'class.mixin' name = fields.Many2one('res.partner', string='Student') class_id = fields.Integer(string='Class') division = fields.Char(string='Division') mark = fields.Float(string="mark")

Enterprise Apply the Mixin to a Model: Apply the mixin to an existing model. For that, first inherit the mixin class in the target model Ie, Class School(models.Model) _name = ‘school.student’ _inherit = [‘class.mixin’]

Enterprise The Benefits of Mixin Classes: Code Reusability: It is possible to reuse the code on multiple models. Modular development: Developers can create separate mixin classes for different types of functionality. Better Code Organization: It helps to keep the code clean and organized. Reduced Code Conflicts: It minimizes the chances of conflicts when multiple developers working on the same.

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