Skip to Content
Menu
This question has been flagged

Hi, I am working on customizing the ListController in an Odoo module and have already applied a patch to the standard ListController. 

However, I now need to further extend this customized controller in a new module. I am not entirely sure about the best practices for extending an already patched controller. Here's the current implementation where it is initially patched the ListController:

import { ListController } from "@web/views/list/list_controller";

patch(ListController.prototype, "XXXX_controller", {
    // Custom implementations
});

Questions:

  1. What is the recommended approach to add additional functionality to this patched ListController?
  2. Should I create another patch, or is there a more efficient method to extend the existing patch?
  3. Are there any potential conflicts or best practices I should be aware of when patching an already extended controller in Odoo's JavaScript framework?

Any insights or examples would be greatly appreciated.

Avatar
Zrušiť
Best Answer

In javascript, you can call parent method by using keyword super​. here is a reference https://stackoverflow.com/questions/11854958/how-to-call-a-parent-method-from-child-class-in-javascript 


so you can make a child method and place the parent method on the top of the child method

class Foo {
  static classMethod() {
    return 'hello';
  }
}

class Bar extends Foo {
  static classMethod() {
    return super.classMethod() + ', too';
  }
}

console.log(Bar.classMethod()); // 'hello, too'


Hope this help

Avatar
Zrušiť
Best Answer

Hi, 

Please refer to this blog for Extend  Tree/List View in Odoo :

 Extend  Tree/List View in Odoo

Hope it helps

Avatar
Zrušiť
Autor

Hi, thanks for your answer.
Actually, I'd like to extend the controller, which has already extend the standard controller, ListController,
import { ListController } from "@web/views/list/list_controller";

If I created another controler to extend ListController, using patch function, it would override the existing extended controller. I'd like to keep the existing extended one.

Thanks

Related Posts Replies Zobrazenia Aktivita
2
júl 23
2988
0
feb 23
2674
1
apr 24
2067
0
jan 24
1657
1
sep 23
3079