5 use Test::More tests => 6;
7 use C4::Biblio qw( AddBiblio DelBiblio );
11 use Koha::Acquisition::Bookseller;
12 use Koha::Acquisition::Order;
15 my $schema = Koha::Database->new()->schema();
16 $schema->storage->txn_begin();
18 my $dbh = C4::Context->dbh;
19 $dbh->{RaiseError} = 1;
25 my $bookseller = Koha::Acquisition::Bookseller->new(
28 address1 => "bookseller's address",
34 my $basketno = C4::Acquisition::NewBasket(
38 my $budgetid = C4::Budgets::AddBudget(
40 budget_code => "budget_code_test_close_reopen",
41 budget_name => "budget_name_test_close_reopen",
45 my $budget = C4::Budgets::GetBudget( $budgetid );
47 my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
48 my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
50 my $order1 = Koha::Acquisition::Order->new(
52 basketno => $basketno,
54 biblionumber => $biblionumber1,
55 budget_id => $budget->{budget_id},
58 my $ordernumber1 = $order1->{ordernumber};
60 my $order2 = Koha::Acquisition::Order->new(
62 basketno => $basketno,
64 biblionumber => $biblionumber2,
65 budget_id => $budget->{budget_id},
68 my $ordernumber2 = $order2->{ordernumber};
70 my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno );
71 is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
72 my @orders = C4::Acquisition::GetOrders( $basketno );
73 is( scalar(@orders), 2, "2 orders are created" );
74 is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new before closing the basket" );
76 C4::Acquisition::CloseBasket( $basketno );
77 @orders = C4::Acquisition::GetOrders( $basketno );
78 is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
80 C4::Acquisition::ReopenBasket( $basketno );
81 @orders = C4::Acquisition::GetOrders( $basketno );
82 is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" );
83 is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopen" );
85 $schema->storage->txn_rollback();