3
votes

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
this.view.model is an option if view exists in your context. If not, try with this.field_manager.datarecord. It has a lot of attributes of the current record, where you'll probably find the current model. Even just in this.field_manager you may find it.forvas

1 Answers

2
votes

As I remember you can access the the model of the widget like this:

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

all widget have this attribute it's string type contains the name of the model.