Getting a visitor's country information
The Odoo CMS has built-in support for GeoIP. In a live environment, you can track a visitor's country based on the IP address. In this recipe, we will get the country of the visitor based on the visitor's IP address.
Getting ready
For this recipe, we will be using the my_library
module from the previous recipe. In this recipe, we will hide some books on the web page based on the visitor's country. You will need to download the GeoIP database for this recipe. After that, you will need to pass the database location from the cli
option, like this:
./odoo-bin -c config_file --geoip-db=location_of_geoip_DB
How to do it...
Follow these steps to restrict books based on country:
- Add the
restrict_country_ids
Many2many
field in thelibrary.book
model, as follows:class LibraryBook(models.Model): _name = 'library.book' _inherit = ['website.seo.metadata...