diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-11-03 15:34:12 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-11-03 15:34:12 +0700 |
| commit | 4aa474f3ced6681a1dfd5ec48806eb690e31c3d8 (patch) | |
| tree | d1dfdaea2768c47e3a53b4fed59223082cbe9481 /indoteknik_api/controllers/api_v1/product.py | |
| parent | 76ccac9630b60ca3774eb83fb13f1a89ee3cabf1 (diff) | |
Rest API Promotion
Diffstat (limited to 'indoteknik_api/controllers/api_v1/product.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 904670e7..aa22a876 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +import ast class Product(controller.Controller): @@ -14,17 +15,18 @@ class Product(controller.Controller): name = kw.get('name') manufactures = kw.get('manufactures') categories = kw.get('categories') + promotions = kw.get('promotions') ready_stock = kw.get('ready_stock') solr_flag = kw.get('solr_flag') - require_betweens = ['name', 'manufactures', 'categories', 'ready_stock', 'solr_flag'] + require_betweens = ['name', 'manufactures', 'categories', 'ready_stock', 'solr_flag', 'promotions'] is_fulfill = False for required in require_betweens: if kw.get(required): is_fulfill = True if not is_fulfill: - return self.response(code=400, description='name or manufactures or categories or ready_stock or solr_flag is required') + return self.response(code=400, description='name or manufactures or categories or ready_stock or solr_flag or promotions is required') query = [('sale_ok', '=', True)] @@ -47,7 +49,15 @@ class Product(controller.Controller): if solr_flag: query.append(('solr_flag', '=', int(solr_flag))) - + + if promotions: + coupon_programs = request.env['coupon.program'].search([('id', 'in', promotions.split(','))]) + promotion_query = [x for coupon_program in coupon_programs for x in ast.literal_eval(coupon_program.rule_products_domain)] + if len(promotion_query) > 1: + or_in_promotion_query = ["|" for x in range(len(promotion_query) - 1)] + promotion_query = or_in_promotion_query + promotion_query + query += promotion_query + is_with_detail = True if kw.get('with_detail') == '1' else False price_from = kw.get('price_from') |
