Skip to content

feat: support tracking categories on manual journals#180

Open
rathga wants to merge 2 commits into
XeroAPI:mainfrom
rathga:feat/manual-journal-tracking
Open

feat: support tracking categories on manual journals#180
rathga wants to merge 2 commits into
XeroAPI:mainfrom
rathga:feat/manual-journal-tracking

Conversation

@rathga

@rathga rathga commented Jun 6, 2026

Copy link
Copy Markdown

Problem

Manual journal lines cannot carry Xero tracking categories through this MCP server. The write path silently discards tracking, and the read serializer never prints it — even though the xero-node ManualJournalLine type supports it and the API returns it. The original author left explicit placeholders:

src/handlers/create-xero-manual-journal.handler.ts: // TODO: tracking can be added here
src/handlers/update-xero-manual-journal.handler.ts: // TODO: tracking can be added here
src/tools/create/create-manual-journal.tool.ts:     // TODO: TODO: tracking can be added here
src/tools/update/update-manual-journal-tool.ts:     // TODO: TODO: tracking can be added here

This matters for anyone who tracks journal lines by category (e.g. per-property or per-department) during reconciliation — the codes simply don't come through.

Changes

  • Shared schema: extract the invoice trackingSchema ({ name, option, trackingCategoryID }) into src/helpers/tracking-schema.ts and reuse it across create-invoice, update-invoice, and both manual-journal tools — removing the existing duplicated copy in the two invoice tools.
  • Write: add tracking (max 2 per line) to the create/update manual-journal line schemas and forward it through both handlers to the Xero API.
  • Read: add formatTracking, which renders a line's tracking as readable category/option text (omitting cleanly when absent), and use it in the list-manual-journals serializer and the create success response. The raw array is never printed (avoids the [object Object] pitfall).
  • Bug fix: the create success response previously stringified its line array to [object Object],[object Object] — it never rendered line details at all. It now joins lines to text, matching the list serializer.
  • Tests: add Vitest coverage for formatTracking.

Verification

Verified end-to-end against a real Xero tenant: created a draft manual journal with tracking on each line, read it back (codes appear), updated the tracking and re-read (new codes appear), and confirmed no [object Object] leaks. npm run lint and npm test pass.

Notes

  • Does not touch src/helpers/format-line-item.ts, so it does not collide with PR Format line item tracking values #178 (invoice/bank-tx tracking formatting).
  • Bank transactions also lack tracking — left as a separate follow-up.

🤖 Generated with Claude Code

Manual journal lines could not carry Xero tracking categories: the write
path discarded `tracking` and the read serializer never printed it, despite
the SDK's `ManualJournalLine` type supporting it. This left placeholder
`// TODO: tracking can be added here` comments on both paths.

- Add a shared `trackingSchema` helper and reuse it across the invoice and
  manual-journal create/update tools (removing the duplicated invoice copy).
- Add `tracking` (max 2 per line) to the create/update manual-journal line
  schemas and forward it through both handlers to the Xero API.
- Add a `formatTracking` helper that renders a line's tracking as readable
  `category/option` text (omitting it cleanly when absent) and use it in the
  list serializer and the create success response.
- Fix the create success response, which stringified its line array to
  `[object Object]`; it now joins lines to text like the list serializer.
- Add Vitest coverage for `formatTracking`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The tool description claimed manual-journal updates "Only works on draft
manual journals", but nothing in the code enforced that and the Xero API
accepts updates to posted journals too (verified live: created a posted
journal, updated its tracking while posted, confirmed the change applied).
The inaccurate text discouraged a valid and common operation (e.g. adding
tracking to already-posted journals during reconciliation).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant