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

Hi all,

Here i want to inherit shopping cart controllers in my custom module?

I know inherit models, views, objects but i dont know iherit controllers. please let me know this...

 

Thanks in advance

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

Say you would like to inherit the MailTrackingController from the OCA module mail_tracking. Here is how you do it.

I know that the mail_tracking module is not in the same directory as the odoo built-in addons. Still the below works(of course your module depends on the other module in the manifest file.)


# import importlib so as to use it
# to import the module that contains the
# controller we are to inherit
import importlib

# use importlib to import the module
# that contains the controller we need to inherit
mail_tracking = importlib.import_module('odoo.addons.mail_tracking')

# create the inheriting controller
class MailTrackingController(mail_tracking.
controllers.main.
MailTrackingController):

def mail_tracking_open(self, db, tracking_email_id, token=False, **kw):
    """
    Some doc sting
    """
    
    response = super(MailTrackingController, self).\
    mail_tracking_open(db, tracking_email_id, token, **kw)
    .
    .
    .



อวตาร
ละทิ้ง

thank you @Kareem Abuzaid, your answer is very explanatory.

คำตอบที่ดีที่สุด

Hi,

For inheriting an existing controller in odoo, please do like this,

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


class WebsiteSaleInherit(WebsiteSale):

@http.route([
'''/shop''',
'''/shop/page/<int:page>''',
'''/shop/category/<model("product.public.category", "[('website_id', 'in', (False, current_website_id))]"):category>''',
'''/shop/category/<model("product.public.category", "[('website_id', 'in', (False, current_website_id))]"):category>/page/<int:page>'''
], type='http', auth="public", website=True)
def shop(self, page=0, category=None, search='', ppg=False, **post):
res = super(WebsiteSaleInherit, self).shop(page=0, category=None, search='', ppg=False, **post)
print("Inherited ....", res)
return res


Full tutorial of the same: How To Inherit Existing Controller in Odoo

Thanks

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

You can refer to following forum question:

https://www.odoo.com/forum/help-1/question/writing-controllers-in-openerp-modules-18656

Hope this helps !!.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
เม.ย. 23
1579
2
มิ.ย. 22
4389
0
ก.ย. 18
3656
0
ธ.ค. 16
3952
0
พ.ย. 19
3729