Bug 11224 : Add UT to routines of C4::Acquisition returning order(s)
[koha.git] / t / db_dependent / Acquisition.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!
4 # Add more tests here!!!
5
6 use Modern::Perl;
7 use POSIX qw(strftime);
8
9 use C4::Bookseller qw( GetBookSellerFromId );
10
11 use Test::More tests => 64;
12
13 BEGIN {
14     use_ok('C4::Acquisition');
15     use_ok('C4::Bookseller');
16     use_ok('C4::Biblio');
17     use_ok('C4::Budgets');
18     use_ok('C4::Bookseller');
19 }
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
76 my $dbh = C4::Context->dbh;
77 $dbh->{AutoCommit} = 0;
78 $dbh->{RaiseError} = 1;
79
80 # Creating some orders
81 my $booksellerid = C4::Bookseller::AddBookseller(
82     {
83         name => "my vendor",
84         address1 => "bookseller's address",
85         phone => "0123456",
86         active => 1,
87         deliverytime => 5,
88     }
89 );
90
91 my $booksellerinfo = C4::Bookseller::GetBookSellerFromId( $booksellerid );
92
93 is($booksellerinfo->{deliverytime}, 5, 'set deliverytime when creating vendor (Bug 10556)');
94
95 my ($basket, $basketno);
96 ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
97 ok($basket   = GetBasket($basketno), "GetBasket($basketno) returns $basket");
98
99 my $budgetid = C4::Budgets::AddBudget(
100     {
101         budget_code => "budget_code_test_getordersbybib",
102         budget_name => "budget_name_test_getordersbybib",
103     }
104 );
105 my $budget = C4::Budgets::GetBudget( $budgetid );
106
107 my @ordernumbers;
108 my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
109 my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
110 my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, '');
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 => {
148         basketno => $basketno,
149         biblionumber => $biblionumber1,
150         budget_id => $budget->{budget_id},
151         uncertainprice=>0,
152         notes=>"some notes",
153     },
154      num => {
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 => {
163         basketno => $basketno,
164         biblionumber => $biblionumber2,
165         budget_id => $budget->{budget_id}
166     },
167      num => {
168         quantity => 42
169     }},
170     {str => {
171         basketno => $basketno,
172         biblionumber => $biblionumber2,
173         budget_id => $budget->{budget_id},
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,
196         rrp => 42,
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
490 );
491
492 my $invoiceid = AddInvoice(
493     invoicenumber => 'invoice',
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,
525     pending => 1
526 });
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" );
528
529 #
530 # Test GetBudgetByOrderNumber
531 #
532
533 ok( GetBudgetByOrderNumber($ordernumbers[0])->{'budget_id'} eq $budgetid, "GetBudgetByOrderNumber returns expected budget" );
534
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 );
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
578 my $order = $lateorders[0];
579 AddClaim( $order->{ordernumber} );
580 my $neworder = GetOrder( $order->{ordernumber} );
581 is( $neworder->{claimed_date}, strftime( "%Y-%m-%d", localtime(time) ), "AddClaim : Check claimed_date" );
582
583 my $firstorder = $search_orders->[0];
584
585 # fake receiving the order
586 ModOrder({
587     ordernumber      => $firstorder->{ordernumber},
588     biblionumber     => $firstorder->{biblionumber},
589     quantityreceived => $firstorder->{quantity},
590 });
591
592 ($datereceived, $new_ordernumber) = ModReceiveOrder(
593     $biblionumber2,
594     $ordernumbers[1],
595     2,
596     undef,
597     12,
598     12,
599     $invoiceid,
600     42,
601     );
602 my $order2 = GetOrder( $ordernumbers[1] );
603 is($order2->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
604 is($order2->{'quantity'}, 40, '40 items on original order');
605 is($order2->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
606
607 $neworder = GetOrder( $new_ordernumber );
608 is($neworder->{'quantity'}, 2, '2 items on new order');
609 is($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order');
610 is($neworder->{'budget_id'}, $budgetid, 'Budget on new order is unchanged');
611
612 my $budgetid2 = C4::Budgets::AddBudget(
613     {
614         budget_code => "budget_code_test_modrecv",
615         budget_name => "budget_name_test_modrecv",
616     }
617 );
618
619 ($datereceived, $new_ordernumber) = ModReceiveOrder(
620     $biblionumber2,
621     $ordernumbers[2],
622     2,
623     undef,
624     12,
625     12,
626     $invoiceid,
627     42,
628     $budgetid2
629     );
630
631 my $order3 = GetOrder( $ordernumbers[2] );
632 is($order3->{'quantityreceived'}, 0, 'Splitting up order did not receive any on original order');
633 is($order3->{'quantity'}, 2, '2 items on original order');
634 is($order3->{'budget_id'}, $budgetid, 'Budget on original order is unchanged');
635
636 $neworder = GetOrder( $new_ordernumber );
637 is($neworder->{'quantity'}, 2, '2 items on new order');
638 is($neworder->{'quantityreceived'}, 2, 'Splitting up order received items on new order');
639 is($neworder->{'budget_id'}, $budgetid2, 'Budget on new order is changed');
640
641 ($datereceived, $new_ordernumber) = ModReceiveOrder(
642     $biblionumber2,
643     $ordernumbers[2],
644     2,
645     undef,
646     12,
647     12,
648     $invoiceid,
649     42,
650     $budgetid2
651     );
652
653 $order3 = GetOrder( $ordernumbers[2] );
654 is($order3->{'quantityreceived'}, 2, 'Order not split up');
655 is($order3->{'quantity'}, 2, '2 items on order');
656 is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
657
658 $dbh->rollback;