Lines 13-18
use Koha::Acquisition::Booksellers;
Link Here
|
13 |
use Koha::Acquisition::Orders; |
13 |
use Koha::Acquisition::Orders; |
14 |
use Koha::Acquisition::Funds; |
14 |
use Koha::Acquisition::Funds; |
15 |
use Koha::Patrons; |
15 |
use Koha::Patrons; |
|
|
16 |
use Koha::Number::Price; |
16 |
|
17 |
|
17 |
use t::lib::TestBuilder; |
18 |
use t::lib::TestBuilder; |
18 |
use t::lib::Mocks; |
19 |
use t::lib::Mocks; |
Lines 20-25
use Koha::DateUtils;
Link Here
|
20 |
|
21 |
|
21 |
use YAML; |
22 |
use YAML; |
22 |
|
23 |
|
|
|
24 |
use t::lib::Mocks; |
25 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
26 |
|
23 |
my $schema = Koha::Database->new->schema; |
27 |
my $schema = Koha::Database->new->schema; |
24 |
$schema->storage->txn_begin; |
28 |
$schema->storage->txn_begin; |
25 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $builder = t::lib::TestBuilder->new; |
Lines 477-482
ModReceiveOrder({
Link Here
|
477 |
invoice => $test_invoice, |
481 |
invoice => $test_invoice, |
478 |
received_items => [], |
482 |
received_items => [], |
479 |
} ); |
483 |
} ); |
|
|
484 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
480 |
|
485 |
|
481 |
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6"); |
486 |
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6"); |
482 |
is ( GetBudgetOrdered( $fund ), '20', "total ordered price is 20"); |
487 |
is ( GetBudgetOrdered( $fund ), '20', "total ordered price is 20"); |
Lines 929-934
subtest 'GetBudgetSpent and GetBudgetOrdered' => sub {
Link Here
|
929 |
$ordered = GetBudgetOrdered( $budget->{budget_id} ); |
934 |
$ordered = GetBudgetOrdered( $budget->{budget_id} ); |
930 |
is( $spent, 6, "After adding invoice adjustment on a different budget should be 6 spent/budget unaffected"); |
935 |
is( $spent, 6, "After adding invoice adjustment on a different budget should be 6 spent/budget unaffected"); |
931 |
is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected"); |
936 |
is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected"); |
|
|
937 |
}; |
938 |
|
939 |
subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub { |
940 |
|
941 |
plan tests => 8; |
942 |
|
943 |
#Let's build an order, we need a couple things though |
944 |
|
945 |
my $spent_biblio = $builder->build({ source => 'Biblio' }); |
946 |
my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); |
947 |
my $spent_invoice = $builder->build({ source => 'Aqinvoice'}); |
948 |
my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' } }); |
949 |
my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } }); |
950 |
my $spent_orderinfo = { |
951 |
basketno => $spent_basket->{basketno}, |
952 |
booksellerid => $spent_vendor->{id}, |
953 |
rrp => 16.99, |
954 |
discount => .42, |
955 |
ecost => 16.91, |
956 |
biblionumber => $spent_biblio->{biblionumber}, |
957 |
currency => $spent_currency->{currency}, |
958 |
tax_rate_on_ordering => 0, |
959 |
tax_value_on_ordering => 0, |
960 |
tax_rate_on_receiving => 0, |
961 |
tax_value_on_receiving => 0, |
962 |
quantity => 8, |
963 |
quantityreceived => 0, |
964 |
datecancellationprinted => undef, |
965 |
datereceived => undef, |
966 |
}; |
967 |
|
968 |
#Okay we have basically what the user would enter, now we do some maths |
969 |
|
970 |
$spent_orderinfo = C4::Acquisition::populate_order_with_prices({ |
971 |
order => $spent_orderinfo, |
972 |
booksellerid => $spent_orderinfo->{booksellerid}, |
973 |
ordering => 1, |
974 |
}); |
975 |
|
976 |
#And let's place the order |
977 |
|
978 |
my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
979 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
980 |
my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
981 |
|
982 |
is($spent_orderinfo->{ecost_tax_excluded}, 9.854200,'We store extra precision in price calculation'); |
983 |
is( Koha::Number::Price->new($spent_orderinfo->{ecost_tax_excluded})->format(), 9.85,'But the price as formatted is two digits'); |
984 |
is($spent_ordered,'78.8336',"We expect the ordered amount to be equal to the estimated price times quantity with full precision"); |
985 |
|
986 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
987 |
$spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
988 |
is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity"); |
989 |
|
990 |
#Okay, now we can receive the order, giving the price as the user would |
991 |
|
992 |
$spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected |
993 |
|
994 |
#Do our maths |
995 |
|
996 |
$spent_orderinfo = C4::Acquisition::populate_order_with_prices({ |
997 |
order => $spent_orderinfo, |
998 |
booksellerid => $spent_orderinfo->{booksellerid}, |
999 |
receiving => 1, |
1000 |
}); |
1001 |
my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
1002 |
|
1003 |
#And receive |
1004 |
|
1005 |
ModReceiveOrder({ |
1006 |
biblionumber => $spent_order->{biblionumber}, |
1007 |
order => $received_order, |
1008 |
invoice => $spent_invoice, |
1009 |
quantityreceived => $spent_order->{quantity}, |
1010 |
budget_id => $spent_order->{budget_id}, |
1011 |
received_items => [], |
1012 |
}); |
1013 |
|
1014 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
1015 |
my $spent_spent = GetBudgetSpent( $spent_order->{budget_id} ); |
1016 |
is($spent_orderinfo->{unitprice_tax_excluded}, 9.854200,'We store extra precision in price calculation'); |
1017 |
is( Koha::Number::Price->new($spent_orderinfo->{unitprice_tax_excluded})->format(), 9.85,'But the price as formatted is two digits'); |
1018 |
is($spent_spent,'78.8336',"We expect the spent amount to be equal to the estimated price times quantity with full precision"); |
1019 |
|
1020 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
1021 |
$spent_spent = GetBudgetSpent( $spent_order->{budget_id} ); |
1022 |
is($spent_spent,'78.8',"We expect the spent amount to be equal to the estimated price rounded times quantity"); |
932 |
|
1023 |
|
933 |
}; |
1024 |
}; |
934 |
|
1025 |
|
935 |
- |
|
|