Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
11866 Vistas

Hello everyone,


I was using the presentation from the Odoo Experience 2018 as basis for creating a new view type from scratch (link below), but it seems it is not compatible anymore with the current version 14.


https://www.youtube.com/watch?v=SIoljYJhTqk


I get the following error when installing the example module provided ( download from https://github.com/Polymorphe57/hello_world_view_code ):


"ValueError: ir.actions.act_window.view.view_mode: required selection fields must define an ondelete policy that implements the proper cleanup of the corresponding records upon module uninstallation. Please use one or more of the following policies: 'set default' (if the field has a default defined), 'cascade', or a single-argument callable where the argument is the recordset containing the specified option."


It seems like the code to add the new view in the available view modes is not compatible anymore, due to it being a selection field with required argument set to True, but without any ondelete argument set. When adding the new view with following code it will not work:

class ActWindowView(models.Model):
_inherit = 'ir.actions.act_window.view'

view_mode = fields.Selection(selection_add=[('hello_world', "Hello World")])

PS: I also tried adding the 'ondelete' argument together with the 'selection_add', but it also fails. I tried ondelete='set null' and ondelete='cascade'. Neither option worked.


Can anyone point me to the right direction to solve this OR show the correct way to implement a new view from scratch compatible with odoo 14?


Thanks in advance!


PS: Even in the Odoo official documentation they explain it like this, but it seems like it does not work with version 14 ( https://www.odoo.com/documentation/14.0/reference/javascript_cheatsheet.html#creating-a-new-view-from-scratch )

Avatar
Descartar

Hi,

    I guess you are facing trouble while adding a selection field. Hope this video helps you,

    https://www.youtube.com/watch?v=4tlfzy-ZtMQ&vl=en

Thanks

Mejor respuesta

Please try:

view_mode = fields.Selection(selection_add=[
    ('hello_world', 'Hello World')
], ondelete={'hello_world': 'cascade'})

Avatar
Descartar

That worked for me, Thanks

Mejor respuesta

I installed the Hello World App example code and I fixed this same cascade problem. But I got other error, when I selected the Hello World App from the main menu. Do I need to set the "ControlPanel" to modelExtension in the Hello World App javascript code (hello_world_view.js)?

TypeError: Cannot read property 'modelExtension' of undefined

    at Class.init (http://localhost:8069/web/static/src/js/views/abstract_view.js:201:72)

    at Class.prototype.<computed> [as init] (http://localhost:8069/web/static/src/js/core/class.js:90:38)

    at Class.init (http://localhost:8069/hello_world_view/static/src/js/hello_world_view.js:118:21)

    at Class.prototype.<computed> [as init] (http://localhost:8069/web/static/src/js/core/class.js:90:38)

    at new Class (http://localhost:8069/web/static/src/js/core/class.js:107:33)

    at Class._createViewController (http://localhost:8069/web/static/src/js/chrome/action_manager_act_window.js:191:24)

    at http://localhost:8069/web/static/src/js/chrome/action_manager_act_window.js:306:43


abstract_view.js


 const searchModelParams = Object.assign({}, params, { action });

        if (this.withControlPanel || this.withSearchPanel) {

            const { arch, fields, favoriteFilters } = params.controlPanelFieldsView || {};

            const archInfo = ActionModel.extractArchInfo({ search: arch }, this.viewType);

            const controlPanelInfo = archInfo[this.config.ControlPanel.modelExtension]; // HERE the 'modelExtension' is undefined

            const searchPanelInfo = archInfo[this.config.SearchPanel.modelExtension];

            this.withSearchPanel = this.withSearchPanel && Boolean(searchPanelInfo);

            Object.assign(searchModelParams, {

                fields,

                favoriteFilters,

                controlPanelInfo,

                searchPanelInfo,

            });

        }


Odoo's documentation is very "poor." Therefore it is wery difficult to learn Odoo development.

Avatar
Descartar

Can't agree more ,even if you post your question you still won't find help

Publicaciones relacionadas Respuestas Vistas Actividad
2
abr 21
1992
0
sept 18
2214
2
abr 15
5979
1
mar 15
9776
0
feb 20
3815