Odoo Help


Before login, how can we check a condition?

on 6/23/14, 3:20 AM 993 views

Before login, I want to check a condition. Where should i wrote the code?

I will give a value in res.users table. When i click login button, it should first check the condition then login.





| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 6/23/14, 3:51 AM

Refer the link http://stackoverflow.com/questions/16028848/openerp-7-login-flow Openerp Login Methods and Files Path mentioned in the LInk.

Before Login to check the condition to override Method def login(self, db, login, password) in openerp/addons/base/res/res_users.py


from openerp import SUPERUSER_ID

class res_users(osv.Model):
    _inherit = 'res.users'
    def login(self, db, login, password):
            users_obj = self.pool.get('res.users')
            cr = pooler.get_db(db).cursor()
            user_id = super(res_users, self).login(db, login, password)
            login_date = None
                if user_id:
                    val = users_obj.browse(cr, SUPERUSER_ID, user_id)
                    login_date = val.login_date
                    current_date = datetime.date.today().strftime('%Y-%m-%d')
            if login_date == current_date:
               raise osv.except_osv(_('Message!'), _("Restrict Login Only one in a day"))
               _logger.info("Login failed for db:%s login:%s", db, login)
               user_id = False                
        except openerp.exceptions.AccessDenied:
            _logger.info("Login failed for db:%s login:%s", db, login)
            user_id = False
        return user_id 




Thanks for the answer

on 6/23/14, 4:46 AM

I want to check login_date with past_date. If(login_date = past_date) restrict login. otherwise he can login to the account. Did u have any idea?

on 6/23/14, 5:15 AM

updated code default res_users table login_date (last login data) details available and check with current date in login method.

on 6/23/14, 6:44 AM

This function, i dont want to check for admin. Then how can i give that? Except admin all other users should check this function

on 6/23/14, 7:29 AM

i replace the code in original base module. But it is not working. Will it work, when i create an inherit module??

on 6/23/14, 8:03 AM

Hi Prakash, Can you explain below code breifly.... i have create a module ,and installed it.But at what condition the error message will shows like------- raise osv.except_osv(_('Message!'), _("Restrict Login Only one in a day"))

on 6/23/14, 8:08 AM

In the same day second time Login the error message shows...

on 6/23/14, 8:19 AM

@prakash: i created a module and inherit the res.users. but its not working. I also want to check all users except admin. is it possible??

on 6/23/14, 8:34 AM

@rosey: yes it is possible if login_date == current_date and user_id != 1: # Default admin id 1. But i not tested the code.

on 6/25/14, 5:19 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/23/14, 3:20 AM
Seen: 993 times
Last updated: 3/16/15, 8:10 AM