From db382ebaffd393151e0ebd8e6579f5c11969a90c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 6 May 2021 08:09:04 -0400 Subject: [PATCH] Bug 27837: Check the MARC directly, not the transformed item If permanent location is mapped, it will exist in the MARC. However, when we are transforming our item hash to MARC, we are losing our permanent location mapping, at least in unit tests. By checking the original MARC for the permenent location, we remove the risk of losing it the "empty" permenent location through the transformation process. We only need to know that it existed in the original item marc to know we need to update it in the database. Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- C4/Items.pm | 3 ++- t/db_dependent/Items.t | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 3ba49a2477..729c6e0b48 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -304,7 +304,8 @@ sub ModItemFromMarc { my $item_object = Koha::Items->find($itemnumber); my $item = TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); - my $has_permanent_location = exists $item->{permanent_location}; + my ( $perm_loc_tag, $perm_loc_subfield ) = C4::Biblio::GetMarcFromKohaField( "items.permanent_location" ); + my $has_permanent_location = defined $item_marc->subfield( $perm_loc_tag, $perm_loc_subfield ); # Retrieving the values for the fields that are not linked my @mapped_fields = Koha::MarcSubfieldStructures->search( diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 23ee75f3be..b28d930ebe 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -1117,11 +1117,11 @@ subtest 'ModItemFromMarc' => sub { $item->permanent_location(""); $item->location('E'); $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber ); + $marc->field('952')->add_subfields( "C", "" ); ModItemFromMarc( $marc, $item->biblionumber, $item->itemnumber ); $item = $item->get_from_storage; is( $item->location, 'E', 'next new location set as expected' ); is( $item->permanent_location, undef, 'permanent location is not updated if previously set as blank string' ); - }; $schema->storage->txn_rollback; -- 2.39.5