Method

invoice.duplicate

Copy a document and its lines into a new unposted document with a new number and date, as GnuCash's Duplicate does.

Copies a document, posted or not, and all its lines into a new unposted document, as GnuCash's Duplicate does. The copy is active, takes the next number from its kind's counter (or id), and has date (default today) as its opened date and the date of every line.

Not copied: the posting itself, and each line's payment method, which goes back to cash, so a duplicated expense voucher loses its card lines. GnuCash does the same. To duplicate several documents with one date, call it once for each.

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":"invoice.duplicate","params":{"invoice":"aa210b7131de44c48b8513cd27c00e95","date":"2024-05-01"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "guid": "…",
    "id": "000003",
    "posted": false,
    "billingId": "CUST-REF-9",
    "entryCount": 2,
    "entries": [
      "…"
    ],
    "…": "…"
  }
}

Command line

red-ale exec --book book.gnucash invoice.duplicate '{"invoice":"aa210b7131de44c48b8513cd27c00e95","date":"2024-05-01"}'

It prints:

{
  "guid": "…",
  "id": "000003",
  "posted": false,
  "billingId": "CUST-REF-9",
  "entryCount": 2,
  "entries": [
    "…"
  ],
  "…": "…"
}

MCP tool call

Tool call:

{"name":"invoice.duplicate","arguments":{"invoice":"aa210b7131de44c48b8513cd27c00e95","date":"2024-05-01"}}

Result:

{
  "structuredContent": {
    "guid": "…",
    "id": "000003",
    "posted": false,
    "billingId": "CUST-REF-9",
    "entryCount": 2,
    "entries": [
      "…"
    ],
    "…": "…"
  }
}

Effect: write, on the Book.

Params

Params of invoice.duplicate.

  • invoice (Guid, required): The document to copy, posted or not.
  • date (Date or null): The date of the copy and of each of its lines, stored at its day-neutral time. Defaults to today.
  • id (string or null): The copy's number. Absent or empty takes the next number from the counter of its kind.

Result

A document with its lines, in GnuCash's order (date, date entered, description, action, GUID).

  • guid (Guid, required): A GUID: 32 hexadecimal digits.
  • id (string, required)
  • type (DocumentKindWire or null): From the owner (through a job to its owner) and the credit-note flag.
  • owner (OwnerInfo, required): An owner: a customer, vendor, employee or job.
  • currency (CommodityId or null)
  • dateOpened (Timestamp, required): An instant, RFC 3339; written in UTC with a Z suffix.
  • posted (boolean, required)
  • datePosted (Timestamp or null)
  • terms (Guid or null)
  • billingId (string, required)
  • notes (string, required)
  • docLink (string or null): The document link (assoc_uri slot), as stored.
  • active (boolean, required)
  • billTo (OwnerInfo or null)
  • chargeAmount (Amount, required): An exact amount. Read from a decimal string ("12.34"), a rational string ("1234/100") or {num, denom} with string members; written as {num, denom}. Never a JSON number.
  • postedAccount (Guid or null)
  • postedTransaction (Guid or null)
  • postedLot (Guid or null)
  • entryCount (integer (uint), required)
  • entries (array of EntryInfo, required): Its lines.