4

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);

});
Mariano DAngelo
  • 920
  • 5
  • 18
  • 39
  • `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 May 20 '19 at 13:23

1 Answers1

2

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.

Charif DZ
  • 14,415
  • 3
  • 21
  • 40
  • yes all fields have it but, but in mine is underfined, becouse I need the model of the current view, its a widget place it in the systray, is there any core module that store the model of the current load view? – Mariano DAngelo May 21 '19 at 12:31
  • What about action manager? I don't know if there is a way to access it directly from odoo variable may be?!! – Charif DZ May 21 '19 at 13:08