This question has been flagged
470 Views

i want to make endpoint to apply a specific discount code on specific sale order 

i do that but the discount didn't work correctly in sale order

		@http.route('/apply_offer', auth='public', website=False, csrf=False, type='http', methods=['POST'])def apply_offer(self, **args):
_response = {"data": None, "success": False, "statusCode": 404, "message": None}
try:
order_number = args.get('order_number', False)
coupon_code = args.get('coupon_code', False)
​if order_number:
​so = request.env['sale.order'].sudo().search([('id', '=', int(order_number))])
​if so and coupon_code:
​status = so._try_apply_code(coupon_code)print(status,status.get('error'))
​if status.get('error'):
​_response = {"data": None, "success": False, "statusCode": 404, "message": status.get('error')}
​else:
  ​_response = {"data": None, "success": True, "statusCode": 200, "message": 'success'}else: _response = {"data": None, "success": False, "statusCode": 404,"message": 'wrong order number or missed coupon coe'}
​else:
  ​_response = {"data": None, "success": False, "statusCode": 401, "message": "no order id"}
except Exception as e:
  _response = {"data": None, "itemsCount": 0, "success": False, "statusCode": 400, "message": str(e)}finally:return json.dumps(_response)
Avatar
Discard

Are you receiving any error after triggering the _try_apply_code function ?

Hi, Which step did not work?

Author

it isn't generating any error but it isn't make the discount in the price