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
|
from .. import controller
from odoo import http
from odoo.http import request
import ast
class CustomerReview(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'last_seen_products', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_last_seen_products(self, **kw):
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'])
@controller.Controller.must_authorized()
def get_customer_review(self):
base_url = request.env['ir.config_parameter'].get_param('web.base.url')
query = [('status', '=', 'tayang')]
reviews = request.env['customer.review'].search(query, order='sequence')
data = []
for review in reviews:
data.append({
'id': review.id,
'sequence': review.sequence,
'image': base_url + 'api/image/customer.review/image/' + str(review.id) if review.image else '',
'customer_name': review.customer_name,
'ulasan': review.ulasan_html,
'name': review.name,
'jabatan': review.jabatan
})
return self.response(data)
|