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 => 154; |
3 |
use Test::More tests => 155; |
4 |
use JSON; |
4 |
use JSON; |
5 |
|
5 |
|
6 |
BEGIN { |
6 |
BEGIN { |
Lines 30-35
my $schema = Koha::Database->new->schema;
Link Here
|
30 |
$schema->storage->txn_begin; |
30 |
$schema->storage->txn_begin; |
31 |
my $builder = t::lib::TestBuilder->new; |
31 |
my $builder = t::lib::TestBuilder->new; |
32 |
my $dbh = C4::Context->dbh; |
32 |
my $dbh = C4::Context->dbh; |
|
|
33 |
$dbh->do(q|DELETE FROM vendor_edi_accounts|); |
33 |
$dbh->do(q|DELETE FROM aqbudgetperiods|); |
34 |
$dbh->do(q|DELETE FROM aqbudgetperiods|); |
34 |
$dbh->do(q|DELETE FROM aqbudgets|); |
35 |
$dbh->do(q|DELETE FROM aqbudgets|); |
35 |
|
36 |
|
Lines 1208-1213
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
Link Here
|
1208 |
is ( @$gbh[0]->{budget_spent}+0, 78.8, "We expect this to be a rounded order cost * quantity"); |
1209 |
is ( @$gbh[0]->{budget_spent}+0, 78.8, "We expect this to be a rounded order cost * quantity"); |
1209 |
is ( @$gbh[0]->{budget_ordered}, 78.8, "We expect this to be a rounded order cost * quantity"); |
1210 |
is ( @$gbh[0]->{budget_ordered}, 78.8, "We expect this to be a rounded order cost * quantity"); |
1210 |
|
1211 |
|
|
|
1212 |
$schema->storage->txn_rollback; |
1213 |
}; |
1214 |
|
1215 |
|
1216 |
subtest 'FieldsForCalculatingFundValues tests' => sub { |
1217 |
plan tests => 10; |
1218 |
|
1219 |
$schema->storage->txn_begin; |
1220 |
|
1221 |
# Test FieldsForCalculatingFundValues() |
1222 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
1223 |
my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
1224 |
is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" ); |
1225 |
is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" ); |
1226 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
1227 |
( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
1228 |
is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" ); |
1229 |
is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" ); |
1230 |
|
1231 |
# Build an order |
1232 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
1233 |
my $item_1 = $builder->build_sample_item; |
1234 |
my $basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); |
1235 |
my $invoice = $builder->build({ source => 'Aqinvoice'}); |
1236 |
my $currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' } }); |
1237 |
my $vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $currency->{currency}, invoiceprice => $currency->{currency} } }); |
1238 |
my $budget_period = $builder->build({ source => 'Aqbudgetperiod' }); |
1239 |
my $budget = $builder->build({ source => 'Aqbudget', value => { |
1240 |
budget_period_id => $budget_period->{budget_period_id}, |
1241 |
budget_parent_id => undef, |
1242 |
} |
1243 |
}); |
1244 |
my $orderinfo = { |
1245 |
basketno => $basket->{basketno}, |
1246 |
booksellerid => $vendor->{id}, |
1247 |
rrp => 16.99, |
1248 |
discount => 0, |
1249 |
ecost => 16.91, |
1250 |
biblionumber => $item_1->biblionumber, |
1251 |
currency => $currency->{currency}, |
1252 |
tax_rate_on_ordering => 0.15, |
1253 |
tax_value_on_ordering => 0, |
1254 |
tax_rate_on_receiving => 0.15, |
1255 |
tax_value_on_receiving => 0, |
1256 |
quantity => 8, |
1257 |
quantityreceived => 0, |
1258 |
datecancellationprinted => undef, |
1259 |
datereceived => undef, |
1260 |
budget_id => $budget->{budget_id}, |
1261 |
}; |
1262 |
|
1263 |
# Do some maths |
1264 |
my $ordered_order = Koha::Acquisition::Order->new($orderinfo); |
1265 |
$ordered_order->populate_with_prices_for_ordering(); |
1266 |
my $ordered_orderinfo = $ordered_order->unblessed(); |
1267 |
|
1268 |
# Place the order |
1269 |
$ordered_order = $builder->build({ source => 'Aqorder', value => $ordered_orderinfo }); |
1270 |
|
1271 |
# Check order values with different CalculateFundValuesIncludingTax options |
1272 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
1273 |
my $budget_ordered = GetBudgetOrdered( $ordered_order->{budget_id} ); |
1274 |
is ( $budget_ordered, 135.92, "We expect this to be the tax exclusive value" ); |
1275 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
1276 |
$budget_ordered = GetBudgetOrdered( $ordered_order->{budget_id} ); |
1277 |
is ( $budget_ordered, 156.32, "We expect this to be the tax inclusive value" ); |
1278 |
|
1279 |
# Receive the order |
1280 |
$orderinfo->{unitprice} = 9.85; #we are paying what we expected |
1281 |
|
1282 |
# Do some maths |
1283 |
my $spent_order = Koha::Acquisition::Order->new($orderinfo); |
1284 |
$spent_order->populate_with_prices_for_receiving(); |
1285 |
my $spent_orderinfo = $spent_order->unblessed(); |
1286 |
my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
1287 |
|
1288 |
# Receive a copy of the order |
1289 |
ModReceiveOrder({ |
1290 |
biblionumber => $spent_orderinfo->{biblionumber}, |
1291 |
order => $received_order, |
1292 |
invoice => $invoice, |
1293 |
quantityreceived => 8, |
1294 |
budget_id => $spent_orderinfo->{budget_id}, |
1295 |
received_items => [], |
1296 |
}); |
1297 |
|
1298 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
1299 |
my $spent_spent = GetBudgetSpent( $spent_orderinfo->{budget_id} ); |
1300 |
is ( $spent_spent, 78.8, "We expect this to be the tax exclusive value" ); |
1301 |
my $gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
1302 |
is ( @$gbh[0]->{budget_spent}, 78.8, "We expect this value to be the tax exclusive value"); |
1303 |
|
1304 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
1305 |
$spent_spent = GetBudgetSpent( $spent_orderinfo->{budget_id} ); |
1306 |
is ( $spent_spent, 90.64 , "We expect this to be the tax inclusive value" ); |
1307 |
$gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
1308 |
is ( @$gbh[0]->{budget_spent}, 90.64, "We expect this value to be the tax inclusive value"); |
1309 |
|
1310 |
$schema->storage->txn_rollback; |
1211 |
}; |
1311 |
}; |
1212 |
|
1312 |
|
1213 |
sub _get_dependencies { |
1313 |
sub _get_dependencies { |
1214 |
- |
|
|