Skip to content
Advertisement

How to override js method in Odoo 15?

Can anyone give me minimal code so that any method I can override for JS method?

changeMode(mode) {
        if (!this.hasPriceControlRights && mode === 'price' ) {
          
            return;
        }
        if (!this.hasManualDiscount && mode === 'discount') {
            return;
        }
        this.trigger('set-numpad-mode', { mode });
    }

Advertisement

Answer

You need to extend in-place a class in the registry, it is documented in the point of sale ClassRegistry.

Example

odoo.define('MODULE_NAME.NumpadWidget', function(require) {
    'use strict';

    const NumpadWidget = require('point_of_sale.NumpadWidget');
    const Registries = require('point_of_sale.Registries');

    const CustomNumpadWidget = NumpadWidget => class extends NumpadWidget {
        changeMode(mode) {
        
            return super.changeMode(mode);
        }
    };

    Registries.Component.extend(NumpadWidget, CustomNumpadWidget);

    return NumpadWidget;
 });
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement