Bug 42001

Summary: Update duplicate purchase order number detection on EDI quote import to optionally send notifications to staff and vendors
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: AcquisitionsAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: Needs Signoff --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: hdunne-howrie, kyle, testopia
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: Sponsored Comma delimited list of Sponsors: Royal Borough of Kensington and Chelsea <https://www.rbkc.gov.uk/>, Westminster City Council <https://www.westminster.gov.uk/>
Crowdfunding goal: 0 Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 20253, 41297    
Bug Blocks: 38195    
Attachments: Bug 42001: Database updates
Bug 42001: Database updates
Bug 42001: Email notifications for duplicate EDI purchase orders
Bug 42001: Unit tests for duplicate order email notifications
Bug 42001: (follow-up) Send new EDI duplicate order preferences to HEA

Description Martin Renvoize (ashimema) 2026-03-05 14:49:00 UTC
EDIFACT quote processing will detect duplicate purchase order numbers and block basket creation from those orders when using the po_is_basketname setting for EDIfact processing.

We should add the ability to notify the supplier, and alert library staff.
Comment 1 Martin Renvoize (ashimema) 2026-03-05 15:08:20 UTC
Created attachment 194517 [details] [review]
Bug 42001: Database updates

Adds system preferences and notice templates for duplicate EDI
purchase order email notifications.

New preferences:
- EdiDuplicateOrderEmailNotice (YesNo)
- EdiDuplicateOrderEmailAddresses (Textarea)

New notice templates:
- EDI_DUP_ORD_LIBRARY - library staff notification
- EDI_DUP_ORD_VENDOR  - vendor contact notification

Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/>
Sponsored-by: Royal Borough of Kensington and Chelsea <https://www.rbkc.gov.uk/>
Comment 2 Martin Renvoize (ashimema) 2026-03-05 15:49:07 UTC
Created attachment 194523 [details] [review]
Bug 42001: Database updates

Adds system preferences and notice templates for duplicate EDI
purchase order email notifications.

New preferences:
- EdiDuplicateOrderEmailNotice (YesNo)
- EdiDuplicateOrderEmailAddresses (Textarea)

New notice templates:
- EDI_DUP_ORD_LIBRARY - library staff notification
- EDI_DUP_ORD_VENDOR  - vendor contact notification

Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/>
Sponsored-by: Royal Borough of Kensington and Chelsea <https://www.rbkc.gov.uk/>
Comment 3 Martin Renvoize (ashimema) 2026-03-05 15:49:08 UTC
Created attachment 194524 [details] [review]
Bug 42001: Email notifications for duplicate EDI purchase orders

When create_edi_order detects a duplicate purchase order number (basket
name conflict with po_is_basketname enabled), send email notifications
to library staff and vendor EDI contacts, mirroring the behaviour
already in place for duplicate EDIFACT invoices (bug 41297).

New preference EdiDuplicateOrderEmailNotice enables/disables the
feature. EdiDuplicateOrderEmailAddresses specifies library recipients.
Vendor contacts flagged with edi_error_notification also receive
notification via EDI_DUP_ORD_VENDOR.

Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/>
Sponsored-by: Royal Borough of Kensington and Chelsea <https://www.rbkc.gov.uk/>
Comment 4 Martin Renvoize (ashimema) 2026-03-05 15:49:10 UTC
Created attachment 194525 [details] [review]
Bug 42001: Unit tests for duplicate order email notifications

Adds a new top-level subtest 'duplicate_order_email_notifications' with
three cases:

1. email_notification_disabled - verifies no mail is queued when
   EdiDuplicateOrderEmailNotice is off, while the duplicate PO block
   still fires correctly.

2. library_email_notification - verifies EDI_DUP_ORD_LIBRARY is
   enqueued to the configured library addresses, with subject and
   content checks.

3. vendor_email_notification - verifies EDI_DUP_ORD_VENDOR is
   enqueued for vendor contacts with edi_error_notification set.

Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/>
Sponsored-by: Royal Borough of Kensington and Chelsea <https://www.rbkc.gov.uk/>
Comment 5 Martin Renvoize (ashimema) 2026-03-05 15:49:11 UTC
Created attachment 194526 [details] [review]
Bug 42001: (follow-up) Send new EDI duplicate order preferences to HEA

Add EdiBlockDuplicateInvoice, EdiBlockDuplicateInvoiceEmailAddresses,
EdiBlockDuplicateInvoiceEmailNotice, EdiDuplicateOrderEmailAddresses,
and EdiDuplicateOrderEmailNotice to the list of system preferences
reported to the Koha usage statistics service (HEA).