@@ -, +, @@ --- t/db_dependent/Budgets.t | 83 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) --- a/t/db_dependent/Budgets.t +++ a/t/db_dependent/Budgets.t @@ -1038,9 +1038,9 @@ subtest 'GetBudgetSpent and GetBudgetOrdered and GetBudgetHierarchy shipping and }; -subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { +subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell FieldsForCalculatingFundValues tests' => sub { - plan tests => 24; + plan tests => 34; #Let's build an order, we need a couple things though t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); @@ -1208,6 +1208,85 @@ subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { is ( @$gbh[0]->{budget_spent}+0, 78.8, "We expect this to be a rounded order cost * quantity"); is ( @$gbh[0]->{budget_ordered}, 78.8, "We expect this to be a rounded order cost * quantity"); + # Test GetBudgetSpent(), GetBudgetOrdered() and GetBudgetHierarchy() with the + # CalculateFundValuesIncludingTax system preference + my $spent_orderinfo_2 = { + basketno => $spent_basket->{basketno}, + booksellerid => $spent_vendor->{id}, + rrp => 16.99, + discount => .42, + ecost => 16.91, + biblionumber => $item_1->biblionumber, + currency => $spent_currency->{currency}, + tax_rate_on_ordering => 0.15, + tax_value_on_ordering => 0, + tax_rate_on_receiving => 0.15, + tax_value_on_receiving => 0, + quantity => 8, + quantityreceived => 0, + datecancellationprinted => undef, + datereceived => undef, + budget_id => $spent_budget->{budget_id}, + sort1 => $spent_sort1->{authorised_value}, + }; + + # Do some maths + my $spent_order_obj_2 = Koha::Acquisition::Order->new($spent_orderinfo_2); + $spent_order_obj_2->populate_with_prices_for_ordering(); + $spent_orderinfo_2 = $spent_order_obj_2->unblessed(); + + #Place the order + my $spent_order_2 = $builder->build({ source => 'Aqorder', value => $spent_orderinfo_2 }); + + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); + $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); + is ( $spent_ordered, 147.36, "We expect this to be the tax exclusive value" ); + + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); + $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); + is ( $spent_ordered, 157.6, "We expect this to be the tax exclusive value" ); + + # Receive the order + $spent_orderinfo_2->{unitprice} = 9.85; #we are paying what we expected + + #Do our maths + $spent_order_obj_2 = Koha::Acquisition::Order->new($spent_orderinfo_2); + $spent_order_obj_2->populate_with_prices_for_receiving(); + $spent_orderinfo_2 = $spent_order_obj_2->unblessed(); + my $received_order_2 = $builder->build({ source => 'Aqorder', value => $spent_orderinfo_2 }); + + #Receive a copy of the order + ModReceiveOrder({ + biblionumber => $spent_order_2->{biblionumber}, + order => $received_order_2, + invoice => $spent_invoice, + quantityreceived => $spent_order_2->{quantity}, + budget_id => $spent_order_2->{budget_id}, + received_items => [], + }); + + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); + $spent_spent = GetBudgetSpent( $spent_order_2->{budget_id} ); + is ( $spent_spent, 147.36, "We expect this to be the tax exclusive value" ); + $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}, 147.36, "We expect this value to be the tax exclusive value"); + + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); + $spent_spent = GetBudgetSpent( $spent_order_2->{budget_id} ); + is ( $spent_spent, 157.6 , "We expect this to be the tax exclusive value" ); + $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id}); + is ( @$gbh[0]->{budget_spent}, 157.6, "We expect this value to be the tax exclusive value"); + + # Test FieldsForCalculatingFundValues() + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); + my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); + is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" ); + is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" ); + t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); + ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); + is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" ); + is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" ); + }; sub _get_dependencies { --