|
Lines 934-965
subtest 'GetBudgetSpent and GetBudgetOrdered' => sub {
Link Here
|
| 934 |
|
934 |
|
| 935 |
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { |
935 |
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { |
| 936 |
|
936 |
|
| 937 |
plan tests => 12; |
937 |
plan tests => 16; |
| 938 |
|
938 |
|
| 939 |
#Let's build an order, we need a couple things though |
939 |
#Let's build an order, we need a couple things though |
| 940 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
940 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 941 |
|
941 |
|
| 942 |
my $spent_biblio = $builder->build({ source => 'Biblio' }); |
942 |
my $spent_biblio = $builder->build({ source => 'Biblio' }); |
| 943 |
my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); |
943 |
my $item_1 = $builder->build({ source => 'Item', value => { biblionumber => $spent_biblio->{biblionumber} } }); |
| 944 |
my $spent_invoice = $builder->build({ source => 'Aqinvoice'}); |
944 |
my $biblioitem_1 = $builder->build({ source => 'Biblioitem', value => { biblionumber => $spent_biblio->{biblionumber}, itemnumber => $item_1->{itemnumber} } }); |
|
|
945 |
my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); |
| 946 |
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' } }); |
947 |
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} } }); |
948 |
my $spent_vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } }); |
|
|
949 |
my $budget_authcat = $builder->build({ source => 'AuthorisedValueCategory', value => {} }); |
| 950 |
my $spent_sort1 = $builder->build({ source => 'AuthorisedValue', value => { |
| 951 |
category => $budget_authcat->{category_name}, |
| 952 |
authorised_value => 'PICKLE', |
| 953 |
} |
| 954 |
}); |
| 955 |
my $spent_budget = $builder->build({ source => 'Aqbudget', value => { |
| 956 |
sort1_authcat => $budget_authcat->{category_name}, |
| 957 |
} |
| 958 |
}); |
| 947 |
my $spent_orderinfo = { |
959 |
my $spent_orderinfo = { |
| 948 |
basketno => $spent_basket->{basketno}, |
960 |
basketno => $spent_basket->{basketno}, |
| 949 |
booksellerid => $spent_vendor->{id}, |
961 |
booksellerid => $spent_vendor->{id}, |
| 950 |
rrp => 16.99, |
962 |
rrp => 16.99, |
| 951 |
discount => .42, |
963 |
discount => .42, |
| 952 |
ecost => 16.91, |
964 |
ecost => 16.91, |
| 953 |
biblionumber => $spent_biblio->{biblionumber}, |
965 |
biblionumber => $spent_biblio->{biblionumber}, |
| 954 |
currency => $spent_currency->{currency}, |
966 |
currency => $spent_currency->{currency}, |
| 955 |
tax_rate_on_ordering => 0, |
967 |
tax_rate_on_ordering => 0, |
| 956 |
tax_value_on_ordering => 0, |
968 |
tax_value_on_ordering => 0, |
| 957 |
tax_rate_on_receiving => 0, |
969 |
tax_rate_on_receiving => 0, |
| 958 |
tax_value_on_receiving => 0, |
970 |
tax_value_on_receiving => 0, |
| 959 |
quantity => 8, |
971 |
quantity => 8, |
| 960 |
quantityreceived => 0, |
972 |
quantityreceived => 0, |
| 961 |
datecancellationprinted => undef, |
973 |
datecancellationprinted => undef, |
| 962 |
datereceived => undef, |
974 |
datereceived => undef, |
|
|
975 |
budget_id => $spent_budget->{budget_id}, |
| 976 |
sort1 => $spent_sort1->{authorised_value}, |
| 963 |
}; |
977 |
}; |
| 964 |
|
978 |
|
| 965 |
#Okay we have basically what the user would enter, now we do some maths |
979 |
#Okay we have basically what the user would enter, now we do some maths |
|
Lines 987-993
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
Link Here
|
| 987 |
#Let's test some budget planning |
1001 |
#Let's test some budget planning |
| 988 |
#Regression tests for bug 18736 |
1002 |
#Regression tests for bug 18736 |
| 989 |
#We need an item to test by BRANCHES |
1003 |
#We need an item to test by BRANCHES |
| 990 |
my $item_1 = $builder->build({ source => 'Item' }); |
|
|
| 991 |
my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber} } }); |
1004 |
my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber} } }); |
| 992 |
my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} ); |
1005 |
my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} ); |
| 993 |
my $cell = { |
1006 |
my $cell = { |
|
Lines 995-1017
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
Link Here
|
| 995 |
cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here |
1008 |
cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here |
| 996 |
budget_id => $spent_order->{budget_id}, |
1009 |
budget_id => $spent_order->{budget_id}, |
| 997 |
budget_period_id => $spent_fund->budget_period_id, |
1010 |
budget_period_id => $spent_fund->budget_period_id, |
|
|
1011 |
sort1_authcat => $spent_order->{sort1_authcat}, |
| 1012 |
sort2_authcat => $spent_order->{sort1_authcat}, |
| 1013 |
}; |
| 1014 |
my $test_values = { |
| 1015 |
'MONTHS' => { |
| 1016 |
authvalue => $spent_order->{entrydate}, |
| 1017 |
expected_rounded => 9.85, |
| 1018 |
expected_exact => 9.8542, |
| 1019 |
}, |
| 1020 |
'BRANCHES' => { |
| 1021 |
authvalue => $item_1->{homebranch}, |
| 1022 |
expected_rounded => 9.85, |
| 1023 |
expected_exact => 9.8542, |
| 1024 |
}, |
| 1025 |
'ITEMTYPES' => { |
| 1026 |
authvalue => $biblioitem_1->{itemtype}, |
| 1027 |
expected_rounded => 78.80, |
| 1028 |
expected_exact => 78.8336, |
| 1029 |
}, |
| 1030 |
'ELSE' => { |
| 1031 |
authvalue => $spent_sort1->{authorised_value}, |
| 1032 |
expected_rounded => 78.8, |
| 1033 |
expected_exact => 78.8336, |
| 1034 |
}, |
| 998 |
}; |
1035 |
}; |
| 999 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
|
|
| 1000 |
my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now |
| 1001 |
is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't |
| 1002 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 1003 |
( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now |
| 1004 |
is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't |
| 1005 |
$cell->{authcat} = 'BRANCHES'; |
| 1006 |
$cell->{authvalue} = $item_1->{homebranch}; |
| 1007 |
( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now |
| 1008 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
| 1009 |
( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now |
| 1010 |
is ( $actual, '9.854200', "We expect this to be full cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered |
| 1011 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 1012 |
( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now |
| 1013 |
is ( $actual, '9.8500', "We expect this to be rounded cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered |
| 1014 |
|
1036 |
|
|
|
1037 |
for my $authcat ( keys %$test_values ) { |
| 1038 |
my $test_val = $test_values->{$authcat}; |
| 1039 |
my $authvalue = $test_val->{authvalue}; |
| 1040 |
my $expected_rounded = $test_val->{expected_rounded}; |
| 1041 |
my $expected_exact = $test_val->{expected_exact}; |
| 1042 |
$cell->{authcat} = $authcat; |
| 1043 |
$cell->{authvalue} = $authvalue; |
| 1044 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
| 1045 |
my ( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_budget); #we are only testing the actual for now |
| 1046 |
is ( $actual+0, $expected_exact, "We expect this to be an exact order cost ($authcat)"); #really we should expect cost*quantity but we don't |
| 1047 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 1048 |
( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_budget); #we are only testing the actual for now |
| 1049 |
is ( $actual+0, $expected_rounded, "We expect this to be a rounded order cost ($authcat)"); #really we should expect cost*quantity but we don't |
| 1050 |
} |
| 1015 |
|
1051 |
|
| 1016 |
#Okay, now we can receive the order, giving the price as the user would |
1052 |
#Okay, now we can receive the order, giving the price as the user would |
| 1017 |
|
1053 |
|
| 1018 |
- |
|
|