Lines 1-6
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
use Modern::Perl; |
2 |
use Modern::Perl; |
3 |
use Test::More tests => 145; |
3 |
use Test::More tests => 146; |
4 |
|
4 |
|
5 |
BEGIN { |
5 |
BEGIN { |
6 |
use_ok('C4::Budgets') |
6 |
use_ok('C4::Budgets') |
Lines 12-22
use C4::Acquisition;
Link Here
|
12 |
use Koha::Acquisition::Booksellers; |
12 |
use Koha::Acquisition::Booksellers; |
13 |
use Koha::Acquisition::Orders; |
13 |
use Koha::Acquisition::Orders; |
14 |
use Koha::Patrons; |
14 |
use Koha::Patrons; |
|
|
15 |
use Koha::Number::Price; |
15 |
|
16 |
|
16 |
use t::lib::TestBuilder; |
17 |
use t::lib::TestBuilder; |
17 |
|
18 |
|
18 |
use YAML; |
19 |
use YAML; |
19 |
|
20 |
|
|
|
21 |
use t::lib::Mocks; |
22 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
23 |
|
20 |
my $schema = Koha::Database->new->schema; |
24 |
my $schema = Koha::Database->new->schema; |
21 |
$schema->storage->txn_begin; |
25 |
$schema->storage->txn_begin; |
22 |
my $builder = t::lib::TestBuilder->new; |
26 |
my $builder = t::lib::TestBuilder->new; |
Lines 470-475
ModReceiveOrder({
Link Here
|
470 |
invoice => $test_invoice, |
474 |
invoice => $test_invoice, |
471 |
received_items => [], |
475 |
received_items => [], |
472 |
} ); |
476 |
} ); |
|
|
477 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
473 |
|
478 |
|
474 |
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6"); |
479 |
is ( GetBudgetSpent( $fund ), 6, "total shipping cost is 6"); |
475 |
is ( GetBudgetOrdered( $fund ), '20', "total ordered price is 20"); |
480 |
is ( GetBudgetOrdered( $fund ), '20', "total ordered price is 20"); |
Lines 909-914
subtest 'GetBudgetSpent and GetBudgetOrdered' => sub {
Link Here
|
909 |
$ordered = GetBudgetOrdered( $budget->{budget_id} ); |
914 |
$ordered = GetBudgetOrdered( $budget->{budget_id} ); |
910 |
is( $spent, 6, "After adding invoice adjustment on a different budget should be 6 spent/budget unaffected"); |
915 |
is( $spent, 6, "After adding invoice adjustment on a different budget should be 6 spent/budget unaffected"); |
911 |
is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected"); |
916 |
is( $ordered, 3, "After adding invoice adjustment on a different budget, should still be 3 ordered/budget unaffected"); |
|
|
917 |
}; |
918 |
|
919 |
subtest 'OrderPriceRounding GetBudgetSpent GetBudgetOrdered tests' => sub { |
920 |
|
921 |
plan tests => 8; |
922 |
|
923 |
#Let's build an order, we need a couple things though |
924 |
|
925 |
my $spent_biblio = $builder->build({ source => 'Biblio' }); |
926 |
my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); |
927 |
my $spent_invoice = $builder->build({ source => 'Aqinvoice'}); |
928 |
my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' } }); |
929 |
my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } }); |
930 |
my $spent_orderinfo = { |
931 |
basketno => $spent_basket->{basketno}, |
932 |
booksellerid => $spent_vendor->{id}, |
933 |
rrp => 16.99, |
934 |
discount => .42, |
935 |
ecost => 16.91, |
936 |
biblionumber => $spent_biblio->{biblionumber}, |
937 |
currency => $spent_currency->{currency}, |
938 |
tax_rate_on_ordering => 0, |
939 |
tax_value_on_ordering => 0, |
940 |
tax_rate_on_receiving => 0, |
941 |
tax_value_on_receiving => 0, |
942 |
quantity => 8, |
943 |
quantityreceived => 0, |
944 |
datecancellationprinted => undef, |
945 |
datereceived => undef, |
946 |
}; |
947 |
|
948 |
#Okay we have basically what the user would enter, now we do some maths |
949 |
|
950 |
$spent_orderinfo = C4::Acquisition::populate_order_with_prices({ |
951 |
order => $spent_orderinfo, |
952 |
booksellerid => $spent_orderinfo->{booksellerid}, |
953 |
ordering => 1, |
954 |
}); |
955 |
|
956 |
#And let's place the order |
957 |
|
958 |
my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
959 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
960 |
my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
961 |
|
962 |
is($spent_orderinfo->{ecost_tax_excluded}, 9.854200,'We store extra precision in price calculation'); |
963 |
is( Koha::Number::Price->new($spent_orderinfo->{ecost_tax_excluded})->format(), 9.85,'But the price as formatted is two digits'); |
964 |
is($spent_ordered,'78.8336',"We expect the ordered amount to be equal to the estimated price times quantity with full precision"); |
965 |
|
966 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
967 |
$spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
968 |
is($spent_ordered,'78.8',"We expect the ordered amount to be equal to the estimated price rounded times quantity"); |
969 |
|
970 |
#Okay, now we can receive the order, giving the price as the user would |
971 |
|
972 |
$spent_orderinfo->{unitprice} = 9.85; #we are paying what we expected |
973 |
|
974 |
#Do our maths |
975 |
|
976 |
$spent_orderinfo = C4::Acquisition::populate_order_with_prices({ |
977 |
order => $spent_orderinfo, |
978 |
booksellerid => $spent_orderinfo->{booksellerid}, |
979 |
receiving => 1, |
980 |
}); |
981 |
my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
982 |
|
983 |
#And receive |
984 |
|
985 |
ModReceiveOrder({ |
986 |
biblionumber => $spent_order->{biblionumber}, |
987 |
order => $received_order, |
988 |
invoice => $spent_invoice, |
989 |
quantityreceived => $spent_order->{quantity}, |
990 |
budget_id => $spent_order->{budget_id}, |
991 |
received_items => [], |
992 |
}); |
993 |
|
994 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
995 |
my $spent_spent = GetBudgetSpent( $spent_order->{budget_id} ); |
996 |
is($spent_orderinfo->{unitprice_tax_excluded}, 9.854200,'We store extra precision in price calculation'); |
997 |
is( Koha::Number::Price->new($spent_orderinfo->{unitprice_tax_excluded})->format(), 9.85,'But the price as formatted is two digits'); |
998 |
is($spent_spent,'78.8336',"We expect the spent amount to be equal to the estimated price times quantity with full precision"); |
999 |
|
1000 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
1001 |
$spent_spent = GetBudgetSpent( $spent_order->{budget_id} ); |
1002 |
is($spent_spent,'78.8',"We expect the spent amount to be equal to the estimated price rounded times quantity"); |
912 |
|
1003 |
|
913 |
}; |
1004 |
}; |
914 |
|
1005 |
|
915 |
- |
|
|