summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/promotion.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-07-24 08:38:12 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-07-24 08:38:12 +0000
commitc344ccd81208b5b466ae047dbb9e084dd5d0f358 (patch)
treec07caf6a1df48719b828fbe270bb62ccc3e0c947 /indoteknik_api/controllers/api_v1/promotion.py
parent989002aca3ed9b1e724e9b98d8ca3513ba598663 (diff)
parent2ad6b4ecf783b5dfe0d4aa11f238cbf6aefd9747 (diff)
Merged in production (pull request #66)
Production
Diffstat (limited to 'indoteknik_api/controllers/api_v1/promotion.py')
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py70
1 files changed, 66 insertions, 4 deletions
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py
index b137fe2e..f84b8c1c 100644
--- a/indoteknik_api/controllers/api_v1/promotion.py
+++ b/indoteknik_api/controllers/api_v1/promotion.py
@@ -1,12 +1,13 @@
from .. import controller
from odoo import http
from odoo.http import request
-import ast
+from datetime import datetime
class Promotion(controller.Controller):
prefix = '/api/v1/'
-
+
+
@http.route(prefix + 'promotion/<id>', auth='public', methods=['GET'])
@controller.Controller.must_authorized()
def get_promotion_by_id(self, **kw):
@@ -14,7 +15,7 @@ class Promotion(controller.Controller):
id = kw.get('id')
if not id:
return self.response(code=400, description='id is required')
-
+
data = {}
id = int(id)
coupon_program = request.env['coupon.program'].search([('id', '=', id)])
@@ -24,6 +25,67 @@ class Promotion(controller.Controller):
'image': base_url + 'api/image/coupon.program/x_studio_image_promo/' + str(coupon_program.id) if coupon_program.x_studio_image_promo else '',
'name': coupon_program.name,
}
+
+ return self.response(data)
+
+
+ @http.route(prefix + 'promotion/home', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def v1_get_promotion_home(self):
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+ programs = request.env['promotion.program'].search([
+ ('start_time', '<=', current_time),
+ ('end_time', '>=', current_time),
+ ('program_line.display_on_homepage', '=', True)
+ ])
+
+ if not programs:
+ return self.response(None)
+
+ data = []
+ for program in programs:
+ data_program = {
+ 'id': program.id,
+ 'name': program.name,
+ 'banner': request.env['ir.attachment'].api_image('promotion.program', 'banner', program.id),
+ 'icon': request.env['ir.attachment'].api_image('promotion.program', 'icon', program.id)
+ }
+ data.append(data_program)
+
+ return self.response(data)
+
+
+ @http.route(prefix + 'promotion/home/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def v1_get_promotion_home_detail(self, id):
+ program_lines = request.env['promotion.program.line'].search([
+ ('display_on_homepage', '=', True),
+ ('promotion_type', '=', 'special_price'),
+ ('program_id', '=', int(id))
+ ])
+ data = []
+ for line in program_lines:
+ product = request.env['product.product'].v2_api_single_response(line.product_id)
+ product_template = line.product_id.product_tmpl_id
+
+ product.update({
+ 'id': product['parent']['id'],
+ 'image': product['parent']['image'],
+ 'name': product['parent']['name'],
+ 'variant_total': len(product_template.product_variant_ids),
+ 'lowest_price': line.calculate_price(product['price']),
+ 'stock_total': product['stock'],
+ 'icon': {
+ 'top': request.env['ir.attachment'].api_image('promotion.program', 'icon_top', line.program_id.id),
+ 'bottom': request.env['ir.attachment'].api_image('promotion.program', 'icon_bottom', line.program_id.id)
+ }
+ })
+
+ product.pop('parent', None)
+ product.pop('price', None)
+ product.pop('stock', None)
+ data.append(product)
+
return self.response(data)
- \ No newline at end of file
+