How to call the python function from js file. I used the following code but i didn't work. Here, i want to show message in js file which is define in .py file. .py file from odoo import models, fields, api
class message_of_the_day(models.Model):
_name = "oepetstore.message_of_the_day"
@api.model
def my_method(self):
return {"hello": "world"}
message = fields.Text()
color = fields.Char(size=20)
.js file
odoo.define('petstore.petstore', function (require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var web_client = require('web.web_client');
var AbstractAction = require('web.AbstractAction');
var ControlPanelMixin = require('web.ControlPanelMixin');
var MessageOfTheDay = Widget.extend({
template: "MessageOfTheDay",
start: function() {
var self = this;
return new instance.web.Model("oepetstore.message_of_the_day")
.query(["message"])
.order_by('-create_date', '-id')
.first()
.then(function(result) {
self.$(".oe_mywidget_message_of_the_day").text(result.message);
});
},
});
var HomePage = AbstractAction.extend(ControlPanelMixin.{
template: "HomePage",
start: function() {
var messageofday = new MessageOfTheDay(this)
messageofday.appendTo(this.$el);
},
});
core.action_registry.add('message.homepage', HomePage);
})
;
I tried to solve the exerciser https://www.odoo.com/documentation/11.0/howtos/web.html#exercises using odoo11 js.