R&D Sneak Peak: Odoo 19 Embraces Pythonic Class Naming for ORM Models

October 15, 2024 by
admin


                                                                                                                 


Get ready, Odoo developers! Odoo 19 will be officially announced next year, yet journey to Odoo 19 has begun, and it brings a significant step towards a more Pythonic approach for defining ORM models. This means saying goodbye to underscores in model names and embracing the CamelCase convention for your classes.


Why the Change?
This shift aims to achieve two key goals:
  • Improved Consistency: CamelCase class names will ensure a more consistent naming scheme across models.
  • Enhanced Pythonic Feel: Removing the _name attribute streamlines code and aligns it better with general Python practices.


How Does it Work?
 
The script updates every class name to match the new convention. The name of a model (dotcase) is determined by the name of its class (camelcase) as follows. Each capital letter is lowercased and is preceded by a period, unless it is the first one or is itself preceded by an underscore. The use of underscores in model names is now discouraged.


             res.users <=> ResUsers
                    ir.ui.view <=> IrUiView
                    ir.config_parameter <=> IrConfig_parameter​


The _name attribute on model classes are removed, except in the case where the model name cannot be derived from the class name. The _inherit attribute is no longer used as a fallback for the model name, and only the list variant is now accepted.
For instance,


Example Transformation
Let's see how the new approach transforms some existing code snippets:


     class  FieldConverter(models.AbstractModel):
​ _name  =  'ir.qweb.field'

      class  IntegerConverter(models.AbstractModel):
      ​ _name  =  'ir.qweb.field.integer'
      ​ _inherit  =  'ir.qweb.field'

        class Integer (models.AbstractModel):
        ​_name  =  'ir.qweb.field.integer'
        ​ _inherit  =  'ir.qweb.field.integer'

    /—————-/——————/
          Becomes:
  /———-—-/—————-/


      class  IrQwebField(models.AbstractModel):

         class  IrQwebFieldInteger(models.AbstractModel):
        ​ _inherit  =  ['ir.qweb.field']

        class  IrQwebFieldInteger(models.AbstractModel):
        ​_inherit  =  ['ir.qweb.field.integer']

 

Stay Tuned for More! 
This is just a glimpse into the exciting changes coming with Odoo 19. Keep an eye on our blog for further updates and insights into the evolving world of Odoo development!