This question has been flagged
2 Replies
10814 Views

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
Discard

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

Best Answer

Please try:

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

Avatar
Discard

That worked for me, Thanks

Best Answer

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
Discard

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