Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang
Jawaban Terbai

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
Buang
Jawaban Terbai

Hi, 

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

 Extend  Tree/List View in Odoo

Hope it helps

Avatar
Buang
Penulis

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

Post Terkait Replies Tampilan Aktivitas
2
Jul 23
2990
0
Feb 23
2687
1
Apr 24
2076
0
Jan 24
1662
1
Sep 23
3082