تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
2656 أدوات العرض

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.

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

Hi, 

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

 Extend  Tree/List View in Odoo

Hope it helps

الصورة الرمزية
إهمال
الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يوليو 23
3011
0
فبراير 23
2692
1
أبريل 24
2095
0
يناير 24
1671
1
سبتمبر 23
3092