Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
5640 Vistas

I am currently working on a custom module for Odoo 17 and facing an issue with JavaScript customization in the Point of Sale (POS) module. I am trying to override the add_product method in the POS, but my changes don't seem to take effect. I've ensured that my JavaScript file is included in the point_of_sale.assets bundle, but I'm not seeing the expected behavior or any console logs that I've added for debugging.


I included the JavaScript file in the point_of_sale.assets bundle in my module's __manifest__.py. Here's a snippet of the code for reference:


odoo.define('give_and_get_order_module.CustomOrder', function(require) {
    'use strict';

    var models = require('point_of_sale.models');
    var OrderSuper = models.Order.prototype;

    models.Order.include({
        add_product: function(product, options) {
            console.log("Custom add_product method called");
            if (!options || !options.quantity) {
                options = options || {};
                options.quantity = -1;
            }
            return OrderSuper.add_product.apply(this, [product, options]);
        },
    });
});

And the relevant part of my __manifest__.py:

'assets': {
    'point_of_sale.assets': [
        'give_and_get_order_module/static/src/js/custom_order.js',
    ],
},

I would appreciate any insights or suggestions on what I might be missing or doing wrong. Is there a specific aspect of POS module customization in Odoo 17 that I need to be aware of?

Thank you in advance for your help!

Avatar
Descartar
Mejor respuesta

Hey Technology Pill Business Solution,


I hope you are doing well.


For inheriting add_product function, we need to follow the steps defined below:

1. Create models.js file under static > src > overrides > models directory.

2. Use the below code for inheriting Order from base models.js using Patch.


/* @odoo-module /


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

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


patch(Order.prototype, {

    async add_product(product, options) {

// Your custom code

        return super.add_product(...arguments);

    },

});


3. Insert custom JS path in manifest.

Note:- Add ‘point_of_sale’ in your customer module’s depends.

- Odoo.define is deprecated in Odoo V17.


Hope this will help you.

Thanks & Regards,
Email:   odoo@aktivsoftware.com      

Skype: kalpeshmaheshwari

Avatar
Descartar
Mejor respuesta

From your code, it seems like you’re correctly including your JavaScript file in the 'point_of_sale.assets' bundle and your method override also looks correct. However, there are a few things you might want to check:

  1. Order of JS files: Ensure that your JavaScript file is loaded after the original file you’re trying to override. The order of JavaScript files in the assets bundle can affect the behavior of your customization.
  2. Module Dependency: Make sure that your custom module depends on the 'point_of_sale' module. You can specify this in the 'depends' section of your '__manifest__.py' file.
  3. Browser Cache: Clear your browser cache or try in incognito mode. Sometimes, the browser might be loading a cached version of your JavaScript file.
  4. Server Restart: After making changes to the '__manifest__.py' file, you need to restart your Odoo server and upgrade your module.

If you’ve checked all of these and your method override is still not working, it might be due to some changes in Odoo 17’s POS module. In Odoo 17, there are new ways to load custom models and fields. You might need to inherit the 'pos.session' model and overwrite the '_pos_ui_models_to_load()' method. Also, creating a custom screen involves patching the 'PosStore' and overriding the '_processData' function.

I hope this helps! If you’re still facing issues, please provide more details about the behavior you’re observing and any error messages you’re seeing. I’ll do my best to assist you further. 

Best regards,
Maciej Burzymowski


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
abr 25
1206
1
ago 24
1978
3
may 24
11182
1
sept 23
3530
0
ago 23
1693