Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2666 Переглядів

I want to override a function and add more new function into an existing Odoo's js file like website_sale.js and a function in '.py' controller files.

So how can i do that by coding in a custom module?

Аватар
Відмінити
Найкраща відповідь

Hi to add or override an existing function in a custom javascript file you have to extend its public widget, you can do it as follows:              

odoo.define('your_module.widget_name', function (require) {
'use strict';

var publicWidget = require('web.public.widget');
//import/require the existing widget that you want to modify
var widget_Variable_name = require('module_name.widget_name');
//or
var widget_Variable_name = require('module_name.widget_name').widget_name;


publicWidget.registry.new_widget_Variable_name = widget_Variable_name.extend({

    function_name: function () {
//        your function definition
    },

})
});
and to add functions to the controller in Python, you have to import the controller and inherit its class as:
from odoo import http
from odoo.http import request
//import the controller you want to add function to
from odoo.addons.website_sale.controllers.main import WebsiteSale


class WebsiteSaleInherit(WebsiteSale):

@http.route(['/your_route'], type='http', auth="public", website=True,
                sitemap=False)
    def your_function(self, your_params(eg:**post)):
        res = super(WebsiteSaleInherit, self).your_function(your_params)
        //your function modifications
        return res

Hope it helps


Аватар
Відмінити