fields_view_get does not exist in Odoo 16

Question:

I was testing the modules of Odoo 15 that I developed in Odoo 16, I was using a lot of the method fields_views_get to have some behaviors to inject domain and context, before to render the component, but currently I can not find this method.

Someone here knows what will be the alternative to achieve some behavior in runtime (modify the XML with the etree component of lxml)?

The main goal here is to inject in the XML data that is very difficult to add without the env object since with the fields_views_get I was able to inject or make queries before returning the XML.

Asked By: Andres

||

Answers:

fields_view_get was renamed to get_view:

fields_view_get becomes get_view.
As it no longer returns the fields description,
keeping the fields in the name fields_view_get no longer makes sense.
Hence removing fields from the method name, it becomes view_get.
As it gets renamed anyway, we take the opportunity to rename it get_view,
which is more in line with the general getter/setter guidelines
in the model object world.
_fields_view_get becomes _get_view. For the same reasons than above.
load_views becomes get_views.

You can find more details in refactor fields_view_get, load_views commit

In the changed files, you can see an example of commit diff of res_users model which replaces:

def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

With:

def get_view(self, view_id=None, view_type='form', **options):
Answered By: Kenly

Basic views generally share the common structure defined below. Placeholders are denoted in all caps:

<record id="MODEL_view_TYPE" model="ir.ui.view">
  <field name="name">NAME</field>
  <field name="model">MODEL</field>
  <field name="arch" type="xml">
    <VIEW_TYPE>
      <VIEW_SPECIFICATIONS/>
    </VIEW_TYPE>
  </field>
</record>
Answered By: fardin mardani
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.