How to get odoo model from javascript?

时间:2019-05-19 03:53:14

标签: odoo odoo-11

I'm trying to do a widget to attach to the sysTrayMenu, I need to know on the on_click event, the current model of the view. I know that I can get it from the current browser url, but I wanted to know if is there a cleaner way to get it from the odoo js api.

For example if the user is in New quotation menu, I need to get sale.order

odoo.define('xx.systray', function (require) {
"use strict";

var config = require('web.config');
var SystrayMenu = require('web.SystrayMenu');
var Widget = require('web.Widget');
var ajax = require('web.ajax');


var xxMenu = Widget.extend({
    template:'solvo-support.helpMenu',
    events: {
        "click": "on_click",
    },
    on_click: function () {

//HERE I NEED TO GET THE CURRENT MODEL 
    },
});

SystrayMenu.Items.push(xxMenu);

});

1 个答案:

答案 0 :(得分:1)

我记得您可以像这样访问小部件的模型:

         this.model // or self.model if you defined self (self = this)

所有小部件都具有此属性,其字符串类型包含模型的名称。