Browse Source

Jan 17: [FIX] Bug Fixed 'geoip_website_redirect'

pull/309/head
Cybrosys Technologies 6 months ago
parent
commit
29430d129e
  1. 2
      geoip_website_redirect/__manifest__.py
  2. 6
      geoip_website_redirect/doc/RELEASE_NOTES.md
  3. 52
      geoip_website_redirect/models/website.py

2
geoip_website_redirect/__manifest__.py

@ -21,7 +21,7 @@
#############################################################################
{
'name': 'Website Geolocation Based Language and Currency',
'version': '17.0.1.0.0',
'version': '17.0.1.1.1',
'category': 'eCommerce, Productivity',
'summary': """Website Geolocation Based Language and Currency Application
for Odoo 17""",

6
geoip_website_redirect/doc/RELEASE_NOTES.md

@ -12,3 +12,9 @@
- The Key word is replaced from the index , manifest and controllers.
#### 29.10.2024
#### Version 17.0.1.1.1
#### BUG FIX
- Fixed the bug when logging in as public user

52
geoip_website_redirect/models/website.py

@ -39,15 +39,45 @@ class Website(models.Model):
change its currency into customers currency """
res = super()._get_current_pricelist()
default = self.env['product.pricelist'].search([])
if res in default:
datas = self.get_user_location()
if datas:
country = CountryInfo(datas['country'])
currency = country.currencies()
currency_dict = self.env['res.currency'].sudo().search([
('name', '=', currency[0]),
('active', 'in', [True, False])])
if currency_dict:
currency_dict.active = True
res.currency_id = currency_dict
public = self.env.ref('base.public_user').id
if public!=self.env.user.id:
if res in default:
datas = self.get_user_location()
if datas:
country = CountryInfo(datas['country'])
currency = country.currencies()
currency_dict = self.env['res.currency'].sudo().search([
('name', '=', currency[0]),
('active', 'in', [True, False])])
if currency_dict:
currency_dict.active = True
res.currency_id = currency_dict
else:
response = requests.get("https://api.ipify.org?format=json")
if response.status_code == 200:
data = response.json()
user_ip = data.get("ip")
response = requests.get(
f'http://ip-api.com/json/{user_ip}',
timeout=20).json()
if response.get("country"):
country = CountryInfo(response.get("country"))
currency = country.currencies()
currency_dict = self.env['res.currency'].sudo().search([
('name', '=', currency[0]),
('active', 'in', [True, False])])
if currency_dict:
currency_dict.active = True
res.currency_id = currency_dict
lang = country.languages()
language = self.env['res.lang'].sudo().search([
('iso_code', '=', lang[0]),
('active', 'in', [True, False])])
if language:
language.active = True
web=self.env['website'].sudo().browse(self.id
)
web.sudo().write({
'language_ids':[(4, language.id)],
})
return res

Loading…
Cancel
Save