summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/promotion.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-07 10:45:51 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-07 10:45:51 +0700
commitf6be42d37a363b86f4a9ec71ccb38c78cbe2d887 (patch)
tree9c297e776f67e35671012e94d3c64007bd5090d7 /indoteknik_api/controllers/api_v1/promotion.py
parentedb3c1c80931078d40a8f56149aeca9efdcdc07d (diff)
parent29a9ec94f1ad131f398cf119a03a7b927a4c6cba (diff)
Merge branch 'production' into purchasing-job
# Conflicts: # indoteknik_custom/__manifest__.py # indoteknik_custom/models/__init__.py # indoteknik_custom/models/automatic_purchase.py # indoteknik_custom/models/purchase_order_line.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/automatic_purchase.xml # indoteknik_custom/views/purchase_order.xml
Diffstat (limited to 'indoteknik_api/controllers/api_v1/promotion.py')
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py22
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'])