3 # This Koha test module is a stub!
4 # Add more tests here!!!
7 use POSIX
qw(strftime);
9 use C4
::Bookseller
qw( GetBookSellerFromId );
11 use Test
::More tests
=> 60;
14 use_ok
('C4::Acquisition');
15 use_ok
('C4::Bookseller');
17 use_ok
('C4::Budgets');
18 use_ok
('C4::Bookseller');
21 my $dbh = C4
::Context
->dbh;
22 $dbh->{AutoCommit
} = 0;
23 $dbh->{RaiseError
} = 1;
25 my $booksellerid = C4
::Bookseller
::AddBookseller
(
28 address1
=> "bookseller's address",
35 my $booksellerinfo = C4
::Bookseller
::GetBookSellerFromId
( $booksellerid );
37 is
($booksellerinfo->{deliverytime
}, 5, 'set deliverytime when creating vendor (Bug 10556)');
39 my ($basket, $basketno);
40 ok
($basketno = NewBasket
($booksellerid, 1), "NewBasket( $booksellerid , 1 ) returns $basketno");
41 ok
($basket = GetBasket
($basketno), "GetBasket($basketno) returns $basket");
43 my $budgetid = C4
::Budgets
::AddBudget
(
45 budget_code
=> "budget_code_test_getordersbybib",
46 budget_name
=> "budget_name_test_getordersbybib",
49 my $budget = C4
::Budgets
::GetBudget
( $budgetid );
51 my ($ordernumber1, $ordernumber2, $ordernumber3);
52 my ($biblionumber1, $biblioitemnumber1) = AddBiblio
(MARC
::Record
->new, '');
53 my ($biblionumber2, $biblioitemnumber2) = AddBiblio
(MARC
::Record
->new, '');
54 ( undef, $ordernumber1 ) = C4
::Acquisition
::NewOrder
(
56 basketno
=> $basketno,
58 biblionumber
=> $biblionumber1,
59 budget_id
=> $budget->{budget_id
},
63 ( undef, $ordernumber2 ) = C4
::Acquisition
::NewOrder
(
65 basketno
=> $basketno,
67 biblionumber
=> $biblionumber2,
68 budget_id
=> $budget->{budget_id
},
72 ( undef, $ordernumber3 ) = C4
::Acquisition
::NewOrder
(
74 basketno
=> $basketno,
76 biblionumber
=> $biblionumber2,
77 budget_id
=> $budget->{budget_id
},
83 my $orders = SearchOrders
({
84 booksellerid
=> $booksellerid,
87 isa_ok
( $orders, 'ARRAY' );
88 is
(scalar(@
$orders), 3, 'retrieved 3 pending orders');
90 ok
( GetBudgetByOrderNumber
($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
92 C4
::Acquisition
::CloseBasket
( $basketno );
93 my @lateorders = GetLateOrders
(0);
94 my $order = $lateorders[0];
95 AddClaim
( $order->{ordernumber
} );
96 my $neworder = GetOrder
( $order->{ordernumber
} );
97 is
( $neworder->{claimed_date
}, strftime
( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
99 my @expectedfields = qw( basketno
107 datecancellationprinted
130 my $firstorder = $orders->[0];
131 for my $field ( @expectedfields ) {
132 ok
( exists( $firstorder->{ $field } ), "This order has a $field field" );
135 # fake receiving the order
137 ordernumber
=> $firstorder->{ordernumber
},
138 biblionumber
=> $firstorder->{biblionumber
},
139 quantityreceived
=> $firstorder->{quantity
},
141 my $pendingorders = SearchOrders
({
142 booksellerid
=> $booksellerid,
145 is
(scalar(@
$pendingorders), 2, 'retrieved 2 pending orders after receiving on one (bug 10723)');
146 my $allorders = SearchOrders
({
147 booksellerid
=> $booksellerid,
149 is
(scalar(@
$allorders), 3, 'retrieved all 3 orders even after after receiving on one (bug 10723)');
151 my $invoiceid = AddInvoice
(invoicenumber
=> 'invoice', booksellerid
=> 1, unknown
=> "unknown");
153 my ($datereceived, $new_ordernumber) = ModReceiveOrder
(
163 my $order2 = GetOrder
( $ordernumber2 );
164 is
($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
165 is
($order2->{'quantity'}, 40, '40 items on original order');
166 is
($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
168 $neworder = GetOrder
( $new_ordernumber );
169 is
($neworder->{'quantity'}, 2, '2 items on new order');
170 is
($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order');
171 is
($neworder->{'budget_id'}, $budgetid, 'Budget on new order is unchanged');
173 my $budgetid2 = C4
::Budgets
::AddBudget
(
175 budget_code
=> "budget_code_test_modrecv",
176 budget_name
=> "budget_name_test_modrecv",
180 ($datereceived, $new_ordernumber) = ModReceiveOrder
(
192 my $order3 = GetOrder
( $ordernumber3 );
193 is
($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
194 is
($order3->{'quantity'}, 2, '2 items on original order');
195 is
($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
197 $neworder = GetOrder
( $new_ordernumber );
198 is
($neworder->{'quantity'}, 2, '2 items on new order');
199 is
($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order');
200 is
($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed');
202 ($datereceived, $new_ordernumber) = ModReceiveOrder
(
214 $order3 = GetOrder
( $ordernumber3 );
215 is
($order3->{'quantityreceived'}, 2, 'Order not split up');
216 is
($order3->{'quantity'}, 2, '2 items on order');
217 is
($order3->{'budget_id'}, $budgetid2, 'Budget has changed');