How it works...

In the first step, we have added a new restricted_country_ids many2many type field in the library.book model. We will hide the book if the website visitor is from the restricted country.

In step 2, we have just added a restricted_country_ids field in the book's form view. If GeoIP and NGINX are configured properly, Odoo will add GeoIP information at request.session.geoip, and then you can get the country code from that.

In the third step, we have fetched the country code from the GeoIP, followed by the recordset of the country, based on the country_code. After getting a visitor's country information, we filtered books with domains based on a restricted country.

If you don't have a real server and you want to test this anyway, you can add a default country code in the controller, like this:
country_code = request.session.geoip and request.session.geoip.get('country_code') or 'IN'
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset