View | Details | Raw Unified | Return to bug 11224
Collapse All | Expand All

(-)a/C4/Acquisition.pm (+1 lines)
Lines 1034-1039 biblio, and biblioitems tables in the Koha database. Link Here
1034
1034
1035
sub GetOrders {
1035
sub GetOrders {
1036
    my ( $basketno, $orderby ) = @_;
1036
    my ( $basketno, $orderby ) = @_;
1037
    return () unless $basketno;
1037
    my $dbh   = C4::Context->dbh;
1038
    my $dbh   = C4::Context->dbh;
1038
    my $query  ="
1039
    my $query  ="
1039
        SELECT biblio.*,biblioitems.*,
1040
        SELECT biblio.*,biblioitems.*,
(-)a/t/db_dependent/Acquisition.t (-85 / +516 lines)
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 => 62;
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-139 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
                   basketgroupid
437
                   basketgroupname
438
                   firstname
439
                   biblioitemnumber
440
                   ecost
441
                   uncertainprice
442
                   creationdate
443
                   datereceived
444
                   orderstatus
445
                   supplierreference
446
                   cancelledby
447
                   isbn
448
                   copyrightdate
449
                   gstrate
450
                   serial
451
                   listprice
452
                   budgetdate
453
                   basketno
454
                   discount
455
                   surname
456
                   freight
457
                   abstract
458
                   title
459
                   closedate
460
                   basketname
461
                   budgetgroup_id
462
                   invoiceid
463
                   author
464
                   parent_ordernumber
465
                   claims_count
466
                   entrydate
467
                   currency
468
                   quantityreceived
469
                   seriestitle
470
                   sort1_authcat
471
                   timestamp
472
                   biblionumber
473
                   unititle
474
                   sort2_authcat
475
                   rrp
476
                   unitprice
477
                   totalamount
478
                   sort1
479
                   ordernumber
480
                   datecreated
481
                   purchaseordernumber
482
                   quantity
483
                   claimed_date
484
                   subscriptionid
485
                   frameworkcode
486
                   sort2
487
                   notes
488
                   datecancellationprinted
489
                   budget_id
81
);
490
);
82
491
83
my $orders = SearchOrders({
492
my $invoiceid = AddInvoice(
493
    invoicenumber => 'invoice',
84
    booksellerid => $booksellerid,
494
    booksellerid => $booksellerid,
495
    unknown => "unknown"
496
);
497
498
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
499
    $biblionumber4,
500
    $ordernumbers[4],
501
    1,
502
    undef,
503
    10,
504
    10,
505
    $invoiceid,
506
    10,
507
    $order_content[4]->{str}->{budget_id}
508
    );
509
510
my $search_orders = SearchOrders({
511
    booksellerid => $booksellerid,
512
    basketno => $basketno
513
});
514
isa_ok( $search_orders, 'ARRAY' );
515
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, $search_orders );
516
is($$test_nbr_fields [0],scalar @expectedfields , "SearchOrders gets orders with the right number of fields" );
517
is(join (" ",@$test_missing_fields),'', "SearchOrders gets orders with no missing fields" );
518
is(join (" ",@$test_extra_fields),'', "SearchOrders gets orders with no unexpected fields" );
519
is(join (" ",@$test_different_fields),'', "SearchOrders gets orders with the right content in every fields" );
520
ok(((scalar @$search_orders == 4) and !grep ($_->{ordernumber} eq $ordernumbers[3], @$search_orders)),"SearchOrders only gets non-cancelled orders" );
521
522
$search_orders = SearchOrders({
523
    booksellerid => $booksellerid,
524
    basketno => $basketno,
85
    pending => 1
525
    pending => 1
86
});
526
});
87
isa_ok( $orders, 'ARRAY' );
527
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');
89
528
90
ok( exists( @$orders[0]->{basketgroupid} ), "SearchOrder: The basketgroupid key exists" );
529
#
91
ok( exists( @$orders[0]->{basketgroupname} ), "SearchOrder: The basketgroupname key exists" );
530
# Test GetBudgetByOrderNumber
531
#
92
532
93
ok( GetBudgetByOrderNumber($ordernumber1)->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
533
ok( GetBudgetByOrderNumber($ordernumbers[0])->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
94
534
95
C4::Acquisition::CloseBasket( $basketno );
535
536
#
537
# Test GetLateOrders
538
#
539
540
@expectedfields = qw (
541
                   orderdate
542
                   author
543
                   budget
544
                   supplierid
545
                   claims_count
546
                   supplier
547
                   publisher
548
                   ordernumber
549
                   quantity
550
                   basketno
551
                   claimed_date
552
                   branch
553
                   estimateddeliverydate
554
                   title
555
                   publicationyear
556
                   unitpricelib
557
                   unitpricesupplier
558
                   subtotal
559
                   latesince
560
);
96
my @lateorders = GetLateOrders(0);
561
my @lateorders = GetLateOrders(0);
562
is(scalar grep ($_->{basketno} eq $basketno, @lateorders),0, "GetLateOrders does not get orders from opened baskets" );
563
C4::Acquisition::CloseBasket( $basketno );
564
@lateorders = GetLateOrders(0);
565
isnt(scalar grep ($_->{basketno} eq $basketno, @lateorders),0, "GetLateOrders gets orders from closed baskets" );
566
ok(!grep ($_->{ordernumber} eq $ordernumbers[3], @lateorders),"GetLateOrders does not gets cancelled orders" );
567
ok(!grep ($_->{ordernumber} eq $ordernumbers[4], @lateorders),"GetLateOrders does not gets reveived orders" );
568
($test_missing_fields,$test_extra_fields,$test_different_fields,$test_nbr_fields) = _check_fields_of_orders (\@expectedfields , \@order_content, \@lateorders );
569
is($$test_nbr_fields [0],scalar @expectedfields , "GetLateOrders gets orders with the right number of fields" );
570
is(join (" ",@$test_missing_fields),'', "GetLateOrders gets orders with no missing fields" );
571
is(join (" ",@$test_extra_fields),'', "GetLateOrders gets orders with no unexpected fields" );
572
is(join (" ",@$test_different_fields),'', "GetLateOrders gets orders with the right content in every fields" );
573
574
#
575
# Test AddClaim
576
#
577
97
my $order = $lateorders[0];
578
my $order = $lateorders[0];
98
AddClaim( $order->{ordernumber} );
579
AddClaim( $order->{ordernumber} );
99
my $neworder = GetOrder( $order->{ordernumber} );
580
my $neworder = GetOrder( $order->{ordernumber} );
100
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
581
is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
101
582
102
my @expectedfields = qw( basketno
583
my $firstorder = $search_orders->[0];
103
                         biblionumber
104
                         invoiceid
105
                         budgetdate
106
                         cancelledby
107
                         closedate
108
                         creationdate
109
                         currency
110
                         datecancellationprinted
111
                         datereceived
112
                         ecost
113
                         entrydate
114
                         firstname
115
                         freight
116
                         gstrate
117
                         listprice
118
                         notes
119
                         ordernumber
120
                         purchaseordernumber
121
                         quantity
122
                         quantityreceived
123
                         rrp
124
                         sort1
125
                         sort2
126
                         subscriptionid
127
                         supplierreference
128
                         surname
129
                         timestamp
130
                         title
131
                         totalamount
132
                         unitprice );
133
my $firstorder = $orders->[0];
134
for my $field ( @expectedfields ) {
135
    ok( exists( $firstorder->{ $field } ), "This order has a $field field" );
136
}
137
584
138
# fake receiving the order
585
# fake receiving the order
139
ModOrder({
586
ModOrder({
Lines 141-165 ModOrder({ Link Here
141
    biblionumber     => $firstorder->{biblionumber},
588
    biblionumber     => $firstorder->{biblionumber},
142
    quantityreceived => $firstorder->{quantity},
589
    quantityreceived => $firstorder->{quantity},
143
});
590
});
144
my $pendingorders = SearchOrders({
145
    booksellerid => $booksellerid,
146
    pending => 1
147
});
148
is(scalar(@$pendingorders), 2, 'retrieved 2 pending orders after receiving on one (bug 10723)');
149
my $allorders = SearchOrders({
150
    booksellerid => $booksellerid,
151
});
152
is(scalar(@$allorders), 3, 'retrieved all 3 orders even after after receiving on one (bug 10723)');
153
591
154
my $invoiceid = AddInvoice(
592
($datereceived, $new_ordernumber) = ModReceiveOrder(
155
    invoicenumber => 'invoice',
156
    booksellerid => $booksellerid,
157
    unknown => "unknown"
158
);
159
160
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
161
    $biblionumber2,
593
    $biblionumber2,
162
    $ordernumber2,
594
    $ordernumbers[1],
163
    2,
595
    2,
164
    undef,
596
    undef,
165
    12,
597
    12,
Lines 167-173 my ($datereceived, $new_ordernumber) = ModReceiveOrder( Link Here
167
    $invoiceid,
599
    $invoiceid,
168
    42,
600
    42,
169
    );
601
    );
170
my $order2 = GetOrder( $ordernumber2 );
602
my $order2 = GetOrder( $ordernumbers[1] );
171
is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
603
is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
172
is($order2->{'quantity'}, 40, '40 items on original order');
604
is($order2->{'quantity'}, 40, '40 items on original order');
173
is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
605
is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
Lines 186-192 my $budgetid2 = C4::Budgets::AddBudget( Link Here
186
618
187
($datereceived, $new_ordernumber) = ModReceiveOrder(
619
($datereceived, $new_ordernumber) = ModReceiveOrder(
188
    $biblionumber2,
620
    $biblionumber2,
189
    $ordernumber3,
621
    $ordernumbers[2],
190
    2,
622
    2,
191
    undef,
623
    undef,
192
    12,
624
    12,
Lines 196-202 my $budgetid2 = C4::Budgets::AddBudget( Link Here
196
    $budgetid2
628
    $budgetid2
197
    );
629
    );
198
630
199
my $order3 = GetOrder( $ordernumber3 );
631
my $order3 = GetOrder( $ordernumbers[2] );
200
is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
632
is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
201
is($order3->{'quantity'}, 2, '2 items on original order');
633
is($order3->{'quantity'}, 2, '2 items on original order');
202
is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
634
is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
Lines 208-214 is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed'); Link Here
208
640
209
($datereceived, $new_ordernumber) = ModReceiveOrder(
641
($datereceived, $new_ordernumber) = ModReceiveOrder(
210
    $biblionumber2,
642
    $biblionumber2,
211
    $ordernumber3,
643
    $ordernumbers[2],
212
    2,
644
    2,
213
    undef,
645
    undef,
214
    12,
646
    12,
Lines 218-224 is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed'); Link Here
218
    $budgetid2
650
    $budgetid2
219
    );
651
    );
220
652
221
$order3 = GetOrder( $ordernumber3 );
653
$order3 = GetOrder( $ordernumbers[2] );
222
is($order3->{'quantityreceived'}, 2, 'Order not split up');
654
is($order3->{'quantityreceived'}, 2, 'Order not split up');
223
is($order3->{'quantity'}, 2, '2 items on order');
655
is($order3->{'quantity'}, 2, '2 items on order');
224
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
656
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
225
- 

Return to bug 11224