0

so I'm working on POS I added a custom qr code to the receipt generated but now I'm getting an encoding error because the async function to decode the image is set to time 0 - I want to override that function

the function is

odoo.define('point_of_sale.ReceiptScreen', function (require) {
    'use strict';

    const { Printer } = require('point_of_sale.Printer');
    const { is_email } = require('web.utils');
    const { useErrorHandlers } = require('point_of_sale.custom_hooks');
    const Registries = require('point_of_sale.Registries');
    const AbstractReceiptScreen = require('point_of_sale.AbstractReceiptScreen');
    const { useAsyncLockedMethod } = require('point_of_sale.custom_hooks');

    const { onMounted, useRef, status } = owl;


    const ReceiptScreen = (AbstractReceiptScreen) => {
        class ReceiptScreen extends AbstractReceiptScreen {
            setup() {
                super.setup();
                useErrorHandlers();
                this.orderReceipt = useRef('order-receipt');
                const order = this.currentOrder;
                const partner = order.get_partner();
                this.orderUiState = order.uiState.ReceiptScreen;
                this.orderUiState.inputEmail = this.orderUiState.inputEmail || (partner && partner.email) || '';
                this.orderUiState.isSendingEmail = false;
                this.is_email = is_email;

                onMounted(() => {

                    setTimeout(async () => {
                        if (status(this) === "mounted") {
                            let images = this.orderReceipt.el.getElementsByTagName('img');
                            for (let image of images) {
                                await image.decode();
                            }
                            await this.handleAutoPrint();
                        }
                    }, 0);
                });

I want to change it to

        await this.handleAutoPrint();  
    }
}, 1000); 

I tried extending the class but the first code runs then mine which should not be the case

4
  • but the first code runs then mine which should not be the case why would you think that? a time out of 0 will execute before a time out of 1000 Commented Oct 18, 2024 at 21:57
  • overriding means altering the behavior, so the 0 should become really irrelevant. OP you are likely overriding it too late... Put up a breakpoint and see when it gets called for the first time, chances are you'll be surprised. Commented Oct 18, 2024 at 22:52
  • why I want override the 0 to 1000 or 500 is I have a custom function that is adding a custom qr code with data fetched from an api so on the actual receipt the qr code is okay but since there's an autoprint function which setimeout = 0 it's not giving the qrcode time to be decoded in await image.decode(); Commented Oct 19, 2024 at 4:42
  • Can you provide more information? how are you doing it? Class above is the root component of receipt screen, show how you are doing Commented Nov 5, 2024 at 11:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.