@ -0,0 +1,44 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html |
||||
|
:alt: License: LGPL-3 |
||||
|
|
||||
|
Website GeoIP Based Language and Currency |
||||
|
======================= |
||||
|
This module allow to view the website content according to login user's country details |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
Developer: Ayisha Sumayya K @cybrosys, Contact: odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
General Public License, Version 3 (LGPL v3). |
||||
|
(https://www.odoo.com/documentation/user/13.0/legal/licenses/licenses.html) |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
External Package: countryinfo |
||||
|
|
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import controllers |
||||
|
from . import models |
@ -0,0 +1,48 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
{ |
||||
|
'name': 'Website GeoIP Based Language and Currency', |
||||
|
'version': '16.0.1.0.0', |
||||
|
'summary': 'Website GeoIP Based Language and Currency Application ' |
||||
|
'for Odoo 16', |
||||
|
'description': """The module helps you to map currency and language |
||||
|
based on Customer's IP address""", |
||||
|
'category': 'eCommerce, Productivity', |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://cybrosys.com', |
||||
|
'images': ['static/description/banner.png'], |
||||
|
'depends': ['base', 'website_sale'], |
||||
|
'data': ['views/login_template.xml'], |
||||
|
'assets': { |
||||
|
'web.assets_frontend': [ |
||||
|
'geoip_website_redirect/static/src/js/action.js', ], |
||||
|
}, |
||||
|
'license': 'LGPL-3', |
||||
|
'auto_install': False, |
||||
|
'installable': True, |
||||
|
'application': False, |
||||
|
'external_dependencies': { |
||||
|
'python': ['countryinfo'], |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import geoip_website_redirect |
@ -0,0 +1,55 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
import requests |
||||
|
from odoo import http |
||||
|
from odoo.http import request |
||||
|
from odoo.addons.web.controllers.home import Home |
||||
|
|
||||
|
|
||||
|
class GeoIP(Home): |
||||
|
""" controller for selecting login user's datas """ |
||||
|
|
||||
|
def get_location(self, ip_address): |
||||
|
""" get location details of user using ip address""" |
||||
|
response = requests.get(f'http://ip-api.com/json/{ip_address}').json() |
||||
|
return {"country": response.get("country")} |
||||
|
|
||||
|
@http.route() |
||||
|
def web_login(self, redirect=None, **kw): |
||||
|
""" on login access customer country information """ |
||||
|
from countryinfo import CountryInfo |
||||
|
result = super(GeoIP, self).web_login(redirect=redirect, **kw) |
||||
|
request.env.user.write({'ip_address': kw.get('user_ip')}) |
||||
|
datas = self.get_location(kw.get('user_ip')) |
||||
|
if datas: |
||||
|
country = CountryInfo(datas['country']) |
||||
|
lang = country.languages() |
||||
|
language = request.env['res.lang'].sudo().search([ |
||||
|
('iso_code', '=', lang[0]), ('active', 'in', [True, False])]) |
||||
|
if language: |
||||
|
language.active = True |
||||
|
request.env['website'].sudo().browse(request.website.id |
||||
|
).language_ids = [ |
||||
|
(4, language.id)] |
||||
|
url = f'/{language.url_code}' |
||||
|
return request.redirect(url) |
||||
|
return result |
@ -0,0 +1,7 @@ |
|||||
|
## Module <geoip_website_redirect> |
||||
|
|
||||
|
#### 18.02.2023 |
||||
|
#### Version 16.0.1.0.0 |
||||
|
#### ADD |
||||
|
|
||||
|
- Initial commit for Website GeoIP Based Language and Currency |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import res_users |
||||
|
from . import website |
@ -0,0 +1,29 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class ResUsers(models.Model): |
||||
|
"""class for adding ip address field in res.users """ |
||||
|
_inherit = "res.users" |
||||
|
|
||||
|
ip_address = fields.Char(string="IP Address", help="IP address of user") |
@ -0,0 +1,60 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Ayisha Sumayya K (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
import requests |
||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class Website(models.Model): |
||||
|
""" class for selecting shop's public pricelist """ |
||||
|
_inherit = 'website' |
||||
|
|
||||
|
def get_user_location(self): |
||||
|
""" get location details of user """ |
||||
|
|
||||
|
response = requests.get( |
||||
|
f'http://ip-api.com/json/{self.env.user.ip_address}').json() |
||||
|
return {"country": response.get("country")} |
||||
|
|
||||
|
def get_current_pricelist(self): |
||||
|
""" get current pricelist if it is public pricelist then |
||||
|
change its currency into customers currency """ |
||||
|
res = super().get_current_pricelist() |
||||
|
default = self.env['product.pricelist'].search([ |
||||
|
'&', ('selectable', '=', True), |
||||
|
'&', ('country_group_ids', '=', False), |
||||
|
'|', ('company_id', '=', False), |
||||
|
('company_id', '=', self.env.company.id)], limit=1) |
||||
|
|
||||
|
if res in default: |
||||
|
from countryinfo import CountryInfo |
||||
|
|
||||
|
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 |
||||
|
return res |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 550 KiB |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 550 KiB |
After Width: | Height: | Size: 406 KiB |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 170 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,25 @@ |
|||||
|
odoo.define('geoip_website_redirect.get_ip', function (require) { |
||||
|
"use strict"; |
||||
|
|
||||
|
var publicWidget = require('web.public.widget'); |
||||
|
//public widget for getting the IP address of the user
|
||||
|
publicWidget.registry.userIpAddress = publicWidget.Widget.extend({ |
||||
|
selector: '.oe_website_login_container', |
||||
|
events: { |
||||
|
'click .oe_login_buttons': '_getIpAddress', |
||||
|
}, |
||||
|
setup(){ |
||||
|
super.setup(); |
||||
|
this._getIpAddress() |
||||
|
}, |
||||
|
//function which give ip address of user
|
||||
|
_getIpAddress: async function(events){ |
||||
|
var self = this; |
||||
|
await $.getJSON("https://api.ipify.org?format=json", function(data) { |
||||
|
self.el.querySelector('#user_ip').value = data.ip; |
||||
|
}); |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
return publicWidget.registry.userIpAddress; |
||||
|
}); |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<template id="user_ip" inherit_id="web.login" name="User IP"> |
||||
|
<xpath expr="//input[@name='csrf_token']" position="after"> |
||||
|
<input type="text" name="user_ip" id="user_ip" class="d-none"/> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</odoo> |