Method

order.close

Close an order that has lines.

Closes an order that has at least one line. A closed order is frozen: no line can be added, changed or removed, and it cannot be closed again. This is the only way to set its closing date, which defaults to now.

Examples

Example: with a copy of the synthetic/business-editable example book open as book.gnucash.

JSON-RPC

Request:

{"jsonrpc":"2.0","id":1,"method":"order.create","params":{"owner":"5b22073fa4e34411b07c14a77147ce6b"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "…"
}

Request:

{"jsonrpc":"2.0","id":2,"method":"order.addEntry","params":{"order":"00ed0000000000000000000000000001","description":"Widgets","quantity":"10","price":"2.50","account":"Income"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": "…"
}

Request:

{"jsonrpc":"2.0","id":3,"method":"order.close","params":{"order":"00ed0000000000000000000000000001","date":"2024-07-02T09:00:00Z"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "closed": true,
    "dateClosed": "2024-07-02T09:00:00Z",
    "entryCount": 1,
    "…": "…"
  }
}

Request:

{"jsonrpc":"2.0","id":4,"method":"order.addEntry","params":{"order":"00ed0000000000000000000000000001","description":"More"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 4,
  "error": {
    "code": 2003,
    "message": "order 000001 is closed",
    "data": {
      "help": "error/conflict"
    }
  }
}

Command line

red-ale exec --book book.gnucash --script - <<'EOF'
order.create {"owner":"5b22073fa4e34411b07c14a77147ce6b"}
order.addEntry {"order":"00ed0000000000000000000000000001","description":"Widgets","quantity":"10","price":"2.50","account":"Income"}
order.close {"order":"00ed0000000000000000000000000001","date":"2024-07-02T09:00:00Z"}
order.addEntry {"order":"00ed0000000000000000000000000001","description":"More"}
EOF

It fails with exit status 2, printing on standard error:

{
  "error": {
    "code": 2003,
    "message": "order 000001 is closed",
    "data": {
      "help": "error/conflict"
    }
  }
}

MCP tool call

Tool call:

{"name":"order.create","arguments":{"owner":"5b22073fa4e34411b07c14a77147ce6b"}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "\"…\""
    }
  ]
}

Tool call:

{"name":"order.addEntry","arguments":{"order":"00ed0000000000000000000000000001","description":"Widgets","quantity":"10","price":"2.50","account":"Income"}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "\"…\""
    }
  ]
}

Tool call:

{"name":"order.close","arguments":{"order":"00ed0000000000000000000000000001","date":"2024-07-02T09:00:00Z"}}

Result:

{
  "structuredContent": {
    "closed": true,
    "dateClosed": "2024-07-02T09:00:00Z",
    "entryCount": 1,
    "…": "…"
  }
}

Tool call:

{"name":"order.addEntry","arguments":{"order":"00ed0000000000000000000000000001","description":"More"}}

Result:

{
  "isError": true,
  "structuredContent": {
    "error": {
      "code": 2003,
      "name": "conflict",
      "message": "order 000001 is closed",
      "data": {
        "help": "error/conflict"
      }
    }
  }
}

Effect: write, on the Book.

Params

Params of order.close.

  • order (Guid, required): The open order.
  • date (Timestamp or null): When it closed; defaults to now, as GnuCash's order dialog does.

Result

An order with its lines, in GnuCash's order.

  • guid (Guid, required): A GUID: 32 hexadecimal digits.
  • id (string, required)
  • owner (OwnerInfo, required): An owner: a customer, vendor, employee or job.
  • dateOpened (Timestamp, required): An instant, RFC 3339; written in UTC with a Z suffix.
  • closed (boolean, required)
  • dateClosed (Timestamp or null)
  • notes (string, required)
  • reference (string, required)
  • active (boolean, required)
  • entryCount (integer (uint), required)
  • entries (array of EntryInfo, required): Its lines.