Hướng dẫn tích hợp Odoo
Kỹ thuật
Odoo gửi phiếu ở trạng thái Done qua HTTPS. Các yêu cầu có body dùng Content-Type: application/json và UTF-8. Tài khoản tích hợp được gán companyCode mặc định là CT01VILP (trường companyCode trong JSON nên gửi "CT01VILP"; nếu bỏ trống hệ thống tự lấy theo tài khoản đăng nhập).
Đăng nhập và quản lý phiên
| Phương thức và đường dẫn | Dữ liệu gửi | Kết quả |
|---|---|---|
POST /api/auth/login | {"username":"TÀI_KHOẢN_ERP","password":"MẬT_KHẨU"} | data.accessToken và data.refreshToken cùng thời hạn. |
POST /api/auth/refresh | {"refreshToken":"REFRESH_TOKEN"} | Cặp token mới. Dùng cặp mới cho các yêu cầu tiếp theo. |
DELETE /api/auth/session | Header Authorization: Bearer ACCESS_TOKEN | Thu hồi phiên. |
Access token có hiệu lực tối đa 15 phút. Phiên hết hạn sau 24 giờ kể từ đăng nhập. Mỗi lần refresh thay cả hai token.
Nhóm API và 8 loại chứng từ ERP
| Nhóm API | Giá trị documentType | Nghiệp vụ ERP |
|---|---|---|
/api/receipts | PURCHASE_DOMESTIC, PURCHASE_IMPORT, SALES_RETURN, STOCK_RECEIPT | Mua hàng nội địa, Mua hàng nhập khẩu, Hàng bán trả lại, Nhập kho |
/api/shipments | SUPPLIER_RETURN, SALES_INVOICE, STOCK_ISSUE | Hàng trả lại NCC, Hóa đơn bán hàng, Xuất kho |
/api/transfers | STOCK_TRANSFER | Chuyển kho |
Dùng POST để tạo, GET /{requestId} để tra cứu đầy đủ đầu phiếu và dòng, PUT /{requestId} để cập nhật khi phiếu còn PENDING kèm revision mới nhất. API kiểm tra ngay các trường bắt buộc và độ dài cột ERP khi POST/PUT.
Trường bắt buộc theo từng loại phiếu
| Loại phiếu | Đầu phiếu bắt buộc | Từng dòng trong lines[] bắt buộc |
|---|---|---|
| Mọi loại phiếu | sourceId, documentType, documentDate (YYYY-MM-DD), referenceNo (tùy chọn companyCode mặc định CT01VILP) | sourceLineId, itemCode, quantity (> 0, tối đa 4 số lẻ) |
STOCK_TRANSFER | fromWarehouseCode, toWarehouseCode (khác kho nguồn), movementCode (max 10) | inventoryAccount, toInventoryAccount (thêm lot/property/property2 nếu mã hàng quản lý) |
STOCK_RECEIPT, STOCK_ISSUE | movementCode (max 20) | warehouseCode, inventoryAccount, offsetAccount (có thể gửi unitPrice) |
PURCHASE_DOMESTIC, PURCHASE_IMPORT | partnerCode, currencyCode (3 ký tự), exchangeRate, controlAccount (TK phải trả), vatAccount (+ importDutyAccount/additionalImportDutyAccount nếu có thuế NK) | warehouseCode, inventoryAccount, purchaseCostAccount, vatCode, unitPrice, sourceAmount, amount, vatAmount, totalAmount |
SUPPLIER_RETURN | partnerCode, currencyCode, exchangeRate, controlAccount, vatAccount (+ originalErpDocumentId nếu trả theo phiếu mua) | warehouseCode, inventoryAccount, vatCode, unitPrice, sourceAmount, amount, vatAmount, totalAmount (+ originalErpLineId nếu đối chiếu dòng) |
SALES_INVOICE | partnerCode, currencyCode, exchangeRate, controlAccount (TK phải thu), vatAccount | warehouseCode, inventoryAccount, incomeAccount, costOfSalesAccount, vatCode, unitPrice, sourceAmount, amount, vatAmount, totalAmount |
SALES_RETURN | partnerCode, currencyCode, exchangeRate, controlAccount, vatAccount (+ originalErpDocumentId nếu trả theo hóa đơn) | warehouseCode, inventoryAccount, returnAccount, costOfSalesAccount, vatCode, unitPrice, sourceAmount, amount, vatAmount, totalAmount |
Trường ERP bổ sung được hỗ trợ đầy đủ
| Phạm vi | Tên trường JSON |
|---|---|
| Đầu phiếu chung | memo, notes, branchCode, toBranchCode, employeeCode, movementCode, deliver (người giao), receiver (người nhận), orderNumber (PO), contractCode, originalErpDocumentId, paymentTypeCode, paymentTermCode, dueDate, attach, attachDate, costCenterCode, costCode, locationCode, productOrderCode |
| Nhập khẩu / Kho / Bán hàng | incotermCode, customsDeclarationNo, customsDeclarationDate, importDutyAccount3, importDutyAccount4, expenseAccount, isExport, exportVatAccount, calPrice, calCost, isPacket, voucherNo, voucherDate, inspectionNo, inspectionDate, invoiceContent, invoiceBuyer, retailCustomerName, retailCustomerTaxCode |
| Tổng tiền & Hóa đơn thuế | amountTotal, vatAmountTotal, importAmountTotal, discountTotal, otherFeeTotal, baseTotal, invoiceNumber (tối đa 20 ký tự cho bán hàng khi có taxInvoice), taxInvoice: {"serial","date","legalName","address","taxCode","itemCaption","formCode","link"} |
Dòng chi tiết (lines[]) | unit, unit2, unitFactor, quantity2, lot, expireDate, property, property2, unitPriceVnd, unitCost, amountCost, discountPercent, discountAmount, cashDiscountPercent, cashDiscountAmount, discountAmount2, discountAccount, vatPercent, importDutyRate, importDuty, additionalImportDutyRate, additionalImportDuty, exportDutyRate, exportDuty, purchaseCost, otherFee, otherFeeAccount, fobPrice, fobAmount, preCustomsFeeFC, preCustomsFeeLC, customsValue, importVatBase, importVatRate, importVatAmount, costCenterCode, costCode, originalErpLineId, poSoi, poVai, orderNumber, productOrderCode, productCode, description, equipId, packetGroup, partSerialNo, assetId, notes |
{
"companyCode": "CT01VILP",
"sourceId": "SO/2026/0001",
"documentType": "SALES_INVOICE",
"documentDate": "2026-11-25",
"referenceNo": "SO/2026/0001",
"partnerCode": "KH001",
"employeeCode": "NV01",
"currencyCode": "VND",
"exchangeRate": 1,
"controlAccount": "131",
"vatAccount": "33311",
"orderNumber": "PO-KH-01",
"memo": "Bán vải thành phẩm",
"invoiceNumber": "00000123",
"taxInvoice": {
"serial": "1C26TYY",
"date": "2026-11-25",
"legalName": "Công ty ABC",
"address": "TP.HCM",
"taxCode": "0300000000"
},
"lines": [
{
"sourceLineId": "L1",
"itemCode": "VAI-01",
"warehouseCode": "KHO-TP",
"quantity": 100,
"unitPrice": 50000,
"sourceAmount": 5000000,
"amount": 5000000,
"vatCode": "V10",
"vatAmount": 500000,
"totalAmount": 5500000,
"inventoryAccount": "155",
"incomeAccount": "5111",
"costOfSalesAccount": "632",
"poSoi": "SOI-2601",
"poVai": "VAI-2601",
"productOrderCode": "LSX-001"
}
]
}
| HTTP | Mã và cách xử lý |
|---|---|
| 400 | INVALID_DOCUMENT, INVALID_LINES, INVALID_JSON. Thiếu trường bắt buộc ERP, sai độ dài hoặc sai nhóm API. |
| 401 | AUTH_REQUIRED. Cấp lại access token hoặc đăng nhập lại. |
| 403 / 404 | FORBIDDEN, REQUEST_NOT_FOUND. Kiểm tra quyền và mã phiếu. |
| 409 | SOURCE_CONFLICT, REVISION_CONFLICT, REQUEST_LOCKED, ERP_PERIOD_CLOSED, ERP_INSUFFICIENT_STOCK. |
| 413 / 429 | BODY_TOO_LARGE (512 KiB), LOGIN_RATE_LIMIT. |
| 422 | ERP_INVALID_DOCUMENT, ERP_INVALID_TRANSFER. Lệch danh mục, tài khoản, lô/thuộc tính hoặc tiền-thuế trên ERP. |
Kế toán
- Đăng nhập bằng tài khoản ERP có quyền duyệt và chọn nhóm nhập hàng, xuất hàng hoặc chuyển kho.
- Mở một phiếu đang Chờ duyệt. Đối chiếu đầy đủ thông tin master trên panel Thông tin duyệt và chi tiết hàng hóa bên dưới.
- Bấm Duyệt để ghi chứng từ vào các bảng ERP và khóa phiếu ở trạng thái Đã duyệt.
- Khi không duyệt, nhập lý do (nếu có) và bấm Không duyệt; phiếu chuyển sang Không duyệt và khóa lại.