diff options
Diffstat (limited to 'fixco_api')
| -rw-r--r-- | fixco_api/controllers/api_v1/sale.py | 49 | ||||
| -rw-r--r-- | fixco_api/controllers/controller.py | 4 |
2 files changed, 40 insertions, 13 deletions
diff --git a/fixco_api/controllers/api_v1/sale.py b/fixco_api/controllers/api_v1/sale.py index abc853d..9b855dd 100644 --- a/fixco_api/controllers/api_v1/sale.py +++ b/fixco_api/controllers/api_v1/sale.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +import json class Sales(controller.Controller): @@ -34,26 +35,50 @@ class Sales(controller.Controller): }) return self.response(data) - @http.route(prefix + 'sale/create', auth='public', methods=['POST', 'OPTIONS'], csrf=False) + @http.route(prefix + 'sale/create', type='json', auth='public', methods=['POST', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() def create_sale_order(self, **kw): - partner_id = int(kw.get('partner_id'), 0) - ref = kw.get('ref') + data = request.jsonrequest + ginee_shop_id = data['ginee_shop_id'] + ref = data['ref'] + lines = data['lines'] + if ginee_shop_id == '0': + return {'status': 'error', 'message': 'partner not found'} + + partner = request.env['res.partner'].search([('ginee_shop_id', '=', ginee_shop_id)]) + if not partner: + return {'status': 'error', 'message': 'partner not found'} + + partner_id = partner.id params = { 'partner_id': partner_id, 'partner_shipping_id': partner_id, 'partner_invoice_id': partner_id, 'client_order_ref': ref, - 'company_id': 4, - 'currency_id': 12, - 'user_id': 8, - 'team_id': 6, - 'warehouse_id': 4, + 'company_id': 4, # Fixco Karya Nusantara + 'currency_id': 12, # IDR + 'user_id': 8, # Web Service it@fixcomart.co.id + 'team_id': 6, # Marketplace + 'warehouse_id': 4, # Bandengan Tengah 'state': 'draft', 'picking_policy': 'direct' } sale_order = request.env['sale.order'].create(params) - return self.response({ - 'id': sale_order.id, - 'name': sale_order.name - }) + param_line = [] + for line in lines: + item_code = line['item_code'] + product = request.env['product.product'].search([('default_code', '=', item_code)]) + if not product: + return {'status': 'error', 'message': 'product not found'} + param_line.append({ + 'order_id': sale_order.id, + 'product_id': product.id, + 'name': product.display_name, + 'product_uom_qty': line['qty'], + 'price_unit': line['price'], + 'tax_id': [13] #tax include + }) + request.env['sale.order.line'].create(param_line) + return { + 'status': 'success', 'message': sale_order.name + } diff --git a/fixco_api/controllers/controller.py b/fixco_api/controllers/controller.py index 0fef51b..4d0ba31 100644 --- a/fixco_api/controllers/controller.py +++ b/fixco_api/controllers/controller.py @@ -55,7 +55,7 @@ class Controller(http.Controller): authorization = wsgienv['HTTP_AUTHORIZATION'] except: authorization = None - request.session.authenticate(config.get('db_name'), 'stephan@indoteknik.co.id', 'P@ssvv0rd755') + request.session.authenticate(config.get('db_name'), 'it@fixcomart.co.id', 'P@ssvv0rd755') token = request.env['ir.config_parameter'].sudo().get_param('rest_api_token') or '' result = False if authorization == token: @@ -139,6 +139,8 @@ class Controller(http.Controller): ] + headers) def unauthorized_response(self): + test = "masuk kesini unauthorized response" + print(test) return self.response(code=401, description='Unauthorized') def search_filter(self, model: str, kw: dict, query: array = []): |
