This question has been flagged

I tried to call a python function from javascript bu getting below error,

    TypeError: odoo.Model is not a constructor

http://localhost:8069/web/content/800-79a133d/web.assets_backend.js:3724
Traceback:
_onBarcodePrint@http://localhost:8069/web/content/800-79a133d/web.assets_backend.js:3724:1133
proxy/<@http://localhost:8069/web/content/641-43f8051/web.assets_common.js:3641:8
dispatch@http://localhost:8069/web/content/641-43f8051/web.assets_common.js:892:378
add/elemData.handle@http://localhost:8069/web/content/641-43f8051/web.assets_common.js:865:151


Here is the code.

*.js

    odoo.define('documents.DocumentsInspector.inherit', function (require) {

"use strict";

  var model = require('documents.DocumentsInspector');

  var core = require('web.core');

  var _t = core._t;

  var qweb = core.qweb;

  var web = require('web.data');

  var DocumentsInspector = model.include({


  events: {

      'click .o_inspector_archive': '_onArchive',

      'click .o_inspector_delete': '_onDelete',

      'click .o_inspector_download': '_onDownload',

      'click .o_inspector_replace': '_onReplace',

      'click .o_inspector_lock': '_onLock',

      'click .o_inspector_share': '_onShare',

      'click .o_inspector_open_chatter': '_onOpenChatter',

      'click .o_inspector_tag_add': '_onTagInputClicked',

      'click .o_inspector_tag_remove': '_onRemoveTag',

      'click .o_inspector_trigger_rule': '_onTriggerRule',

      'click .o_inspector_object_name': '_onOpenResource',

      'click .o_preview_available': '_onOpenPreview',

      'click .o_document_pdf': '_onOpenPDF',

      'mouseover .o_inspector_trigger_hover': '_onMouseoverRule',

      'mouseout .o_inspector_trigger_hover': '_onMouseoutRule',

      'click .o_inspector_print': '_onBarcodePrint',

  },


  /**

   * @private

   */

  _onBarcodePrint: function () {

    new odoo.Model('ir.attachment').call('print_barcode'); //Here getting an error.

  },

  });

});




     *.py

     class IRAttachment(models.Model):

    _inherit = 'ir.attachment'

    barcode = fields.Char('Barcode')

    def print_barcode(self):

        print ('Am here')


And one more, actually i rewrite the `events` above again. How can i add new events to existing events without rewrite the complete code.? 

Avatar
Discard
Best Answer

_onBarcodePrint: function (){
            this._rpc({

                model: 'ir.attachment',

                method: 'print_barcode',

                args: [],

            })

}


Use RPC calls to the python function.


To extend events,


events: _.extend({}, model.prototype.events, {

//your events

}


(Haven't checked and verified, You get the idea)

Accept and Upvote, if helpful
Avatar
Discard