Odoo Help

Welcome!

This community 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.

0

Before login, how can we check a condition?

By
rosey
on 6/23/14, 3:20 AM 705 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.

 

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
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):
        try:
            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
            try:            
                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')
            except:
                pass
            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

rosey
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?

rosey
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.

Prakash
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

rosey
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??

rosey
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"))

Odoo
on 6/23/14, 8:08 AM

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

Prakash
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??

rosey
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.

Prakash
on 6/25/14, 5:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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