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 <chris@bigballofwax.co.nz>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-11-14 16:18:09 +01:00 committed by Tomas Cohen Arazi
parent dc5b944863
commit f19a1777a0
2 changed files with 44 additions and 3 deletions

View file

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

View file

@ -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'" );