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

(-)a/t/db_dependent/Budgets.t (-3 / +81 lines)
Lines 1038-1046 subtest 'GetBudgetSpent and GetBudgetOrdered and GetBudgetHierarchy shipping and Link Here
1038
1038
1039
};
1039
};
1040
1040
1041
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
1041
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell FieldsForCalculatingFundValues tests' => sub {
1042
1042
1043
    plan tests => 24;
1043
    plan tests => 34;
1044
1044
1045
#Let's build an order, we need a couple things though
1045
#Let's build an order, we need a couple things though
1046
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
1046
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
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
    # Test GetBudgetSpent(), GetBudgetOrdered() and GetBudgetHierarchy() with the 
1212
    # CalculateFundValuesIncludingTax system preference
1213
    my $spent_orderinfo_2 = {
1214
        basketno                => $spent_basket->{basketno},
1215
        booksellerid            => $spent_vendor->{id},
1216
        rrp                     => 16.99,
1217
        discount                => .42,
1218
        ecost                   => 16.91,
1219
        biblionumber            => $item_1->biblionumber,
1220
        currency                => $spent_currency->{currency},
1221
        tax_rate_on_ordering    => 0.15,
1222
        tax_value_on_ordering   => 0,
1223
        tax_rate_on_receiving   => 0.15,
1224
        tax_value_on_receiving  => 0,
1225
        quantity                => 8,
1226
        quantityreceived        => 0,
1227
        datecancellationprinted => undef,
1228
        datereceived            => undef,
1229
        budget_id               => $spent_budget->{budget_id},
1230
        sort1                   => $spent_sort1->{authorised_value},
1231
    };
1232
1233
    # Do some maths
1234
    my $spent_order_obj_2 = Koha::Acquisition::Order->new($spent_orderinfo_2);
1235
    $spent_order_obj_2->populate_with_prices_for_ordering();
1236
    $spent_orderinfo_2 = $spent_order_obj_2->unblessed();
1237
1238
    #Place the order
1239
    my $spent_order_2 = $builder->build({ source => 'Aqorder', value => $spent_orderinfo_2 });
1240
1241
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
1242
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
1243
    is ( $spent_ordered, 147.36, "We expect this to be the tax exclusive value" );
1244
1245
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
1246
    $spent_ordered = GetBudgetOrdered( $spent_order->{budget_id} );
1247
    is ( $spent_ordered, 157.6, "We expect this to be the tax exclusive value" );
1248
1249
    # Receive the order
1250
    $spent_orderinfo_2->{unitprice} = 9.85; #we are paying what we expected
1251
1252
    #Do our maths
1253
    $spent_order_obj_2 = Koha::Acquisition::Order->new($spent_orderinfo_2);
1254
    $spent_order_obj_2->populate_with_prices_for_receiving();
1255
    $spent_orderinfo_2 = $spent_order_obj_2->unblessed();
1256
    my $received_order_2 = $builder->build({ source => 'Aqorder', value => $spent_orderinfo_2 });
1257
1258
    #Receive a copy of the order
1259
    ModReceiveOrder({
1260
            biblionumber => $spent_order_2->{biblionumber},
1261
            order => $received_order_2,
1262
            invoice => $spent_invoice,
1263
            quantityreceived => $spent_order_2->{quantity},
1264
            budget_id => $spent_order_2->{budget_id},
1265
            received_items => [],
1266
    });
1267
1268
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
1269
    $spent_spent = GetBudgetSpent( $spent_order_2->{budget_id} );
1270
    is ( $spent_spent, 147.36, "We expect this to be the tax exclusive value" );
1271
    $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id});
1272
    is ( @$gbh[0]->{budget_spent}, 147.36, "We expect this value to be the tax exclusive value");
1273
1274
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
1275
    $spent_spent = GetBudgetSpent( $spent_order_2->{budget_id} );
1276
    is ( $spent_spent, 157.6 , "We expect this to be the tax exclusive value" );
1277
    $gbh = GetBudgetHierarchy($spent_budget->{budget_period_id});
1278
    is ( @$gbh[0]->{budget_spent}, 157.6, "We expect this value to be the tax exclusive value");
1279
1280
    # Test FieldsForCalculatingFundValues()
1281
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '1');
1282
    my ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
1283
    is ( $unitprice_field, 'unitprice_tax_included', "We expect this to be unitprice_tax_included" );
1284
    is ( $ecost_field, 'ecost_tax_included', "We expect this to be ecost_tax_included" );
1285
    t::lib::Mocks::mock_preference('CalculateFundValuesIncludingTax', '0');
1286
    ( $unitprice_field, $ecost_field ) = C4::Budgets->FieldsForCalculatingFundValues();
1287
    is ( $unitprice_field, 'unitprice_tax_excluded', "We expect this to be unitprice_tax_excluded" );
1288
    is ( $ecost_field, 'ecost_tax_excluded', "We expect this to be ecost_tax_excluded" );
1289
1211
};
1290
};
1212
1291
1213
sub _get_dependencies {
1292
sub _get_dependencies {
1214
- 

Return to bug 31631