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

Is there any way to patch a owl service function?


Just to give some context the idea is to reimplement the function _triggerDownload from the ActionService (@web/webclient/actions/action_service)


I have read the documentation have seen ways to patch components but not services.

Any help is appreciated.

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

Had to patch the start method from the service, although it works it does not seem to be the "best practice" to perform this override since I have to keep and manage all the code from the service in my reimplementation.

Still waiting for a better solution :)

Найкраща відповідь

In Odoo OWL, you can patch a service function by using the extend() method provided by the Owl framework. The extend() method allows you to override the behavior of an existing service function by providing a new implementation for that function.

Here is an example of how you could use the extend() method to patch the _triggerDownload function in the ActionService:

import { ActionService } from '@web/webclient/actions/action_service';

ActionService.extend({
    _triggerDownload(id, action) {
        // Your new implementation of the _triggerDownload function goes here
    }
});

Keep in mind that patching service functions in this way should be done with caution, as it can potentially cause conflicts with other parts of the system that rely on the original behavior of the service. It's always a good idea to carefully test your changes and make sure they don't cause any unexpected issues.

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

Hi, I read you found a way to patch the start method? I've been trying but nothings happening. Is this the correct code?

odoo.define("crm_custom.CopyFunction", function(require){
/** @odoo-module**/
'use strict';
var actionService = require("@web/webclient/actions/action_service")
const { patch } = require('web.utils')
patch(actionService, 'crm_custom.CopyFunction', {
start(env){
console.log("test")
}
})

});


I also added this to web.assets_backend but nothing is happening

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

#bump

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лип. 25
308
0
січ. 25
859
1
бер. 24
1518
0
вер. 23
2795
1
трав. 23
2140