@ -0,0 +1,54 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg |
||||
|
:target: https://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. |
||||
|
|
||||
|
Installation |
||||
|
============= |
||||
|
* Install external python package countryinfo. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
* No additional configurations needed. |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
General Public License, Version 3 (LGPL-3). |
||||
|
(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
* Developer: (V17) Ashwin A, |
||||
|
(V16) Ayisha Sumayya K, |
||||
|
(V15) Mohammed Dilshad Tk, |
||||
|
(V14) Mohammed Dilshad Tk |
||||
|
* Contact: odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
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 |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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,49 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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': '17.0.1.0.0', |
||||
|
'category': 'eCommerce, Productivity', |
||||
|
'summary': """Website GeoIP Based Language and Currency Application |
||||
|
for Odoo 17""", |
||||
|
'description': """The module helps you to map currency and language |
||||
|
based on User's IP address""", |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://cybrosys.com', |
||||
|
'depends': ['website_sale'], |
||||
|
'data': ['views/login_template.xml'], |
||||
|
'assets': { |
||||
|
'web.assets_frontend': [ |
||||
|
'geoip_website_redirect/static/src/js/userIpAddress.js', |
||||
|
], |
||||
|
}, |
||||
|
'external_dependencies': { |
||||
|
'python': ['countryinfo'], |
||||
|
}, |
||||
|
'images': ['static/description/banner.jpg'], |
||||
|
'license': 'LGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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,54 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 countryinfo import CountryInfo |
||||
|
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}', timeout=20).json() |
||||
|
return {"country": response.get("country")} |
||||
|
|
||||
|
@http.route() |
||||
|
def web_login(self, redirect=None, **kw): |
||||
|
""" On login access customer country information """ |
||||
|
result = super().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> |
||||
|
|
||||
|
#### 20.07.2024 |
||||
|
#### Version 17.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) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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,53 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 countryinfo import CountryInfo |
||||
|
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}', timeout=20).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([]) |
||||
|
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 |
||||
|
return res |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 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: 4.3 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 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: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 550 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 93 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 294 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 104 KiB |
After Width: | Height: | Size: 18 KiB |
@ -0,0 +1,20 @@ |
|||||
|
/** @odoo-module **/ |
||||
|
import publicWidget from '@web/legacy/js/public/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; |
||||
|
}); |
||||
|
}, |
||||
|
}); |
@ -0,0 +1,9 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<odoo> |
||||
|
<!-- Inheriting and adding a input field on web.login --> |
||||
|
<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> |