Daily updates from Odoo
Thursday, July 23, 2020
2 changes
Enhancements to existing features
This update streamlines how Odoo prepares default values when users create new records, avoiding unnecessary work and reducing the risk of inconsistent defaults. It also fixes some company-specific default value issues, helping forms and wizards open more reliably across several business apps.
Original PR description
##### `default_get` is one of the main Odoo methods: * Form views opening with new records triggers one default_get, requesting the values of the fields in the view * Records creation (`create`…
##### `default_get` is one of the main Odoo methods: * Form views opening with new records triggers one default_get, requesting the values of the fields in the view * Records creation (`create` calls) goes through 1 default_get call by values pair (unless all fields values are given to the create). Therefore, `default_get` overrides have to be correctly designed, to avoid any unnecessary operations (and guarantee the consistency and coherence of default values). 1) Do not specify unwanted defaults in `default_get`: When default_get is called, the wanted fields are specified through the `fields_list` arg. Providing the defaults for unrequested fields will only lead to unnecessary operations. 2) Leave generic `default_get` behavior to the ORM level as much as possible: * `default_` context keys should only be managed at ORM level. The `default_get` overrides shouldn't use the value in context, only the values returned by the `super` call. NB: to ensure that the ORM `default_get` correctly consider those context keys, the fields should be in present in the view. * Replace/shorten `default_get` overrides when a `default` can be specified on the field itself instead. The ORM won't call it when the field default is not needed. 3) Fix some defaults issues when found: * Potentially wrong defaults in multi-company environments * Defaults of fields depending on other fields defaults should be specified in `default_get` overrides, not in the `default` attribute of the field 4) When possible, remove/simplify operations done in `default_get` overrides. Enterprise counterpart of https://github.com/odoo/odoo/pull/54246
Studio now works better with an underlying performance improvement that skips loading fields hidden by default. Users can still choose to show invisible fields when editing forms, while benefiting from faster form rendering in normal use.
Original PR description
Community PR odoo/odoo#54368 implements an optimization of the form renderer consisting in skipping the rendering of invisible fields (invisible="1"). However, in Studio, we sometimes need to display them (in 'show invisible' mode). We thus toggle the given flag when necessary. This commit allows adapt tests accordingly.