Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
1068 Zobrazení

ODOO 18

I’m working on a POS module where I’m trying to apply a patch. The component is invoice_button. The issue is that when I run the POS to test it, the patch doesn’t take effect: if I add a console.log inside the onWillInvoiceOrder function, it doesn’t run. However, the console.log does run if I load it before the patch.


Could you guide me on what might be going wrong? I’m attaching some code and the module’s structure.

point_of_sale [invoice_button] -> l10n_mx_edi_pos [invoice_button] -> my_module [invoice_button]

All the other POS assets (JS included) are working as expected.

# Code

import { InvoiceButton } from "@point_of_sale/app/screens/ticket_screen/invoice_button/invoice_button";

import { AddInfoPopup } from "@l10n_mx_edi_pos/app/add_info_popup/add_info_popup";

import { makeAwaitable } from "@point_of_sale/app/store/make_awaitable_dialog";

import { patch } from "@web/core/utils/patch";


patch(InvoiceButton.prototype, {

async onWillInvoiceOrder(order, newPartner) {

if (this.pos.company.country_id?.code !== "MX") {

return true;

}

const payload = await makeAwaitable(this.dialog, AddInfoPopup, {

order,

newPartner,

});

if (payload) {

order.l10n_mx_edi_cfdi_to_public =

payload.l10n_mx_edi_cfdi_to_public === true ||

payload.l10n_mx_edi_cfdi_to_public === "1";

order.l10n_mx_edi_usage = payload.l10n_mx_edi_usage;

// Add new field for payment term

order.payment_term_id = payload.clientPaymentTerm || 0;

await this.pos.data.ormWrite("pos.order", [order.id], {

l10n_mx_edi_cfdi_to_public: order.l10n_mx_edi_cfdi_to_public,

l10n_mx_edi_usage: order.l10n_mx_edi_usage,

payment_term_id: order.payment_term_id,

});

}

return Boolean(payload);

},

});

# Manifest

"depends": [

"point_of_sale",

"pos_settle_due",

"l10n_mx_edi_pos",

],

"assets": {

"point_of_sale._assets_pos": [

"bck_pos_uso_cfdi/static/src/**/*",

],

},





Avatar
Zrušit
Nejlepší odpověď

Hii,

/** @odoo-module **/


import { patch } from "@web/core/utils/patch";

import { registry } from "@web/core/registry";

import { InvoiceButton } from "@point_of_sale/app/screens/ticket_screen/invoice_button/invoice_button";

import { AddInfoPopup } from "@l10n_mx_edi_pos/app/add_info_popup/add_info_popup";

import { makeAwaitable } from "@point_of_sale/app/store/make_awaitable_dialog";


// Optional: Confirm patch is loaded

console.log("[bck_pos_uso_cfdi] Patching InvoiceButton...");


registry.category("pos_screens").add("patch_invoice_button", {

    async setup() {

        patch(InvoiceButton.prototype, {

            async onWillInvoiceOrder(order, newPartner) {

                console.log("[bck_pos_uso_cfdi] onWillInvoiceOrder triggered");


                if (this.pos.company.country_id?.code !== "MX") {

                    return true;

                }


                const payload = await makeAwaitable(this.dialog, AddInfoPopup, {

                    order,

                    newPartner,

                });


                if (payload) {

                    order.l10n_mx_edi_cfdi_to_public =

                        payload.l10n_mx_edi_cfdi_to_public === true ||

                        payload.l10n_mx_edi_cfdi_to_public === "1";

                    order.l10n_mx_edi_usage = payload.l10n_mx_edi_usage;

                    order.payment_term_id = payload.clientPaymentTerm || 0;


                    await this.pos.data.ormWrite("pos.order", [ order.id ], {

                        l10n_mx_edi_cfdi_to_public: order.l10n_mx_edi_cfdi_to_public,

                        l10n_mx_edi_usage: order.l10n_mx_edi_usage,

                        payment_term_id: order.payment_term_id,

                    });

                }


                return Boolean(payload);

            },

        });


        console.log("[bck_pos_uso_cfdi] Patch applied to InvoiceButton");

    },

});


I hope it is of full use.

Avatar
Zrušit
Nejlepší odpověď

Hi,


You should patch the overridden InvoiceButton from l10n_mx_edi_pos, not the original @point_of_sale one.

1- Update the import.

import { InvoiceButton } from "@l10n_mx_edi_pos/app/screens/ticket_screen/invoice_button/invoice_button";

2- Then apply your patch as you did:

patch(InvoiceButton.prototype, {

  async onWillInvoiceOrder(order, newPartner) {

    console.log("Patched button clicked");  // Debug

    ...

  }

});


3- In your __manifest__.py, ensure your module is loaded after l10n_mx_edi_pos in the assets list:

"assets": {

    "point_of_sale._assets_pos": [

        "l10n_mx_edi_pos/static/src/**/*",  # already loaded before

        "bck_pos_uso_cfdi/static/src/**/*",  # your module after

    ],

},


This ensures your patch runs after all upstream overrides.


Hope it helps

Avatar
Zrušit
Nejlepší odpověď

Hey there! Sounds like you’re running into a typical odoo snag with module loading. If `console.log` in `onWillInvoiceOrder` isn't firing when it should, you might be seeing a module load order mess. It’s all about getting your custom module load after the ones you’re patching. Your manifest’s got `point_of_sale`, `pos_settle_due`, and `l10n_mx_edi_pos`, but ya gotta make sure `my_module` is coming in last so it can properly override what it needs to.


I'd say check the order of the modules loading and see if `my_module` is last. Play around with sequence numbers or interdependencies in those manifests. If that `console.log` worked when loaded sooner, it’s a hint that your patch ain't getting there in time during app start.


Also, make sure the assets for your module are in play. Clearing caches, updating dependencies, and server restarts can be a bit trial n’ error here, but load order fixes often dust it off. Odoo's cache can be quirky, for me it's been a real head-scratcher at times.


Don't forget to flip on developer mode. It’s a lifesaver for this kinda chase. Post more context or logs if you’re still stuck - it helps others help you out. Good luck!

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
8
zář 25
5386
4
srp 25
2136
3
dub 25
1564
1
bře 25
1653
1
srp 24
2444