From 2088b6857e9dd0d41acb53582897703586b7116d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 7 Aug 2019 11:00:49 -0500 Subject: [PATCH] Bug 23463: Fix CancelReceipt.t Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Items.pm | 9 ++------- Koha/Item.pm | 9 +++++++-- t/db_dependent/Acquisition/CancelReceipt.t | 2 +- t/db_dependent/Circulation/issue.t | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 5769b9ce0b..80edaeb948 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -276,15 +276,10 @@ sub ModItemFromMarc { my $localitemmarc = MARC::Record->new; $localitemmarc->append_fields( $item_marc->field($itemtag) ); - my $item = TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); - my $default_values = _build_default_values_for_mod_marc(); my $item_object = Koha::Items->find($itemnumber); - foreach my $item_field ( keys %$default_values ) { - $item_object->$item_field($default_values->{$item_field}) - unless exists $item->{$item_field}; - } + my $item = TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); + $item_object->set($item); my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); - $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields))->store; $item_object->store; diff --git a/Koha/Item.pm b/Koha/Item.pm index 0aeaee15b3..4304b8a58e 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -135,8 +135,13 @@ sub store { } } - if ( defined $self->location and $self->location ne 'CART' and $self->location ne 'PROC' and not $self->permanent_location ) { - $self->permanent_location($self->location); + my %updated_columns = $self->_result->get_dirty_columns; + if ( defined $self->location + and $self->location ne 'CART' + and $self->location ne 'PROC' + and not exists $updated_columns{permanent_location} ) + { + $self->permanent_location( $self->location ); } $self->timestamp(undef) if $self->timestamp; # Maybe move this to Koha::Object->store? diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index fa2509678b..0455a80f96 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -167,6 +167,6 @@ my $item1 = Koha::Items->find( $itemnumber1 ); is( $item1->notforloan, 9, "The notforloan value has been updated with '9'" ); my $item2 = Koha::Items->find( $itemnumber2 ); -is( $item2->notforloan, 0, "The notforloan value has been updated with '9'" ); +is( $item2->notforloan, 0, "The notforloan value has been updated with '0'" ); $schema->storage->txn_rollback(); diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index 6f312e4773..7e3072efe5 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -394,8 +394,8 @@ ok( $item2->location eq 'FIC', 'UpdateItemLocationOnCheckin does not modify valu t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', 'FIC: GEN' ); AddReturn( 'barcode_4', $branchcode_1 ); $item2 = Koha::Items->find( $itemnumber2 ); -ok( $item2->location eq 'GEN', q{UpdateItemLocationOnCheckin updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} ); -ok( $item2->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckin updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} ); +is( $item2->location, 'GEN', q{UpdateItemLocationOnCheckin updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} ); +is( $item2->permanent_location, 'GEN', q{UpdateItemLocationOnCheckin updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} ); AddReturn( 'barcode_4', $branchcode_1 ); $item2 = Koha::Items->find( $itemnumber2 ); ok( $item2->location eq 'GEN', q{UpdateItemLocationOnCheckin does not update location value from 'GEN' with setting "FIC: GEN"} ); -- 2.39.5