Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
8775 มุมมอง

I need to inherit 'def shop'  function from the path addons/website_sale/controllers/main.py . How to super a function in controller.

Thanks in advance


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You can use the following method for super any function on controllers

Under Odoo, one can also override an existing function in the controller as per the need. It is different than overriding a function in models. For example, one can take the controller function in the ‘website_sale’ module. In this module, there is a function ‘payment_confirmation’ at the route ‘/shop/confirmation’. 


To override this function, firstly one has to import the class on which the function is included.


from odoo.addons.website_sale.controllers.main import WebsiteSale


So now, we have imported the class via specifying the path of the file in which the function class exists. Here the ‘main’ is the file and ‘WebsiteSale’ is the class of the function.

One can override the controller function as , 

 

from odoo.addons.website_sale.controllers.main import WebsiteSale


class WebsiteSaleInherit(WebsiteSale):


@http.route()
   def payment_confirmation(self, **post):
       res_super = super(WebsiteSaleInherit, self).payment_confirmation(self, **post)
                                                  #My Code                                       .                                                
       return res_super


อวตาร
ละทิ้ง
ผู้เขียน

Thank you very much......Its working

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 19
5309
How to use .qcontext in odoo12? แก้ไขแล้ว
1
พ.ย. 19
5057
2
ก.ค. 25
4374
1
ต.ค. 23
3616
How to inherit web controllers แก้ไขแล้ว
1
พ.ค. 24
4598