From 8a579e5c6171a641388ad98836dbdb0c410d6362 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 May 2018 16:56:26 +0100 Subject: [PATCH] Bug 20780: Add handling for AcqItemSetSubfieldsWhenRecieved in EDI Signed-off-by: Brendan Gallagher Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- Koha/EDI.pm | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 5770d7dd52..6af28b5ce7 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -30,7 +30,7 @@ use Koha::Database; use C4::Acquisition qw( NewBasket CloseBasket ModOrder); use C4::Suggestions qw( ModSuggestion ); use C4::Items qw(AddItem); -use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio ); +use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField ); use Koha::Edifact::Order; use Koha::Edifact; use Log::Log4perl; @@ -388,6 +388,23 @@ sub receipt_items { } push @{ $branch_map{$b} }, $item; } + + # Handling for 'AcqItemSetSubfieldsWhenReceived' + my @affects; + my $biblionumber; + my $itemfield; + if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { + @affects = split q{\|}, + C4::Context->preference("AcqItemSetSubfieldsWhenReceived"); + if (@affects) { + $biblionumber = $schema->resultset('Aqorder')->find($ordernumber) + ->biblionumber->biblionumber; + my $frameworkcode = GetFrameworkCode($biblionumber); + ($itemfield) = GetMarcFromKohaField( 'items.itemnumber', + $frameworkcode ); + } + } + my $gir_occurrence = 0; while ( $gir_occurrence < $quantity ) { my $branch = $inv_line->girfield( 'branch', $gir_occurrence ); @@ -410,6 +427,18 @@ sub receipt_items { } } + # Handling for 'AcqItemSetSubfieldsWhenReceived' + if (@affects) { + my $item_marc = C4::Items::GetMarcItem( $biblionumber, $item->itemnumber ); + for my $affect (@affects) { + my ( $sf, $v ) = split q{=}, $affect, 2; + foreach ( $item_marc->field($itemfield) ) { + $_->update( $sf => $v ); + } + } + C4::Items::ModItemFromMarc( $item_marc, $biblionumber, $item->itemnumber ); + } + $item->update; } else { -- 2.39.5