summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/user_activity_log.py
blob: bf1414db56951e2f0fb90093144c1d21041e1431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from odoo import models, fields
from datetime import datetime, timedelta
import logging, re

_logger = logging.getLogger(__name__)


class UserActivityLog(models.Model):
    _name = 'user.activity.log'
    _rec_name = 'page_title'

    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")

    def clean_activity_log(self):
        current_time = datetime.now()
        delta_time = current_time - timedelta(days=60)

        delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
        self.env['user.activity.log'].search([
            ('create_date', '<', delta_time),
        ]).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
            template.solr_flag = 2

    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', 'https://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/%'),
            ('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) + int(1)
            activity_log.update_product = True