Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

723
Views
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 });
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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;
 });
about 4 years ago · Juan Pablo Isaza Report

0

This might help you, I inherit the point of sale widget screen as the below code,

odoo.define('js_frame_work_sample.jsframework', function (require) {
"use strict";

var Screens = require('point_of_sale.screens');
var core = require('web.core');
var _t = core._t;

Screens.PaymentScreenWidget.include({
    order_is_valid: function(force_validation) {
    var self = this;
    var order = this.pos.get_order();

    // FIXME: this check is there because the backend is unable to
    // process empty orders. This is not the right place to fix it.
    var order_paid = order.get_total_paid()
    console.log("order Paid", order_paid)

    if (order_paid <= 30) {
    alert("The sub total is below 30, No purchase")
    return false;
    }

    if (order.get_orderlines().length === 0) {
        this.gui.show_popup('error',{
            'title': _t('Empty Order'),
            'body':  _t('There must be at least one product in your order before it can be validated'),
        });
        return false;
    }

    if (!order.is_paid() || this.invoicing) {
        return false;
    }

    // The exact amount must be paid if there is no cash payment method defined.
    if (Math.abs(order.get_total_with_tax() - order.get_total_paid()) > 0.00001) {
        var cash = false;
        for (var i = 0; i < this.pos.cashregisters.length; i++) {
            cash = cash || (this.pos.cashregisters[i].journal.type === 'cash');
        }
        if (!cash) {
            this.gui.show_popup('error',{
                title: _t('Cannot return change without a cash payment method'),
                body:  _t('There is no cash payment method available in this point of sale to handle the change.\n\n Please pay the exact amount or add a cash payment method in the point of sale configuration'),
            });
            return false;
        }
    }

    // if the change is too large, it's probably an input error, make the user confirm.
    if (!force_validation && order.get_total_with_tax() > 0 && (order.get_total_with_tax() * 1000 < order.get_total_paid())) {
        this.gui.show_popup('confirm',{
            title: _t('Please Confirm Large Amount'),
            body:  _t('Are you sure that the customer wants to  pay') +
                   ' ' +
                   this.format_currency(order.get_total_paid()) +
                   ' ' +
                   _t('for an order of') +
                   ' ' +
                   this.format_currency(order.get_total_with_tax()) +
                   ' ' +
                   _t('? Clicking "Confirm" will validate the payment.'),
            confirm: function() {
                self.validate_order('confirm');
            },
        });
        return false;
    }

    return true;
},


});

});

It work's fine with the validation of order_paid not less than 30.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!