From 55ca3c5581de4b794020c8d555f3f472be641b71 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 11 Jul 2014 12:09:32 +0200 Subject: [PATCH] Bug 12557: Add a way to revert the changes made on items on receving Bug 8307 introduces the AcqItemSetSubfieldsWhenReceived pref. You can now update an item field on receiving (if you create items on ordering). But if the receipt is cancel, there is no way to revert these changes. This patch adds a new pref AcqItemSetSubfieldsWhenReceiptIsCancelled to allow to revert changes previously done on receiving Test plan: 0/ Set the AcqCreateItems to 'ordering' 1/ Fill AcqItemSetSubfieldsWhenReceived with o=1 (UNIMARC) or 7=1 (MARC21). 2/ Fill AcqItemSetSubfieldsWhenReceiptIsCancelled with o=2 (UNIMARC) or 7=2 (MARC21) 3/ Create an order with some items 4/ Receive the order and verify the notforloan value is set to 1 5/ Cancel the receipt and verify the notforloan value is set to 2 Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Acquisition.pm | 20 ++++++++++++++++++++ t/db_dependent/Acquisition/CancelReceipt.t | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 5fc45c77e3..a043e93227 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1665,6 +1665,26 @@ sub CancelReceipt { } + if(C4::Context->preference('AcqCreateItem') eq 'ordering') { + my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceiptIsCancelled"); + if ( @affects ) { + my @itemnumbers = GetItemnumbersFromOrder( $parent_ordernumber ); + for my $in ( @itemnumbers ) { + my $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber( $in ); + my $frameworkcode = GetFrameworkCode($biblionumber); + my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $frameworkcode ); + my $item = C4::Items::GetMarcItem( $biblionumber, $in ); + for my $affect ( @affects ) { + my ( $sf, $v ) = split q{=}, $affect, 2; + foreach ( $item->field($itemfield) ) { + $_->update( $sf => $v ); + } + } + C4::Items::ModItemFromMarc( $item, $biblionumber, $in ); + } + } + } + return $parent_ordernumber; } diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index e2d4e4d7eb..7304dc3f2a 100644 --- a/t/db_dependent/Acquisition/CancelReceipt.t +++ b/t/db_dependent/Acquisition/CancelReceipt.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use C4::Context; use C4::Acquisition; use C4::Biblio; @@ -70,6 +70,7 @@ my $order = GetOrder( $ordernumber ); is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 0, "Create items on receiving: 0 item exist after cancelling a receipt"); t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering'); +t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7 ( undef, $ordernumber ) = C4::Acquisition::NewOrder( { basketno => $basketno1, @@ -95,4 +96,7 @@ CancelReceipt($ordernumber); $order = GetOrder( $ordernumber ); is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 1, "Create items on ordering: items are not deleted after cancelling a receipt"); +my $item = C4::Items::GetItem( $itemnumber ); +is( $item->{notforloan}, 9, "The notforloan value has been updated with '9'" ); + $dbh->rollback; -- 2.39.5