2017-06-30 62 views

Trả lời

3

Bạn chỉ cần ghi đè Bộ điều khiển đăng nhập web trong mô-đun của mình.

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) 

Trong phương pháp trên, chúng tôi đã chỉ cần chuyển hướng URL trong /web debug = 1?.

Bạn cũng có thể làm điều đó cho người dùng cụ thể, như chỉ cần tạo nhóm Chế độ gỡ lỗi tự động.

Chỉ nhóm người dùng này mới có thể tự động đăng nhập bằng chế độ gỡ lỗi.

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' 

Bạn có thể tìm thấy mô-đun Odoo Cộng đồng từ bên dưới liên kết.

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

Điều này có thể giúp bạn.

Các vấn đề liên quan