Bug 13321: Rename variables
[koha.git] / t / db_dependent / Acquisition / OrderFromSubscription.t
index 12ca9a4..d0a970a 100644 (file)
@@ -1,21 +1,22 @@
 use Modern::Perl;
 
-use Test::More tests => 12;
-use Data::Dumper;
+use Test::More tests => 13;
 
 use_ok('C4::Acquisition');
 use_ok('C4::Biblio');
+use_ok('C4::Bookseller');
 use_ok('C4::Budgets');
 use_ok('C4::Serials');
 
+use Koha::Acquisition::Order;
+use Koha::Database;
+
 # Start transaction
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
-my $supplierlist=eval{GetSuppliersWithLateIssues()};
-ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
-
 my $booksellerid = C4::Bookseller::AddBookseller(
     {
         name => "my vendor",
@@ -28,9 +29,9 @@ my $booksellerid = C4::Bookseller::AddBookseller(
 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
 my $budgetid;
 my $bpid = AddBudgetPeriod({
-    budget_period_startdate => '01-01-2015',
-    budget_period_enddate   => '12-31-2015',
-    budget_description      => "budget desc"
+    budget_period_startdate   => '01-01-2015',
+    budget_period_enddate     => '12-31-2015',
+    budget_period_description => "budget desc"
 });
 
 my $budget_id = AddBudget({
@@ -38,8 +39,6 @@ my $budget_id = AddBudget({
     budget_amount      => "123.132",
     budget_name        => "Périodiques",
     budget_notes       => "This is a note",
-    budget_description => "Serials",
-    budget_active      => 1,
     budget_period_id   => $bpid
 });
 
@@ -58,8 +57,8 @@ ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) re
 
 my $cost = 42.00;
 my $subscription = GetSubscription( $subscriptionid );
-my $ordernumber;
-( $basketno, $ordernumber ) = NewOrder({
+
+my $order = Koha::Acquisition::Order->new({
     biblionumber => $subscription->{biblionumber},
     entrydate => '01-01-2013',
     quantity => 1,
@@ -69,29 +68,33 @@ my $ordernumber;
     basketno => $basketno,
     rrp => $cost,
     ecost => $cost,
-    gstrate => 0.0500,
+    tax_rate => 0.0500,
     orderstatus => 'new',
     subscriptionid => $subscription->{subscriptionid},
     budget_id => $budget_id,
-});
+})->insert;
+my $ordernumber = $order->{ordernumber};
 
 my $is_currently_on_order = subscriptionCurrentlyOnOrder( $subscription->{subscriptionid} );
 is ( $is_currently_on_order, 1, "The subscription is currently on order");
 
-my $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
+$order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
 is ( $order->{subscriptionid}, $subscription->{subscriptionid}, "test subscriptionid for the last order not received");
 ok( $order->{ecost} == $cost, "test cost for the last order not received");
 
+$dbh->do(q{DELETE FROM aqinvoices});
+my $invoiceid = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
+
+my $invoice = GetInvoice( $invoiceid );
+$invoice->{datereceived} = '02-01-2013';
+
 my ( $datereceived, $new_ordernumber ) = ModReceiveOrder(
     {
         biblionumber     => $biblionumber,
-        ordernumber      => $ordernumber,
+        order            => $order,
         quantityreceived => 1,
-        cost             => $cost,
-        ecost            => $cost,
-        rrp              => $cost,
         budget_id        => $budget_id,
-        datereceived     => '02-01-2013'
+        invoice          => $invoice,
     }
 );
 
@@ -102,5 +105,9 @@ ok( $order->{ecost} == $cost, "test cost for the last order received");
 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
 is ( $order, undef, "test no not received order for a received order");
 
+my @invoices = GetInvoices();
+my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} } @invoices;
+is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
+
 # Cleanup
-$dbh->rollback;
+$schema->storage->txn_rollback();