@@ -, +, @@ --- C4/Acquisition.pm | 3 ++- t/db_dependent/Acquisition.t | 55 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -1299,7 +1299,7 @@ sub NewOrder { =head3 NewOrderItem - &NewOrderItem(); + &NewOrderItem( $itemnumber, $ordernumber ); =cut @@ -1838,6 +1838,7 @@ cancelled. sub DelOrder { my ($ordernumber,$biblionumber) = @_; + return if !$ordernumber; my $dbh = C4::Context->dbh; my $query = " UPDATE aqorders --- a/t/db_dependent/Acquisition.t +++ a/t/db_dependent/Acquisition.t @@ -7,8 +7,10 @@ use Modern::Perl; use POSIX qw(strftime); use C4::Bookseller qw( GetBookSellerFromId ); +use C4::Items qw (AddItem GetItem); +use C4::Branch qw (ModBranch); -use Test::More tests => 79; +use Test::More tests => 83; BEGIN { use_ok('C4::Acquisition'); @@ -925,4 +927,55 @@ is( $nonexistent_order, undef, 'GetOrder returns undef if no ordernumber is give $nonexistent_order = GetOrder( 424242424242 ); is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' ); +# +# test DelOrder +# use: +# &DelOrder($ordernumber,$biblionumber); + +# create 3 items on the same record and link 2 of them to the order +# we use the order $ordernumbers[2], which has the status 'complete' and no cancellation date before we try to delete it + +# Add a branch +my $b1 = { + add => 1, + branchcode => 'BRA', + branchname => 'BranchA', + branchaddress1 => 'adr1A', + branchaddress2 => 'adr2A', + branchaddress3 => 'adr3A', + branchzip => 'zipA', + branchcity => 'cityA', + branchstate => 'stateA', + branchcountry => 'countryA', + branchphone => 'phoneA', + branchfax => 'faxA', + branchemail => 'emailA', + branchurl => 'urlA', + branchip => 'ipA', + branchprinter => undef, + branchnotes => 'noteA', + opac_info => 'opacA' +}; +ModBranch($b1); + +my ($item_bibnum1, $item_bibitemnum1, $itemnumber1) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +my ($item_bibnum3, $item_bibitemnum3, $itemnumber3) = AddItem({ homebranch => 'BRA', holdingbranch => 'BRA' } , $biblionumber2); +NewOrderItem ($itemnumber1, $ordernumbers[2]); +NewOrderItem ($itemnumber2, $ordernumbers[2]); + +# If no ordernumber is passed, the function returns undef and does not try to update database +my $return_DelOrder = DelOrder (); +is($return_DelOrder , undef, 'DelOrder returns undef with no param'); +# Cancel the order with the given order, by filling the datecancellationprinted and orderstatus fields. +DelOrder ($ordernumbers[2],$biblionumber2); +$order3 = GetOrder( $ordernumbers[2] ); +ok(($order3->{'orderstatus'} eq 'cancelled')&& (defined $order3->{'datecancellationprinted'}),'DelOrders update orderstatus and fill datecancellationprinted fields'); + +# All the items linked with that order are deleted (in items, not in aqorders_items by the way) +ok(!defined GetItem($itemnumber1) && !defined GetItem($itemnumber2), "DelOrder deletes items linked with order in items table"); + +# Other items (created manually) are not deleted. +is(GetItem($itemnumber3)->{biblionumber},$biblionumber2, "DelOrder does not delete item created manually"); + $dbh->rollback; --