3d61550e22
The C4::Acquisition module should be exploded in order to add readability and maintainability to this part of the code. This patch is a POC, it introduces a new Koha::Acquisition::Order module and put in it the code from NewOrder and NewOrderItem. Test plan: 1/ Create an order, modify it, receive it, cancel the receipt. 2/ Launch the prove command on all unit tests modified by this patch and verify that all pass. Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
83 lines
2.3 KiB
Perl
83 lines
2.3 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
use Modern::Perl;
|
|
|
|
use Test::More tests => 6;
|
|
use C4::Acquisition;
|
|
use C4::Biblio qw( AddBiblio DelBiblio );
|
|
use C4::Bookseller;
|
|
use C4::Budgets;
|
|
use C4::Context;
|
|
|
|
use Koha::Acquisition::Order;
|
|
|
|
# Start transaction
|
|
my $dbh = C4::Context->dbh;
|
|
$dbh->{AutoCommit} = 0;
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
$dbh->do(q{
|
|
DELETE FROM aqorders;
|
|
});
|
|
|
|
my $booksellerid = C4::Bookseller::AddBookseller(
|
|
{
|
|
name => "my vendor",
|
|
address1 => "bookseller's address",
|
|
phone => "0123456",
|
|
active => 1
|
|
}
|
|
);
|
|
|
|
my $basketno = C4::Acquisition::NewBasket(
|
|
$booksellerid
|
|
);
|
|
|
|
my $budgetid = C4::Budgets::AddBudget(
|
|
{
|
|
budget_code => "budget_code_test_close_reopen",
|
|
budget_name => "budget_name_test_close_reopen",
|
|
}
|
|
);
|
|
|
|
my $budget = C4::Budgets::GetBudget( $budgetid );
|
|
|
|
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
|
|
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
|
|
|
|
my $order1 = Koha::Acquisition::Order->new(
|
|
{
|
|
basketno => $basketno,
|
|
quantity => 24,
|
|
biblionumber => $biblionumber1,
|
|
budget_id => $budget->{budget_id},
|
|
}
|
|
)->insert;
|
|
my $ordernumber1 = $order1->{ordernumber};
|
|
|
|
my $order2 = Koha::Acquisition::Order->new(
|
|
{
|
|
basketno => $basketno,
|
|
quantity => 42,
|
|
biblionumber => $biblionumber2,
|
|
budget_id => $budget->{budget_id},
|
|
}
|
|
)->insert;
|
|
my $ordernumber2 = $order2->{ordernumber};
|
|
|
|
my $nb_biblio = C4::Acquisition::GetBiblioCountByBasketno( $basketno );
|
|
is ( $nb_biblio, 2, "There are 2 biblio for this basket" );
|
|
my @orders = C4::Acquisition::GetOrders( $basketno );
|
|
is( scalar(@orders), 2, "2 orders are created" );
|
|
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new before closing the basket" );
|
|
|
|
C4::Acquisition::CloseBasket( $basketno );
|
|
@orders = C4::Acquisition::GetOrders( $basketno );
|
|
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 2, "2 orders are ordered, the basket is closed" );
|
|
|
|
C4::Acquisition::ReopenBasket( $basketno );
|
|
@orders = C4::Acquisition::GetOrders( $basketno );
|
|
is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" );
|
|
is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopen" );
|
|
|
|
$dbh->rollback;
|