+};
+
+subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub {
+
+ plan tests => 8;
+
+#Let's build an order, we need a couple things though
+
+ my $spent_biblio = $builder->build({ source => 'Biblio' });
+ my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
+ my $spent_invoice = $builder->build({ source => 'Aqinvoice'});
+ my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' } });
+ my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } });
+ my $spent_orderinfo = {
+ basketno => $spent_basket->{basketno},
+ booksellerid => $spent_vendor->{id},
+ rrp => 16.99,
+ discount => .42,
+ ecost => 16.91,
+ biblionumber => $spent_biblio->{biblionumber},
+ currency => $spent_currency->{currency},
+ tax_rate_on_ordering => 0,
+ tax_value_on_ordering => 0,
+ tax_rate_on_receiving => 0,
+ tax_value_on_receiving => 0,
+ quantity => 8,
+ quantityreceived => 0,
+ datecancellationprinted => undef,
+ datereceived => undef,
+ };
+
+#Okay we have basically what the user would enter, now we do some maths
+
+ $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
+ order => $spent_orderinfo,
+ booksellerid => $spent_orderinfo->{booksellerid},
+ ordering => 1,
+ });
+
+#And let's place the order
+
+ my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
+ t::lib::Mocks::mock_preference('OrderPriceRounding','');
+ my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
+
+ is($spent_orderinfo->{ecost_tax_excluded}, 9.854200,'We store extra precision in price calculation');
+ is( Koha::Number::Price->new($spent_orderinfo->{ecost_tax_excluded})->format(), 9.85,'But the price as formatted is two digits');
+ is($spent_ordered,'78.8336',"We expect the ordered amount to be equal to the estimated price times quantity with full precision");
+
+ t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
+ $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
+ is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity");
+
+#Okay, now we can receive the order, giving the price as the user would
+
+ $spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected
+
+#Do our maths
+
+ $spent_orderinfo = C4::Acquisition::populate_order_with_prices({
+ order => $spent_orderinfo,
+ booksellerid => $spent_orderinfo->{booksellerid},
+ receiving => 1,
+ });
+ my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
+
+#And receive
+
+ ModReceiveOrder({
+ biblionumber => $spent_order->{biblionumber},
+ order => $received_order,
+ invoice => $spent_invoice,
+ quantityreceived => $spent_order->{quantity},
+ budget_id => $spent_order->{budget_id},
+ received_items => [],
+ });
+
+ t::lib::Mocks::mock_preference('OrderPriceRounding','');
+ my $spent_spent = GetBudgetSpent( $spent_order->{budget_id} );
+ is($spent_orderinfo->{unitprice_tax_excluded}, 9.854200,'We store extra precision in price calculation');
+ is( Koha::Number::Price->new($spent_orderinfo->{unitprice_tax_excluded})->format(), 9.85,'But the price as formatted is two digits');
+ is($spent_spent,'78.8336',"We expect the spent amount to be equal to the estimated price times quantity with full precision");
+
+ t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
+ $spent_spent = GetBudgetSpent( $spent_order->{budget_id} );
+ is($spent_spent,'78.8',"We expect the spent amount to be equal to the estimated price rounded times quantity");