我們將添加一個 DELETE
路由,用於刪除維修訂單。
from odoo import http
from odoo.http import request
import json
class RepairOrderController(http.Controller):
# DELETE 請求:刪除維修訂單
@http.route('/repair/orders/<int:order_id>', type='json', auth='public', methods=['DELETE'], csrf=False)
def delete_repair_order(self, order_id):
try:
# 查找訂單
repair_order = request.env['repair.order'].sudo().browse(order_id)
if not repair_order.exists():
return http.Response(
json.dumps({'status': 'error', 'message': 'Order not found'}),
content_type='application/json'
)
# 刪除維修訂單
repair_order.sudo().unlink()
return http.Response(
json.dumps({
'status': 'success',
'message': 'Repair order deleted successfully',
'order_id': order_id
}),
content_type='application/json'
)
except Exception as e:
return http.Response(
json.dumps({'status': 'error', 'message': str(e)}),
content_type='application/json'
)
DELETE
http://localhost:8069/repair/orders/<order_id>
(例如 http://localhost:8069/repair/orders/1
)Content-Type: application/json
DELETE
請求來刪除維修訂單。URL
設置為 http://localhost:8069/repair/orders/<order_id>
,並將 order_id
替換為具體的維修訂單 ID。DELETE
請求應返回:{
"status": "success",
"message": "Repair order deleted successfully",
"order_id": 1
}