copilot_frontend
copilot_order

Save Budget

Saves a complete order (pedido) to database and creates/updates contact in HubSpot.

This endpoint:

  1. Gets province name from database
  2. Updates commercial phone if provided and different from current
  3. Gets "pedido" status from database to use as estado_id
  4. Creates/updates contact in HubSpot with client data
  5. Updates contact with all order properties (payment, installation, subsidies, etc.)
  6. Updates deal property "pedido_de_venta_backend" = "Si"
  7. Saves order in presup_presupuestos table with estado="pedido" and all order data

🔒 Protected Endpoint: Requires JWT authentication and 'ui_comercial' or 'admin' role

Args: request: SaveOrderRequest with client data, calculation data (already calculated from Vue), selected option, and complete order data (payment, installation, subsidies, etc.) current_user: Current authenticated user

Returns: SaveBudgetResponse with success status, order ID, and HubSpot contact ID

Raises: ErrValidation: If user does not have comercial_id ErrNotFound: If province or "pedido" status not found Exception: If HubSpot or database save fails

post/api/order/save

Request body

selected_optioninteger nullable

ID/name of the selected budget option

budget_idinteger required

ID del presupuesto existente a convertir en pedido

comercial_idinteger nullable

Override comercial ID. Admin use only: assigns order to the specified comercial instead of the current user

guardar_borradorboolean

Si True, guarda como borrador (sin HubSpot y sin cambiar estado a pedido)

Response

Successful Response

successboolean required

Whether the save was successful

messagestring required

Success/error message

budget_idinteger nullable

ID of the created budget in database

hubspot_contact_idstring nullable

HubSpot contact ID (created or updated)

hubspot_warningstring nullable

Warning message if HubSpot operation partially failed (e.g., invalid property)

Changes