-
- Downloads
[IMP] base, web: support `x_active` for archiving
While x_name has long been automatically supported as an equivalent of name, x_active was not. This commit adds this behaviour OoB, both in the ORM and the web client. On the ORM-side, a new `_active_name` attribute is supported on models. This attribute specifies the field that should behave as an active marker for records of the model. It is supported the same way `active` has been until now (filtering by the `active_test` context key and toggled by the `action_archive`, `action_unarchive` and `toggle_active` methods). Although no check has been added on the field's type, it is assumed to be a boolean field (the same way no check is present on the `(x_)name` field). On the client-side, the list view and form view now both support detecting the presence of either `active` or `x_active` on records, automatically adding an '(Un)Archive' button in the Action menu if such a field is detected. Note that the ORM implementation does actually need the field to be named in any specific way, but since the web client has no mechanism to load information regarding a model (the lifecycle of an action loading includes loading the action, view and record(s) but no generic information about the model itself besides what is included in the views), we restrict the field's name to `(x_)active` to avoid confusion as any other name would work at the ORM-level but not in the client. In the future, the client might be able to more elegantly get information about models, but this was not the scope of this change and this solution should cover most cases. Note that the `active` field will always takes precedence over the `x_active` field to avoid confusing the polarity, even if both fields are present on the model. In the case of a custom field, it might be slightly annoying that the default value of a Boolean field is `False`, which means that upon adding the column, all existing records are automatically archived. This can easily be worked around using an `ir.default` record for that particular field and an update of existing records (e.g. through the list view). The goal of this change was not to make it easy to add support for custom active fields, but to make it possible - we have therefore kept this implementation which introduces few changes while adding enough flexibility for developers. See https://twitter.com/zubair_shafiq/status/1202587553871880192?s=20 for more info regarding supporting any `_active_name` in the web client. Co-authored-by:Raphael Collet <rco@odoo.com>
Showing
- addons/web/static/src/js/views/basic/basic_model.js 21 additions, 0 deletionsaddons/web/static/src/js/views/basic/basic_model.js
- addons/web/static/src/js/views/basic/basic_view.js 1 addition, 1 deletionaddons/web/static/src/js/views/basic/basic_view.js
- addons/web/static/src/js/views/form/form_controller.js 9 additions, 4 deletionsaddons/web/static/src/js/views/form/form_controller.js
- addons/web/static/tests/views/basic_model_tests.js 54 additions, 1 deletionaddons/web/static/tests/views/basic_model_tests.js
- odoo/addons/base/tests/test_search.py 40 additions, 0 deletionsodoo/addons/base/tests/test_search.py
- odoo/fields.py 4 additions, 3 deletionsodoo/fields.py
- odoo/models.py 36 additions, 18 deletionsodoo/models.py
Loading
Please register or sign in to comment