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

Hi,


Is it possible to override an OWL component without unregistering it?

I would like to adjust the `SwitchCompanyMenu` component with some additional functionality. However components like these are registered to the `systray` Registry. Can I override the Javascript/XML import or do I need to remove the entry from the Registry? The latter seems a bit inconvenient.
Odoo would import `switch_company_menu.xml` and `switch_company_menu.js` from the web addon and then I would remove the registered item from the `systray` Registry, so I can register a custom item with expanded functionality.

Couldn't find an answer to this in the docs and on the forum, perhaps I've been looking in the wrong direction.

Thanks in advance.

Eddy


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

I guess it is possible, but how will you handle updates then? Isn't it better to create a new one inheriting the existing one? That way it would be never overwritten upon udating.

Автор

That's exactly what I'm trying to do. However if I want to extend the class, I'm already importing the component. So the component shouldn't be added to the systray Registry. That way I don't need to remove it like the code below.

```
import { SwitchCompanyMenu } from "@web/webclient/switch_company_menu/switch_company_menu";

export class CompanyMenu extends SwitchCompanyMenu {
// Expand SwitchCompanyMenu class with functionality
}

export const systrayItem = {
Component: CompanyMenu,
isDisplayed(env) {
const { availableCompanies } = env.services.company;
return Object.keys(availableCompanies).length > 1;
},
};

registry.category("systray").remove("SwitchCompanyMenu");
registry.category("systray").add("CompanyMenu", systrayItem, { sequence: 1 });
```

Автор

Is it not possible to have code snippets?

@Eddy I am faced with the same situation. Have you found a better solution?

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

I think what you need to ovveride the logic using 'patch'. Use import { patch } from "@web/core/utils/patch"; then u will be able modify or extend logic. if you use class.. extend it mean that you will create a new one base on what you extend when patch mean overide , add logic to it

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
черв. 22
7383
2
груд. 24
6000
1
груд. 23
3760
2
лип. 25
603
2
лип. 25
1187