Skip to Content
Menú
This question has been flagged
1 Respondre
1725 Vistes

Hello,


I want to modify a the method "_printReceipt" in the class "AbstractReceiptScreen" from the POS.

Actually the method is like that 

odoo.define('point_of_sale.AbstractReceiptScreen', function (require) {
    'use strict';
    const { nextFrame } = require('point_of_sale.utils');
    const PosComponent = require('point_of_sale.PosComponent');
    const Registries = require('point_of_sale.Registries');

    const { useRef } = owl;

    class AbstractReceiptScreen extends PosComponent {
        setup() {
            super.setup();
            this.orderReceipt = useRef('order-receipt');
        }
        async _printReceipt() {
           
            if (this.env.proxy.printer) {
                const printResult = await this.env.proxy.printer.print_receipt(this.orderReceipt.el.innerHTML);
                if (printResult.successful) {
                    return [...]

And I want to add an 'if' at the begining of the function (and keep the code after) like that

async _printReceipt() {
            if (...) {
​ // some code
​ } else
            if (this.env.proxy.printer) {
                const printResult = await this.env.proxy.printer.print_receipt(this.orderReceipt.el.innerHTML);
                if (printResult.successful) {
                    return true;
                } else {

I try something like that but it did'nt work

odoo.define('eggs_ticket.AbstractReceiptScreen', function (require) {
    'use strict';
    var receiptScreen = require("point_of_sale.AbstractReceiptScreen");

    receiptScreen.include({ // error here, it say that include methode doesn't exist
        async _printReceipt() {
            console.log("je suis dans le truc la dedans")
        },
    });
});


Thank you for your help


regards

Avatar
Descartar
Best Answer

Use mixins https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends#mix-ins

odoo.define('eggs_ticket.AbstractReceiptScreen', function (require) {
    'use strict';
    var receiptScreen = require("point_of_sale.AbstractReceiptScreen");

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



    const AbstractReceiptScreenExtend = (AbstractReceiptScreen) => {

        return class extends AbstractReceiptScreen {


                async _printReceipt() {


                    if () {

                       // some code

                    }

​super._printReceipt();

            };

    };

    Registries.Component.extend(AbstractReceiptScreen, AbstractReceiptScreenExtend);

    return AbstractReceiptScreen;

});





Avatar
Descartar
Related Posts Respostes Vistes Activitat
3
de gen. 24
13729
0
de nov. 16
4232
2
de nov. 24
3478
0
de set. 23
2135
1
de maig 16
5591