summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-06-05 11:03:10 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-06-05 11:03:10 +0700
commit8d87673201e7339cb946c36e8f91579e135d5c5b (patch)
treecf17537384f05b26632b47e217f4c5536f5edc60 /indoteknik_api/controllers/api_v1
parent9306992db370c793e8cab494038b0de5b61b600f (diff)
api promotion program line get program line by promotion_type
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py
index 221f6e10..aca092af 100644
--- a/indoteknik_api/controllers/api_v1/promotion.py
+++ b/indoteknik_api/controllers/api_v1/promotion.py
@@ -28,7 +28,51 @@ class Promotion(controller.Controller):
'remaining_qty': remaining_qty,
'used_percentage': percent_remaining,
})
+
+ @http.route(prefix + 'program-line', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_promotion_type(self, **kw):
+ type = kw.get('type')
+ program_line = request.env['promotion.program.line'].search([
+ ("promotion_type", "=", type),
+ ("active", "=", True)
+ ])
+
+ if not type:
+ program_line = request.env['promotion.program.line'].search([("active", "=", True)])
+
+ data = []
+ for line in program_line:
+ product_list = []
+ for product in line.product_ids:
+ product_list.append({
+ 'id': product.product_id.id,
+ 'name': product.product_id.name,
+ 'qty': product.qty
+ })
+ free_product_list = []
+ for free_product in line.product_ids:
+ free_product_list.append({
+ 'id': free_product.product_id.id,
+ 'name': free_product.product_id.name,
+ 'qty': product.qty
+ })
+
+ data.append({
+ 'id': line.id,
+ 'name': line.name,
+ 'program': line.program_id.name,
+ 'promotion_type': line.promotion_type,
+ 'active': line.active,
+ 'description': line.description,
+ 'package_limit': line.package_limit,
+ 'package_limit_user': line.package_limit_user,
+ 'package_limit_trx': line.package_limit_trx,
+ 'price': line.price,
+ 'products': product_list
+ })
+ return self.response(data)
@http.route(prefix + 'promotion/<id>', auth='public', methods=['GET'])
@controller.Controller.must_authorized()