summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-18 08:22:29 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-18 08:22:29 +0700
commit65929f7a9c00639a7b1c360ebc9870b221aa5339 (patch)
tree04fe40072cda5622f30192073fae3de93c2f694d
parent78b151a7e90e84dfa3898b75cf4440c714ba9305 (diff)
remove useless code, add last seen products, add compile product in user activity log
-rw-r--r--indoteknik_api/controllers/api_v1/customer.py38
-rw-r--r--indoteknik_api/controllers/api_v1/product.py6
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py28
3 files changed, 68 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/customer.py b/indoteknik_api/controllers/api_v1/customer.py
index f6d6d40d..57120751 100644
--- a/indoteknik_api/controllers/api_v1/customer.py
+++ b/indoteknik_api/controllers/api_v1/customer.py
@@ -7,6 +7,44 @@ import ast
class CustomerReview(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'last_seen_products', auth='public', methods=['GET', 'OPTIONS'])
+ def get_last_seen_products(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+
+ email = str(kw.get('email', ''))
+ if not email:
+ return self.response(code=401, description='Unauthorized')
+
+ activity_logs = request.env['user.activity.log'].search([
+ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('email', '=', email),
+ ], order='create_date desc', limit=5)
+
+ data = []
+ templates = []
+ for activity_log in activity_logs:
+ strip_index = i = 0
+ for c in activity_log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ template_id = activity_log.url[strip_index + 1:len(activity_log.url)]
+ if '#' in template_id:
+ continue
+ if any(ch.isalpha() for ch in template_id):
+ continue
+ template = request.env['product.template'].search([('id', '=', template_id)])
+ templates.append(template)
+
+ data.append({
+ 'email': email,
+ 'products': [request.env['product.template'].api_single_response(x) for x in templates]
+ })
+ return self.response(data)
+
+
+
@http.route(prefix + 'customer_review', auth='public', methods=['GET', 'OPTIONS'])
def get_customer_review(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index fc8e2610..78b03203 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -19,10 +19,10 @@ class Product(controller.Controller):
is_brand_only = int(kw.get('is_brand_only', 0))
base_url = request.env['ir.config_parameter'].get_param('web.base.url')
- current_time = datetime.now()
- delta_time = current_time - timedelta(days=30)
+ # current_time = datetime.now()
+ # delta_time = current_time - timedelta(days=30)
- delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
query_products = [
('type', '=', 'product'),
('active', '=', True),
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index bf1414db..3cf7bd58 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -14,14 +14,40 @@ class UserActivityLog(models.Model):
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')
+
+ def compile_product(self):
+ logs = self.env['user.activity.log'].search([
+ ('email', '!=', False),
+ ('product_id', '=', False),
+ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('url', 'not ilike', 'shopping')
+ ], limit=1000, order='create_date desc')
+ for log in logs:
+ _logger.info(log.url)
+ strip_index = i = 0
+ for c in log.url:
+ if c == '-':
+ strip_index = i
+ i += 1
+ product_id = log.url[strip_index + 1:len(log.url)]
+ if '#' in product_id:
+ continue
+ if any(ch.isalpha() for ch in product_id):
+ continue
+ product = self.env['product.template'].search([
+ ('id', '=', product_id)
+ ])
+ log.product_id = product
def clean_activity_log(self):
current_time = datetime.now()
- delta_time = current_time - timedelta(days=60)
+ delta_time = current_time - timedelta(days=180)
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
self.env['user.activity.log'].search([
('create_date', '<', delta_time),
+ ('email', '=', 'False'),
]).unlink()
def reset_rank_search_weekly(self):