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