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