diff options
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/promotion.py | 44 |
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() |
