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