Skip to Content
Menu
This question has been flagged
1 Reply
321 Views

Hello everyone, I'm trying to change a rule in the Odoo loyalty program, the points one, but I'm just starting to program and I have some questions, how do I declare a file in the manifest to patch another Odoo file? How should it start? I'm sharing my sample files since at the moment I can't get it to load or detect the file. If there were examples and how they declare them in their manifesto, it would help me a lot, at least so I can recognize them. Logically, I'll worry about it later, hehe.


Thank you very much.


/** @odoo-module **/


// plealtad/static/src/js/patches/pos_order_loyalty.js


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

import { Order } from "@point_of_sale/app/store/models";


alert('[Mascotier] Archivo JS cargado en POS OWL');

console.log('[Mascotier] pos_order_loyalty.js CARGADO ✔');


// Función de validación

function isLoyaltyAllowed(partner, programName = 'mascotier_rewards_points') {

    if (!partner || !partner.x_partner_loy_active) {

        console.warn(`[Mascotier] Partner ineligible para programa ${programName}`);

        return false;

    }

    const program = partner.loyalty_programs?.find(p => p.name === programName);

    return !!program;

}


// Guardar método original

const originalGetClaimableRewards = Order.prototype.getClaimableRewards;


// Aplicar patch

patch(Order.prototype, {

    getClaimableRewards() {

        console.log('[Mascotier] Ejecutando patch getClaimableRewards');

        const partner = this.get_partner();

        if (!isLoyaltyAllowed(partner)) {

            return [];

        }

        return originalGetClaimableRewards.call(this);

    },

});


 MANIFEST:


    'data': [

        'views/customer_registration_template.xml',

        'views/customer_dashboard_template.xml',

        'views/customer_reset_pass_request_template.xml',

        'views/customer_reset_pass_pin_template.xml',

        'views/customer_reset_pass_update_template.xml',

        'views/customer_login_template.xml',

        'views/pin_verification_template.xml',

        'security/ir.model.access.csv',

        'data/copomex_data.xml',

        'data/cron_cleanup.xml',

        'data/cron_pin_cleanup.xml',

    ],

    'assets': {

        'web.assets_frontend': [

            'plealtad/static/src/img/logo_mascotier.png',

            'plealtad/static/src/js/fields_validation.js',

            'plealtad/static/src/js/pin_timer.js',

        ],

        'point_of_sale.assets': [

            'plealtad/static/src/js/patches/pos_order_loyalty.js',

        ],

    },

    'installable': True,

    'application': False,

    'auto_install': False,

}


Avatar
Discard
Best Answer

Hi,

To get your custom POS patch to load, make sure:

  1. Your JS file is in this exact folder path:

    plealtad/static/src/js/patches/pos_order_loyalty.js

  2. Your __manifest__.py should have this under 'assets':

    'assets': { 'point_of_sale.assets': [ 'plealtad/static/src/js/patches/pos_order_loyalty.js', ], },

  3. Your JS file should start with:

    /** @odoo-module **/

  4. Restart the Odoo server and clear your browser cache (or hard refresh with Ctrl+F5).
  5. Check the browser console — if you see your console.log or alert, the file loaded


Hope it helps

Avatar
Discard