-1

i need clarity about _super in JS. I tried to inherit a widget and call a super method. I tried a different way to super the function. Only one way got worked. But when analysing the Odoo source code we can see other methods are used for supering a method. I need to know why Odoo uses different super methods at different times.

Here is my sample code:

*.js

         odoo.define('pos_session_route.payment', function (require) {
      "use strict";

      var account_payment = require('account.payment');
      var AbstractField = require('web.AbstractField');
      var core = require('web.core');
      var field_registry = require('web.field_registry');

      var QWeb = core.qweb;
      var _t = core._t;
        console.log('paymenyyyyy',account_payment);

              account_payment.ShowPaymentLineWidget.include({
      //        AbstractField.include({

                  payment_widget : function () {

                  console.log('paymenyyyyy');

                  },
                  _render:function(){
                  console.log('hihooo');
      // account_payment.prototype._super.apply(this.arguments); didn't work
      // account_payment.ShowPaymentLineWidget.prototype._super.apply(this.arguments); didn't work
      // this._super.apply(this, arguments);didn't work
                  this._super(this.arguments); it works

                  }

                  })


      });
KbiR
  • 4,047
  • 6
  • 37
  • 103

1 Answers1

0

In Odoo 15, the AbstractField is an Owl Component.

With Owl Components, you better call the super with super(...arguments);

For non Owl Components, you can call the super with this._super.apply(this, arguments);

Also, reading your code, I'd suggest you separate what you're doing in the AbstractField and what you're doing in your account_payment. But that's not my business, you can have your reasons to do so ^^

Hope it helped !

Pierre Locus
  • 306
  • 2
  • 7