I want to create a new view_type in Odoo 14. I followed these instructions: https://www.odoo.com/documentation/14.0/fr/developer/reference/javascript/javascript_cheatsheet.html#creating-a-new-view-from-scratch and also this video: https://www.youtube.com/watch?v=SIoljYJhTqk&ab_channel=Odoo
I have this issue when I load the view: TypeError: Cannot read property 'modelExtension' of undefined
My JS:
odoo.define("personal_calendar_view.PersonalCalendarView", function(require){
"use_strict";
var AbstractController = require("web.AbstractController");
var AbstractModel = require("web.AbstractModel");
var AbstractRenderer = require("web.AbstractRenderer");
var AbstractView = require("web.AbstractView");
var ViewRegistry = require("web.view_registry");
var PersonalCalendarController = AbstractController.extend({});
var PersonalCalendarRenderer = AbstractRenderer.extend({});
var PersonalCalendarModel = AbstractModel.extend({});
var PersonalCalendarView = AbstractView.extend({
config: {
Model: PersonalCalendarModel,
Controller: PersonalCalendarController,
Renderer: PersonalCalendarRenderer,
},
view_type: "personal_calendar",
});
ViewRegistry.add("personal_calendar", PersonalCalendarView);
return PersonalCalendarView;
});
My python:
class View(models.Model):
_inherit = 'ir.ui.view'
type = fields.Selection(selection_add=[('personal_calendar', 'Personal calendar'),('general_calendar', 'General calendar')])
class ActWindowView(models.Model):
_inherit = 'ir.actions.act_window.view'
view_mode = fields.Selection(selection_add=[('personal_calendar', 'Personal calendar'),('general_calendar', 'General calendar')], ondelete={'personal_calendar': 'cascade','general_calendar':'cascade'})
And my XML:
<record id="view_planning_personal_calendar" model="ir.ui.view">
<field name="name">planning.scheduler.personal.calendar</field>
<field name="model">planning.scheduler</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<personal_calendar>
<field name="name"/>
<field name="user_id"/>
</personal_calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_personal_schedule">
<field name="name">Personal Schedule</field>
<field name="res_model">planning.scheduler</field>
<field name="view_mode">personal_calendar</field>
<field name="view_id" ref="view_planning_personal_calendar"/>
</record>
The stacktrace is:
Uncaught (in promise) TypeError: Cannot read property 'modelExtension' of undefined
at Class.init (web.assets_backend.js:1262)
at Class.prototype.<computed> [as init] (web.assets_common.js:4632)
at new Class (web.assets_common.js:4633)
at Class._createViewController (web.assets_backend.js:452)
at web.assets_backend.js:457
init @ web.assets_backend.js:1262
prototype.<computed> @ web.assets_common.js:4632
Class @ web.assets_common.js:4633
_createViewController @ web.assets_backend.js:452
(anonymous) @ web.assets_backend.js:457
setTimeout (async)
(anonymous) @ web.assets_common.js:1621
fire @ web.assets_common.js:1605
fireWith @ web.assets_common.js:1611
fire @ web.assets_common.js:1612
fire @ web.assets_common.js:1605
fireWith @ web.assets_common.js:1611
mightThrow @ web.assets_common.js:1618
process @ web.assets_common.js:1618
setTimeout (async)
(anonymous) @ web.assets_common.js:1621
fire @ web.assets_common.js:1605
fireWith @ web.assets_common.js:1611
fire @ web.assets_common.js:1612
fire @ web.assets_common.js:1605
fireWith @ web.assets_common.js:1611
done @ web.assets_common.js:2013
(anonymous) @ web.assets_common.js:2026
load (async)
send @ web.assets_common.js:2026
ajax @ web.assets_common.js:2005
(anonymous) @ web.assets_common.js:4587
_genericJsonRpc @ web.assets_common.js:4582
jsonRpc @ web.assets_common.js:4587
rpc @ web.assets_common.js:4588
query @ web.assets_common.js:4826
load_views @ web.assets_backend.js:597
load_views @ web.assets_backend.js:490
(anonymous) @ web.assets_common.js:4774
trigger @ web.assets_common.js:4772
_trigger_up @ web.assets_common.js:4778
_trigger_up @ web.assets_common.js:4778
trigger_up @ web.assets_common.js:4778
(anonymous) @ web.assets_common.js:4842
loadViews @ web.assets_common.js:4842
_loadViews @ web.assets_backend.js:461
_executeWindowAction @ web.assets_backend.js:453
_handleAction @ web.assets_backend.js:459
(anonymous) @ web.assets_common.js:4635
_handleAction @ web.assets_backend.js:479
(anonymous) @ web.assets_common.js:4635
(anonymous) @ web.assets_backend.js:421
Promise.then (async)
doAction @ web.assets_backend.js:421
do_action @ web.assets_backend.js:494
(anonymous) @ web.assets_backend.js:509
Promise.then (async)
on_hashchange @ web.assets_backend.js:509
new_handler @ web.assets_backend.js:313
dispatch @ web.assets_common.js:1726
elemData.handle @ web.assets_common.js:1712
Did someone had an idea?
When extend AbstractView, proceed like this:
var PersonalCalendarView = AbstractView.extend({
config: _.extend({}, AbstractView.prototype.config, {
Model: PersonalCalendarModel,
Controller: PersonalCalendarController,
Renderer: PersonalCalendarRenderer,
}),
});