summaryrefslogtreecommitdiff
path: root/indoteknik_api
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-24 11:43:52 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-24 11:43:52 +0700
commit2a3a0a7e88ef24456eeda070a7d74f1457efdb18 (patch)
tree2bb4cd374d46b5d5e4fb6e32fe239c5ccc83daf4 /indoteknik_api
parent287cf8497b4b6bb825870ee2b3d1b49d4c29ab6a (diff)
parent646b9e22fc11f6f1d1b556761a3df2df61f8f59b (diff)
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_api')
-rw-r--r--indoteknik_api/controllers/api_v1/content.py31
-rw-r--r--indoteknik_api/controllers/api_v1/product.py8
-rw-r--r--indoteknik_api/models/product_product.py8
-rw-r--r--indoteknik_api/models/product_template.py13
-rw-r--r--indoteknik_api/models/x_manufactures.py7
5 files changed, 50 insertions, 17 deletions
diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py
index 3d4e443a..32828244 100644
--- a/indoteknik_api/controllers/api_v1/content.py
+++ b/indoteknik_api/controllers/api_v1/content.py
@@ -6,6 +6,37 @@ from odoo.http import request
class WebsiteContent(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'banner', auth='public', methods=['GET', 'OPTIONS'])
+ def get_banner(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+
+ category_id = int(kw.get('category_id'), 0)
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ]
+
+ if category_id > 0:
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ('x_banner_category', '=', category_id),
+ ]
+
+ data = []
+ banners = request.env['x_banner.banner'].search(query)
+ for banner in banners:
+ data.append({
+ # 'image': base_url + 'api/image/x_banner.banner/image' + str(banner.id) if banner.x_banner_image else '',
+ 'banner_image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
+ 'category_id': banner.x_banner_category.id,
+ 'category_image': banner.x_banner_category.x_name,
+ 'name': banner.x_name,
+ 'url': banner.x_url_banner,
+ 'status': banner.x_status_banner,
+ })
+ return self.response(data)
+
@http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS'])
def get_product_ads(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 78b03203..23dcf48e 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -19,6 +19,8 @@ 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')
+ limit_new_products = request.env['ir.config_parameter'].get_param('limit.new.product')
+ limit_new_products = int(limit_new_products)
# current_time = datetime.now()
# delta_time = current_time - timedelta(days=30)
@@ -28,9 +30,11 @@ class Product(controller.Controller):
('active', '=', True),
('image_128', '!=', False),
('website_description', '!=', False),
+ # ('write_uid', '!=', 1),
+ ('x_manufacture', '!=', False),
# ('create_date', '>=', delta_time),
]
- new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250)
+ new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=limit_new_products)
brands = []
for product in new_products:
brands.append(product.x_manufacture)
@@ -57,6 +61,8 @@ class Product(controller.Controller):
('x_manufacture', '=', brand.id),
('image_128', '!=', False),
('website_description', '!=', False),
+ # ('write_uid', '!=', 1),
+ ('x_manufacture', '!=', False),
# ('create_date', '>=', delta_time),
]
count_products = request.env['product.template'].search_count(query)
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 6b02d91e..2e84b9f4 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -5,7 +5,6 @@ class ProductProduct(models.Model):
_inherit = 'product.product'
def api_single_response(self, product_product):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
product_template = product_product.product_tmpl_id
@@ -14,7 +13,7 @@ class ProductProduct(models.Model):
'parent': {
'id': product_template.id,
'name': product_template.name,
- 'image': base_url + 'api/image/product.template/image_256/' + str(product_template.id) if product_template.image_256 else '',
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id),
},
'code': product_product.default_code or '',
'name': product_product.display_name,
@@ -27,13 +26,12 @@ class ProductProduct(models.Model):
return data
def api_manufacture(self, product_template):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
if product_template.x_manufacture:
manufacture = product_template.x_manufacture
return {
'id': manufacture.id,
'name': manufacture.x_name,
- 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '',
- 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '',
+ 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id),
+ 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id),
}
return {} \ No newline at end of file
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 9e8d04bc..72dda17f 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -5,12 +5,11 @@ class ProductTemplate(models.Model):
_inherit = 'product.template'
def api_single_response(self, product_template, with_detail=''):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
data = {
'id': product_template.id,
- 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '',
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id),
'code': product_template.default_code or '',
'name': product_template.name,
'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default_discount_id),
@@ -23,7 +22,7 @@ class ProductTemplate(models.Model):
if with_detail != '':
data_with_detail = {
- 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id),
'display_name': product_template.display_name,
'variants': [self.env['product.product'].api_single_response(variant) for variant in product_template.product_variant_ids],
'description': product_template.website_description or '',
@@ -31,12 +30,13 @@ class ProductTemplate(models.Model):
data.update(data_with_detail)
if with_detail == 'SOLR':
+ is_image_found = self.env['ir.attachment'].is_found('product.template', 'image_128', product_template.id)
rate = 0
if data['lowest_price']['price'] > 0:
rate += 1
if product_template.have_promotion_program:
rate += 1
- if product_template.image_128:
+ if is_image_found:
rate += 1
if product_template.website_description:
rate += 1
@@ -52,14 +52,13 @@ class ProductTemplate(models.Model):
return data
def api_manufacture(self, product_template):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
if product_template.x_manufacture:
manufacture = product_template.x_manufacture
return {
'id': manufacture.id,
'name': manufacture.x_name,
- 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '',
- 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '',
+ 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id),
+ 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id),
}
return {}
diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py
index 19fdcb9c..b85f6d27 100644
--- a/indoteknik_api/models/x_manufactures.py
+++ b/indoteknik_api/models/x_manufactures.py
@@ -5,19 +5,18 @@ class Manufactures(models.Model):
_inherit = 'x_manufactures'
def api_single_response(self, manufacture, with_detail=False):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
data = {
'id': manufacture.id,
- 'logo': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(manufacture.id) if manufacture.x_logo_manufacture else '',
+ 'logo': self.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', manufacture.id),
'name': manufacture.x_name
}
if with_detail:
data_with_detail = {
'description': manufacture.x_short_desc,
'banners': [
- base_url + 'api/image/x_banner.banner/x_banner_image/' + str(x.id)
+ self.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', x.id)
for x in manufacture.x_manufactures_banners
- if x.x_status_banner == 'tayang' and x.x_banner_image
+ if x.x_status_banner == 'tayang'
]
}
data.update(data_with_detail)