Skip to content

OD113 fields-view-get-removed

fields_view_get() is removed; override _get_view() or get_views().

Category Severity Series Needs the index
Deprecation Error 16.0 and later no

What it reports

A model class that defines a fields_view_get() method, in a module of series 16.0 or later.

Why it matters

From 16.0, the web client loads views through get_views(), which builds each view's architecture with _get_view(). Nothing in Odoo calls fields_view_get() any more, so an override of it raises no error and changes nothing: the view appears without the changes it was meant to make. In 16.0, fields_view_get() survives only as a deprecated method that calls get_views(); from 17.0 it is gone, and a super().fields_view_get() call in the override fails as well.

Modules of earlier series are not checked, since fields_view_get() is the right method there. _get_view() receives the architecture as an lxml element and its result is cached per view and language, so a change that depends on the user belongs in get_view(), which runs on each call, or in an inherited view restricted with groups.

Example

models/sale_order.py
class SaleOrder(models.Model):
    _inherit = "sale.order"

    @api.model
    def fields_view_get(self, view_id=None, view_type="form", toolbar=False, submenu=False):
        res = super().fields_view_get(view_id, view_type, toolbar, submenu)
        if view_type == "form":
            arch = etree.fromstring(res["arch"])
            for node in arch.xpath("//field[@name='client_order_ref']"):
                node.set("required", "1")
            res["arch"] = etree.tostring(arch, encoding="unicode")
        return res

The web client never calls this method, so the customer reference stays optional.

models/sale_order.py
class SaleOrder(models.Model):
    _inherit = "sale.order"

    @api.model
    def _get_view(self, view_id=None, view_type="form", **options):
        arch, view = super()._get_view(view_id, view_type, **options)
        if view_type == "form":
            for node in arch.xpath("//field[@name='client_order_ref']"):
                node.set("required", "1")
        return arch, view

Suppressing

def fields_view_get(self, view_id=None, view_type="form", **kwargs):  # odooscan: ignore[OD113]

See suppressing a finding.