From 509aebd60eb4b3f4a3e7d0be42873fab9dbbb0ad Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Feb 2022 17:15:11 +0000 Subject: [PATCH] Bug 30135: Add EdifactLSQ mapping preference This patch adds a new system preference, EdifactLSQ, to allow configuration of the ambiguous LSQ, sequence code, field included in the EDIFACT specifications. Originally the field was hard coded to map to 'location', but as per the specification it could have been mapped to 'ccode'. From the specification: A code or other designation which identifies stock which is to be shelved in a specified sequence or collection. Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers --- Koha/EDI.pm | 17 ++++++++++------- Koha/Edifact/Line.pm | 2 +- Koha/Edifact/Order.pm | 12 +++++++----- installer/data/mysql/atomicupdate/bug_30135.pl | 14 ++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../modules/admin/preferences/acquisitions.pref | 8 ++++++++ 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_30135.pl diff --git a/Koha/EDI.pm b/Koha/EDI.pm index e4e7478259..43ea19cb84 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -869,8 +869,6 @@ sub quote_item { my $new_item = { itype => $item->girfield( 'stock_category', $occurrence ), - location => - $item->girfield( 'collection_code', $occurrence ), itemcallnumber => $item->girfield( 'shelfmark', $occurrence ) || $item->girfield( 'classification', $occurrence ) @@ -879,11 +877,15 @@ sub quote_item { $item->girfield( 'branch', $occurrence ), homebranch => $item->girfield( 'branch', $occurrence ), }; + + my $lsq_field = C4::Context->preference('EdifactLSQ'); + $new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); + if ( $new_item->{itype} ) { $item_hash->{itype} = $new_item->{itype}; } - if ( $new_item->{location} ) { - $item_hash->{location} = $new_item->{location}; + if ( $new_item->{$lsq_field} ) { + $item_hash->{$lsq_field} = $new_item->{$lsq_field}; } if ( $new_item->{itemcallnumber} ) { $item_hash->{itemcallnumber} = @@ -957,8 +959,6 @@ sub quote_item { replacementprice => $price, itype => $item->girfield( 'stock_category', $occurrence ), - location => - $item->girfield( 'collection_code', $occurrence ), itemcallnumber => $item->girfield( 'shelfmark', $occurrence ) || $item->girfield( 'classification', $occurrence ) @@ -967,6 +967,8 @@ sub quote_item { $item->girfield( 'branch', $occurrence ), homebranch => $item->girfield( 'branch', $occurrence ), }; + my $lsq_field = C4::Context->preference('EdifactLSQ'); + $new_item->{$lsq_field} = $item->girfield( 'sequence_code', $occurrence ); $new_item->{biblionumber} = $bib->{biblionumber}; $new_item->{biblioitemnumber} = $bib->{biblioitemnumber}; my $kitem = Koha::Item->new( $new_item )->store; @@ -1173,7 +1175,8 @@ sub _create_item_from_quote { $item_hash->{booksellerid} = $quote->vendor_id; $item_hash->{price} = $item_hash->{replacementprice} = $item->price; $item_hash->{itype} = $item->girfield('stock_category'); - $item_hash->{location} = $item->girfield('collection_code'); + my $lsq_field = C4::Context->preference('EdifactLSQ'); + $item_hash->{$lsq_field} = $item->girfield('sequence_code'); my $note = {}; diff --git a/Koha/Edifact/Line.pm b/Koha/Edifact/Line.pm index 172e4fbe18..379ef13605 100644 --- a/Koha/Edifact/Line.pm +++ b/Koha/Edifact/Line.pm @@ -686,7 +686,7 @@ sub extract_gir { LQT => 'part_order_quantity', LRS => 'record_sublocation', LSM => 'shelfmark', - LSQ => 'collection_code', + LSQ => 'sequence_code', LST => 'stock_category', LSZ => 'size_code', LVC => 'coded_servicing_instruction', diff --git a/Koha/Edifact/Order.pm b/Koha/Edifact/Order.pm index 548c62c429..e43da925d5 100644 --- a/Koha/Edifact/Order.pm +++ b/Koha/Edifact/Order.pm @@ -373,17 +373,18 @@ sub order_line { # DTM Optional date constraints on delivery # we dont currently support this in koha # GIR copy-related data + my $lsq_field = C4::Context->preference('EdifactLSQ'); my @items; if ( $basket->effective_create_items eq 'ordering' ) { - my @linked_itemnumbers = $orderline->aqorders_items; + my @linked_itemnumbers = $orderline->aqorders_items; foreach my $item (@linked_itemnumbers) { my $i_obj = $schema->resultset('Item')->find( $item->itemnumber ); if ( defined $i_obj ) { push @items, { branchcode => $i_obj->get_column('homebranch'), itype => $i_obj->effective_itemtype, - location => $i_obj->location, + $lsq_field => $i_obj->$lsq_field, itemcallnumber => $i_obj->itemcallnumber, }; } @@ -411,7 +412,7 @@ sub order_line { { branchcode => $item->{branchcode}, itype => $item->{itype}, - location => $item->{location}, + $lsq_field => $item->{$lsq_field}, itemcallnumber => $item->{itemcallnumber}, }; } @@ -543,6 +544,7 @@ sub gir_segments { my $budget_code = $orderfields->{budget_code}; my @segments; my $sequence_no = 1; + my $lsq_field = C4::Context->preference('EdifactLSQ'); foreach my $item (@onorderitems) { my $elements_added = 0; my @gir_elements; @@ -558,9 +560,9 @@ sub gir_segments { push @gir_elements, { identity_number => 'LST', data => $item->{itype} }; } - if ( $item->{location} ) { + if ( $item->{$lsq_field} ) { push @gir_elements, - { identity_number => 'LSQ', data => $item->{location} }; + { identity_number => 'LSQ', data => $item->{$lsq_field} }; } if ( $item->{itemcallnumber} ) { push @gir_elements, diff --git a/installer/data/mysql/atomicupdate/bug_30135.pl b/installer/data/mysql/atomicupdate/bug_30135.pl new file mode 100755 index 0000000000..54994e6c64 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_30135.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "30135", + description => "Add EdifactLSQ mapping system preference", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('EdifactLSQ', 'location', 'location|ccode', "Map EDI sequence code (GIR+LSQ) to Koha Item field', 'Choice') + }); + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index a11b54ef42..9fab1e0cc1 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -189,6 +189,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','YesNo'), ('EDIFACT','0',NULL,'Enables EDIFACT acquisitions functions','YesNo'), ('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice'), +('EdifactLSQ', 'location', 'location|ccode', "Map EDI sequence code (GIR+LSQ) to Koha Item field', 'Choice'), ('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL), ('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL), ('ElasticsearchMARCFormat', 'ISO2709', 'ISO2709|ARRAY', 'Elasticsearch MARC format. ISO2709 format is recommended as it is faster and takes less space, whereas array is searchable.', 'Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index e037b9282d..3be75cec9e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -138,3 +138,11 @@ Acquisitions: automatic: "Do" manual: "Don't" - " automatically import EDIFACT invoice message files when they are downloaded." + - + - "Map sequence code (GIR:LSQ) field to Koha item " + - pref: EdifactLSQ + default: location + choices: + location: "location" + ccode: "ccode" + - " field." -- 2.39.5