Browse Source

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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Kyle Hall 3 years ago
committed by Jonathan Druart
parent
commit
db382ebaff
  1. 3
      C4/Items.pm
  2. 2
      t/db_dependent/Items.t

3
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(

2
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;

Loading…
Cancel
Save