summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-11-22 09:05:48 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-11-22 09:05:48 +0700
commit1d144203dfc9cdaef66c8ab70e7a7432ea9e8bc8 (patch)
tree76f52f1bb4b4f947841d04f2bd450166ee090f00
parent75694b2b47729a71f1ec50639063f0e924aa90b2 (diff)
add search ranking by weekly in product template
-rwxr-xr-xindoteknik_custom/models/product_template.py1
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py40
2 files changed, 41 insertions, 0 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 743667cc..1e23477b 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -34,6 +34,7 @@ class ProductTemplate(models.Model):
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)
+ search_rank_weekly = fields.Integer(string='Search Rank Weekly', 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 97d1684b..e02372fc 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -1,4 +1,5 @@
from odoo import models, fields
+from datetime import datetime, timedelta
import logging, re
_logger = logging.getLogger(__name__)
@@ -19,6 +20,45 @@ class UserActivityLog(models.Model):
('email', 'not ilike', '%@%'),
]).unlink()
+ def reset_rank_search_weekly(self):
+ templates = self.env['product.template'].search([
+ ('type', '=', 'product'),
+ ('active', '=', True),
+ ('search_rank_weekly', '>', 0),
+ ])
+ for template in templates:
+ template.search_rank_weekly = 0
+
+ def update_rank_search_weekly(self):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=7)
+
+ # current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+
+ activity_logs = self.env['user.activity.log'].search([
+ ('url', 'ilike', '%indoteknik.co%/shop/product/%'),
+ ('create_date', '>', delta_time),
+ ], limit=4000)
+ 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_weekly = int(template.search_rank_weekly) + int(1)
+ template.solr_flag = 2
+
def update_rank_search(self):
activity_logs = self.env['user.activity.log'].search([
('url', 'ilike', '%/shop/product/%'),