lot.scrubAccount
Assign an account's splits to lots by FIFO and repair every lot, optionally for its sub-accounts too.
Assigns an account's splits to lots by FIFO and repairs every lot, as GnuCash's Scrub Account does for lots; with
subaccounts: true it does the whole subtree. Only accounts with trades are scrubbed (stock and mutual fund
accounts, and any account with a split in another commodity than its own). Use it once on an account that has never
had lots; run again, it changes nothing.
Examples
Example: with a copy of the reports/investment-lots example book open as book.gnucash.
JSON-RPC
Request:
{"jsonrpc":"2.0","id":1,"method":"lot.scrubAccount","params":{"account":"Root:Assets:Broker:AAPL"}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"lotsCreated": [
"…",
"…"
],
"lotsDeleted": [],
"transactionsChanged": [
"…",
"…",
"…"
],
"…": "…"
}
}
Request:
{"jsonrpc":"2.0","id":2,"method":"lot.list","params":{"account":"Root:Assets:Broker:AAPL"}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": [
{
"title": "Lot 0",
"balance": {
"num": "40",
"denom": "1"
},
"splitCount": 2,
"…": "…"
},
{
"title": "Lot 1",
"balance": {
"num": "50",
"denom": "1"
},
"splitCount": 1,
"…": "…"
}
]
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
lot.scrubAccount {"account":"Root:Assets:Broker:AAPL"}
lot.list {"account":"Root:Assets:Broker:AAPL"}
EOF
It prints:
[
{
"lotsCreated": [
"…",
"…"
],
"lotsDeleted": [],
"transactionsChanged": [
"…",
"…",
"…"
],
"…": "…"
},
[
{
"title": "Lot 0",
"balance": {
"num": "40",
"denom": "1"
},
"splitCount": 2,
"…": "…"
},
{
"title": "Lot 1",
"balance": {
"num": "50",
"denom": "1"
},
"splitCount": 1,
"…": "…"
}
]
]
MCP tool call
Tool call:
{"name":"lot.scrubAccount","arguments":{"account":"Root:Assets:Broker:AAPL"}}
Result:
{
"structuredContent": {
"lotsCreated": [
"…",
"…"
],
"lotsDeleted": [],
"transactionsChanged": [
"…",
"…",
"…"
],
"…": "…"
}
}
Tool call:
{"name":"lot.list","arguments":{"account":"Root:Assets:Broker:AAPL"}}
Result:
{
"content": [
{
"type": "text",
"text": "[{\"title\":\"Lot 0\",\"balance\":{\"num\":\"40\",\"denom\":\"1\"},\"splitCount\":2,\"…\":\"…\"},{\"title\":\"Lot 1\",\"balance\":{\"num\":\"50\",\"denom\":\"1\"},\"splitCount\":1,\"…\":\"…\"}]"
}
]
}
Effect: write, on the Book.
Params
Params of lot.scrubAccount.
account(AccountRef, required): The account.subaccounts(boolean): Scrub every sub-account first, as GnuCash's tree scrub does.
Result
What a scrub or gains computation changed.
lotsCreated(array of Guid, required): Lots made.lotsDeleted(array of Guid, required): Lots deleted.transactionsCreated(array of Guid, required): Transactions made: gains transactions.transactionsChanged(array of Guid, required): Transactions changed: cut or merged splits, updated gains.transactionsDeleted(array of Guid, required): Transactions deleted: gains transactions of merged splits.accountsCreated(array of Guid, required): Accounts made:Orphaned Gains-<CUR>.