From f4e66a6fc6563ff86b7e6deb8d4390ddc355c41f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 8 Jul 2025 14:45:19 +0100 Subject: [PATCH] Bug 20253: Optionally use buyer's purchase order number from EDIFACT quote as basket name This enhancement allows libraries to configure vendors to use the buyer's purchase order number (from RFF+ON segments) as the basket name instead of the EDIFACT filename, improving searchability and reference tracking. Backend Changes: - Added purchase_order_number() method to Koha::Edifact::Message to extract RFF+ON segments from message-level data (before first LIN segment) - Modified process_quote() in Koha::EDI to use purchase order number for basket naming when configured, with fallback to filename Frontend Changes: - Updated admin/edi_accounts.pl to handle po_is_basketname parameter - Added "Use purhase order numbers" option to EDI accounts template Test Plan: 1. Apply patches and run database update 2. Go to Administration > Acquisitions > EDI accounts 3. Create or edit a vendor EDI account 4. Verify "Use purchase order numbers" option appears 5. Enable "Use purchase order numbers" and save 6. Process an EDIFACT quote file that contains RFF+ON segments 7. Verify the created basket name uses the purchase order number instead of filename 8. Process a quote file without RFF+ON segments 9. Verify the basket name falls back to the filename 10. Test with "Use purchase order numbers" disabled 11. Verify basket names use filenames regardless of RFF+ON presence 12. Run tests: prove t/Edifact.t t/db_dependent/Koha/EDI.t The feature is optional and backward compatible - existing behavior is unchanged unless explicitly configured. --- Koha/EDI.pm | 27 +++-- Koha/Edifact/Message.pm | 20 ++++ admin/edi_accounts.pl | 1 + .../prog/en/modules/admin/edi_accounts.tt | 108 ++++++++++++------ 4 files changed, 112 insertions(+), 44 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 6b485bf864c..ce349b501db 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -645,11 +645,29 @@ sub process_quote { my $split_message; my @added_baskets; # if auto & multiple baskets need to order all + # Get vendor EDI account configuration + my $v = $schema->resultset('VendorEdiAccount')->search( + { + vendor_id => $quote_message->vendor_id, + } + )->single; + if ( @{$messages} && $quote_message->vendor_id ) { + foreach my $msg ( @{$messages} ) { ++$message_count; + + # Determine basket name based on vendor configuration + my $basket_name = $quote_message->filename; + if ( $v && $v->po_is_basketname ) { + my $purchase_order_number = $msg->purchase_order_number; + if ($purchase_order_number) { + $basket_name = $purchase_order_number; + } + } + my $basketno = NewBasket( - $quote_message->vendor_id, 0, $quote_message->filename, q{}, + $quote_message->vendor_id, 0, $basket_name, q{}, q{} . q{} ); push @added_baskets, $basketno; @@ -691,12 +709,7 @@ sub process_quote { $quote_message->status($status); $quote_message->update; # status and basketno link # Do we automatically generate orders for this vendor - my $v = $schema->resultset('VendorEdiAccount')->search( - { - vendor_id => $quote_message->vendor_id, - } - )->single; - if ( $v->auto_orders ) { + if ( $v && $v->auto_orders ) { for my $b (@added_baskets) { create_edi_order( { diff --git a/Koha/Edifact/Message.pm b/Koha/Edifact/Message.pm index 5983b4b670e..3a0c2fbd74a 100644 --- a/Koha/Edifact/Message.pm +++ b/Koha/Edifact/Message.pm @@ -183,6 +183,22 @@ sub supplier_ean { } +sub purchase_order_number { + my $self = shift; + foreach my $s ( @{ $self->{datasegs} } ) { + if ( $s->tag eq 'LIN' ) { + last; + } + if ( $s->tag eq 'RFF' ) { + my $qualifier = $s->elem( 0, 0 ); + if ( $qualifier eq 'ON' ) { + return $s->elem( 0, 1 ); + } + } + } + return; +} + sub lineitems { my $self = shift; if ( $self->{quotation_lines} ) { @@ -280,6 +296,10 @@ Missing POD for buyer_ean. Missing POD for supplier_ean. +=head2 purchase_order_number + +Missing POD for purchase_order_number. + =head2 lineitems Missing POD for lineitems. diff --git a/admin/edi_accounts.pl b/admin/edi_accounts.pl index 410bcb8eaf4..da084238f81 100755 --- a/admin/edi_accounts.pl +++ b/admin/edi_accounts.pl @@ -94,6 +94,7 @@ if ( $op eq 'acct_form' ) { auto_orders => $input->param('auto_orders') ? 1 : 0, id_code_qualifier => scalar $input->param('id_code_qualifier'), plugin => scalar $input->param('plugin'), + po_is_basketname => $input->param('po_is_basketname') ? 1 : 0, }; if ($id) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt index 4e554f03eb7..88dfcd41dca 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt @@ -95,9 +95,10 @@ New account [% END %] -
- Account details + +
+ Basic Information
  1. @@ -111,6 +112,10 @@ [% END %]
  2. +
  3. + + +
  4. [% IF plugins %]
  5. @@ -129,9 +134,45 @@ [% END %]
  6. - - + + +
  7. +
  8. + + +
  9. +
  10. + +
  11. +
+
+ + +
+ Transport Settings +
  1. [% transport_types = [ 'FTP', 'SFTP', 'FILE' ] %] @@ -177,39 +218,13 @@
    The upload directory specifies the directory on the ftp site to which orders are uploaded.
  2. -
  3. - - -
  4. -
  5. - - -
  6. -
  7. - - -
  8. +
+
+ + +
+ Message Types +
  1. [% IF account.quotes_enabled %] @@ -242,6 +257,13 @@ [% END %]
  2. +
+
+ + +
+ Functional Switches +
  1. [% IF account.auto_orders %] @@ -251,6 +273,18 @@ [% END %]
    With automatic ordering quotes generate orders without staff intervention.
  2. +
  3. + + [% IF account.po_is_basketname %] + + [% ELSE %] + + [% END %] +
    + When enabled, basket names are used as purchase order numbers.
    For received QUOTE messages, we will use the RFF+ON field to populate the basket name.
    For generated ORDER messages, we will use the + basket name to populate the BGM segment.
    +
-- 2.50.0