https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43875 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 208629 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208629&action=edit Bug 43875: Do not auto-close invoices that have EDIFACT processing errors Bug 40932 closes an invoice automatically, when every item on its non-cancelled orders has been received, from circulation check-in, from the close completed invoices job and from the "check and close" action on the invoice page. All three call Koha::Acquisition::Invoice::check_and_close. It only looks at the orders that are linked to the invoice. An invoice line that EDI processing could not receive, because it refers to a cancelled order, has no order number, an unknown order or a deleted record, is not linked to the invoice, so it cannot be seen here. The supplier has invoiced for the line, so the invoice total in Koha is short, and once the other items are checked in the invoice is closed. Closing an invoice is often what triggers a finance integration to pay it, so a line for something that was cancelled and never received could be paid, or the shortfall could go unnoticed. check_and_close now returns 0, as it does for an invoice that is not ready, when the invoice has EDIFACT processing errors. The invoice can still be closed by hand once staff have checked it with the supplier. The errors that count are those recorded for the invoice number in the message the invoice came from, and the message-level ones that affect the whole file, as the invoice page shows under "Processing errors". Koha::Acquisition::Invoice::edifact_errors returns them, and acqui/invoice.pl uses it instead of repeating the query. This is deliberately cautious: any recorded error, including a warning such as a line for an order that is already complete, keeps an invoice from closing automatically. A flag for only the lines that were skipped would be more precise but needs a change to the database. Test plan: 1. Apply the patch 2. prove t/db_dependent/Circulation/AutoCloseInvoiceOnCheckin.t => the subtest 'check_and_close: EDIFACT processing errors keep invoice open' passes 3. Set AutoCloseInvoicesOnCheckin. Receive an EDIFACT invoice for two orders with items, where one line refers to an order that has been cancelled 4. Check in all the items of the order that was received => the invoice stays open and the invoice page shows the processing error 5. Use "check and close" on the invoice page, or run the close completed invoices job => the invoice is still open 6. Close the invoice by hand => it closes Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.