From a2786c6de70701966f53ec9087b79c9ff1185ce0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Aug 2014 11:02:48 +0200 Subject: [PATCH] Bug 12557: Partially received - the change should affect the new order If the receipt in not on the whole order but only on a part of it, the change should be done on the itemnumber linked to the "new order", the one we are reverting. Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Acquisition.pm | 3 ++- t/db_dependent/Acquisition/CancelReceipt.t | 27 +++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index a043e93227..d55eda9e36 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1605,6 +1605,8 @@ sub CancelReceipt { my $parent_ordernumber = $order->{'parent_ordernumber'}; + my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); + if($parent_ordernumber == $ordernumber || not $parent_ordernumber) { # The order line has no parent, just mark it as not received $query = qq{ @@ -1668,7 +1670,6 @@ 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); diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index b94e17fd67..ed99c984c9 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 => 3; +use Test::More tests => 4; use C4::Context; use C4::Acquisition; use C4::Biblio; @@ -69,7 +69,8 @@ CancelReceipt($ordernumber); my $order = GetOrder( $ordernumber ); is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 0, "Create items on receiving: 0 item exist after cancelling a receipt"); -$itemnumber = AddItem({}, $biblionumber); +my $itemnumber1 = AddItem({}, $biblionumber); +my $itemnumber2 = AddItem({}, $biblionumber); 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( @@ -81,23 +82,27 @@ t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9 } ); -ModReceiveOrder( +NewOrderItem($itemnumber1, $ordernumber); +NewOrderItem($itemnumber2, $ordernumber); + +my ( undef, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, ordernumber => $ordernumber, - quantityreceived => 2, - datereceived => dt_from_string + quantityreceived => 1, + datereceived => dt_from_string, + received_items => [ $itemnumber1 ], } ); -NewOrderItem($itemnumber, $ordernumber); +CancelReceipt($new_ordernumber); -CancelReceipt($ordernumber); +is(scalar( GetItemnumbersFromOrder($ordernumber) ), 2, "Create items on ordering: items are not deleted after cancelling a receipt"); -$order = GetOrder( $ordernumber ); -is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 1, "Create items on ordering: items are not deleted after cancelling a receipt"); +my $item1 = C4::Items::GetItem( $itemnumber1 ); +is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" ); -my $item = C4::Items::GetItem( $itemnumber ); -is( $item->{notforloan}, 9, "The notforloan value has been updated with '9'" ); +my $item2 = C4::Items::GetItem( $itemnumber2 ); +is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" ); $dbh->rollback; -- 2.39.5