Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/handlers/update-xero-credit-note.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/update/update-credit-note.tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.\
Expand Down