From 1cf8f511153d959b46e69cb7bc1f0f7bea5d2242 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 18 Aug 2017 15:16:55 +0000 Subject: [PATCH] Bug 18999: Add regression tests Added regression test for GetBudgetSpent() and GetBudgetOrdered() into the t/db_dependent/Budgets.t Test plan: 1. Go into your koha-shell 2. set the PERL5LIB variable 3. Run t/db_dependent/Budgets.t All tests should pass Sponsored-by: Catalyst IT Signed-off-by: Lee Jamison Signed-off-by: Josef Moravec Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit 776692f31167f32c1621168249a9ebfea2accc96) Signed-off-by: Fridolin Somers (cherry picked from commit 2df9a4c0e0793065ce6787d683a68bef72075ff6) Signed-off-by: Katrin Fischer --- t/db_dependent/Budgets.t | 83 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 07818069ef..ec4ee4c82b 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -1,6 +1,6 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 142; +use Test::More tests => 144; BEGIN { use_ok('C4::Budgets') @@ -393,6 +393,87 @@ is( GetBudgetHierarchySpent( $budget_id1 ), 160, "total spent for budget1 is 160 is( GetBudgetHierarchySpent( $budget_id11 ), 100, "total spent for budget11 is 100" ); is( GetBudgetHierarchySpent( $budget_id111 ), 20, "total spent for budget111 is 20" ); +# GetBudgetSpent and GetBudgetOrdered +my $budget_period_amount = 100; +my $budget_amount = 50; + +my $budget = AddBudgetPeriod( + { + budget_period_startdate => '2017-08-22', + budget_period_enddate => '2018-08-22', + budget_period_description => 'Test budget', + budget_period_active => 1, + budget_period_total => $budget_period_amount, + } +); + +my $fund = AddBudget( + { + budget_code => 'Test fund', + budget_name => 'Test fund', + budget_period_id => $budget, + budget_parent_id => undef, + budget_amount => $budget_amount, + } +); + +my $vendor = Koha::Acquisition::Bookseller->new( + { + name => "test vendor", + address1 => "test address", + phone => "0123456", + active => 1, + deliverytime => 5, + } +)->store; + +my $vendorid = $vendor->id; + +my $basketnumber = C4::Acquisition::NewBasket( $vendorid, 1 ); +my ( $biblio, $biblioitem ) = C4::Biblio::AddBiblio( MARC::Record->new, '' ); + +my @orders = ( + { + budget_id => $fund, + pending_quantity => 1, + spent_quantity => 0, + }, +); + +my $invoiceident = AddInvoice( invoicenumber => 'invoice_test_clone', booksellerid => $vendorid, shipmentdate => '2017-08-22', shipmentcost => 6, shipmentcost_budgetid => $fund ); +my $test_invoice = GetInvoice( $invoiceident ); +my $individual_item_price = 10; + +my $order = Koha::Acquisition::Order->new( + { + basketno => $basketnumber, + biblionumber => $biblio, + budget_id => $fund, + order_internalnote => "internalnote", + order_vendornote => "vendor note", + quantity => 2, + cost_tax_included => $individual_item_price, + rrp_tax_included => $individual_item_price, + listprice => $individual_item_price, + ecost_tax_included => $individual_item_price, + discount => 0, + uncertainprice => 0, + } +)->insert; + +ModReceiveOrder({ + bibionumber => $biblio, + order => $order, + budget_id => $fund, + quantityreceived => 2, + invoice => $test_invoice, + received_items => [], +} ); + +is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6"); +is ( GetBudgetOrdered( $fund ), '20.000000', "total ordered price is 20"); + + # CloneBudgetPeriod my $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod( { -- 2.39.5