Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
10 Trả lời
40254 Lượt xem

when user log in openerp use browse, I want to get his computer ip address? how to get it? pls help, I search the code two days and not result. thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

use this chunk of code

USER_PRIVATE_FIELDS = ['password']
@api.model
def _check_credentials(self, password):
result = super(LoginUserDetail, self)._check_credentials(password)
ip_address = request.httprequest.environ['REMOTE_ADDR']
vals = {'name': self.name,
'ip_address': ip_address
}
self.env['login.detail'].sudo().create(vals)
return result


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Use a web server upfront and check it's log.

I use nginx upfront, as a reverse proxy for OpenERP, so that is's accessed through HTTPS. Looking through nginx's log I'm able to check client IP addresses and the signatures for the browsers used.

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks very much.

Tác giả

I have not use nginx and I search the default oe log file, find must set log_level is debug_rpc_answer then can show the IP. so if have other method can get the IP? thanks

Câu trả lời hay nhất

https://www.odoo.com/forum/help-1/question/how-to-get-openerp-client-ip-74427

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello. may the best way to modify http.py

looking for : class WebRequest(object):

    def init(self, params):
    self.params = dict(params)
    # OpenERP session setup
    self.session_id = self.params.pop("session_id", None) or uuid.uuid4().hex
    self.session = self.httpsession.get(self.session_id)
    if not self.session:
        self.httpsession[self.session_id] = self.session = session.OpenERPSession()
    self.session.config = self.config
    self.context = self.params.pop('context', None)
    #-----------------------------------------------------------------
    # add client ip to context
    if type(self.context) == dict:
            self.context['remote_addr'] = self.httprequest.remote_addr
    # ----------------------------------------------------------------               
    self.debug = self.params.pop('debug', False) != False

It's work for me on 6.1 Bye.

Ảnh đại diện
Huỷ bỏ

Thank Buddy.. But how i use in my own py file or can we add it context dictionary, the main purpose is to store the client ip address in db for every transaction

  • in xml file --------------------------------

<script> $(document).ready(function(){ $(document).delegate(".oe_form_button_edit , .oe_list_add , .oe_form_button_create ",'click',function() { ipfill(); });

function ipfill() { $.getJSON("http://smart-ip.net/geoip-json?callback=?", function(data){ $('.ipcaptuaring').children().val(data.host); }); } ipfill(); }); </script>

<field name="ipaddress" class="ipcaptuaring"/>

  • in py file -----------------------------------

'ipaddress':fields.char('ip Address')

Câu trả lời hay nhất

By default, Odoo supports the variable `request.httprequest.remote_addr` which trace the remote IP address in every single http request. 

So it should be the HTTP request modification which can be found at odoo/http.py file, read the logic business and try by yourself.




Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 24
9489
3
thg 9 24
21724
5
thg 12 24
53010
4
thg 7 24
10601
7
thg 8 23
10992