diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-22 13:43:42 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-22 13:43:42 +0700 |
| commit | 329668e82ca9e4ebd2ee93d6670380abf6ed6377 (patch) | |
| tree | 4180e03acdd15f33654a6cf3d5e8f856ac677848 /indoteknik_api/controllers/api_v1 | |
| parent | 4e9a5a025012afe63133524eeea8987b9af9e050 (diff) | |
Add program line to order line relation, update remaining_qty response on get product promotion api, show order line on program line
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product_variant.py | 12 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/promotion.py | 27 |
2 files changed, 12 insertions, 27 deletions
diff --git a/indoteknik_api/controllers/api_v1/product_variant.py b/indoteknik_api/controllers/api_v1/product_variant.py index 999ced6f..cec54fda 100644 --- a/indoteknik_api/controllers/api_v1/product_variant.py +++ b/indoteknik_api/controllers/api_v1/product_variant.py @@ -2,6 +2,7 @@ from .. import controller from odoo import http from odoo.http import request + class ProductVariant(controller.Controller): prefix = '/api/v1/' @@ -20,3 +21,14 @@ class ProductVariant(controller.Controller): return self.response(data) + @http.route(prefix + 'product_variant/<product_id>/promotions', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_product_variant_promotions(self, product_id): + product_id = int(product_id) + user_data = self.verify_user_token() + + program_line = request.env['promotion.program.line'] + program_lines = program_line.get_active_promotions(product_id) + program_lines = program_line.res_format(program_lines, user_data) + + return self.response(program_lines) diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py index 991a3eb9..948681fd 100644 --- a/indoteknik_api/controllers/api_v1/promotion.py +++ b/indoteknik_api/controllers/api_v1/promotion.py @@ -94,30 +94,3 @@ class Promotion(controller.Controller): data.append(product) return self.response(data) - - @http.route(prefix + 'promotion/product/<id>', auth='public', methods=['GET', 'OPTIONS']) - def v1_get_promotion_by_product_id(self, id): - id = int(id) - current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') - product = request.env['product.template'].search([('id', '=', id)]) - variant_ids = [variant.id for variant in product.product_variant_ids] - program_lines = request.env['promotion.program.line'].search([ - ('program_id.start_time', '<=', current_time), - ('program_id.end_time', '>=', current_time), - ('product_id.id', 'in', variant_ids) - ]) - - data = [] - ir_attachment = request.env['ir.attachment'] - for line in program_lines: - data.append({ - 'name': line.name, - 'image': ir_attachment.api_image('promotion.program.line', 'image', line.id), - 'type': line.promotion_type, - 'minimum_purchase_qty': line.minimum_purchase_qty, - 'applies_multiply': line.applies_multiply, - 'limit_qty': line.limit_qty, - 'limit_qty_user': line.limit_qty_user, - 'limit_qty_transaction': line.limit_qty_transaction, - }) - return self.response(data) |
