Skip to main content

Overview

The Orden Compra mutations provide functionality to create purchase orders from procurement requisitions and manage order status. These operations integrate with SAP procurement systems for order processing.

Available Mutations

CreateOcProcurment

Create a purchase order in the procurement system from an existing requisition (SOLPED).

Mutation Definition

mutation CreateOcProcurment(
  $solped: String!
  $proveedor: String!
  $incoterm: String!
  $organizacion: String!
  $clasedocumento: String!
  $items: [ApiOcRequestDetailDto!]!
) {
  createOcProcurment(
    solped: $solped
    proveedor: $proveedor
    incoterm: $incoterm
    organizacion: $organizacion
    clasedocumento: $clasedocumento
    items: $items
  ) {
    success
    hasErrorService
    hasWarnings
    responseUnparsed
    response {
      documento
      return {
        type
        id
        number
        message
        message_v1
        message_v2
        message_v3
        message_v4
        parameter
        system
      }
    }
  }
}

Input Parameters

solped
String
required
The SOLPED (requisition) number from which to create the purchase order.
proveedor
String
required
The supplier/vendor code who will fulfill the order.
incoterm
String
required
The INCOTERM (International Commercial Terms) that defines shipping and delivery responsibilities.Common values: FOB, CIF, EXW, DDP, etc.
organizacion
String
required
The purchasing organization code in the SAP system.
clasedocumento
String
required
The document class or type identifier for the purchase order.
items
[ApiOcRequestDetailDto!]!
required
An array of line items to include in the purchase order.

Response Fields

success
Boolean
Indicates whether the purchase order was successfully created. true if successful, false otherwise.
hasErrorService
Boolean
Indicates if there was an error communicating with the external procurement service.
hasWarnings
Boolean
Indicates if the operation completed but with warnings that should be reviewed.
responseUnparsed
String
The raw, unparsed response from the SAP procurement system for debugging purposes.
response
ApiOcResponse
The parsed response from the procurement system.

Example Request

mutation {
  createOcProcurment(
    solped: "4500123456"
    proveedor: "PROV-001"
    incoterm: "FOB"
    organizacion: "ORG-100"
    clasedocumento: "NB"
    items: [
      {
        posicion: "1"
        codiva: "V1"
        idRequerimiento: 5001
      },
      {
        posicion: "2"
        codiva: "V1"
        idRequerimiento: 5002
      }
    ]
  ) {
    success
    hasErrorService
    response {
      documento
      return {
        type
        message
      }
    }
  }
}

Example Response (Success)

{
  "data": {
    "createOcProcurment": {
      "success": true,
      "hasErrorService": false,
      "response": {
        "documento": "4500789012",
        "return": [
          {
            "type": "S",
            "message": "Purchase order 4500789012 created successfully"
          }
        ]
      }
    }
  }
}

Example Response (Error)

{
  "data": {
    "createOcProcurment": {
      "success": false,
      "hasErrorService": false,
      "response": {
        "documento": "",
        "return": [
          {
            "type": "E",
            "message": "Supplier PROV-001 is blocked for purchasing organization ORG-100",
            "parameter": "PROVEEDOR"
          }
        ]
      }
    }
  }
}

DesbloquearPedido

Unblock a purchase order that has been blocked in the system.

Mutation Definition

mutation DesbloquearPedido($input: DesbloquearPedidoInput!) {
  desbloquearPedido(input: $input) {
    return {
      type
      id
      number
      message
      message_v1
      message_v2
      message_v3
      message_v4
      parameter
      system
    }
  }
}

Input Parameters

input
DesbloquearPedidoInput
required
The input object containing the order information to unblock.

Response Fields

return
[PedidoMensaje]
An array of messages returned from the unblock operation.

Example Request

mutation {
  desbloquearPedido(input: { pedido: "4500789012" }) {
    return {
      type
      message
      parameter
    }
  }
}

Example Response (Success)

{
  "data": {
    "desbloquearPedido": {
      "return": [
        {
          "type": "S",
          "message": "Order 4500789012 has been successfully unblocked",
          "parameter": null
        }
      ]
    }
  }
}

Example Response (Error)

{
  "data": {
    "desbloquearPedido": {
      "return": [
        {
          "type": "E",
          "message": "Order 4500789012 not found or already unblocked",
          "parameter": "PEDIDO"
        }
      ]
    }
  }
}

Implementation Details

Authentication

Both mutations require proper authentication:
  • OAuth 2.0 Bearer token authentication
  • Tokens are obtained from the configured authentication service
  • Credentials are managed through appsettings.json configuration

Source Code References

CreateOcProcurment

Mutation.cs:906-932Handles position normalization (multiplying by 10) and calls the SAP procurement API.

DesbloquearPedido

Schema/OrdenCompra/PedidoMutation.cs:16-30Sends unblock requests to external service endpoint.

External Service Integration

CreateOcProcurment

  • Service: ApiOc (Helpers/Oc/ApiOc.cs:62)
  • Endpoint: Configured in ApiProcurmentReg:UrlOc
  • Method: POST
  • Authentication: OAuth 2.0 Client Credentials flow

DesbloquearPedido

  • Service: PedidoTrasladoService (Services/OrdenCompra/PedidoTrasladoService.cs:21)
  • Endpoint: Configured in urlDesbloqueoPedido:Url
  • Method: POST
  • Authentication: Bearer token via AuthService

Error Handling

Always check the hasErrorService and success flags in the response to determine if the operation completed successfully. The return array may contain multiple messages with different severity levels.

Common Error Types

  • E (Error): Critical errors that prevented order creation
  • W (Warning): The operation completed but with warnings
  • I (Information): Informational messages about the process
  • S (Success): Successful operation confirmation

Best Practices

  1. Validate Input: Ensure all supplier codes, organization codes, and document classes exist in SAP before calling the mutation
  2. Position Numbers: The system automatically multiplies position numbers by 10, so use sequential integers (1, 2, 3…)
  3. Error Messages: Parse the return array to display all relevant messages to users
  4. Idempotency: Check if an order already exists for the SOLPED before creating a new one
  5. Logging: Store the responseUnparsed field for debugging and audit purposes

Use Cases

Procurement Automation

Automate purchase order creation from approved requisitions:
# After requisition approval
mutation AutoCreatePO($solpedId: String!) {
  createOcProcurment(
    solped: $solpedId
    proveedor: "VENDOR-123"
    incoterm: "CIF"
    organizacion: "PURCHASING-ORG"
    clasedocumento: "NB"
    items: [
      # Items from requisition
    ]
  ) {
    success
    response {
      documento
    }
  }
}

Order Status Management

Unblock orders that were temporarily held:
mutation UnblockOrder($orderNumber: String!) {
  desbloquearPedido(input: { pedido: $orderNumber }) {
    return {
      type
      message
    }
  }
}