diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-10-12 16:52:46 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-10-12 16:52:46 +0700 |
| commit | c4b6e2d594b8cbd7d424673d04741a1a4cb2ff81 (patch) | |
| tree | da13382d8d442a991a23e058f2021e0a96c73c87 /indoteknik_api/controllers/api_v1/manufacture.py | |
| parent | dae117ce9bb219557c9a4fc995e93bc4a88ea03f (diff) | |
Update Feature:
- filter product_name, manufactures, categories in flash sale
- add categories in product response
- create get manufacture and category by page
Diffstat (limited to 'indoteknik_api/controllers/api_v1/manufacture.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/manufacture.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/manufacture.py b/indoteknik_api/controllers/api_v1/manufacture.py new file mode 100644 index 00000000..3cb6ed0f --- /dev/null +++ b/indoteknik_api/controllers/api_v1/manufacture.py @@ -0,0 +1,37 @@ +from .. import controller +from odoo import http +from odoo.http import request + + +class Manufacture(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'manufacture/page/<page>', auth='public', methods=['GET']) + def get_manufacture(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + + manufacture_ids = [] + page = kw.get('page') + if page == 'flash-sale': + active_flash_sale = request.env['product.pricelist'].get_active_flash_sale() + if active_flash_sale: + manufacture_ids = [x.product_id.x_manufacture.id for x in active_flash_sale.item_ids] + elif page == 'category': + category_id = kw.get('category_id') + if not category_id: + return self.response(code=400, description='category_id is required') + product_variants = request.env['product.product'].search([('public_categ_ids', '=', int(category_id))]) + manufacture_ids = [x.x_manufacture.id for x in product_variants] + else: + return self.response(code=400, description='data not found') + + manufactures = request.env['x_manufactures'].search([('id', 'in', manufacture_ids)]) + data = [] + for manufacture in manufactures: + data.append({ + 'id': manufacture.id, + 'name': manufacture.x_name + }) + return self.response(data) +
\ No newline at end of file |
