From 91221583906dcac1e032ffb9203c9e330b38512b Mon Sep 17 00:00:00 2001 From: Richard Davies Date: Wed, 10 Jun 2026 16:54:59 +0100 Subject: [PATCH] feat: allow date/reference updates on authorised credit notes Co-Authored-By: Claude Fable 5 --- src/handlers/update-xero-credit-note.handler.ts | 17 ++++++++++++++--- src/tools/update/update-credit-note.tool.ts | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/handlers/update-xero-credit-note.handler.ts b/src/handlers/update-xero-credit-note.handler.ts index c0b7e8ec..6e69a2bb 100644 --- a/src/handlers/update-xero-credit-note.handler.ts +++ b/src/handlers/update-xero-credit-note.handler.ts @@ -69,12 +69,23 @@ export async function updateXeroCreditNote( const creditNoteStatus = existingCreditNote?.status; - // Only allow updates to DRAFT credit notes - if (creditNoteStatus !== CreditNote.StatusEnum.DRAFT) { + // DRAFT credit notes can be fully updated. AUTHORISED credit notes only + // accept changes to the date and reference; everything else is rejected. + if (creditNoteStatus === CreditNote.StatusEnum.AUTHORISED) { + if (lineItems || contactId) { + return { + result: null, + isError: true, + error: + "Only the date and reference of an authorised credit note can be updated. " + + "Line items and contact cannot be changed.", + }; + } + } else if (creditNoteStatus !== CreditNote.StatusEnum.DRAFT) { return { result: null, isError: true, - error: `Cannot update credit note because it is not a draft. Current status: ${creditNoteStatus}`, + error: `Cannot update credit note because its status is ${creditNoteStatus}. Only draft credit notes can be fully updated; authorised credit notes can have their date and reference updated.`, }; } diff --git a/src/tools/update/update-credit-note.tool.ts b/src/tools/update/update-credit-note.tool.ts index a3b676c3..58c505b6 100644 --- a/src/tools/update/update-credit-note.tool.ts +++ b/src/tools/update/update-credit-note.tool.ts @@ -13,7 +13,9 @@ const lineItemSchema = z.object({ const UpdateCreditNoteTool = CreateXeroTool( "update-credit-note", - "Update a credit note in Xero. Only works on draft credit notes.\ + "Update a credit note in Xero. Draft credit notes can be fully updated.\ + Authorised (approved) credit notes can only have their date and reference updated;\ + to change anything else, the credit note must be a draft.\ All line items must be provided. Any line items not provided will be removed. Including existing line items.\ Do not modify line items that have not been specified by the user.\ When a credit note is updated, a deep link to the credit note in Xero is returned.\