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