|
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 => 156; |
| 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 1092-1098
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
Link Here
|
| 1092 |
$spent_orderinfo = $spent_order_obj->unblessed(); |
1093 |
$spent_orderinfo = $spent_order_obj->unblessed(); |
| 1093 |
|
1094 |
|
| 1094 |
#And let's place the order |
1095 |
#And let's place the order |
| 1095 |
|
|
|
| 1096 |
my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
1096 |
my $spent_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo }); |
| 1097 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
1097 |
t::lib::Mocks::mock_preference('OrderPriceRounding',''); |
| 1098 |
my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
1098 |
my $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} ); |
|
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"); |
1208 |
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"); |
1209 |
is ( @$gbh[0]->{budget_ordered}, 78.8, "We expect this to be a rounded order cost * quantity"); |
| 1210 |
|
1210 |
|
|
|
1211 |
$schema->storage->txn_rollback; |
| 1212 |
}; |
| 1213 |
|
| 1214 |
# Bug 31631 |
| 1215 |
subtest 'FieldsForCalculatingFundValues with a vendor NOT including tax in their list and invoice prices tests' => sub { |
| 1216 |
plan tests => 10; |
| 1217 |
|
| 1218 |
$schema->storage->txn_begin; |
| 1219 |
|
| 1220 |
# Test FieldsForCalculatingFundValues() |
| 1221 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1222 |
my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
| 1223 |
is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" ); |
| 1224 |
is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" ); |
| 1225 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1226 |
( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
| 1227 |
is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" ); |
| 1228 |
is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" ); |
| 1229 |
|
| 1230 |
# Test GetBudgetOrdered() |
| 1231 |
# ----------------------- |
| 1232 |
|
| 1233 |
# Build an order |
| 1234 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 1235 |
my $item_1 = $builder->build_sample_item; |
| 1236 |
my $invoice = $builder->build({ source => 'Aqinvoice'}); |
| 1237 |
my $currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' } }); |
| 1238 |
my $vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, invoiceincgst => 0, listprice => $currency->{currency}, invoiceprice => $currency->{currency} } }); |
| 1239 |
my $basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0, booksellerid => $vendor->{id} } }); |
| 1240 |
my $budget_period = $builder->build({ source => 'Aqbudgetperiod' }); |
| 1241 |
my $budget = $builder->build({ source => 'Aqbudget', value => { |
| 1242 |
budget_period_id => $budget_period->{budget_period_id}, |
| 1243 |
budget_parent_id => undef, |
| 1244 |
} |
| 1245 |
}); |
| 1246 |
my $orderdata = { |
| 1247 |
basketno => $basket->{basketno}, |
| 1248 |
booksellerid => $vendor->{id}, |
| 1249 |
rrp => 10, |
| 1250 |
discount => 0, |
| 1251 |
ecost => 10, |
| 1252 |
biblionumber => $item_1->biblionumber, |
| 1253 |
currency => $currency->{currency}, |
| 1254 |
tax_rate_on_ordering => 0.15, |
| 1255 |
tax_value_on_ordering => 1.5, |
| 1256 |
tax_rate_on_receiving => 0.15, |
| 1257 |
tax_value_on_receiving => 0, |
| 1258 |
quantity => 1, |
| 1259 |
quantityreceived => 0, |
| 1260 |
datecancellationprinted => undef, |
| 1261 |
datereceived => undef, |
| 1262 |
budget_id => $budget->{budget_id}, |
| 1263 |
}; |
| 1264 |
|
| 1265 |
# Do some maths |
| 1266 |
my $order = Koha::Acquisition::Order->new($orderdata); |
| 1267 |
$order->populate_with_prices_for_ordering(); |
| 1268 |
$orderdata = $order->unblessed(); |
| 1269 |
|
| 1270 |
# Place the order |
| 1271 |
$order = $builder->build({ source => 'Aqorder', value => $orderdata }); |
| 1272 |
|
| 1273 |
# Check order values with different CalculateFundValuesIncludingTax options |
| 1274 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1275 |
my $budget_ordered = GetBudgetOrdered( $order->{budget_id} ); |
| 1276 |
is ( $budget_ordered, 10, "We expect this to be the tax exclusive value" ); |
| 1277 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1278 |
$budget_ordered = GetBudgetOrdered( $order->{budget_id} ); |
| 1279 |
is ( $budget_ordered, 11.5, "We expect this to be the tax inclusive value" ); |
| 1280 |
|
| 1281 |
# Test GetBudgetSpent() and GetBudgetHierarchy() |
| 1282 |
# ----------------------------------------------- |
| 1283 |
|
| 1284 |
# Receive the order |
| 1285 |
$orderdata->{unitprice} = 10; #we are paying what we expected |
| 1286 |
|
| 1287 |
# Do some maths |
| 1288 |
$order = Koha::Acquisition::Order->new($orderdata); |
| 1289 |
$order->populate_with_prices_for_receiving(); |
| 1290 |
$orderdata = $order->unblessed(); |
| 1291 |
my $received_order = $builder->build({ source => 'Aqorder', value => $orderdata }); |
| 1292 |
|
| 1293 |
# Receive a copy of the order |
| 1294 |
ModReceiveOrder({ |
| 1295 |
biblionumber => $orderdata->{biblionumber}, |
| 1296 |
order => $received_order, |
| 1297 |
invoice => $invoice, |
| 1298 |
quantityreceived => 1, |
| 1299 |
budget_id => $orderdata->{budget_id}, |
| 1300 |
received_items => [], |
| 1301 |
}); |
| 1302 |
|
| 1303 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1304 |
my $spent_amount = GetBudgetSpent( $orderdata->{budget_id} ); |
| 1305 |
is ( $spent_amount, 10, "We expect this to be the tax exclusive value" ); |
| 1306 |
my $gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
| 1307 |
is ( @$gbh[0]->{budget_spent}, 10, "We expect this value to be the tax exclusive value"); |
| 1308 |
|
| 1309 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1310 |
$spent_amount = GetBudgetSpent( $orderdata->{budget_id} ); |
| 1311 |
is ( $spent_amount, 11.5, "We expect this to be the tax inclusive value" ); |
| 1312 |
$gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
| 1313 |
is ( @$gbh[0]->{budget_spent}, 11.5, "We expect this value to be the tax inclusive value"); |
| 1314 |
|
| 1315 |
$schema->storage->txn_rollback; |
| 1316 |
}; |
| 1317 |
|
| 1318 |
# Bug 31631 |
| 1319 |
subtest 'FieldsForCalculatingFundValues with a vendor that IS including tax in their list and invoice prices tests' => sub { |
| 1320 |
plan tests => 10; |
| 1321 |
|
| 1322 |
$schema->storage->txn_begin; |
| 1323 |
|
| 1324 |
# Test FieldsForCalculatingFundValues() |
| 1325 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1326 |
my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
| 1327 |
is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" ); |
| 1328 |
is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" ); |
| 1329 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1330 |
( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues(); |
| 1331 |
is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" ); |
| 1332 |
is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" ); |
| 1333 |
|
| 1334 |
# Test GetBudgetOrdered() |
| 1335 |
# ----------------------- |
| 1336 |
|
| 1337 |
# Build an order |
| 1338 |
t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent'); |
| 1339 |
my $item_1 = $builder->build_sample_item; |
| 1340 |
my $invoice = $builder->build({ source => 'Aqinvoice'}); |
| 1341 |
my $currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' } }); |
| 1342 |
my $vendor = $builder->build({ source => 'Aqbookseller',value => { listincgst => 1, invoiceincgst => 1, listprice => $currency->{currency}, invoiceprice => $currency->{currency} } }); |
| 1343 |
my $basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0, booksellerid => $vendor->{id} } }); |
| 1344 |
my $budget_period = $builder->build({ source => 'Aqbudgetperiod' }); |
| 1345 |
my $budget = $builder->build({ source => 'Aqbudget', value => { |
| 1346 |
budget_period_id => $budget_period->{budget_period_id}, |
| 1347 |
budget_parent_id => undef, |
| 1348 |
} |
| 1349 |
}); |
| 1350 |
my $orderdata = { |
| 1351 |
basketno => $basket->{basketno}, |
| 1352 |
booksellerid => $vendor->{id}, |
| 1353 |
rrp => 10, |
| 1354 |
discount => 0, |
| 1355 |
ecost => 10, |
| 1356 |
biblionumber => $item_1->biblionumber, |
| 1357 |
currency => $currency->{currency}, |
| 1358 |
tax_rate_on_ordering => 0.15, |
| 1359 |
tax_value_on_ordering => 1.5, |
| 1360 |
tax_rate_on_receiving => 0.15, |
| 1361 |
tax_value_on_receiving => 0, |
| 1362 |
quantity => 1, |
| 1363 |
quantityreceived => 0, |
| 1364 |
datecancellationprinted => undef, |
| 1365 |
datereceived => undef, |
| 1366 |
budget_id => $budget->{budget_id}, |
| 1367 |
}; |
| 1368 |
|
| 1369 |
# Do some maths |
| 1370 |
my $order = Koha::Acquisition::Order->new($orderdata); |
| 1371 |
$order->populate_with_prices_for_ordering(); |
| 1372 |
$orderdata = $order->unblessed(); |
| 1373 |
|
| 1374 |
# Place the order |
| 1375 |
$order = $builder->build({ source => 'Aqorder', value => $orderdata }); |
| 1376 |
|
| 1377 |
# Check order values with different CalculateFundValuesIncludingTax options |
| 1378 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1379 |
my $budget_ordered = GetBudgetOrdered( $order->{budget_id} ); |
| 1380 |
is ( $budget_ordered, 8.7, "We expect this to be the tax exclusive value" ); |
| 1381 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1382 |
$budget_ordered = GetBudgetOrdered( $order->{budget_id} ); |
| 1383 |
is ( $budget_ordered, 10, "We expect this to be the tax inclusive value" ); |
| 1384 |
|
| 1385 |
# Test GetBudgetSpent() and GetBudgetHierarchy() |
| 1386 |
# ----------------------------------------------- |
| 1387 |
|
| 1388 |
# Receive the order |
| 1389 |
$orderdata->{unitprice} = 10; #we are paying what we expected |
| 1390 |
|
| 1391 |
# Do some maths |
| 1392 |
$order = Koha::Acquisition::Order->new($orderdata); |
| 1393 |
$order->populate_with_prices_for_receiving(); |
| 1394 |
$orderdata = $order->unblessed(); |
| 1395 |
my $received_order = $builder->build({ source => 'Aqorder', value => $orderdata }); |
| 1396 |
|
| 1397 |
# Receive a copy of the order |
| 1398 |
ModReceiveOrder({ |
| 1399 |
biblionumber => $orderdata->{biblionumber}, |
| 1400 |
order => $received_order, |
| 1401 |
invoice => $invoice, |
| 1402 |
quantityreceived => 1, |
| 1403 |
budget_id => $orderdata->{budget_id}, |
| 1404 |
received_items => [], |
| 1405 |
}); |
| 1406 |
|
| 1407 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0'); |
| 1408 |
my $spent_amount = GetBudgetSpent( $orderdata->{budget_id} ); |
| 1409 |
is ( $spent_amount, 8.7, "We expect this to be the tax exclusive value" ); |
| 1410 |
my $gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
| 1411 |
is ( @$gbh[0]->{budget_spent}, 8.7, "We expect this value to be the tax exclusive value"); |
| 1412 |
|
| 1413 |
t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1'); |
| 1414 |
$spent_amount = GetBudgetSpent( $orderdata->{budget_id} ); |
| 1415 |
is ( $spent_amount, 10, "We expect this to be the tax inclusive value" ); |
| 1416 |
$gbh = GetBudgetHierarchy($budget->{budget_period_id}); |
| 1417 |
is ( @$gbh[0]->{budget_spent}, 10, "We expect this value to be the tax inclusive value"); |
| 1418 |
|
| 1419 |
$schema->storage->txn_rollback; |
| 1211 |
}; |
1420 |
}; |
| 1212 |
|
1421 |
|
| 1213 |
sub _get_dependencies { |
1422 |
sub _get_dependencies { |
| 1214 |
- |
|
|