|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use Test::More tests => 18; |
| 5 |
use Data::Dumper; |
| 6 |
|
| 7 |
use C4::Acquisition qw( NewOrder NewBasket GetBasketsInfosByBookseller ); |
| 8 |
use C4::Biblio qw( AddBiblio ); |
| 9 |
use C4::Bookseller qw( AddBookseller ); |
| 10 |
use C4::Budgets qw( AddBudget ); |
| 11 |
use C4::Context; |
| 12 |
my $dbh = C4::Context->dbh; |
| 13 |
$dbh->{AutoCommit} = 0; |
| 14 |
$dbh->{RaiseError} = 1; |
| 15 |
|
| 16 |
my $supplierid = C4::Bookseller::AddBookseller( |
| 17 |
{ |
| 18 |
name => 'my vendor', |
| 19 |
address1 => 'bookseller\'s address', |
| 20 |
phone => '0123456', |
| 21 |
active => 1, |
| 22 |
deliverytime => 5, |
| 23 |
} |
| 24 |
); |
| 25 |
|
| 26 |
my $basketno; |
| 27 |
ok($basketno = NewBasket($supplierid, 1), 'NewBasket( $supplierid , 1 ) returns $basketno'); |
| 28 |
|
| 29 |
my $budgetid = C4::Budgets::AddBudget( |
| 30 |
{ |
| 31 |
budget_code => 'budget_code_test_getordersbybib', |
| 32 |
budget_name => 'budget_name_test_getordersbybib', |
| 33 |
} |
| 34 |
); |
| 35 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
| 36 |
|
| 37 |
my ($ordernumber1, $ordernumber2, $ordernumber3); |
| 38 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
| 39 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
| 40 |
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); |
| 41 |
|
| 42 |
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( |
| 43 |
{ |
| 44 |
basketno => $basketno, |
| 45 |
quantity => 2, |
| 46 |
biblionumber => $biblionumber1, |
| 47 |
budget_id => $budget->{budget_id}, |
| 48 |
} |
| 49 |
); |
| 50 |
|
| 51 |
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( |
| 52 |
{ |
| 53 |
basketno => $basketno, |
| 54 |
quantity => 4, |
| 55 |
biblionumber => $biblionumber2, |
| 56 |
budget_id => $budget->{budget_id}, |
| 57 |
} |
| 58 |
); |
| 59 |
|
| 60 |
my $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); |
| 61 |
is( scalar(@$baskets), 1, 'Start: 1 basket' ); |
| 62 |
my $basket = $baskets->[0]; |
| 63 |
is( $basket->{total_items}, 6, 'Start with 6 items' ); |
| 64 |
is( $basket->{total_biblios}, 2, 'Start with 2 biblios' ); |
| 65 |
is( $basket->{total_items_cancelled}, 0, 'Start with 0 item cancelled' ); |
| 66 |
is( $basket->{total_biblios_cancelled}, 0, 'Start with 0 biblio cancelled' ); |
| 67 |
|
| 68 |
C4::Acquisition::DelOrder( $biblionumber2, $ordernumber2 ); |
| 69 |
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); |
| 70 |
is( scalar(@$baskets), 1, 'Order2 deleted, still 1 basket' ); |
| 71 |
$basket = $baskets->[0]; |
| 72 |
is( $basket->{total_items}, 6, 'Order2 deleted, still 6 items' ); |
| 73 |
is( $basket->{total_biblios}, 2, 'Order2 deleted, still 2 biblios' ); |
| 74 |
is( $basket->{total_items_cancelled}, 4, 'Order2 deleted, 4 items cancelled' ); |
| 75 |
is( $basket->{total_biblios_cancelled}, 1, 'Order2 deleted, 2 biblios cancelled' ); |
| 76 |
|
| 77 |
C4::Acquisition::DelOrder( $biblionumber1, $ordernumber1 ); |
| 78 |
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); |
| 79 |
is( scalar(@$baskets), 1, 'Both orders deleted, still 1 basket' ); |
| 80 |
$basket = $baskets->[0]; |
| 81 |
is( $basket->{total_items}, 6, 'Both orders deleted, still 6 items' ); |
| 82 |
is( $basket->{total_biblios}, 2, 'Both orders deleted, still 6 biblios' ); |
| 83 |
is( $basket->{total_items_cancelled}, 6, 'Both orders deleted, 6 items cancelled' ); |
| 84 |
is( $basket->{total_biblios_cancelled}, 2, 'Both orders deleted, 2 biblios cancelled' ); |
| 85 |
|
| 86 |
C4::Acquisition::CloseBasket( $basketno ); |
| 87 |
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid ); |
| 88 |
is( scalar(@$baskets), 0, 'Basket is closed, 0 basket opened' ); |
| 89 |
$baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid, 1 ); |
| 90 |
is( scalar(@$baskets), 1, 'Basket is closed, test allbasket parameter'); |
| 91 |
|
| 92 |
|
| 93 |
$dbh->rollback |