summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-13 10:10:15 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-13 10:10:15 +0700
commit02bdb845c9722030f23d386ca6548e79f036a35a (patch)
treeae8028405f24f0212a3b98f032cf15c065e3d111
parentb87787893d25f735bdf9aba164bc8b1f23e2b72f (diff)
add model ip lookup (grouping ip)
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/ip_lookup.py59
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv4
-rw-r--r--indoteknik_custom/views/ip_lookup.xml69
5 files changed, 133 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 1643d9d1..da82d2bd 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -59,6 +59,7 @@
'views/custom_mail_marketing.xml',
'views/website_ads.xml',
'views/leads_monitoring.xml',
+ 'views/ip_lookup.xml',
'report/report.xml',
'report/report_banner_banner.xml',
'report/report_banner_banner2.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 121bd0f4..55eca2e7 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -47,3 +47,4 @@ from . import x_product_tags
from . import website_ads
from . import leads_monitoring
from . import midtrans
+from . import ip_lookup
diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py
new file mode 100644
index 00000000..0fbb03ea
--- /dev/null
+++ b/indoteknik_custom/models/ip_lookup.py
@@ -0,0 +1,59 @@
+from odoo import models, api, fields
+import logging
+import requests
+import json
+
+_logger = logging.getLogger(__name__)
+
+
+class IpLookup(models.Model):
+ _name = 'ip.lookup'
+
+ date_from = fields.Date(string='Date From', required=True)
+ date_to = fields.Date(string='Date To', required=True)
+ lookup_line = fields.One2many('ip.lookup.line', 'ip_lookup_id', string='Lookup Lines', auto_join=True)
+
+ def generate_ip_lookup(self):
+ query = [
+ ('create_date', '>=', self.date_from),
+ ('create_date', '<=', self.date_to),
+ ('ip_address', '!=', False)
+ ]
+ logss = self.env['user.activity.log'].search(query)
+ ips = []
+ for log in logss:
+ ips.append(log.ip_address)
+ logs = list(dict.fromkeys(ips))
+
+ count = 0
+ for log in logs:
+ self.env['ip.lookup.line'].create([{
+ 'ip_lookup_id': self.id,
+ 'ip_address': log
+ }])
+ count += 1
+ _logger.info('IP Lookup Generated %s' % count)
+
+ def _load_ip_address_lookup(self):
+ domain = [
+ ('lookup', '=', False),
+ ]
+ logs = self.env['ip.lookup.line'].search(domain, limit=45, order='create_date asc')
+ for log in logs:
+ try:
+ ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json()
+ del ipinfo['status']
+ log.lookup = json.dumps(ipinfo, indent=4, sort_keys=True)
+ except:
+ log.lookup = ''
+
+
+class IpLookupLine(models.Model):
+ _name = 'ip.lookup.line'
+
+ ip_lookup_id = fields.Many2one('ip.lookup', string='Lookup Ref', required=True, ondelete='cascade', index=True,
+ copy=False)
+ ip_address = fields.Char(string='IP Address')
+ lookup = fields.Char(string='Lookup')
+ country = fields.Char(string='Country')
+
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 83d9e2ed..2cfe86a9 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -30,4 +30,6 @@ access_website_ads,access.website.ads,model_website_ads,,1,1,1,1
access_leads_monitoring,access.leads.monitoring,model_leads_monitoring,,1,1,1,1
access_midtrans_notification,access.midtrans.notification,model_midtrans_notification,,1,1,1,1
access_midtrans_recurring,access.midtrans.recurring,model_midtrans_recurring,,1,1,1,1
-access_midtrans_account,access.midtrans.account,model_midtrans_account,,1,1,1,1 \ No newline at end of file
+access_midtrans_account,access.midtrans.account,model_midtrans_account,,1,1,1,1
+access_ip_lookup,access.ip.lookup,model_ip_lookup,,1,1,1,1
+access_ip_lookup_line,access.ip.lookup.line,model_ip_lookup_line,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/ip_lookup.xml b/indoteknik_custom/views/ip_lookup.xml
new file mode 100644
index 00000000..c276e9d5
--- /dev/null
+++ b/indoteknik_custom/views/ip_lookup.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="ip_lookup_tree" model="ir.ui.view">
+ <field name="name">ip.lookup.tree</field>
+ <field name="model">ip.lookup</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="date_from"/>
+ <field name="date_to"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="ip_lookup_line_tree" model="ir.ui.view">
+ <field name="name">ip.lookup.line.tree</field>
+ <field name="model">ip.lookup.line</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="ip_address"/>
+ <field name="lookup"/>
+ <field name="country"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="ip_lookup_form" model="ir.ui.view">
+ <field name="name">ip.lookup.form</field>
+ <field name="model">ip.lookup</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet string="ip">
+ <div class="oe_button_box" name="button_box"/>
+ <group>
+ <group>
+ <div>
+ <button name="generate_ip_lookup"
+ string="Generate"
+ type="object"
+ class="mr-2 oe_highlight oe_edit_only"/>
+ </div>
+ <field name="date_from"/>
+ <field name="date_to"/>
+ </group>
+ </group>
+ <notebook>
+ <page string="Lines">
+ <field name="lookup_line"/>
+ </page>
+ </notebook>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="ip_lookup_action" model="ir.actions.act_window">
+ <field name="name">IP Lookup</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">ip.lookup</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_ip_lookup"
+ name="IP Lookup"
+ sequence="4"
+ parent="website.website_visitor_menu"
+ action="ip_lookup_action"
+ />
+</odoo> \ No newline at end of file