diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-10-13 09:50:34 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-10-13 09:50:34 +0000 |
| commit | 6668257b1c892fdcf366a446587c0aaf31f42651 (patch) | |
| tree | 49557e0332571ecc7db0d42af215476eee880cf2 /indoteknik_api/controllers/api_v1/manufacture.py | |
| parent | 6029c9e3a0b42a6faef373e6dd2f5bf57cef17a0 (diff) | |
| parent | 867e718b83282fdc7f4a7e77eb386b9b6014d8af (diff) | |
Merged in feature/rest-api (pull request #9)
Feature/rest api
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..ba2e3be9 --- /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='page possible value is flash-sale, category') + + 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 |
