summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-02-29 14:21:05 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-02-29 14:21:05 +0700
commit0b5b43646b92298dddcdb7eec1a590d90cadd1e8 (patch)
tree2b34e0e79bc2612183831a35f96fb7550d17f99b
parentee48a727e2617d8e094847dfb5bf9d5279db165a (diff)
Update feature user activity log with utm source
-rwxr-xr-xindoteknik_custom/__manifest__.py3
-rwxr-xr-xindoteknik_custom/models/__init__.py2
-rw-r--r--indoteknik_custom/models/web_logging/__init__.py2
-rw-r--r--[-rwxr-xr-x]indoteknik_custom/models/web_logging/user_activity_log.py (renamed from indoteknik_custom/models/user_activity_log.py)47
-rw-r--r--indoteknik_custom/models/web_logging/web_utm_source.py17
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--[-rwxr-xr-x]indoteknik_custom/views/web_logging/user_activity_log.xml (renamed from indoteknik_custom/views/user_activity_log.xml)6
-rw-r--r--indoteknik_custom/views/web_logging/web_utm_source.xml45
8 files changed, 110 insertions, 13 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 30e8e176..571b36c3 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -27,7 +27,8 @@
'views/purchase_pricelist.xml',
'views/sale_monitoring.xml',
'views/sale_monitoring_detail.xml',
- 'views/user_activity_log.xml',
+ 'views/web_logging/user_activity_log.xml',
+ 'views/web_logging/web_utm_source.xml',
'views/user_company_request.xml',
'views/vit_kelurahan.xml',
'views/vit_kecamatan.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 7c5e46e6..69cbffca 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -33,7 +33,6 @@ from . import stock_picking_return
from . import stock_picking_type
from . import stock_picking
from . import stock_vendor
-from . import user_activity_log
from . import user_company_request
from . import users
from . import website_brand_homepage
@@ -103,3 +102,4 @@ from . import report_logbook_sj
from . import role_permission
from . import cust_commision
from . import report_stock_forecasted
+from . import web_logging \ No newline at end of file
diff --git a/indoteknik_custom/models/web_logging/__init__.py b/indoteknik_custom/models/web_logging/__init__.py
new file mode 100644
index 00000000..9c686e54
--- /dev/null
+++ b/indoteknik_custom/models/web_logging/__init__.py
@@ -0,0 +1,2 @@
+from . import web_utm_source
+from . import user_activity_log \ No newline at end of file
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/web_logging/user_activity_log.py
index 9630e3ab..f48e9352 100755..100644
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/web_logging/user_activity_log.py
@@ -1,9 +1,12 @@
-from odoo import models, fields, api
-from odoo.http import request
+import json
+import logging
+import re
from datetime import datetime, timedelta
-import logging, re
+
import requests
-import json
+from odoo import fields, models, api
+from odoo.http import request
+from urllib.parse import urlparse, parse_qs
_logger = logging.getLogger(__name__)
@@ -14,16 +17,44 @@ class UserActivityLog(models.Model):
page_title = fields.Char(string="Judul Halaman")
url = fields.Char(string="URL")
+ res_user_id = fields.Many2one("res.users", string="User")
+ email = fields.Char(string="Email")
+ update_product = fields.Boolean(string="Update Product")
+ product_id = fields.Many2one('product.template', string='Product')
+ utm_source_id = fields.Many2one('web.utm.source', string='UTM Source')
+
ip_address = fields.Char('IP Address')
ip_address_lookup = fields.Text('IP Address Lookup')
ip_location_city = fields.Text('IP Location City')
ip_location_country = fields.Text('IP Location Country')
ip_location_country_code = fields.Text('IP Location Country Code')
ip_location_map = fields.Html('Embedded Map', compute='_compute_ip_location_map', sanitize=False)
- res_user_id = fields.Many2one("res.users", string="User")
- email = fields.Char(string="Email")
- update_product = fields.Boolean(string="Update Product")
- product_id = fields.Many2one('product.template', string='Product')
+
+
+ # @api.constrains('url')
+ # def _constrains_url(self):
+ # for rec in self:
+ # rec.fill_utm_source()
+ @api.model
+ def create(self, vals):
+ result = super(UserActivityLog, self).create(vals)
+ result.fill_utm_source()
+ return result
+
+ def fill_utm_source(self):
+ for rec in self:
+ if not rec.url:
+ rec.utm_source_id = False
+ continue
+
+ parsed_url = urlparse(rec.url)
+ params = parse_qs(parsed_url.query)
+ utm_source_value = params.get('utm_source')
+
+ if not utm_source_value: continue
+
+ utm_source = self.env['web.utm.source'].find_or_create_key(utm_source_value[0])
+ rec.utm_source_id = utm_source.id or False
def _parse_json(self, json_string, key):
result = ''
diff --git a/indoteknik_custom/models/web_logging/web_utm_source.py b/indoteknik_custom/models/web_logging/web_utm_source.py
new file mode 100644
index 00000000..baeb0e9b
--- /dev/null
+++ b/indoteknik_custom/models/web_logging/web_utm_source.py
@@ -0,0 +1,17 @@
+from odoo import fields, models
+
+
+class UserActivityLog(models.Model):
+ _name = 'web.utm.source'
+
+ name = fields.Char(string='Name')
+ key = fields.Char(string='Key', unique=True)
+
+ def find_or_create_key(self, key):
+ utm_source = self.search([('key', '=', key)], limit=1)
+ if not utm_source:
+ utm_source = self.create({
+ 'name': key,
+ 'key': key
+ })
+ return utm_source \ No newline at end of file
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 5af34c11..65bd6e90 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -8,6 +8,7 @@ access_x_partner_purchase_order,access.x.partner.purchase.order,model_x_partner_
access_x_product_tags,access.x.product.tags,model_x_product_tags,,1,1,1,1
access_stock_vendor,access.stock.vendor,model_stock_vendor,,1,1,1,1
access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1
+access_web_utm_source,access.web.utm.source,model_web_utm_source,,1,1,1,1
access_purchase_pricelist,access.purchase.pricelist,model_purchase_pricelist,,1,1,1,1
access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1
access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1
diff --git a/indoteknik_custom/views/user_activity_log.xml b/indoteknik_custom/views/web_logging/user_activity_log.xml
index 91c14b4d..ec6d1fa2 100755..100644
--- a/indoteknik_custom/views/user_activity_log.xml
+++ b/indoteknik_custom/views/web_logging/user_activity_log.xml
@@ -6,10 +6,9 @@
<field name="arch" type="xml">
<tree default_order="create_date desc" create="0" export_xlsx="0">
<field name="create_date"/>
- <field name="page_title"/>
- <field name="ip_address"/>
- <field name="ip_location_country"/>
<field name="url" widget="url"/>
+ <field name="page_title"/>
+ <field name="utm_source_id"/>
<field name="res_user_id"/>
<field name="email"/>
</tree>
@@ -27,6 +26,7 @@
<field name="create_date"/>
<field name="page_title"/>
<field name="url" widget="url"/>
+ <field name="utm_source_id"/>
<field name="res_user_id"/>
<field name="email"/>
<field name="ip_address"/>
diff --git a/indoteknik_custom/views/web_logging/web_utm_source.xml b/indoteknik_custom/views/web_logging/web_utm_source.xml
new file mode 100644
index 00000000..6ffbd95f
--- /dev/null
+++ b/indoteknik_custom/views/web_logging/web_utm_source.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="web_utm_source_tree" model="ir.ui.view">
+ <field name="name">web.utm.source.tree</field>
+ <field name="model">web.utm.source</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="name"/>
+ <field name="key"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="web_utm_source_form" model="ir.ui.view">
+ <field name="name">web.utm.source.form</field>
+ <field name="model">web.utm.source</field>
+ <field name="arch" type="xml">
+ <form create="0" edit="0">
+ <sheet>
+ <group>
+ <group>
+ <field name="name"/>
+ <field name="key"/>
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="web_utm_source_action" model="ir.actions.act_window">
+ <field name="name">Web UTM Source</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">web.utm.source</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_web_utm_source"
+ name="UTM Source"
+ sequence="3"
+ parent="website.website_visitor_menu"
+ action="web_utm_source_action"
+ />
+</odoo> \ No newline at end of file