Sometime we need to modify a certain behavior when accessing odoo url (route). That time we need to do inheritance to odoo controller and then put our desired custom behavior when the url triggered. The way to inherit an odoo controller is slightly different than to inherit odoo object/model.
In this tutorial i will do inheritance on odoo route "/shop/checkout" which is the url route when doing website sale checkout, because i want to show some specific product information on the website that i cant call in the xml template unless i parse the data from python controller to xml view. Lets jump into it.
Here is the base controller
Here is the inheritance controller
in the example above i import base controller class (WebsiteSale) and use it as parameter on my new class (WebsiteSaleInherit). Thats it !!
Comment below if you have any questions.
In this tutorial i will do inheritance on odoo route "/shop/checkout" which is the url route when doing website sale checkout, because i want to show some specific product information on the website that i cant call in the xml template unless i parse the data from python controller to xml view. Lets jump into it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from odoo import http, tools, _ | |
class WebsiteSale(http.Controller): | |
@http.route(['/shop/checkout'], type='http', auth="public", website=True) | |
def checkout(self, **post): | |
# we have base code in here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from odoo.addons.website_sale.controllers.main import WebsiteSale | |
class WebsiteSaleInherit(WebsiteSale): | |
@http.route(['/shop/checkout'], type='http', auth="public", website=True) | |
def checkout(self, **post): | |
# use super to call prevously defined checkout methods so we not overriding the method but extend it. | |
res = super(WebsiteSale, self).checkout(**post) | |
# code your bugs in here ;) |
in the example above i import base controller class (WebsiteSale) and use it as parameter on my new class (WebsiteSaleInherit). Thats it !!
Comment below if you have any questions.
Comments
Post a Comment