diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-01-04 02:27:45 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-01-04 02:27:45 +0000 |
| commit | 63abd2dc32f952af7234f3d6a7774cbb8c7bcb47 (patch) | |
| tree | b4cee127fc7d467b33cef4ffae9218f8acb9aeaa /indoteknik_api/controllers/api_v1/promotion.py | |
| parent | 13b31fc3d89957d23582efb2c51ab143ca1d425a (diff) | |
| parent | 717cb3b43c729e265603b3df61234c0b430742a7 (diff) | |
Merged in change/feature/promotion-program (pull request #133)
Change/feature/promotion program
Diffstat (limited to 'indoteknik_api/controllers/api_v1/promotion.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/promotion.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py index f84b8c1c..221f6e10 100644 --- a/indoteknik_api/controllers/api_v1/promotion.py +++ b/indoteknik_api/controllers/api_v1/promotion.py @@ -6,6 +6,28 @@ from datetime import datetime class Promotion(controller.Controller): prefix = '/api/v1/' + + @http.route(prefix + 'program-line/<id>/stock', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_promotion_stock(self, id): + program_line = request.env['promotion.program.line'].browse(int(id)) + if not program_line.id: + return self.response(code=400, description='program not found') + + user_data = self.verify_user_token() + + limit_qty = program_line._res_limit_qty() + remaining_qty = program_line._get_remaining_qty(user_data) + + percent_remaining = 0 + if limit_qty['all'] > 0: + percent_remaining = (limit_qty['all'] - remaining_qty['all']) / limit_qty['all'] * 100 + + return self.response({ + 'limit_qty': limit_qty, + 'remaining_qty': remaining_qty, + 'used_percentage': percent_remaining, + }) @http.route(prefix + 'promotion/<id>', auth='public', methods=['GET']) |
