How to inherit controller and add my own method
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
3
Odpowiedzi
2569
Widoki
How to inherit controller and add my own method
Hi,
Try refer the blog below which helps you to write your own code in an existing controller method.
https://www.cybrosys.com/blog/web-controllers-in-odoo
Regards
i did this and now it's working if u check my code..
but it create my record on the backend however after the POST action return the link defined with "undifined" and no redirection
class CustomWebsiteHrRecruitment(WebsiteHrRecruitment):
@http.route(['/jobs',
'/jobs/country/',
'/jobs/department/',
'/jobs/country//department/',
'/jobs/office/',
'/jobs/country//office/',
'/jobs/department//office/',
'/jobs/country//department//office/',
], type='http', auth="public", website=True)
def jobs(self, country=None, department=None, office_id=None, **kwargs):
res = super(CustomWebsiteHrRecruitment, self).jobs(country=None,
department=None,
office_id=None,
**kwargs)
dpts = request.env['hr.department'].sudo().search([])
vals = {'dpts' : dpts,}
res.qcontext.update(vals)
_logger.info("=====>::: %s :::<======"%(res.qcontext))
return res
@http.route('/create/spontaneous_application/', type="http", auth="public", website=True)
def create_spontaneous_application(self,self_id, **kw):
vals = {'name' : 'Spontaneous Application\'s %s'%(kw.get('partner_name')),
'department_id' : kw.get('dpt'),
'description' : kw.get('description')}
spontaneous_application = request.env['hr.job'].create(vals)
_logger.info("======>Spontaneous Application : %s created<========"%(spontaneous_application.name))
return http.request.render('/', {})
but in the second method in the controller my redirection on the home page doesn't work. can someone help me pls ?
You can redirect instead of render.
Like :- return http.request.redirect("/")
it's not working too :(
my logs:
2021-10-25 13:58:10,944 1 INFO scin_db odoo.addons.custum.controllers.main: ======>Spontaneous Application : Spontaneous Application's Moustapha Ndiaye created<========
2021-10-25 13:58:10,944 1 INFO scin_db odoo.addons.custum.controllers.main: ======> Application of : Moustapha Ndiaye 's Application created<========
2021-10-25 13:58:10,947 1 INFO scin_db werkzeug: 41.83.44.156 - - [25/Oct/2021 13:58:10] "POST /create/spontaneous_application/undefined HTTP/1.1" 302 - 540 0.230 1.824
Can you please try with following return statment?
return http.request.redirect('/web')
Thank Yogesh Sakhreliya but not working until now.. I think it's about the website_form. i will check the documentation of this module
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
2
lip 25
|
5976 | ||
Data from website with controller
Rozwiązane
|
|
2
lip 24
|
4096 | |
|
3
kwi 24
|
4755 | ||
|
0
wrz 22
|
803 | ||
|
0
wrz 21
|
1882 |
try this:
1- https://learnopenerp.blogspot.com/2020/08/inherit-web-login-controller-in-odoo.html
2- https://learnopenerp.blogspot.com/2021/09/inherit-login-and-logout-web-controller.html
3- https://learnopenerp.blogspot.com/2018/08/odoo-web-controller.html