Bug 41297 - Add duplicate invoice number detection on EDI invoice import
Summary: Add duplicate invoice number detection on EDI invoice import
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Martin Renvoize (ashimema)
QA Contact: Testopia
URL:
Keywords:
Depends on: 40383
Blocks: 38195
  Show dependency treegraph
 
Reported: 2025-11-25 10:25 UTC by Martin Renvoize (ashimema)
Modified: 2025-11-26 15:47 UTC (History)
1 user (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: Sponsored
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 41297: Block duplicate EDIFACT invoice processing (64.05 KB, patch)
2025-11-26 15:45 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 41297: Block duplicate EDIFACT invoice processing (64.05 KB, patch)
2025-11-26 15:46 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 41297: Block duplicate EDIFACT invoice processing (64.20 KB, patch)
2025-11-26 15:47 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Renvoize (ashimema) 2025-11-25 10:25:10 UTC
EDIFACT invoice processing should detect and block duplicate invoice numbers, notify the supplier (possibly via an EDI CONTRL message), and alert library staff.

While Koha has the AcqWarnOnDuplicateInvoice system preference for manual invoice creation (implemented in Bug 10366), this check is not applied to invoices created automatically via EDIFACT/EDI processing in Koha/EDI.pm.
Comment 1 Martin Renvoize (ashimema) 2025-11-26 15:45:19 UTC
Created attachment 189962 [details] [review]
Bug 41297: Block duplicate EDIFACT invoice processing

This patch adds duplicate invoice detection and blocking for EDIFACT
invoice processing, with email notifications to library staff and
vendors.

Key features:
1. System preferences to enable/disable duplicate blocking and email
   notifications
2. Database index on aqinvoices (invoicenumber, booksellerid) for
   performance
3. Email notifications using the message_queue (GetPreparedLetter →
   EnqueueLetter pattern)
4. Vendor contact-based notifications via a new
   aqcontacts.edi_error_notification flag
5. Two notice templates (EDI_DUP_INV_LIBRARY and EDI_DUP_INV_VENDOR)

Changes:
- Add EdiBlockDuplicateInvoice system preference
- Add EdiBlockDuplicateInvoiceEmailNotice system preference
- Add EdiBlockDuplicateInvoiceEmailAddresses system preference
- Add edi_error_notification column to aqcontacts table
- Add duplicate invoice detection logic to Koha::EDI::process_invoice
- Add email notification support using standard Koha messaging queue
- Add "Contact about EDI errors" checkbox to vendor contacts UI
- Add notice templates to sample_notices.yml for fresh installations
- Add test coverage in t/db_dependent/Koha/EDI.t

Test plan:
1. Run database update: perl installer/data/mysql/updatedatabase.pl
2. Enable system preferences:
   - Set EdiBlockDuplicateInvoice to "Block"
   - Set EdiBlockDuplicateInvoiceEmailNotice to "Send"
   - Set EdiBlockDuplicateInvoiceEmailAddresses to valid email(s)
3. Edit a vendor and add a contact with "Contact about EDI errors" enabled
4. Process an EDIFACT invoice
5. Attempt to process the same invoice again - should be blocked
6. Check message_queue table for queued notifications
7. Run tests: prove t/db_dependent/Koha/EDI.t :: duplicate_invoice_blocking
Comment 2 Martin Renvoize (ashimema) 2025-11-26 15:46:44 UTC Comment hidden (obsolete)
Comment 3 Martin Renvoize (ashimema) 2025-11-26 15:47:20 UTC Comment hidden (obsolete)