From eb43c0114f7827627400ba938e87cf8ee2c99093 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. --- 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 100644 installer/data/mysql/atomicupdate/bug_30135.pl diff --git a/Koha/EDI.pm b/Koha/EDI.pm index e4e7478259..db15afa4d8 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 f21a7a8b76..d966cb7d9d 100644 --- a/Koha/Edifact/Order.pm +++ b/Koha/Edifact/Order.pm @@ -381,17 +381,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, }; } @@ -419,7 +420,7 @@ sub order_line { { branchcode => $item->{branchcode}, itype => $item->{itype}, - location => $item->{location}, + $lsq_field => $item->{$lsq_field}, itemcallnumber => $item->{itemcallnumber}, }; } @@ -551,6 +552,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; @@ -566,9 +568,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 100644 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 dd83a00fd8..def655eaa1 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -187,6 +187,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DumpTemplateVarsOpac', '0', NULL , 'If enabled, dump all Template Toolkit variable to a comment in the html source for the opac.', 'YesNo'), ('EasyAnalyticalRecords','0','','If on, display in the catalogue screens tools to easily setup analytical record relationships','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 7d6a3c3bc4..93a6434355 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 @@ -130,3 +130,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.20.1