Lines 8-14
use POSIX qw(strftime);
Link Here
|
8 |
|
8 |
|
9 |
use C4::Bookseller qw( GetBookSellerFromId ); |
9 |
use C4::Bookseller qw( GetBookSellerFromId ); |
10 |
|
10 |
|
11 |
use Test::More tests => 60; |
11 |
use Test::More tests => 64; |
12 |
|
12 |
|
13 |
BEGIN { |
13 |
BEGIN { |
14 |
use_ok('C4::Acquisition'); |
14 |
use_ok('C4::Acquisition'); |
Lines 18-27
BEGIN {
Link Here
|
18 |
use_ok('C4::Bookseller'); |
18 |
use_ok('C4::Bookseller'); |
19 |
} |
19 |
} |
20 |
|
20 |
|
|
|
21 |
# Sub used for testing C4::Acquisition subs returning order(s) : GetOrdersByStatus,GetOrders, GetDeletedOrders, GetOrder etc. |
22 |
# (\@test_missing_fields,\@test_extra_fields,\@test_different_fields,$test_nbr_fields) = _check_fields_of_order ($exp_fields, $original_order_content, $order_to_check); |
23 |
# params : |
24 |
# $exp_fields : arrayref whose elements are the keys we expect to find |
25 |
# $original_order_content : hashref whose 2 keys str and num contains hashrefs containing content fields of the order created with NewOrder |
26 |
# $order_to_check : hashref whose keys/values are the content of an order returned by the C4::Acquisition sub we are testing |
27 |
# returns : |
28 |
# \@test_missing_fields : arrayref void if ok ; otherwise contains the list of fields missing in $order_to_check |
29 |
# \@test_extra_fields : arrayref void if ok ; otherwise contains the list of fields unexpected in $order_to_check |
30 |
# \@test_different_fields : arrayref void if ok ; otherwise contains the list of fields which value is not the same in between $order_to_check and |
31 |
# $test_nbr_fields : contains the number of fields of $order_to_check |
32 |
|
33 |
sub _check_fields_of_order { |
34 |
my ($exp_fields, $original_order_content, $order_to_check) = @_; |
35 |
my @test_missing_fields = (); |
36 |
my @test_extra_fields = (); |
37 |
my @test_different_fields = (); |
38 |
my $test_nbr_fields = scalar (keys %$order_to_check); |
39 |
foreach my $field ( @$exp_fields ) { |
40 |
push @test_missing_fields, $field unless exists( $order_to_check->{ $field }); |
41 |
} |
42 |
foreach my $field ( keys %$order_to_check) { |
43 |
push @test_extra_fields, $field unless grep (/^$field$/, @$exp_fields); |
44 |
} |
45 |
foreach my $field ( keys %{$original_order_content->{str}}) { |
46 |
push @test_different_fields, $field unless (! exists $order_to_check->{ $field }) or ($original_order_content->{str}->{$field} eq $order_to_check->{ $field }); |
47 |
} |
48 |
foreach my $field ( keys %{$original_order_content->{num}}) { |
49 |
push @test_different_fields, $field unless (! exists $order_to_check->{ $field }) or ($original_order_content->{num}->{$field} == $order_to_check->{ $field }); |
50 |
} |
51 |
return ( \@test_missing_fields,\@test_extra_fields,\@test_different_fields,$test_nbr_fields); |
52 |
} |
53 |
|
54 |
# Sub used for testing C4::Acquisition subs returning several orders |
55 |
# (\@test_missing_fields,\@test_extra_fields,\@test_different_fields,\@test_nbr_fields) = _check_fields_of_orders ($exp_fields, $original_orders_content, $orders_to_check) |
56 |
sub _check_fields_of_orders { |
57 |
my ($exp_fields, $original_orders_content, $orders_to_check) = @_; |
58 |
my @test_missing_fields = (); |
59 |
my @test_extra_fields = (); |
60 |
my @test_different_fields = (); |
61 |
my @test_nbr_fields = (); |
62 |
foreach my $order_to_check (@$orders_to_check ) { |
63 |
my $original_order_content = (grep {$_->{str}->{ordernumber} eq $order_to_check-> {ordernumber}} @$original_orders_content)[0]; |
64 |
my ($t_missing_fields,$t_extra_fields,$t_different_fields,$t_nbr_fields) = _check_fields_of_order ($exp_fields,$original_order_content,$order_to_check); |
65 |
push @test_missing_fields, @$t_missing_fields; |
66 |
push @test_extra_fields, @$t_extra_fields; |
67 |
push @test_different_fields, @$t_different_fields; |
68 |
push @test_nbr_fields, $t_nbr_fields; |
69 |
} |
70 |
@test_missing_fields = keys %{{map {$_ => 1} @test_missing_fields}}; |
71 |
@test_extra_fields = keys %{{map {$_ => 1} @test_extra_fields}}; |
72 |
@test_different_fields = keys %{{map {$_ => 1} @test_different_fields}}; |
73 |
return (\@test_missing_fields,\@test_extra_fields,\@test_different_fields,\@test_nbr_fields); |
74 |
} |
75 |
|
21 |
my $dbh = C4::Context->dbh; |
76 |
my $dbh = C4::Context->dbh; |
22 |
$dbh->{AutoCommit} = 0; |
77 |
$dbh->{AutoCommit} = 0; |
23 |
$dbh->{RaiseError} = 1; |
78 |
$dbh->{RaiseError} = 1; |
24 |
|
79 |
|
|
|
80 |
# Creating some orders |
25 |
my $booksellerid = C4::Bookseller::AddBookseller( |
81 |
my $booksellerid = C4::Bookseller::AddBookseller( |
26 |
{ |
82 |
{ |
27 |
name => "my vendor", |
83 |
name => "my vendor", |
Lines 48-136
my $budgetid = C4::Budgets::AddBudget(
Link Here
|
48 |
); |
104 |
); |
49 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
105 |
my $budget = C4::Budgets::GetBudget( $budgetid ); |
50 |
|
106 |
|
51 |
my ($ordernumber1, $ordernumber2, $ordernumber3); |
107 |
my @ordernumbers; |
52 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
108 |
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); |
53 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
109 |
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); |
54 |
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder( |
110 |
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); |
55 |
{ |
111 |
my ($biblionumber4, $biblioitemnumber4) = AddBiblio(MARC::Record->new, ''); |
|
|
112 |
|
113 |
|
114 |
# |
115 |
# Test NewOrder |
116 |
# |
117 |
|
118 |
my ($mandatoryparams, $return_error,$basketnum); |
119 |
|
120 |
# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing |
121 |
eval {($basketnum, $ordernumbers[0] ) = C4::Acquisition::NewOrder()}; |
122 |
$return_error = $@; |
123 |
ok ((!(defined $basketnum || defined $ordernumbers[0])) && (defined $return_error),"NewOrder with no params returns undef and croaks"); |
124 |
|
125 |
$mandatoryparams = { |
126 |
basketno => $basketno, |
127 |
quantity => 24, |
128 |
biblionumber => $biblionumber1, |
129 |
budget_id => $budget->{budget_id}, |
130 |
}; |
131 |
my @mandatoryparams_keys = keys %$mandatoryparams; |
132 |
foreach my $mandatoryparams_key (@mandatoryparams_keys) { |
133 |
my %test_missing_mandatoryparams = %$mandatoryparams; |
134 |
delete $test_missing_mandatoryparams {$mandatoryparams_key}; |
135 |
eval {($basketnum, $ordernumbers[0] ) = C4::Acquisition::NewOrder(\%test_missing_mandatoryparams)}; |
136 |
$return_error = $@; |
137 |
my $expected_error = "Mandatory parameter $mandatoryparams_key missing"; |
138 |
ok ((!(defined $basketnum || defined $ordernumbers[0])) && ( index ($return_error, $expected_error) >=0 ),"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message"); |
139 |
} |
140 |
|
141 |
# FIXME to do : test the other features of NewOrder |
142 |
|
143 |
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with == |
144 |
# Ex : a price of 50.1 will be stored internally as 5.100000 |
145 |
|
146 |
my @order_content = ( |
147 |
{str => { |
56 |
basketno => $basketno, |
148 |
basketno => $basketno, |
57 |
quantity => 24, |
|
|
58 |
biblionumber => $biblionumber1, |
149 |
biblionumber => $biblionumber1, |
59 |
budget_id => $budget->{budget_id}, |
150 |
budget_id => $budget->{budget_id}, |
60 |
} |
151 |
uncertainprice=>0, |
61 |
); |
152 |
notes=>"some notes", |
62 |
|
153 |
}, |
63 |
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder( |
154 |
num => { |
64 |
{ |
155 |
quantity => 24, |
|
|
156 |
listprice=>50.121111, |
157 |
ecost => 38.15, |
158 |
rrp => 40.15, |
159 |
discount =>5.1111, |
160 |
gstrate=>0.0515 |
161 |
}}, |
162 |
{str => { |
65 |
basketno => $basketno, |
163 |
basketno => $basketno, |
66 |
quantity => 42, |
|
|
67 |
biblionumber => $biblionumber2, |
164 |
biblionumber => $biblionumber2, |
68 |
budget_id => $budget->{budget_id}, |
165 |
budget_id => $budget->{budget_id} |
69 |
} |
166 |
}, |
70 |
); |
167 |
num => { |
71 |
|
168 |
quantity => 42 |
72 |
( undef, $ordernumber3 ) = C4::Acquisition::NewOrder( |
169 |
}}, |
73 |
{ |
170 |
{str => { |
74 |
basketno => $basketno, |
171 |
basketno => $basketno, |
75 |
quantity => 4, |
|
|
76 |
biblionumber => $biblionumber2, |
172 |
biblionumber => $biblionumber2, |
77 |
budget_id => $budget->{budget_id}, |
173 |
budget_id => $budget->{budget_id}, |
78 |
ecost => 42, |
174 |
uncertainprice=>0, |
|
|
175 |
notes=>"ordernotes" |
176 |
}, |
177 |
num =>{ |
178 |
quantity => 4, |
179 |
ecost => 42.1, |
180 |
rrp => 42.1, |
181 |
listprice=>10.1, |
182 |
ecost => 38.1, |
183 |
rrp => 11.0, |
184 |
discount =>5.1, |
185 |
gstrate=>0.1 |
186 |
}}, |
187 |
{str =>{ |
188 |
basketno => $basketno, |
189 |
biblionumber => $biblionumber3, |
190 |
budget_id => $budget->{budget_id}, |
191 |
notes=>"ordernotes" |
192 |
}, |
193 |
num => { |
194 |
quantity => 4, |
195 |
ecost => 40, |
79 |
rrp => 42, |
196 |
rrp => 42, |
80 |
} |
197 |
listprice=>10, |
|
|
198 |
ecost => 38.15, |
199 |
rrp => 11.00, |
200 |
discount =>0, |
201 |
uncertainprice=>0, |
202 |
gstrate=>0 |
203 |
}}, |
204 |
{str =>{ |
205 |
basketno => $basketno, |
206 |
biblionumber => $biblionumber4, |
207 |
budget_id => $budget->{budget_id}, |
208 |
notes=>"ordernotes" |
209 |
}, |
210 |
num => { |
211 |
quantity => 1, |
212 |
ecost => 10, |
213 |
rrp => 10, |
214 |
listprice=>10, |
215 |
ecost => 10, |
216 |
rrp => 10, |
217 |
discount =>0, |
218 |
uncertainprice=>0, |
219 |
gstrate=>0 |
220 |
}} |
221 |
); |
222 |
|
223 |
# Create 4 orders in database |
224 |
for (0..4) { |
225 |
my %ocontent ; |
226 |
@ocontent { keys %{$order_content[$_]->{num}} } = values %{$order_content[$_]->{num}}; |
227 |
@ocontent { keys %{$order_content[$_]->{str}} } = values %{$order_content[$_]->{str}}; |
228 |
( undef, $ordernumbers[$_] ) = C4::Acquisition::NewOrder(\%ocontent); |
229 |
$order_content[$_]->{str}->{ordernumber} = $ordernumbers[$_]; |
230 |
} |
231 |
|
232 |
|
233 |
# Test UT sub _check_fields_of_order |
234 |
|
235 |
my ($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_order ([qw /a b c d e/], {str=>{a=>"bla",b=>"105"},num=>{c=>15.12}}, {a=>"blabla",f=>"f",b=>"105",c=>15.1200,g=>''}); |
236 |
ok ((($test_nbr_fields == 5) and (join (" ",sort @$test_missing_fields) eq 'd e') and (join (" ",sort @$test_extra_fields) eq 'f g') and (join(" ",@$test_different_fields) eq 'a')), "_check_fields_of_order can check an order (test 1)"); |
237 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_order ([qw /a b c /], {str=>{a=>"bla",b=>"105"},num=>{c=>15.00}}, {a=>"bla",b=>"105",c=>15}); |
238 |
ok ((($test_nbr_fields == 3) and (scalar @$test_missing_fields == 0) and (scalar @$test_extra_fields == 0) and (scalar @$test_different_fields == 0)) , "_check_fields_of_order can check an order (test 2)"); |
239 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_order ([qw /a b c d e/], {str=>{a=>"bla",b=>"105"},num=>{c=>15.12}}, {a=>"blabla",b=>"105",c=>15,d=>"error"}); |
240 |
ok ((($test_nbr_fields == 4) and (join (" ",sort @$test_missing_fields) eq 'e') and (scalar @$test_extra_fields == 0) and (join(" ",@$test_different_fields) eq 'a c')) , "_check_fields_of_order can check an order (test 3)"); |
241 |
|
242 |
|
243 |
# |
244 |
# test GetOrder |
245 |
# |
246 |
|
247 |
my @expectedfields = qw( |
248 |
ordernumber |
249 |
biblionumber |
250 |
entrydate |
251 |
quantity |
252 |
currency |
253 |
listprice |
254 |
totalamount |
255 |
datereceived |
256 |
invoiceid |
257 |
freight |
258 |
unitprice |
259 |
quantityreceived |
260 |
cancelledby |
261 |
datecancellationprinted |
262 |
notes |
263 |
supplierreference |
264 |
purchaseordernumber |
265 |
basketno |
266 |
timestamp |
267 |
rrp |
268 |
ecost |
269 |
unitpricesupplier |
270 |
unitpricelib |
271 |
gstrate |
272 |
discount |
273 |
budget_id |
274 |
budgetgroup_id |
275 |
budgetdate |
276 |
sort1 |
277 |
sort2 |
278 |
sort1_authcat |
279 |
sort2_authcat |
280 |
uncertainprice |
281 |
claims_count |
282 |
claimed_date |
283 |
subscriptionid |
284 |
parent_ordernumber |
285 |
orderstatus |
286 |
title |
287 |
author |
288 |
basketname |
289 |
branchcode |
290 |
publicationyear |
291 |
copyrightdate |
292 |
editionstatement |
293 |
isbn |
294 |
ean |
295 |
seriestitle |
296 |
publishercode |
297 |
publisher |
298 |
budget |
299 |
supplier |
300 |
supplierid |
301 |
estimateddeliverydate |
302 |
orderdate |
303 |
quantity_to_receive |
304 |
subtotal |
305 |
latesince |
306 |
); |
307 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_order (\@expectedfields , $order_content[0], GetOrder($ordernumbers[0])); |
308 |
is($test_nbr_fields,scalar @expectedfields , "GetOrder gets an order with the right number of fields" ); |
309 |
is(join (" ",@$test_missing_fields),'', "GetOrder gets an order with no missing fields" ); |
310 |
is(join (" ",@$test_extra_fields),'', "GetOrder gets an order with no unexpected fields" ); |
311 |
is(join (" ",@$test_different_fields),'', "GetOrder gets an order with the right content in every fields" ); |
312 |
|
313 |
# |
314 |
# Test GetOrders |
315 |
# |
316 |
|
317 |
my @base_expectedfields = qw( |
318 |
ordernumber |
319 |
ecost |
320 |
uncertainprice |
321 |
marc |
322 |
cancelledby |
323 |
url |
324 |
isbn |
325 |
copyrightdate |
326 |
serial |
327 |
cn_suffix |
328 |
cn_item |
329 |
marcxml |
330 |
freight |
331 |
cn_class |
332 |
title |
333 |
pages |
334 |
budget_encumb |
335 |
budget_name |
336 |
number |
337 |
itemtype |
338 |
totalissues |
339 |
author |
340 |
budget_permission |
341 |
parent_ordernumber |
342 |
size |
343 |
claims_count |
344 |
currency |
345 |
seriestitle |
346 |
timestamp |
347 |
editionstatement |
348 |
budget_parent_id |
349 |
publishercode |
350 |
unitprice |
351 |
collectionvolume |
352 |
budget_amount |
353 |
budget_owner_id |
354 |
datecreated |
355 |
claimed_date |
356 |
subscriptionid |
357 |
editionresponsibility |
358 |
sort2 |
359 |
notes |
360 |
volumedate |
361 |
budget_id |
362 |
illus |
363 |
ean |
364 |
biblioitemnumber |
365 |
datereceived |
366 |
orderstatus |
367 |
supplierreference |
368 |
agerestriction |
369 |
budget_branchcode |
370 |
gstrate |
371 |
listprice |
372 |
budget_code |
373 |
budgetdate |
374 |
basketno |
375 |
discount |
376 |
abstract |
377 |
collectionissn |
378 |
publicationyear |
379 |
collectiontitle |
380 |
invoiceid |
381 |
budgetgroup_id |
382 |
place |
383 |
issn |
384 |
quantityreceived |
385 |
entrydate |
386 |
cn_source |
387 |
sort1_authcat |
388 |
budget_notes |
389 |
biblionumber |
390 |
unititle |
391 |
sort2_authcat |
392 |
budget_expend |
393 |
rrp |
394 |
cn_sort |
395 |
totalamount |
396 |
lccn |
397 |
sort1 |
398 |
volume |
399 |
purchaseordernumber |
400 |
quantity |
401 |
budget_period_id |
402 |
frameworkcode |
403 |
volumedesc |
404 |
datecancellationprinted |
405 |
); |
406 |
@expectedfields = (@base_expectedfields, ('transferred_from_timestamp','transferred_from')); |
407 |
is(GetOrders(),undef,"GetOrders with no params returns undef"); |
408 |
DelOrder ($order_content[3]->{str}->{biblionumber},$ordernumbers[3]); |
409 |
my @get_orders = GetOrders($basketno); |
410 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, \@get_orders); |
411 |
is($$test_nbr_fields [0],scalar @expectedfields , "GetOrders gets orders with the right number of fields" ); |
412 |
is(join (" ",@$test_missing_fields),'', "GetOrders gets orders with no missing fields" ); |
413 |
is(join (" ",@$test_extra_fields),'', "GetOrders gets orders with no unexpected fields" ); |
414 |
is(join (" ",@$test_different_fields),'', "GetOrders gets orders with the right content in every fields" ); |
415 |
ok(((scalar @get_orders == 4) and !grep ($_->{ordernumber} eq $ordernumbers[3], @get_orders)),"GetOrders only gets non-cancelled orders" ); |
416 |
|
417 |
# |
418 |
# Test GetCancelledOrders |
419 |
# |
420 |
|
421 |
@expectedfields = (@base_expectedfields, ('transferred_to_timestamp','transferred_to')); |
422 |
is(GetCancelledOrders(),undef,"GetCancelledOrders with no params returns undef"); |
423 |
@get_orders = GetCancelledOrders($basketno); |
424 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, \@get_orders); |
425 |
is($$test_nbr_fields [0],scalar @expectedfields , "GetCancelledOrders gets orders with the right number of fields" ); |
426 |
is(join (" ",@$test_missing_fields),'', "GetCancelledOrders gets orders with no missing fields" ); |
427 |
is(join (" ",@$test_extra_fields),'', "GetCancelledOrders gets orders with no unexpected fields" ); |
428 |
is(join (" ",@$test_different_fields),'', "GetCancelledOrders gets orders with the right content in every fields" ); |
429 |
ok(((scalar @get_orders == 1) and grep ($_->{ordernumber} eq $ordernumbers[3], @get_orders)),"GetCancelledOrders only gets cancelled orders" ); |
430 |
|
431 |
# |
432 |
# Test SearchOrders |
433 |
# |
434 |
|
435 |
@expectedfields = qw ( |
436 |
firstname |
437 |
biblioitemnumber |
438 |
ecost |
439 |
uncertainprice |
440 |
creationdate |
441 |
datereceived |
442 |
orderstatus |
443 |
supplierreference |
444 |
cancelledby |
445 |
isbn |
446 |
copyrightdate |
447 |
gstrate |
448 |
serial |
449 |
listprice |
450 |
budgetdate |
451 |
basketno |
452 |
discount |
453 |
surname |
454 |
freight |
455 |
abstract |
456 |
title |
457 |
closedate |
458 |
basketname |
459 |
budgetgroup_id |
460 |
invoiceid |
461 |
author |
462 |
parent_ordernumber |
463 |
claims_count |
464 |
entrydate |
465 |
currency |
466 |
quantityreceived |
467 |
seriestitle |
468 |
sort1_authcat |
469 |
timestamp |
470 |
biblionumber |
471 |
unititle |
472 |
sort2_authcat |
473 |
rrp |
474 |
unitprice |
475 |
totalamount |
476 |
sort1 |
477 |
ordernumber |
478 |
datecreated |
479 |
purchaseordernumber |
480 |
quantity |
481 |
claimed_date |
482 |
subscriptionid |
483 |
frameworkcode |
484 |
sort2 |
485 |
notes |
486 |
datecancellationprinted |
487 |
budget_id |
81 |
); |
488 |
); |
82 |
|
489 |
|
83 |
my $orders = SearchOrders({ |
490 |
my $invoiceid = AddInvoice( |
|
|
491 |
invoicenumber => 'invoice', |
84 |
booksellerid => $booksellerid, |
492 |
booksellerid => $booksellerid, |
|
|
493 |
unknown => "unknown" |
494 |
); |
495 |
|
496 |
my ($datereceived, $new_ordernumber) = ModReceiveOrder( |
497 |
$biblionumber4, |
498 |
$ordernumbers[4], |
499 |
1, |
500 |
undef, |
501 |
10, |
502 |
10, |
503 |
$invoiceid, |
504 |
10, |
505 |
$order_content[4]->{str}->{budget_id} |
506 |
); |
507 |
|
508 |
my $search_orders = SearchOrders({ |
509 |
booksellerid => $booksellerid, |
510 |
basketno => $basketno |
511 |
}); |
512 |
isa_ok( $search_orders, 'ARRAY' ); |
513 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, $search_orders ); |
514 |
is($$test_nbr_fields [0],scalar @expectedfields , "SearchOrders gets orders with the right number of fields" ); |
515 |
is(join (" ",@$test_missing_fields),'', "SearchOrders gets orders with no missing fields" ); |
516 |
is(join (" ",@$test_extra_fields),'', "SearchOrders gets orders with no unexpected fields" ); |
517 |
is(join (" ",@$test_different_fields),'', "SearchOrders gets orders with the right content in every fields" ); |
518 |
ok(((scalar @$search_orders == 4) and !grep ($_->{ordernumber} eq $ordernumbers[3], @$search_orders)),"SearchOrders only gets non-cancelled orders" ); |
519 |
|
520 |
$search_orders = SearchOrders({ |
521 |
booksellerid => $booksellerid, |
522 |
basketno => $basketno, |
85 |
pending => 1 |
523 |
pending => 1 |
86 |
}); |
524 |
}); |
87 |
isa_ok( $orders, 'ARRAY' ); |
525 |
ok(((scalar @$search_orders == 3) and !grep ((($_->{ordernumber} eq $ordernumbers[3]) or ($_->{ordernumber} eq $ordernumbers[4])), @$search_orders)),"SearchOrders with pending params gets only pending orders" ); |
88 |
is(scalar(@$orders), 3, 'retrieved 3 pending orders'); |
526 |
|
|
|
527 |
# |
528 |
# Test GetBudgetByOrderNumber |
529 |
# |
89 |
|
530 |
|
90 |
ok( GetBudgetByOrderNumber($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" ); |
531 |
ok( GetBudgetByOrderNumber($ordernumbers[0])->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" ); |
91 |
|
532 |
|
92 |
C4::Acquisition::CloseBasket( $basketno ); |
533 |
|
|
|
534 |
# |
535 |
# Test GetLateOrders |
536 |
# |
537 |
|
538 |
@expectedfields = qw ( |
539 |
orderdate |
540 |
author |
541 |
budget |
542 |
supplierid |
543 |
claims_count |
544 |
supplier |
545 |
publisher |
546 |
ordernumber |
547 |
quantity |
548 |
basketno |
549 |
claimed_date |
550 |
branch |
551 |
estimateddeliverydate |
552 |
title |
553 |
publicationyear |
554 |
unitpricelib |
555 |
unitpricesupplier |
556 |
subtotal |
557 |
latesince |
558 |
); |
93 |
my @lateorders = GetLateOrders(0); |
559 |
my @lateorders = GetLateOrders(0); |
|
|
560 |
is(scalar grep ($_->{basketno} eq $basketno, @lateorders),0, "GetLateOrders does not get orders from opened baskets" ); |
561 |
C4::Acquisition::CloseBasket( $basketno ); |
562 |
@lateorders = GetLateOrders(0); |
563 |
isnt(scalar grep ($_->{basketno} eq $basketno, @lateorders),0, "GetLateOrders gets orders from closed baskets" ); |
564 |
ok(!grep ($_->{ordernumber} eq $ordernumbers[3], @lateorders),"GetLateOrders does not gets cancelled orders" ); |
565 |
ok(!grep ($_->{ordernumber} eq $ordernumbers[4], @lateorders),"GetLateOrders does not gets reveived orders" ); |
566 |
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, \@lateorders ); |
567 |
is($$test_nbr_fields [0],scalar @expectedfields , "GetLateOrders gets orders with the right number of fields" ); |
568 |
is(join (" ",@$test_missing_fields),'', "GetLateOrders gets orders with no missing fields" ); |
569 |
is(join (" ",@$test_extra_fields),'', "GetLateOrders gets orders with no unexpected fields" ); |
570 |
is(join (" ",@$test_different_fields),'', "GetLateOrders gets orders with the right content in every fields" ); |
571 |
|
572 |
# |
573 |
# Test AddClaim |
574 |
# |
575 |
|
94 |
my $order = $lateorders[0]; |
576 |
my $order = $lateorders[0]; |
95 |
AddClaim( $order->{ordernumber} ); |
577 |
AddClaim( $order->{ordernumber} ); |
96 |
my $neworder = GetOrder( $order->{ordernumber} ); |
578 |
my $neworder = GetOrder( $order->{ordernumber} ); |
97 |
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" ); |
579 |
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" ); |
98 |
|
580 |
|
99 |
my @expectedfields = qw( basketno |
581 |
my $firstorder = $search_orders->[0]; |
100 |
biblionumber |
|
|
101 |
invoiceid |
102 |
budgetdate |
103 |
cancelledby |
104 |
closedate |
105 |
creationdate |
106 |
currency |
107 |
datecancellationprinted |
108 |
datereceived |
109 |
ecost |
110 |
entrydate |
111 |
firstname |
112 |
freight |
113 |
gstrate |
114 |
listprice |
115 |
notes |
116 |
ordernumber |
117 |
purchaseordernumber |
118 |
quantity |
119 |
quantityreceived |
120 |
rrp |
121 |
sort1 |
122 |
sort2 |
123 |
subscriptionid |
124 |
supplierreference |
125 |
surname |
126 |
timestamp |
127 |
title |
128 |
totalamount |
129 |
unitprice ); |
130 |
my $firstorder = $orders->[0]; |
131 |
for my $field ( @expectedfields ) { |
132 |
ok( exists( $firstorder->{ $field } ), "This order has a $field field" ); |
133 |
} |
134 |
|
582 |
|
135 |
# fake receiving the order |
583 |
# fake receiving the order |
136 |
ModOrder({ |
584 |
ModOrder({ |
Lines 138-162
ModOrder({
Link Here
|
138 |
biblionumber => $firstorder->{biblionumber}, |
586 |
biblionumber => $firstorder->{biblionumber}, |
139 |
quantityreceived => $firstorder->{quantity}, |
587 |
quantityreceived => $firstorder->{quantity}, |
140 |
}); |
588 |
}); |
141 |
my $pendingorders = SearchOrders({ |
|
|
142 |
booksellerid => $booksellerid, |
143 |
pending => 1 |
144 |
}); |
145 |
is(scalar(@$pendingorders), 2, 'retrieved 2 pending orders after receiving on one (bug 10723)'); |
146 |
my $allorders = SearchOrders({ |
147 |
booksellerid => $booksellerid, |
148 |
}); |
149 |
is(scalar(@$allorders), 3, 'retrieved all 3 orders even after after receiving on one (bug 10723)'); |
150 |
|
589 |
|
151 |
my $invoiceid = AddInvoice( |
590 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
152 |
invoicenumber => 'invoice', |
|
|
153 |
booksellerid => $booksellerid, |
154 |
unknown => "unknown" |
155 |
); |
156 |
|
157 |
my ($datereceived, $new_ordernumber) = ModReceiveOrder( |
158 |
$biblionumber2, |
591 |
$biblionumber2, |
159 |
$ordernumber2, |
592 |
$ordernumbers[1], |
160 |
2, |
593 |
2, |
161 |
undef, |
594 |
undef, |
162 |
12, |
595 |
12, |
Lines 164-170
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
Link Here
|
164 |
$invoiceid, |
597 |
$invoiceid, |
165 |
42, |
598 |
42, |
166 |
); |
599 |
); |
167 |
my $order2 = GetOrder( $ordernumber2 ); |
600 |
my $order2 = GetOrder( $ordernumbers[1] ); |
168 |
is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); |
601 |
is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); |
169 |
is($order2->{'quantity'}, 40, '40 items on original order'); |
602 |
is($order2->{'quantity'}, 40, '40 items on original order'); |
170 |
is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); |
603 |
is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); |
Lines 183-189
my $budgetid2 = C4::Budgets::AddBudget(
Link Here
|
183 |
|
616 |
|
184 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
617 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
185 |
$biblionumber2, |
618 |
$biblionumber2, |
186 |
$ordernumber3, |
619 |
$ordernumbers[2], |
187 |
2, |
620 |
2, |
188 |
undef, |
621 |
undef, |
189 |
12, |
622 |
12, |
Lines 193-199
my $budgetid2 = C4::Budgets::AddBudget(
Link Here
|
193 |
$budgetid2 |
626 |
$budgetid2 |
194 |
); |
627 |
); |
195 |
|
628 |
|
196 |
my $order3 = GetOrder( $ordernumber3 ); |
629 |
my $order3 = GetOrder( $ordernumbers[2] ); |
197 |
is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); |
630 |
is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order'); |
198 |
is($order3->{'quantity'}, 2, '2 items on original order'); |
631 |
is($order3->{'quantity'}, 2, '2 items on original order'); |
199 |
is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); |
632 |
is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged'); |
Lines 205-211
is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed');
Link Here
|
205 |
|
638 |
|
206 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
639 |
($datereceived, $new_ordernumber) = ModReceiveOrder( |
207 |
$biblionumber2, |
640 |
$biblionumber2, |
208 |
$ordernumber3, |
641 |
$ordernumbers[2], |
209 |
2, |
642 |
2, |
210 |
undef, |
643 |
undef, |
211 |
12, |
644 |
12, |
Lines 215-221
is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed');
Link Here
|
215 |
$budgetid2 |
648 |
$budgetid2 |
216 |
); |
649 |
); |
217 |
|
650 |
|
218 |
$order3 = GetOrder( $ordernumber3 ); |
651 |
$order3 = GetOrder( $ordernumbers[2] ); |
219 |
is($order3->{'quantityreceived'}, 2, 'Order not split up'); |
652 |
is($order3->{'quantityreceived'}, 2, 'Order not split up'); |
220 |
is($order3->{'quantity'}, 2, '2 items on order'); |
653 |
is($order3->{'quantity'}, 2, '2 items on order'); |
221 |
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed'); |
654 |
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed'); |
222 |
- |
|
|