Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo- Enable developer mode by default for a user

I am using Odoo 10-e. I want to enable developer mode for a user by default when he logs in and that user is other then admin. Is this possible in odoo 10 ?

like image 433
Ahsan Attari Avatar asked Jun 30 '17 13:06

Ahsan Attari


1 Answers

You need to just override Web login controller in your module.

Ex:

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http, _
import odoo
from odoo.http import route
from odoo.http import request 
from odoo.addons.web.controllers.main import Home, ensure_db

class DebugMode(Home):

    @http.route('/web/login', type='http', auth="none")
    def web_login(self, redirect=None, **kw):
        ensure_db()
        request.params['login_success'] = False
        if request.httprequest.method == 'GET' and redirect and request.session.uid:
            return http.redirect_with_hash(redirect)

        if not request.uid:
            request.uid = odoo.SUPERUSER_ID

        values = request.params.copy()
        try:
            values['databases'] = http.db_list()
        except odoo.exceptions.AccessDenied:
            values['databases'] = None
        if request.httprequest.method == 'POST':
            old_uid = request.uid
            uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
            if uid is not False:
                request.params['login_success'] = True
                if not redirect:
                    redirect = '/web?debug=1'
                return http.redirect_with_hash(redirect)
            request.uid = old_uid
            values['error'] = _("Wrong login/password")
        return request.render('web.login', values)

In above method, we have simply redirect URL in /web?debug=1.

You can do it for specific users as well like just create group Auto Debug Mode.

The only group of this users can auto login with debug mode.

Ex :

<record model="res.groups" id="group_auto_debug_mode">
    <field name="name">Auto Debug Mode</field>
    <field name="users" eval="[(4, ref('base.user_root'))]"/>                                   
</record>
if request.env['res.users'].browse(request.uid).has_group('module_name.group_auto_debug_mode'):
    redirect = '/web?debug=1'
else:
    redirect = '/web'

You can find Odoo Community module from below link.

https://apps.odoo.com/apps/modules/10.0/admin_auto_debug_mode/

This may help you.

like image 57
Emipro Technologies Pvt. Ltd. Avatar answered Nov 02 '22 13:11

Emipro Technologies Pvt. Ltd.