diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-11-22 09:05:48 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-11-22 09:05:48 +0700 |
| commit | 1d144203dfc9cdaef66c8ab70e7a7432ea9e8bc8 (patch) | |
| tree | 76f52f1bb4b4f947841d04f2bd450166ee090f00 /indoteknik_custom/models/user_activity_log.py | |
| parent | 75694b2b47729a71f1ec50639063f0e924aa90b2 (diff) | |
add search ranking by weekly in product template
Diffstat (limited to 'indoteknik_custom/models/user_activity_log.py')
| -rwxr-xr-x | indoteknik_custom/models/user_activity_log.py | 40 |
1 files changed, 40 insertions, 0 deletions
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/%'), |
