Edit line items: create, update, and delete
When you edit a Beleg (receipt/expense document), you send the full set of line items you want to keep, and the platform reconciles them against what is already stored. This article explains that full-replacement model — how rows are created, updated, and deleted in one save. Editing requires the belege:transition permission and a Beleg in Draft or Needs Clarification.
Full-replacement, not incremental
There is no "delete row 3" or "add one row" call. Instead, every update carries the complete line-item array the Beleg should have after the save. The platform compares that array with the stored line items and works out what to create, update, and delete. This all-or-nothing approach is what keeps the header totals consistent — line items are never mutated outside this flow.
How each row is matched
Matching is done by the line item's id:
| Row in your request | Meaning | Result |
|---|---|---|
| No id (null) | New row | Created as a new line item. |
| Has an id that exists on the Beleg | Existing row | Updated in place with your values. |
| An existing id you omit from the request | Removed row | Deleted from the Beleg. |
Warning: Anything you leave out is deleted. To keep a line item, include it in the array with its existing id. To keep it unchanged, resend it with the same values.
A worked example
Suppose a Beleg has line items with ids 10, 11, and 12. You save an update containing:
- id 10 with a corrected quantity — item 10 is updated.
- id 12 unchanged — item 12 is kept.
- a row with no id — a new item is created.
- id 11 is not present — item 11 is deleted.
The result is three line items: the edited 10, the untouched 12, and the new one.
What happens on save
- The line items are validated at the boundary: required fields per line, at least one line item, no more than 20, and active financial references.
- The Beleg is loaded with its existing line items and confirmed to be in an editable state.
- Full replacement is applied: rows are created, updated, or deleted by id match.
- Every line item's net, VAT, and gross amount is recomputed and rows are re-sequenced 1…n by sort order.
- The header totals are recomputed.
- Everything is persisted in a single transaction, the applicable rules are re-evaluated, and audit events (
BelegLineItemsUpdated,BelegTotalsRecomputed) are recorded.
Note: The whole save is atomic. If any line fails validation — for example an inactive cost center or a 21st row — nothing is written and the Beleg keeps its previous line items and totals.
Reordering rows
You can set a sort order on each row to control its position. After the save, the platform normalizes the sort order to a gap-free 1…n sequence based on the values you sent (ties broken by id), so drag-and-drop reordering in the grid persists cleanly without you managing the numbers.
Related
- Add line items to a Beleg
- How header totals are recomputed on every change
- How net, VAT, and gross amounts are calculated
- When you can edit a Beleg: editable states