View | Details | Raw Unified | Return to bug 31631
Collapse All | Expand All

(-)a/t/db_dependent/Budgets.t (-2 / +111 lines)
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 $spent_basket   = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
1235
    my $spent_invoice  = $builder->build({ source => 'Aqinvoice'});
1236
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'BOO' }  });
1237
    my $spent_vendor   = $builder->build({ source => 'Aqbookseller',value => { listincgst => 0, listprice => $spent_currency->{currency}, invoiceprice => $spent_currency->{currency} } });
1238
    my $budget_authcat = $builder->build({ source => 'AuthorisedValueCategory', value => {} });
1239
    my $spent_sort1    = $builder->build({ source => 'AuthorisedValue', value => {
1240
            category => $budget_authcat->{category_name},
1241
            authorised_value => 'PICKLE',
1242
        }
1243
    });
1244
    my $spent_budget_period = $builder->build({ source => 'Aqbudgetperiod', value => {
1245
        }
1246
    });
1247
    my $spent_budget = $builder->build({ source => 'Aqbudget', value => {
1248
            sort1_authcat => $budget_authcat->{category_name},
1249
            budget_period_id => $spent_budget_period->{budget_period_id},
1250
            budget_parent_id => undef,
1251
        }
1252
    });
1253
    my $orderinfo = {
1254
        basketno                => $spent_basket->{basketno},
1255
        booksellerid            => $spent_vendor->{id},
1256
        rrp                     => 16.99,
1257
        discount                => 0,
1258
        ecost                   => 16.91,
1259
        biblionumber            => $item_1->biblionumber,
1260
        currency                => $spent_currency->{currency},
1261
        tax_rate_on_ordering    => 0.15,
1262
        tax_value_on_ordering   => 0,
1263
        tax_rate_on_receiving   => 0.15,
1264
        tax_value_on_receiving  => 0,
1265
        quantity                => 8,
1266
        quantityreceived        => 0,
1267
        datecancellationprinted => undef,
1268
        datereceived            => undef,
1269
        budget_id               => $spent_budget->{budget_id},
1270
        sort1                   => $spent_sort1->{authorised_value},
1271
    };
1272
1273
    # Do some maths
1274
    my $ordered_order = Koha::Acquisition::Order->new($orderinfo);
1275
    $ordered_order->populate_with_prices_for_ordering();
1276
    my $ordered_orderinfo = $ordered_order->unblessed();
1277
    
1278
    # Place the order
1279
    $ordered_order = $builder->build({ source => 'Aqorder', value => $ordered_orderinfo });
1280
    
1281
    # Check order values with different CalculateFundValuesIncludingTax options
1282
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
1283
    my $budget_ordered = GetBudgetOrdered( $ordered_order->{budget_id} );
1284
    is ( $budget_ordered, 135.92, "We expect this to be the tax exclusive value" );
1285
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
1286
    $budget_ordered = GetBudgetOrdered( $ordered_order->{budget_id} );
1287
    is ( $budget_ordered, 156.32, "We expect this to be the tax inclusive value" );
1288
1289
    # Receive the order
1290
    $orderinfo->{unitprice} = 9.85; #we are paying what we expected
1291
1292
    # Do some maths
1293
    my $spent_order = Koha::Acquisition::Order->new($orderinfo);
1294
    $spent_order->populate_with_prices_for_receiving();
1295
    my $spent_orderinfo = $spent_order->unblessed();
1296
    my $received_order = $builder->build({ source => 'Aqorder', value => $spent_orderinfo });
1297
     
1298
    # Receive a copy of the order
1299
    ModReceiveOrder({
1300
            biblionumber => $spent_orderinfo->{biblionumber},
1301
            order => $received_order,
1302
            invoice => $spent_invoice,
1303
            quantityreceived => 8,
1304
            budget_id => $spent_orderinfo->{budget_id},
1305
            received_items => [],
1306
    });
1307
1308
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
1309
    my $spent_spent = GetBudgetSpent( $spent_orderinfo->{budget_id} );
1310
    is ( $spent_spent, 78.8, "We expect this to be the tax exclusive value" );
1311
    my $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id});
1312
    is ( @$gbh[0]->{budget_spent}, 78.8, "We expect this value to be the tax exclusive value");
1313
1314
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
1315
    $spent_spent = GetBudgetSpent( $spent_orderinfo->{budget_id} );
1316
    is ( $spent_spent, 90.64 , "We expect this to be the tax inclusive value" );
1317
    $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id});
1318
    is ( @$gbh[0]->{budget_spent}, 90.64, "We expect this value to be the tax inclusive value");
1319
1320
    $schema->storage->txn_rollback;
1211
};
1321
};
1212
1322
1213
sub _get_dependencies {
1323
sub _get_dependencies {
1214
- 

Return to bug 31631