Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
3 |
# This Koha test module is a stub! |
4 |
# Add more tests here!!! |
5 |
|
6 |
use strict; |
7 |
use warnings; |
8 |
|
9 |
use C4::Bookseller qw( GetBookSellerFromId ); |
10 |
use C4::Biblio qw( AddBiblio ); |
11 |
|
12 |
use Test::More tests => 14; |
13 |
|
14 |
BEGIN { |
15 |
use_ok('C4::Acquisition'); |
16 |
} |
17 |
|
18 |
my $dbh = C4::Context->dbh; |
19 |
$dbh->{AutoCommit} = 0; |
20 |
$dbh->{RaiseError} = 1; |
21 |
|
22 |
my $booksellerid = C4::Bookseller::AddBookseller( |
23 |
{ |
24 |
name => "my vendor", |
25 |
address1 => "bookseller's address", |
26 |
phone => "0123456", |
27 |
active => 1 |
28 |
} |
29 |
); |
30 |
|
31 |
my $booksellerinfo = GetBookSellerFromId( $booksellerid ); |
32 |
my $basketno = NewBasket($booksellerid, 1); |
33 |
my $basket = GetBasket($basketno); |
34 |
|
35 |
my $budgetid = C4::Budgets::AddBudget( |
36 |
{ |
37 |
budget_code => "budget_code_test_getordersbybib", |
38 |
budget_name => "budget_name_test_getordersbybib", |
39 |
} |
40 |
); |
41 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
42 |
|
43 |
my ($ordernumber1, $ordernumber2, $ordernumber3); |
44 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
45 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
46 |
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); |
47 |
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( |
48 |
{ |
49 |
basketno => $basketno, |
50 |
quantity => 2, |
51 |
biblionumber => $biblionumber1, |
52 |
budget_id => $budget->{budget_id}, |
53 |
} |
54 |
); |
55 |
|
56 |
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( |
57 |
{ |
58 |
basketno => $basketno, |
59 |
quantity => 1, |
60 |
biblionumber => $biblionumber2, |
61 |
budget_id => $budget->{budget_id}, |
62 |
} |
63 |
); |
64 |
|
65 |
( undef, $ordernumber3 ) = C4::Acquisition::NewOrder( |
66 |
{ |
67 |
basketno => $basketno, |
68 |
quantity => 1, |
69 |
biblionumber => $biblionumber3, |
70 |
budget_id => $budget->{budget_id}, |
71 |
ecost => 42, |
72 |
rrp => 42, |
73 |
} |
74 |
); |
75 |
|
76 |
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown"); |
77 |
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown"); |
78 |
|
79 |
my ($datereceived, $new_ordernumber) = ModReceiveOrder( |
80 |
$biblionumber1, |
81 |
$ordernumber1, |
82 |
2, |
83 |
undef, |
84 |
12, |
85 |
12, |
86 |
$invoiceid1, |
87 |
42 |
88 |
); |
89 |
|
90 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
91 |
$biblionumber2, |
92 |
$ordernumber2, |
93 |
1, |
94 |
undef, |
95 |
5, |
96 |
5, |
97 |
$invoiceid2, |
98 |
42 |
99 |
); |
100 |
|
101 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
102 |
$biblionumber3, |
103 |
$ordernumber3, |
104 |
1, |
105 |
undef, |
106 |
12, |
107 |
12, |
108 |
$invoiceid2, |
109 |
42 |
110 |
); |
111 |
|
112 |
|
113 |
my $invoice1 = GetInvoiceDetails($invoiceid1); |
114 |
my $invoice2 = GetInvoiceDetails($invoiceid2); |
115 |
|
116 |
is(scalar @{$invoice1->{'orders'}}, 1, 'Invoice1 has only one order'); |
117 |
is(scalar @{$invoice2->{'orders'}}, 2, 'Invoice2 has only two orders'); |
118 |
|
119 |
my @invoices = GetInvoices(); |
120 |
cmp_ok(scalar @invoices, '>=', 2, 'GetInvoices returns at least two invoices'); |
121 |
|
122 |
@invoices = GetInvoices(invoicenumber => 'invoice2'); |
123 |
cmp_ok(scalar @invoices, '>=', 1, 'GetInvoices returns at least one invoice when a specific invoice is requested'); |
124 |
|
125 |
my $invoicesummary1 = GetInvoice($invoiceid1); |
126 |
is($invoicesummary1->{'invoicenumber'}, 'invoice1', 'GetInvoice retrieves correct invoice'); |
127 |
is($invoicesummary1->{'invoicenumber'}, $invoice1->{'invoicenumber'}, 'GetInvoice and GetInvoiceDetails retrieve same information'); |
128 |
|
129 |
ModInvoice(invoiceid => $invoiceid1, invoicenumber => 'invoice11'); |
130 |
$invoice1 = GetInvoiceDetails($invoiceid1); |
131 |
is($invoice1->{'invoicenumber'}, 'invoice11', 'ModInvoice changed invoice number'); |
132 |
|
133 |
is($invoice1->{'closedate'}, undef, 'Invoice is not closed before CloseInvoice call'); |
134 |
CloseInvoice($invoiceid1); |
135 |
$invoice1 = GetInvoiceDetails($invoiceid1); |
136 |
isnt($invoice1->{'closedate'}, undef, 'Invoice is closed after CloseInvoice call'); |
137 |
ReopenInvoice($invoiceid1); |
138 |
$invoice1 = GetInvoiceDetails($invoiceid1); |
139 |
is($invoice1->{'closedate'}, undef, 'Invoice is open after ReopenInvoice call'); |
140 |
|
141 |
|
142 |
MergeInvoices($invoiceid1, [ $invoiceid2 ]); |
143 |
|
144 |
my $mergedinvoice = GetInvoiceDetails($invoiceid1); |
145 |
is(scalar @{$mergedinvoice->{'orders'}}, 3, 'Merged invoice has three orders'); |
146 |
|
147 |
my $invoiceid3 = AddInvoice(invoicenumber => 'invoice3', booksellerid => $booksellerid, unknown => "unknown"); |
148 |
my $invoicecount = GetInvoices(); |
149 |
DelInvoice($invoiceid3); |
150 |
@invoices = GetInvoices(); |
151 |
is(scalar @invoices, $invoicecount - 1, 'DelInvoice deletes invoice'); |
152 |
is(GetInvoice($invoiceid3), undef, 'DelInvoice deleted correct invoice'); |
153 |
|
154 |
END { |
155 |
$dbh and $dbh->rollback; |
156 |
} |