eCMR con Odoo: Documentos sincronizados
Cuando un eCMR se completa, puedes descargar su PDF y adjuntarlo a la factura en Odoo.
Webhook en eCMR
bash
curl -X POST "https://ecmr.api.pro.cargoffer.com/notifications" \
-H "Authorization: Bearer *** \
-H "Content-Type: application/json" \
-d '{
"url": "https://tu-odoo.com/webhook/ecmr",
"events": ["ecmr_delivered"]
}'Descargar PDF del eCMR
bash
curl -X GET "https://ecmr.api.pro.cargoffer.com/ecmr/file/{service_code}" \
-H "Authorization: Bearer *** \
-o "ecmr_{service_code}.pdf"Verificar estado del PDF:
bash
curl -X GET "https://ecmr.api.pro.cargoffer.com/ecmr/pdf-status/{service_code}" \
-H "Authorization: Bearer *** Python con Odoo
```python
import requests, base64, xmlrpc.client
ECMR_TOKEN=*** = descargar_pdf_ecmr(service_code):
r = requests.get(
f"https://ecmr.api.pro.cargoffer.com/ecmr/file/{service_code}",
headers={"Authorization": f"Bearer {ECMR_TOKEN}"}
)
return r.content
def adjuntar_a_factura_odoo(pdf_content, factura_id):
models.execute_kw("db", 1, "pass",
"ir.attachment", "create", [{
"name": f"ecmr.pdf",
"res_model": "account.move",
"res_id": factura_id,
"datas": base64.b64encode(pdf_content).decode(),
"type": "binary"
}])