Bug 10275: UT: OrderFromSubscription.t needs to create its own data
[koha.git] / t / db_dependent / Acquisition / OrderFromSubscription.t
1 use Modern::Perl;
2
3 use Test::More tests => 12;
4 use Data::Dumper;
5
6 use_ok('C4::Acquisition');
7 use_ok('C4::Biblio');
8 use_ok('C4::Budgets');
9 use_ok('C4::Serials');
10 my $supplierlist=eval{GetSuppliersWithLateIssues()};
11 ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
12
13 my $booksellerid = C4::Bookseller::AddBookseller(
14     {
15         name => "my vendor",
16         address1 => "bookseller's address",
17         phone => "0123456",
18         active => 1
19     }
20 );
21
22 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
23 my $budgetid;
24 my $bpid = AddBudgetPeriod({
25     budget_period_startdate => '01-01-2015',
26     budget_period_enddate   => '12-31-2015',
27     budget_description      => "budget desc"
28 });
29
30 my $budget_id = AddBudget({
31     budget_code        => "ABCD",
32     budget_amount      => "123.132",
33     budget_name        => "Périodiques",
34     budget_notes       => "This is a note",
35     budget_description => "Serials",
36     budget_active      => 1,
37     budget_period_id   => $bpid
38 });
39
40 my $subscriptionid = NewSubscription(
41     undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
42     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
43     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
44     undef,      undef,  undef, undef, undef,      undef,         undef,  1,
45     "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
46     "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
47 );
48 die unless $subscriptionid;
49
50 my ($basket, $basketno);
51 ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
52
53 my $cost = 42.00;
54 my $subscription = GetSubscription( $subscriptionid );
55 my $ordernumber;
56 ( $basketno, $ordernumber ) = NewOrder({
57     biblionumber => $subscription->{biblionumber},
58     entrydate => '01-01-2013',
59     quantity => 1,
60     currency => 'USD',
61     listprice => $cost,
62     notes => "This is a note",
63     basketno => $basketno,
64     rrp => $cost,
65     ecost => $cost,
66     gstrate => 0.0500,
67     orderstatus => 0,
68     subscriptionid => $subscription->{subscriptionid},
69     budget_id => $budget_id,
70 });
71
72 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
73 is ( $is_currently_on_order, 1, "The subscription is currently on order");
74
75 my $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
76 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
77 ok( $order->{ecost} == $cost, "test cost for the last order not received");
78
79 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
80     $biblionumber, $ordernumber, 1, undef, $cost, $cost,
81     undef, $cost, $budget_id, '02-01-2013', undef);
82
83 $order = GetLastOrderReceivedFromSubscriptionid( $subscription->{subscriptionid} );
84 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order received");
85 ok( $order->{ecost} == $cost, "test cost for the last order received");
86
87 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
88 is ( $order, undef, "test no not received order for a received order");
89
90 # cleaning
91 END {
92     DelSubscription( $subscription->{subscriptionid} );
93     DelOrder( $subscription->{biblionumber}, $ordernumber );
94     DelBudgetPeriod($bpid);
95     DelBudget($budget_id);
96     DelBasket( $basketno );
97     DelBiblio($biblionumber);
98 };