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.

1

how to get openerp client IP

By
divya
on 1/28/15, 8:40 AM 1,672 views

I want to get openerp user client ip address, and in my module add some code copy from web module, as below:

def _get_ipaddress(self, req,httprequest, environ):
        wsgienv = req.httprequest.environ
        env = dict(
         HTTP_HOST=wsgienv['HTTP_HOST'],
         REMOTE_ADDR=wsgienv['REMOTE_ADDR'],
         )
        _logger.log("env:%d", env)
        return True

But get Error​:AttributeError: 'cursor' object has no attribute 'httprequest'

 

where params come from : req, httprequest and environ ? Method are called by default with : cr, uid, context where : cr -- database cursor | uid -- current user id | context (dictionary) -- context arguments, like lang, time zone Synthax OLD API = https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/ But if you start, try to use new api : https://www.odoo.com/documentation/8.0

Jérémy Kersten (jke)
on 1/29/15, 7:22 AM
4

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 1/29/15, 7:16 AM

Not tested, but it should works:

You can add import:

from openerp.http import request

And change your function _get_ipaddress with:

    def _get_ipaddress(self, cr, uid, context=None):
        return request.httprequest.environ['REMOTE_ADDR'] 

 

Also fir you information, you don't need to specify the size... It has been deprecated in v8.

        'ip_address' : fields.char('IP Address', readonly=True),

 

 

 

If you start with Odoo, Take an eye on https://www.odoo.com/documentation/8.0/howtos/backend.html

 

Good luck 

Great solution Jérémy. Accepted & upvoted :)

Yenthe
on 1/29/15, 7:23 AM
0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 1/29/15, 4:18 AM

It seems this method is still using the old ORM. In that case, the signature of the method would start with something like "(self,cr,uid, etc etc.)". The "cr" or "cursor" being the first argument.

In your code, req is apparantly seen as the cursor and therefore Odoo is unable to find the attribute on that cursor.

Make sure that you use the right way (OSV vs Models)  and/or check the signature for your method.

plss help iam new to openerp

divya
on 1/29/15, 4:40 AM
0
divya
On 1/29/15, 6:30 AM


class hr_attendence(osv.osv):

    def _get_ipaddress(self,cr, uid,context=None):
        wsgienv = cr.httprequest.environ
        env = dict(
         HTTP_HOST=wsgienv['HTTP_HOST'],
         REMOTE_ADDR=wsgienv['REMOTE_ADDR'],
         )
        _logger.log("env:%d", env)
        return True
    
    _inherit = 'hr.attendance'

    _columns = {
    #'ipaddress':fields.char('ip Address')
           'ip_address' : fields.char('IP Address', readonly=True, size=64)
        }

    _defaults = {
        'ip_address': _get_ipaddress,
    }

    
hr_attendence()

*getting same error*

* * AttributeError: 'cursor' object has no attribute 'httprequest'

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

3 follower(s)

Stats

Asked: 1/28/15, 8:40 AM
Seen: 1672 times
Last updated: 1/12/16, 2:20 AM