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

(-)a/t/db_dependent/Circulation.t (-3 / +196 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 48;
21
use Test::More tests => 49;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
24
Lines 4062-4068 subtest 'Filling a hold should cancel existing transfer' => sub { Link Here
4062
    is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting");
4062
    is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting");
4063
};
4063
};
4064
4064
4065
subtest 'Tests for NoRefundOnLostReturnedItemsAge' => sub {
4065
subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddReturn' => sub {
4066
4066
4067
    plan tests => 4;
4067
    plan tests => 4;
4068
4068
Lines 4249-4254 subtest 'Tests for NoRefundOnLostReturnedItemsAge' => sub { Link Here
4249
    };
4249
    };
4250
};
4250
};
4251
4251
4252
subtest 'Tests for NoRefundOnLostReturnedItemsAge with AddIssue' => sub {
4253
4254
    plan tests => 4;
4255
4256
    t::lib::Mocks::mock_preference('BlockReturnOfLostItems', 0);
4257
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
4258
    my $patron  = $builder->build_object(
4259
        {
4260
            class => 'Koha::Patrons',
4261
            value => { categorycode => $patron_category->{categorycode} }
4262
        }
4263
    );
4264
    my $patron2  = $builder->build_object(
4265
        {
4266
            class => 'Koha::Patrons',
4267
            value => { categorycode => $patron_category->{categorycode} }
4268
        }
4269
    );
4270
4271
    my $biblionumber = $builder->build_sample_biblio(
4272
        {
4273
            branchcode => $library->branchcode,
4274
        }
4275
    )->biblionumber;
4276
4277
    # And the circulation rule
4278
    Koha::CirculationRules->search->delete;
4279
    Koha::CirculationRules->set_rules(
4280
        {
4281
            categorycode => undef,
4282
            itemtype     => undef,
4283
            branchcode   => undef,
4284
            rules        => {
4285
                issuelength => 14,
4286
                lengthunit  => 'days',
4287
            }
4288
        }
4289
    );
4290
    $builder->build(
4291
        {
4292
            source => 'CirculationRule',
4293
            value  => {
4294
                branchcode   => undef,
4295
                categorycode => undef,
4296
                itemtype     => undef,
4297
                rule_name    => 'refund',
4298
                rule_value   => 1
4299
            }
4300
        }
4301
    );
4302
4303
    subtest 'NoRefundOnLostReturnedItemsAge = undef' => sub {
4304
        plan tests => 3;
4305
4306
        t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee',   1 );
4307
        t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', undef );
4308
4309
        my $lost_on = dt_from_string->subtract( days => 7 )->date;
4310
4311
        my $item = $builder->build_sample_item(
4312
            {
4313
                biblionumber     => $biblionumber,
4314
                library          => $library->branchcode,
4315
                replacementprice => '42',
4316
            }
4317
        );
4318
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
4319
        LostItem( $item->itemnumber, 'cli', 0 );
4320
        $item->_result->itemlost(1);
4321
        $item->_result->itemlost_on( $lost_on );
4322
        $item->_result->update();
4323
4324
        my $a = Koha::Account::Lines->search(
4325
            {
4326
                itemnumber     => $item->id,
4327
                borrowernumber => $patron->borrowernumber
4328
            }
4329
        )->next;
4330
        ok( $a, "Found accountline for lost fee" );
4331
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
4332
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
4333
        $a = $a->get_from_storage;
4334
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
4335
        $a->delete;
4336
        $issue->delete;
4337
    };
4338
4339
    subtest 'NoRefundOnLostReturnedItemsAge > length of days item has been lost' => sub {
4340
        plan tests => 3;
4341
4342
        t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee',   1 );
4343
        t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
4344
4345
        my $lost_on = dt_from_string->subtract( days => 6 )->date;
4346
4347
        my $item = $builder->build_sample_item(
4348
            {
4349
                biblionumber     => $biblionumber,
4350
                library          => $library->branchcode,
4351
                replacementprice => '42',
4352
            }
4353
        );
4354
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
4355
        LostItem( $item->itemnumber, 'cli', 0 );
4356
        $item->_result->itemlost(1);
4357
        $item->_result->itemlost_on( $lost_on );
4358
        $item->_result->update();
4359
4360
        my $a = Koha::Account::Lines->search(
4361
            {
4362
                itemnumber     => $item->id,
4363
                borrowernumber => $patron->borrowernumber
4364
            }
4365
        )->next;
4366
        ok( $a, "Found accountline for lost fee" );
4367
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
4368
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
4369
        $a = $a->get_from_storage;
4370
        is( $a->amountoutstanding + 0, 0, "Lost fee was refunded" );
4371
        $a->delete;
4372
    };
4373
4374
    subtest 'NoRefundOnLostReturnedItemsAge = length of days item has been lost' => sub {
4375
        plan tests => 3;
4376
4377
        t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee',   1 );
4378
        t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
4379
4380
        my $lost_on = dt_from_string->subtract( days => 7 )->date;
4381
4382
        my $item = $builder->build_sample_item(
4383
            {
4384
                biblionumber     => $biblionumber,
4385
                library          => $library->branchcode,
4386
                replacementprice => '42',
4387
            }
4388
        );
4389
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
4390
        LostItem( $item->itemnumber, 'cli', 0 );
4391
        $item->_result->itemlost(1);
4392
        $item->_result->itemlost_on( $lost_on );
4393
        $item->_result->update();
4394
4395
        my $a = Koha::Account::Lines->search(
4396
            {
4397
                itemnumber     => $item->id,
4398
                borrowernumber => $patron->borrowernumber
4399
            }
4400
        )->next;
4401
        ok( $a, "Found accountline for lost fee" );
4402
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
4403
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
4404
        $a = $a->get_from_storage;
4405
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
4406
        $a->delete;
4407
    };
4408
4409
    subtest 'NoRefundOnLostReturnedItemsAge < length of days item has been lost' => sub {
4410
        plan tests => 3;
4411
4412
        t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee',   1 );
4413
        t::lib::Mocks::mock_preference( 'NoRefundOnLostReturnedItemsAge', 7 );
4414
4415
        my $lost_on = dt_from_string->subtract( days => 8 )->date;
4416
4417
        my $item = $builder->build_sample_item(
4418
            {
4419
                biblionumber     => $biblionumber,
4420
                library          => $library->branchcode,
4421
                replacementprice => '42',
4422
            }
4423
        );
4424
        my $issue = AddIssue( $patron->unblessed, $item->barcode );
4425
        LostItem( $item->itemnumber, 'cli', 0 );
4426
        $item->_result->itemlost(1);
4427
        $item->_result->itemlost_on( $lost_on );
4428
        $item->_result->update();
4429
4430
        my $a = Koha::Account::Lines->search(
4431
            {
4432
                itemnumber     => $item->id,
4433
                borrowernumber => $patron->borrowernumber
4434
            }
4435
        );
4436
        $a = $a->next;
4437
        ok( $a, "Found accountline for lost fee" );
4438
        is( $a->amountoutstanding + 0, 42, "Lost fee charged correctly" );
4439
        $issue = AddIssue( $patron2->unblessed, $item->barcode );
4440
        $a = $a->get_from_storage;
4441
        is( $a->amountoutstanding + 0, 42, "Lost fee was not refunded" );
4442
        $a->delete;
4443
    };
4444
};
4445
4252
$schema->storage->txn_rollback;
4446
$schema->storage->txn_rollback;
4253
C4::Context->clear_syspref_cache();
4447
C4::Context->clear_syspref_cache();
4254
$branches = Koha::Libraries->search();
4448
$branches = Koha::Libraries->search();
4255
- 

Return to bug 20815