İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
2695 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
En İyi Yanıt

Hi, 

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

 Extend  Tree/List View in Odoo

Hope it helps

Avatar
Vazgeç
Üretici

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Tem 23
3036
0
Şub 23
2714
1
Nis 24
2122
0
Oca 24
1699
1
Eyl 23
3123