fix(bookkeeping): honor underlag VAT via vat_amount override in categorize flow (#717)
* fix(bookkeeping): honor underlag VAT via vat_amount override in categorize flow
The categorize flow always derived VAT as rate × gross/(1+rate) from the
transaction amount, with no way to use the underlag's actual moms. On e.g.
a restaurant receipt with dricks (no VAT on the tip), the agent could see
the document's correct VAT but the staged booking recomputed the wrong
rate-based amount on every attempt.
- buildMappingResultFromCategory: optional vatAmountOverride replaces the
rate-derived VAT line ("Ingående/Utgående moms (enligt underlag)"; 0 =
no VAT line). Rejects negatives, amounts above the 25%-extraction bound,
and combination with reverse_charge / VAT-less treatments / private.
- gnubok_categorize_transaction: new vat_amount input, threaded into the
staged preview and persisted in the operation params.
- commitCategorizeTransaction: reads params.vat_amount so the approved
posting matches the staged preview exactly.
- PATCH /api/pending-operations/[id]: accepts vat_amount (null clears);
preserves a staged override across category edits while the treatment
still carries rate-based VAT, drops it when it no longer does.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* review: guard order + agent guidance on vat_amount (PR #717 bots)
- Check treatment compatibility before the 25%-extraction bound so an
oversized override on reverse_charge reports the actual mistake (the
treatment), not the amount. Document why the typeof re-check stays:
commit-time params come from jsonb, so TS types don't hold at runtime.
- vat_amount property description now warns that foreign VAT is never
deductible as ingående moms and that a 0-moms document should use
vat_treatment="exempt" rather than vat_amount=0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(mcp): tools/list payload budget + reject vat_amount 0
core-only failed: the verbose vat_amount descriptions pushed the projected
tools/list payload to 36,051 tokens (ceiling 36,000; main is at 35,862).
Per the guard's own guidance, trim descriptions instead of bumping:
now 35,943.
Folds in the Swedish review's round-2 point while trimming: vat_amount 0
is now rejected with a pointer to vat_treatment "exempt". A 0-moms
document is an exempt supply — "exempt" produces the identical expense
booking and the correct income account (3004), so 0 had no use case and
only created a silent momsdeklaration misclassification path. Schema
declares exclusiveMinimum: 0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(bookkeeping): use roundOre for vat_amount math (antipattern ratchet)
Second core-only failure: the naive-ore-round ratchet caught the new
Math.round(x*100)/100 lines (662 > baseline 661). Switch the override
path to roundOre from lib/money — including the pre-existing computed-VAT
line this PR touched — and ratchet the baseline down (659, raw-route-auth
168 locked in from main-side fixes).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
f548b04aed
commit
8e8b63a200
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_comment": "Ratchet baseline for scripts/checks/no-new-antipatterns.mjs. These counts may only decrease. Re-run with --update after a migration lowers them. Goal: both reach 0 (A1 route-auth campaign, D1 rounding codemod).",
|
||||
"rawRouteAuth": {
|
||||
"count": 171,
|
||||
"count": 168,
|
||||
"files": [
|
||||
"app/api/account/delete/route.ts",
|
||||
"app/api/account/password/route.ts",
|
||||
@@ -39,7 +39,6 @@
|
||||
"app/api/bookkeeping/voucher-gaps/route.ts",
|
||||
"app/api/calendar/feed/route.ts",
|
||||
"app/api/cash-accounts/route.ts",
|
||||
"app/api/company/check-org-number/route.ts",
|
||||
"app/api/company/current/route.ts",
|
||||
"app/api/company/members/[id]/route.ts",
|
||||
"app/api/company/members/invite/[id]/route.ts",
|
||||
@@ -142,7 +141,6 @@
|
||||
"app/api/salary/runs/[id]/payslips/send/route.ts",
|
||||
"app/api/salary/runs/[id]/preview/route.ts",
|
||||
"app/api/salary/runs/[id]/review/route.ts",
|
||||
"app/api/salary/runs/[id]/route.ts",
|
||||
"app/api/salary/tax-tables/lookup/route.ts",
|
||||
"app/api/salary/tax-tables/status/route.ts",
|
||||
"app/api/settings/api-keys/[id]/route.ts",
|
||||
@@ -171,12 +169,11 @@
|
||||
"app/api/transactions/[id]/uncategorize/route.ts",
|
||||
"app/api/transactions/batch-match-invoices/route.ts",
|
||||
"app/api/transactions/create-from-document/route.ts",
|
||||
"app/api/transactions/route.ts",
|
||||
"app/api/transactions/suggest-categories/route.ts",
|
||||
"app/api/vat/validate/route.ts"
|
||||
]
|
||||
},
|
||||
"naiveOreRound": {
|
||||
"count": 661
|
||||
"count": 659
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user