Browse Source

May 17 : [ADD] Initial Commit 'geoip_website_redirect'

pull/257/head
Sayooj 2 years ago
parent
commit
5078f3bea2
  1. 44
      geoip_website_redirect/README.rst
  2. 23
      geoip_website_redirect/__init__.py
  3. 48
      geoip_website_redirect/__manifest__.py
  4. 22
      geoip_website_redirect/controllers/__init__.py
  5. 55
      geoip_website_redirect/controllers/geoip_website_redirect.py
  6. 7
      geoip_website_redirect/doc/RELEASE_NOTES.md
  7. 23
      geoip_website_redirect/models/__init__.py
  8. 29
      geoip_website_redirect/models/res_users.py
  9. 60
      geoip_website_redirect/models/website.py
  10. BIN
      geoip_website_redirect/static/description/assets/cybro-icon.png
  11. BIN
      geoip_website_redirect/static/description/assets/cybro-odoo.png
  12. BIN
      geoip_website_redirect/static/description/assets/icons/1-icon.png
  13. BIN
      geoip_website_redirect/static/description/assets/icons/2-icon.png
  14. BIN
      geoip_website_redirect/static/description/assets/icons/3-icon.png
  15. BIN
      geoip_website_redirect/static/description/assets/icons/4-icon.png
  16. BIN
      geoip_website_redirect/static/description/assets/icons/5-icon.png
  17. BIN
      geoip_website_redirect/static/description/assets/icons/6-icon.png
  18. BIN
      geoip_website_redirect/static/description/assets/icons/Hospital Management-icon.png
  19. BIN
      geoip_website_redirect/static/description/assets/icons/check.png
  20. BIN
      geoip_website_redirect/static/description/assets/icons/chevron.png
  21. BIN
      geoip_website_redirect/static/description/assets/icons/cogs.png
  22. BIN
      geoip_website_redirect/static/description/assets/icons/consultation.png
  23. 1
      geoip_website_redirect/static/description/assets/icons/down.svg
  24. BIN
      geoip_website_redirect/static/description/assets/icons/ecom-black.png
  25. BIN
      geoip_website_redirect/static/description/assets/icons/education-black.png
  26. BIN
      geoip_website_redirect/static/description/assets/icons/hotel-black.png
  27. BIN
      geoip_website_redirect/static/description/assets/icons/license.png
  28. BIN
      geoip_website_redirect/static/description/assets/icons/lifebuoy.png
  29. BIN
      geoip_website_redirect/static/description/assets/icons/main.png
  30. BIN
      geoip_website_redirect/static/description/assets/icons/manufacturing-black.png
  31. BIN
      geoip_website_redirect/static/description/assets/icons/pos-black.png
  32. BIN
      geoip_website_redirect/static/description/assets/icons/puzzle.png
  33. BIN
      geoip_website_redirect/static/description/assets/icons/restaurant-black.png
  34. BIN
      geoip_website_redirect/static/description/assets/icons/service-black.png
  35. BIN
      geoip_website_redirect/static/description/assets/icons/support.png
  36. BIN
      geoip_website_redirect/static/description/assets/icons/trading-black.png
  37. BIN
      geoip_website_redirect/static/description/assets/icons/training.png
  38. BIN
      geoip_website_redirect/static/description/assets/icons/update.png
  39. BIN
      geoip_website_redirect/static/description/assets/icons/user.png
  40. BIN
      geoip_website_redirect/static/description/assets/icons/whatsapp.png
  41. BIN
      geoip_website_redirect/static/description/assets/icons/wrench.png
  42. BIN
      geoip_website_redirect/static/description/assets/main.png
  43. BIN
      geoip_website_redirect/static/description/assets/screenshots/Screenshot 4.png
  44. BIN
      geoip_website_redirect/static/description/assets/screenshots/Screenshot1.png
  45. BIN
      geoip_website_redirect/static/description/assets/screenshots/Screenshot2.png
  46. BIN
      geoip_website_redirect/static/description/assets/screenshots/Screenshot3.png
  47. BIN
      geoip_website_redirect/static/description/banner.png
  48. BIN
      geoip_website_redirect/static/description/icon.png
  49. 1442
      geoip_website_redirect/static/description/index.html
  50. 25
      geoip_website_redirect/static/src/js/action.js
  51. 8
      geoip_website_redirect/views/login_template.xml

44
geoip_website_redirect/README.rst

@ -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>`__

23
geoip_website_redirect/__init__.py

@ -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

48
geoip_website_redirect/__manifest__.py

@ -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'],
}
}

22
geoip_website_redirect/controllers/__init__.py

@ -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

55
geoip_website_redirect/controllers/geoip_website_redirect.py

@ -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

7
geoip_website_redirect/doc/RELEASE_NOTES.md

@ -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

23
geoip_website_redirect/models/__init__.py

@ -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

29
geoip_website_redirect/models/res_users.py

@ -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")

60
geoip_website_redirect/models/website.py

@ -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

BIN
geoip_website_redirect/static/description/assets/cybro-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
geoip_website_redirect/static/description/assets/cybro-odoo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
geoip_website_redirect/static/description/assets/icons/1-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
geoip_website_redirect/static/description/assets/icons/2-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
geoip_website_redirect/static/description/assets/icons/3-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
geoip_website_redirect/static/description/assets/icons/4-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
geoip_website_redirect/static/description/assets/icons/5-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
geoip_website_redirect/static/description/assets/icons/6-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
geoip_website_redirect/static/description/assets/icons/Hospital Management-icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
geoip_website_redirect/static/description/assets/icons/check.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
geoip_website_redirect/static/description/assets/icons/chevron.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

BIN
geoip_website_redirect/static/description/assets/icons/cogs.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
geoip_website_redirect/static/description/assets/icons/consultation.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

1
geoip_website_redirect/static/description/assets/icons/down.svg

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="512" height="512" x="0" y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512" xml:space="preserve" class=""><g><g id="Layer_2" data-name="Layer 2"><path d="m12 1a11 11 0 1 0 11 11 11.013 11.013 0 0 0 -11-11zm5.707 9.707-5 5a1 1 0 0 1 -1.414 0l-5-5a1 1 0 0 1 1.414-1.414l4.293 4.293 4.293-4.293a1 1 0 0 1 1.414 1.414z" fill="#781d96" data-original="#000000" class=""></path></g></g></svg>

After

Width:  |  Height:  |  Size: 542 B

BIN
geoip_website_redirect/static/description/assets/icons/ecom-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

BIN
geoip_website_redirect/static/description/assets/icons/education-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

BIN
geoip_website_redirect/static/description/assets/icons/hotel-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 911 B

BIN
geoip_website_redirect/static/description/assets/icons/license.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
geoip_website_redirect/static/description/assets/icons/lifebuoy.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
geoip_website_redirect/static/description/assets/icons/main.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

BIN
geoip_website_redirect/static/description/assets/icons/manufacturing-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

BIN
geoip_website_redirect/static/description/assets/icons/pos-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

BIN
geoip_website_redirect/static/description/assets/icons/puzzle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

BIN
geoip_website_redirect/static/description/assets/icons/restaurant-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

BIN
geoip_website_redirect/static/description/assets/icons/service-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

BIN
geoip_website_redirect/static/description/assets/icons/support.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
geoip_website_redirect/static/description/assets/icons/trading-black.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

BIN
geoip_website_redirect/static/description/assets/icons/training.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

BIN
geoip_website_redirect/static/description/assets/icons/update.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
geoip_website_redirect/static/description/assets/icons/user.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 B

BIN
geoip_website_redirect/static/description/assets/icons/whatsapp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
geoip_website_redirect/static/description/assets/icons/wrench.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
geoip_website_redirect/static/description/assets/main.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

BIN
geoip_website_redirect/static/description/assets/screenshots/Screenshot 4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

BIN
geoip_website_redirect/static/description/assets/screenshots/Screenshot1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

BIN
geoip_website_redirect/static/description/assets/screenshots/Screenshot2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
geoip_website_redirect/static/description/assets/screenshots/Screenshot3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

BIN
geoip_website_redirect/static/description/banner.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
geoip_website_redirect/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

1442
geoip_website_redirect/static/description/index.html

File diff suppressed because it is too large

25
geoip_website_redirect/static/src/js/action.js

@ -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;
});

8
geoip_website_redirect/views/login_template.xml

@ -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>
Loading…
Cancel
Save