View | Details | Raw Unified | Return to bug 26579
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-62 / +1 lines)
Lines 66-72 BEGIN { Link Here
66
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
66
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
67
        &GetBasketgroups &ReOpenBasketgroup
67
        &GetBasketgroups &ReOpenBasketgroup
68
68
69
        &DelOrder &ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber
69
        &ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber
70
        &GetOrderFromItemnumber
70
        &GetOrderFromItemnumber
71
        &SearchOrders &GetHistory &GetRecentAcqui
71
        &SearchOrders &GetHistory &GetRecentAcqui
72
        &ModReceiveOrder &CancelReceipt
72
        &ModReceiveOrder &CancelReceipt
Lines 1825-1891 sub SearchOrders { Link Here
1825
1825
1826
#------------------------------------------------------------#
1826
#------------------------------------------------------------#
1827
1827
1828
=head3 DelOrder
1829
1830
  &DelOrder($biblionumber, $ordernumber);
1831
1832
Cancel the order with the given order and biblio numbers. It does not
1833
delete any entries in the aqorders table, it merely marks them as
1834
cancelled.
1835
1836
=cut
1837
1838
sub DelOrder {
1839
    my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_;
1840
    my $error;
1841
    my $dbh = C4::Context->dbh;
1842
    my $query = "
1843
        UPDATE aqorders
1844
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1845
    ";
1846
    if($reason) {
1847
        $query .= ", cancellationreason = ? ";
1848
    }
1849
    $query .= "
1850
        WHERE biblionumber=? AND ordernumber=?
1851
    ";
1852
    my $sth = $dbh->prepare($query);
1853
    if($reason) {
1854
        $sth->execute($reason, $bibnum, $ordernumber);
1855
    } else {
1856
        $sth->execute( $bibnum, $ordernumber );
1857
    }
1858
    $sth->finish;
1859
1860
    my $order = Koha::Acquisition::Orders->find($ordernumber);
1861
    my $items = $order->items;
1862
    while ( my $item = $items->next ) { # Should be moved to Koha::Acquisition::Order->delete
1863
        my $delcheck = $item->safe_delete;
1864
1865
        if($delcheck ne '1') {
1866
            $error->{'delitem'} = 1;
1867
        }
1868
    }
1869
1870
    if($delete_biblio) {
1871
        # We get the number of remaining items
1872
        my $biblio = Koha::Biblios->find( $bibnum );
1873
        my $itemcount = $biblio->items->count;
1874
1875
        # If there are no items left,
1876
        if ( $itemcount == 0 ) {
1877
            # We delete the record
1878
            my $delcheck = DelBiblio($bibnum);
1879
1880
            if($delcheck) {
1881
                $error->{'delbiblio'} = 1;
1882
            }
1883
        }
1884
    }
1885
1886
    return $error;
1887
}
1888
1889
=head3 TransferOrder
1828
=head3 TransferOrder
1890
1829
1891
    my $newordernumber = TransferOrder($ordernumber, $basketno);
1830
    my $newordernumber = TransferOrder($ordernumber, $basketno);
(-)a/t/db_dependent/Acquisition.t (-38 / +3 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 80;
22
use Test::More tests => 66;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw(dt_from_string output_pref);
25
use Koha::DateUtils qw(dt_from_string output_pref);
Lines 292-298 for ( 0 .. 5 ) { Link Here
292
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
292
    $order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_];
293
}
293
}
294
294
295
DelOrder( $order_content[3]->{str}->{biblionumber}, $ordernumbers[3] );
295
Koha::Acquisition::Orders->find($ordernumbers[3])->cancel;
296
296
297
my $invoiceid = AddInvoice(
297
my $invoiceid = AddInvoice(
298
    invoicenumber => 'invoice',
298
    invoicenumber => 'invoice',
Lines 527-566 is( $nonexistent_order, undef, 'GetOrder returns undef if no ordernumber is give Link Here
527
$nonexistent_order = GetOrder( 424242424242 );
527
$nonexistent_order = GetOrder( 424242424242 );
528
is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' );
528
is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' );
529
529
530
# Tests for DelOrder
531
$order1 = GetOrder($ordernumbers[0]);
532
my $error = DelOrder($order1->{biblionumber}, $order1->{ordernumber});
533
ok((not defined $error), "DelOrder does not fail");
534
$order1 = GetOrder($order1->{ordernumber});
535
ok((defined $order1->{datecancellationprinted}), "order is cancelled");
536
ok((not defined $order1->{cancellationreason}), "order has no cancellation reason");
537
ok((defined Koha::Biblios->find( $order1->{biblionumber} )), "biblio still exists");
538
539
$order2 = GetOrder($ordernumbers[1]);
540
$error = DelOrder($order2->{biblionumber}, $order2->{ordernumber}, 1);
541
ok((not defined $error), "DelOrder does not fail");
542
$order2 = GetOrder($order2->{ordernumber});
543
ok((defined $order2->{datecancellationprinted}), "order is cancelled");
544
ok((not defined $order2->{cancellationreason}), "order has no cancellation reason");
545
ok((not defined Koha::Biblios->find( $order2->{biblionumber} )), "biblio does not exist anymore");
546
547
my $order4 = GetOrder($ordernumbers[3]);
548
$error = DelOrder($order4->{biblionumber}, $order4->{ordernumber}, 1, "foobar");
549
ok((not defined $error), "DelOrder does not fail");
550
$order4 = GetOrder($order4->{ordernumber});
551
ok((defined $order4->{datecancellationprinted}), "order is cancelled");
552
ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
553
ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore");
554
555
my $order5 = GetOrder($ordernumbers[4]);
556
Koha::Item->new({ barcode => '0102030405', biblionumber => $order5->{biblionumber} })->store;
557
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
558
$order5 = GetOrder($order5->{ordernumber});
559
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
560
ok((defined Koha::Biblios->find( $order5->{biblionumber} )), "biblio still exists");
561
562
# End of tests for DelOrder
563
564
subtest 'ModOrder' => sub {
530
subtest 'ModOrder' => sub {
565
    plan tests => 1;
531
    plan tests => 1;
566
    ModOrder( { ordernumber => $order1->{ordernumber}, unitprice => 42 } );
532
    ModOrder( { ordernumber => $order1->{ordernumber}, unitprice => 42 } );
Lines 640-647 sub run_flavoured_tests { Link Here
640
    $orders = GetHistory( isbn => '0136019706' );
606
    $orders = GetHistory( isbn => '0136019706' );
641
    is( scalar(@$orders), 1, "GetHistory searches correctly by ISBN" );
607
    is( scalar(@$orders), 1, "GetHistory searches correctly by ISBN" );
642
608
643
    my $order = GetOrder($ordernumber);
609
    Koha::Acquisition::Orders->find($ordernumber)->cancel;
644
    DelOrder($order->{biblionumber}, $order->{ordernumber}, 1);
645
}
610
}
646
611
647
# Do "flavoured" tests
612
# Do "flavoured" tests
(-)a/t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t (-2 / +2 lines)
Lines 83-89 $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); Link Here
83
$basket = $baskets->[0];
83
$basket = $baskets->[0];
84
is( $basket->{uncertainprices}, 0, "Uncertain prcies returns number of uncertain items");
84
is( $basket->{uncertainprices}, 0, "Uncertain prcies returns number of uncertain items");
85
85
86
C4::Acquisition::DelOrder( $biblionumber2, $ordernumber2 );
86
Koha::Acquisition::Orders->find($ordernumber2)->cancel;
87
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
87
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
88
is( scalar(@$baskets), 1, 'Order2 deleted, still 1 basket' );
88
is( scalar(@$baskets), 1, 'Order2 deleted, still 1 basket' );
89
$basket = $baskets->[0];
89
$basket = $baskets->[0];
Lines 93-99 is( $basket->{total_items_cancelled}, 4, 'Order2 deleted, 4 items cancelled' ); Link Here
93
is( $basket->{expected_items}, 2, 'Order2 deleted, now 2 items are expected' );
93
is( $basket->{expected_items}, 2, 'Order2 deleted, now 2 items are expected' );
94
is( $basket->{total_biblios_cancelled}, 1, 'Order2 deleted, 1 biblios cancelled' );
94
is( $basket->{total_biblios_cancelled}, 1, 'Order2 deleted, 1 biblios cancelled' );
95
95
96
C4::Acquisition::DelOrder( $biblionumber1, $ordernumber1 );
96
Koha::Acquisition::Orders->find($ordernumber1)->cancel;
97
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
97
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid );
98
is( scalar(@$baskets), 1, 'Both orders deleted, still 1 basket' );
98
is( scalar(@$baskets), 1, 'Both orders deleted, still 1 basket' );
99
$basket = $baskets->[0];
99
$basket = $baskets->[0];
(-)a/t/db_dependent/Acquisition/close_reopen_basket.t (-3 / +2 lines)
Lines 81-90 C4::Acquisition::ReopenBasket( $basketno ); Link Here
81
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order is ordered, the basket is reopened" );
81
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order is ordered, the basket is reopened" );
82
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopened" );
82
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopened" );
83
83
84
C4::Acquisition::DelOrder( $biblionumber1, $ordernumber1 );
84
Koha::Acquisition::Orders->find($ordernumber1)->cancel;
85
my ( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
85
my ( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
86
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
86
is( $order->{ordernumber}, $ordernumber1, 'The order returned by GetOrders should have been the right one' );
87
is( $order->{orderstatus}, 'cancelled', 'DelOrder should have set status to cancelled' );
87
is( $order->{orderstatus}, 'cancelled', 'cancelling the order should have set status to cancelled' );
88
88
89
C4::Acquisition::CloseBasket( $basketno );
89
C4::Acquisition::CloseBasket( $basketno );
90
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
90
( $order ) = C4::Acquisition::GetOrders( $basketno, {cancelled => 1} );
91
- 

Return to bug 26579