From f19a1777a0847ce2dc10b7f259bf76fc2d382d19 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 14 Nov 2014 16:18:09 +0100 Subject: [PATCH] Bug 13319: Fix Koha::Acq::Order should set parent_ordernumber The tests highligh the problem: if the parent_ordernumber attribute is not set on inserting an order, the object returned by the method does not contain the value (undef). Test plan: Verify the tests are consistent and prove t/db_dependent/Acquisition/CancelReceipt.t should return green. You can also verify that receive partially an order and cancel the receipt work as expected. Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Order.pm | 3 +- t/db_dependent/Acquisition/CancelReceipt.t | 44 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 67a998210e..15b9867023 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -51,7 +51,8 @@ sub insert { $self->{ordernumber} = $rs->id; unless ( $self->{parent_ordernumber} ) { - $rs->update( { parent_ordernumber => $self->{ordernumber} } ); + $self->{parent_ordernumber} = $self->{ordernumber}; + $rs->update( { parent_ordernumber => $self->{parent_ordernumber} } ); } return $self; diff --git a/t/db_dependent/Acquisition/CancelReceipt.t b/t/db_dependent/Acquisition/CancelReceipt.t index 3ef83b383d..1946550caa 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 => 4; +use Test::More tests => 12; use C4::Context; use C4::Acquisition; use C4::Biblio; @@ -85,9 +85,19 @@ $order = Koha::Acquisition::Order->new( )->insert; $ordernumber = $order->{ordernumber}; +is( $order->{parent_ordernumber}, $order->{ordernumber}, + "Insert an order should set parent_order=ordernumber, if no parent_ordernumber given" +); + $order->add_item( $itemnumber1 ); $order->add_item( $itemnumber2 ); +is( + scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + 2, + "Create items on ordering: 2 items should be linked to the order before receiving" +); + my ( undef, $new_ordernumber ) = ModReceiveOrder( { biblionumber => $biblionumber, @@ -98,9 +108,39 @@ my ( undef, $new_ordernumber ) = ModReceiveOrder( } ); +my $new_order = GetOrder( $new_ordernumber ); + +is( $new_order->{ordernumber}, $new_ordernumber, + "ModReceiveOrder should return a correct ordernumber" ); +isnt( $new_ordernumber, $ordernumber, + "ModReceiveOrder should return a different ordernumber" ); +is( $new_order->{parent_ordernumber}, $ordernumber, + "The new order created by ModReceiveOrder should be linked to the parent order" +); + +is( + scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + 1, + "Create items on ordering: 1 item should still be linked to the original order after receiving" +); +is( + scalar( GetItemnumbersFromOrder($new_ordernumber) ), + 1, + "Create items on ordering: 1 item should be linked to new order after receiving" +); + CancelReceipt($new_ordernumber); -is(scalar( GetItemnumbersFromOrder($ordernumber) ), 2, "Create items on ordering: items are not deleted after cancelling a receipt"); +is( + scalar( GetItemnumbersFromOrder($new_ordernumber) ), + 0, + "Create items on ordering: no item should be linked to the cancelled order" +); +is( + scalar( GetItemnumbersFromOrder( $order->{ordernumber} ) ), + 2, + "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'" );