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

I am using the following code to get user ip information to record activity history, but the received ip is the ip of the active server, my Odoo server is deployed on ubuntu server 22.04


This is my code:

def _get_info_active(self):
"""
:return: ip_address, location, device_name
"""
try:
client_ip = request.httprequest.environ['REMOTE_ADDR']
location_info = {}
try:
response = requests.get(f'https://ipinfo.io/{client_ip}/json')
location_info = response.json()
except requests.RequestException:
location_info = {"error": "Could not retrieve location info"}

user_agent = request.httprequest.user_agent.string
return client_ip, f"{location_info.get('city')}, {location_info.get('region')}, {location_info.get('country')}", user_agent

except Exception as e:
raise UserError(str(e))
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Check https://www.odoo.com/forum/help-1/how-to-check-when-a-user-was-last-active-odoo-18-264495 and https://github.com/odoo/odoo/blob/18.0/odoo/addons/base/models/res_device.py#L82 (maybe you can review our code to see how we do it)

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

I can't find it on Odoo16

We did not add this until version 18

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
4545
7
thg 2 24
12264
0
thg 11 17
4066
1
thg 5 25
1115
0
thg 11 24
1292