diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-10-05 15:19:27 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-10-05 15:19:27 +0700 |
| commit | 14cb30c3f2fb8b15baaf32ab9fca7bb9bda73845 (patch) | |
| tree | e4039e13e934db6ee148f766882bb82af8db1d7a /indoteknik_custom/controllers/api/product.py | |
| parent | d1bc570eae2818bc4b535840f2eb3061b99ca98b (diff) | |
Update struktur API and fitur API flash sale
Diffstat (limited to 'indoteknik_custom/controllers/api/product.py')
| -rw-r--r-- | indoteknik_custom/controllers/api/product.py | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/indoteknik_custom/controllers/api/product.py b/indoteknik_custom/controllers/api/product.py deleted file mode 100644 index 3b1c4ce8..00000000 --- a/indoteknik_custom/controllers/api/product.py +++ /dev/null @@ -1,95 +0,0 @@ -import base64 - -from .. import api_controller -from odoo import http -from odoo.http import request - - -class ProductApi(api_controller.ApiController): - @http.route('/api/product/search', auth='public', methods=['GET']) - def search_product(self, **kw): - self.authenticate(kw) - query = kw.get('query') - if not query: - return self.response(code=400, description='Field query is required') - - query = '%' + query.replace(' ', '%') + '%' - domain = [ - ('sale_ok', '=', True), - '|', - ('default_code', 'ilike', query), - ('name', 'ilike', query) - ] - - manufactures = kw.get('manufactures') - if manufactures: - manufactures = [int(x) for x in manufactures.split(',')] - domain.append(('x_manufacture', 'in', manufactures)) - - categories = kw.get('categories') - if categories: - categories = [int(x) for x in categories.split(',')] - domain.append(('public_categ_ids', 'child_of', categories)) - - product_variants = request.env['product.product'].search(domain) - product_variant_ids = [v['id'] for v in product_variants] - - base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') - domain = [ - ('product_variant_ids', 'in', product_variant_ids) - ] - product_templates = self.search_with_api_params('product.template', kw, domain) - data = { - 'total_records': len(request.env['product.template'].search(domain)), - 'products': [] - } - for product_template in product_templates: - stock = 0 - for product_variant in product_template.product_variant_ids: - stock += product_variant.qty_stock_vendor - - discount_price = 0 - price = product_template.web_price - if price > 0: - if product_template.taxes_id: - if not product_template.taxes_id.price_include: - price += (price * product_template.taxes_id.amount / 100) - else: - price += (price * 11 / 100) - - promotion = {} - manufacture = {} - if product_template.x_manufacture: - manufacture.update({ - 'id': product_template.x_manufacture.id, - 'name': product_template.x_manufacture.x_name, - }) - domain = [ - ('rule_products_domain', 'ilike', product_template.x_manufacture.x_name), - ('active', '=', True) - ] - coupon_program = request.env['coupon.program'].search(domain, limit=1) - if coupon_program: - discount_price = price - (price * coupon_program.discount_percentage / 100) - icon_1 = (base_url + 'api/image/coupon.program/x_studio_field_Ifopn/' + str(coupon_program.id)) if coupon_program.x_studio_field_Ifopn else '' - icon_2 = (base_url + 'api/image/coupon.program/x_studio_field_2Ul77/' + str(coupon_program.id)) if coupon_program.x_studio_field_2Ul77 else '' - promotion.update({ - 'name': coupon_program.name, - 'discount_percentage': coupon_program.discount_percentage, - 'icon_1': icon_1, - 'icon_2': icon_2 - }) - - data['products'].append({ - 'id': product_template.id, - 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '', - 'name': product_template.name, - 'price': price, - 'discount_price': discount_price, - 'total_variant': len(product_template.product_variant_ids), - 'stock': stock, - 'manufacture': manufacture, - 'promotion': promotion, - }) - - return self.response(data) |
