Method

account.renumber

Renumber the codes of an account's immediate sub-accounts.

GnuCash's "Renumber sub-accounts": gives an account's immediate sub-accounts codes in display order, prefix-NNN for interval, twice interval, and so on. The prefix defaults to the account's own code, the interval to 10 and the digits to 3. Grandchildren are not touched, and nothing checks that the codes are unique. An account with no sub-accounts is refused with invalid.

Examples

Example: with a copy of the reports/test-data example book open as book.gnucash.

JSON-RPC

Request:

{"jsonrpc":"2.0","id":1,"method":"account.renumber","params":{"account":"Root:Asset","prefix":"1","interval":100}}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "account": "…",
      "fullName": "Root:Asset:Bank",
      "code": "1-100"
    },
    {
      "account": "…",
      "fullName": "Root:Asset:GBP Bank",
      "code": "1-200"
    },
    {
      "account": "…",
      "fullName": "Root:Asset:Wallet",
      "code": "1-300"
    }
  ]
}

Command line

red-ale exec --book book.gnucash account.renumber '{"account":"Root:Asset","prefix":"1","interval":100}'

It prints:

[
  {
    "account": "…",
    "fullName": "Root:Asset:Bank",
    "code": "1-100"
  },
  {
    "account": "…",
    "fullName": "Root:Asset:GBP Bank",
    "code": "1-200"
  },
  {
    "account": "…",
    "fullName": "Root:Asset:Wallet",
    "code": "1-300"
  }
]

MCP tool call

Tool call:

{"name":"account.renumber","arguments":{"account":"Root:Asset","prefix":"1","interval":100}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "[{\"account\":\"…\",\"fullName\":\"Root:Asset:Bank\",\"code\":\"1-100\"},{\"account\":\"…\",\"fullName\":\"Root:Asset:GBP Bank\",\"code\":\"1-200\"},{\"account\":\"…\",\"fullName\":\"Root:Asset:Wallet\",\"code\":\"1-300\"}]"
    }
  ]
}

Effect: write, on the Book.

Params

Params of account.renumber.

  • account (AccountRef, required): The account whose immediate sub-accounts are renumbered.
  • prefix (string or null): Prefix, joined to the number by -; by default the account's own code. Empty means none.
  • interval (integer (int64) or null): Step between codes, 1 to 10000; default 10.
  • digits (integer (int64) or null): Minimum digits, 1 to 100; default 3. Never fewer than the largest number needs.

Result

Type: array of NewCode.