diff options
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category.py | 63 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/partner.py | 5 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 11 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 8 |
4 files changed, 53 insertions, 34 deletions
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py index 09b8ff8c..7d66ad01 100644 --- a/indoteknik_api/controllers/api_v1/category.py +++ b/indoteknik_api/controllers/api_v1/category.py @@ -123,34 +123,47 @@ class Category(controller.Controller): return self.response(response_data) - @http.route(prefix + 'category/tree', auth='public', methods=['GET', 'OPTIONS']) - @controller.Controller.must_authorized() - def get_category_tree(self): - parent_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', False)], ['id', 'name']) - data = [] - for parent_category in parent_categories: - parent_data = { - 'id': parent_category['id'], - 'name': parent_category['name'], - 'childs': [] - } - child_1_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', parent_category['id'])], ['id', 'name']) - for child_1_category in child_1_categories: - child_1_data = { - 'id': child_1_category['id'], - 'name': child_1_category['name'], + class CategoryManagement(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'category/tree', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def get_category_tree(self): + parent_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', False)], + ['id', 'name', 'image_1920']) + data = [] + for parent_category in parent_categories: + category_data_ids = [parent_category['id']] + parent_data = { + 'id': parent_category['id'], + 'name': parent_category['name'], + 'image': request.env['ir.attachment'].sudo().api_image('product.public.category', 'image_1920', + parent_category['id']), + 'category_data_ids': category_data_ids, 'childs': [] } - child_2_categories = request.env['product.public.category'].search_read([('parent_frontend_id', '=', child_1_category['id'])], ['id', 'name']) - for child_2_category in child_2_categories: - child_2_data = { - 'id': child_2_category['id'], - 'name': child_2_category['name'], + child_1_categories = request.env['product.public.category'].search_read( + [('parent_frontend_id', '=', parent_category['id'])], ['id', 'name']) + for child_1_category in child_1_categories: + child_1_data = { + 'id': child_1_category['id'], + 'name': child_1_category['name'], + 'childs': [] } - child_1_data['childs'].append(child_2_data) - parent_data['childs'].append(child_1_data) - data.append(parent_data) - return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) + category_data_ids.append(child_1_category['id']) + child_2_categories = request.env['product.public.category'].search_read( + [('parent_frontend_id', '=', child_1_category['id'])], ['id', 'name']) + for child_2_category in child_2_categories: + child_2_data = { + 'id': child_2_category['id'], + 'name': child_2_category['name'], + } + child_1_data['childs'].append(child_2_data) + category_data_ids.append(child_2_category['id']) + parent_data['childs'].append(child_1_data) + parent_data['category_data_ids'] = category_data_ids + data.append(parent_data) + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) @http.route(prefix + 'categories_homepage/ids', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py index a6e14a19..69a2f861 100644 --- a/indoteknik_api/controllers/api_v1/partner.py +++ b/indoteknik_api/controllers/api_v1/partner.py @@ -142,9 +142,12 @@ class Partner(controller.Controller): partner_industry = request.env['res.partner.industry'].search([]) data = [] for industry in partner_industry: + full_name = industry.full_name + category = full_name.title() if full_name else '-' data.append({ 'id': industry.id, - 'name': industry.name + 'name': industry.name, + 'category': category }) return self.response(data) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 0da7f894..b351bacc 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -403,20 +403,21 @@ class SaleOrder(controller.Controller): 'shipping_paid_by': 'customer', 'carrier_id': params['value']['carrier_id'], 'delivery_service_type': params['value']['delivery_service_type'], - 'flash_sale': params['value']['flash_sale'], + 'flash_sale': params['value']['flash_sale'], 'note_website': params['value']['note_website'], 'customer_type': 'nonpkp', 'npwp': '0', 'user_id': 3222 # User ID: Nadia Rauhadatul Firdaus } + + sales_partner = request.env['res.partner'].browse(parameters['partner_id']) + if sales_partner and sales_partner.user_id and sales_partner.user_id.id not in [25]: # 25: System + parameters['user_id'] = sales_partner.user_id.id + if params['value']['type'] == 'sale_order': parameters['approval_status'] = 'pengajuan1' sale_order = request.env['sale.order'].create([parameters]) sale_order.onchange_partner_contact() - - sales_partner = sale_order.partner_id.user_id - if sales_partner and sales_partner not in [25]: # 25: System - parameters['user_id'] = sales_partner.id user_id = params['value']['user_id'] user_cart = request.env['website.user.cart'] diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 9b89e82c..b9fd9f56 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -1,3 +1,5 @@ +import base64 + from .. import controller from odoo import http from odoo.http import request @@ -104,10 +106,10 @@ class User(controller.Controller): password = kw.get('password') if not name or not email or not password: return self.response(code=400, description='email, name and password is required') - + company = kw.get('company', False) phone = kw.get('phone') - + response = { 'register': False, 'reason': None @@ -120,7 +122,7 @@ class User(controller.Controller): else: user.send_activation_mail() response['reason'] = 'NOT_ACTIVE' - + return self.response(response) user_data = { |
