Enable Dark Mode!
geo-ip-installation-in-odoo-15-on-premises-database.jpg
By: Naveen

Geo IP Installation in Odoo 15(On-Premises Database)

Technical Odoo 15

GeoIP is an IP-based geo-location mapping tool that is used for mapping IP addresses to a real-geographic location Internet-connected device. GeoIP can be used for details such as Country, Region (City), latitude/longitude, ISP, and other valuable things from the IP address of the target device.

There are many providers of GeoIP services, and their prices, accuracy, and available data may vary. MaxMind, Ip2location, Ipinfo, IPligence, etc. offer fee-based databases that can be easily integrated into Applications. Most geolocation Providers offer APIs and Documentation for using them in many coding languages that can be used to process GeoIP data. So in this example, we will install Maxmind’s GeoIP free database(GeoLite2) to Odoo, which can be used for further operations using the details of website visitors/Users such as Country, City, Latitude/Longitude, etc., and also the OS used here is Ubuntu 20.04 LTS.

As our first step, we need to install the geoip2 python library on our server. We can use the below code to install it.

pip install geoip2

As the next step, we have to create an account in MaxMind in order to download the Database file. Also, we have to generate a License Key from that account, which is used to query the web services and authenticate the GeoIP update program. For getting the Database file and updating them, MaxMind gave us two options such as

1. Manual download from their website

2. Using their own updating software called GeoIP Update program.

Also, two file formats are available. Those are the ‘.mmdb’ and ‘.csv’ files.

In this example, we manually downloaded the database file in ‘.mmdb’ format and placed it in Odoo’s preferred file directory /usr/share/GeoIP/ using the below command.

mv ~/Downloads/GeoLite2-City.mmdb /usr/share/GeoIP/

If we want to use a custom path for the database file, we can use the –geoip-db option in the odoo.conf or in the Odoo CommandLine Interface like the below-given code.

--geoip-db= ~/Downloads/GeoLite2-City.mmdb

Now for using GeoIP in the python file we can use the example code given below for importing the GeoIPResolver to our code.

from odoo.addons.http_routing.geoipresolver import GeoIPResolver

After importing the code we can use the below code to get the location of Geolite database file.

geofile_location = config.get('geoip_database')

After that, we can use the below-given code to initialize the GeoIPResolver.

If we want to use a custom path for the database file, you can replace the ‘geofile_location’ parameter with your custom location_path for the mmdb file.

geoip_resolver = GeoIPResolver.open(geofile_location) or False

Now, you can use the code below to use GeoIPResolver. The ‘ip_address’ parameter holds the IP address we need to process with GeoIPResolver.

Response = geoip_resolver.resolve(ip_address)

The response from the above code is like the given example below.

{'city': 'Kozhikode', 'country_code': 'IN', 'country_name': 'India', 'latitude': 11.2189, 'longitude': 75.7268, 'region': 'KL', 'time_zone': 'Asia/Kolkata'}

From the response, you can get the details such as city, country_code, country_name, latitude &longitude, region, and timezone.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message