summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-11-15 17:29:45 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-11-15 17:29:45 +0700
commit9d0dbdfe0e08ecab850860fa2b23ffb64fa6dae1 (patch)
tree220ea2b61605eb12d349300b766722b161f345be
parentd23592de2c631cf1b7bbdc53cfca7a95607c0b36 (diff)
add search rank in product template
-rwxr-xr-xindoteknik_custom/models/product_template.py1
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py31
-rwxr-xr-xindoteknik_custom/views/product_template.xml1
3 files changed, 33 insertions, 0 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 5d34fbc8..114899e6 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -33,6 +33,7 @@ class ProductTemplate(models.Model):
web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0)
virtual_qty = fields.Float(string='Virtual Qty', default=0)
solr_flag = fields.Integer(string='Solr Flag', default=0)
+ search_rank = fields.Integer(string='Search Rank', default=0)
# def write(self, vals):
# if 'solr_flag' not in vals and self.solr_flag == 1:
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index 07079714..ab85d47f 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -1,4 +1,7 @@
from odoo import models, fields
+import logging, re
+
+_logger = logging.getLogger(__name__)
class UserActivityLog(models.Model):
@@ -9,8 +12,36 @@ class UserActivityLog(models.Model):
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")
def clean_activity_log(self):
self.env['user.activity.log'].search([
('email', 'not ilike', '%@%'),
]).unlink()
+
+ def update_rank_search(self):
+ activity_logs = self.env['user.activity.log'].search([
+ ('url', 'ilike', '%/shop/product/%'),
+ ('update_product', '=', False),
+ # ('url', 'not ilike', '%/shop/product/%google-ads-shopping'),
+ # ('id', '=', 211957)
+ ], limit=1000)
+
+ for activity_log in activity_logs:
+ _logger.info(activity_log.url)
+ strip_index = i = 0
+ for c in activity_log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ _logger.info(activity_log.url[strip_index+1:len(activity_log.url)])
+ product_id = activity_log.url[strip_index+1:len(activity_log.url)]
+ if '#' in product_id:
+ continue
+ if any(ch.isalpha() for ch in product_id):
+ continue
+ template = self.env['product.template'].search([
+ ('id', '=', product_id)
+ ], limit=1)
+ template.search_rank += int(template.search_rank+1)
+ activity_log.update_product = True
diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml
index d97359b6..0e774012 100755
--- a/indoteknik_custom/views/product_template.xml
+++ b/indoteknik_custom/views/product_template.xml
@@ -45,6 +45,7 @@
<field name="website_ribbon_id" position="after">
<field name="last_calculate_rating" attrs="{'readonly': [('type', '=', 'product')]}"/>
<field name="product_rating"/>
+ <field name="search_rank"/>
<field name="web_price_sorting" attrs="{'readonly': [('type', '=', 'product')]}"/>
<field name="solr_flag"/>
</field>