How to use fields_get method in Odoo 18

CelineGeorge1 288 views 8 slides Aug 29, 2025
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

fields_get allows for more flexible and dynamic Odoo customizations, making your modules more adaptable to different scenarios and user roles. It's an essential method for advanced Odoo development.


Slide Content

How to use fields_get method in Odoo 18 Enterprise

Enterprise Introduction In this slide, we’ll discuss on how to use fields_get method in Odoo 18. In Odoo development, understanding how to change field properties dynamically can greatly enhance the flexibility and functionality of your modules. The fields_get() is a useful method that allows developers to retrieve and modify metadata of fields defined in Odoo models.

Enterprise The fields_get() will actually return the definition of each field in a model. The returned value is a dictionary (indexed by field name) of dictionaries. The _inherits fields are included. The string, help, and selection (if present) attributes are translated. The fields_get() will be useful in scenarios where: Hide fields from Custom Filter and Custom Group by menu in search view based on conditions. Hiding or making fields readonly based on user roles or other conditions. Conditionally preventing the field from being exported. We can see each of these examples.

Enterprise Hide field from Groupby/Filters based on condition. from odoo import api, models class AccountMove (models.Model) : _inherit = 'account.move' @api.model def fields_get (self, allfields=None, attributes=None) : res = super().fields_get(allfields, attributes) if self.env.company.id != 2 : if res.get( 'partner_id' ): res[ 'partner_id' ][ 'searchable' ] = False return res

Enterprise Change field string based on condition from odoo import api, fields, models class ProductTemplate (models.Model) : _inherit = 'product.template' @api.model def fields_get (self, allfields=None, attributes=None) : res = super().fields_get(allfields, attributes) print(res, "ress" ) if 'default_code' in res: res[ 'default_code' ][ 'string' ] = 'Product Code.' return res

Enterprise Set a field as non-exportable based on condition. from odoo import api, models class AccountMove (models.Model) : _inherit = 'account.move' @api.model def fields_get (self, allfields=None, attributes=None) : res = super().fields_get(allfields, attributes) if self._context.get( 'default_move_type' ) == 'out_invoice' : if 'payment_state' in res: res[ 'payment_state' ][ 'exportable' ] = False return res

Enterprise Like the above mentioned examples, you can modify all other field attributes using the fields_get() . Using fields_get() in Odoo can significantly enhance customizations and allow dynamic adjustments of field properties based on user context or business logic which leads to a more flexible and user-centric experience.

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