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

(-)a/t/db_dependent/Circulation.t (-2 / +224 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 => 70;
21
use Test::More tests => 73;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
Lines 5487-5492 subtest 'Do not return on renewal (LOST charge)' => sub { Link Here
5487
    );
5487
    );
5488
};
5488
};
5489
5489
5490
subtest 'Lost status does not change when preferences are set to 0' => sub {
5491
    plan tests => 2;
5492
5493
    my $library = $builder->build_object( { class => "Koha::Libraries" } );
5494
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
5495
    t::lib::Mocks::mock_userenv({ patron => $manager,branchcode => $manager->branchcode });
5496
5497
    my $biblio = $builder->build_sample_biblio;
5498
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5499
5500
    my $item = $builder->build_sample_item(
5501
        {
5502
            biblionumber     => $biblio->biblionumber,
5503
            library          => $library->branchcode,
5504
            replacementprice => 99,
5505
            itype            => $itemtype,
5506
            itemlost         => 1,
5507
        }
5508
    );
5509
5510
    my $debitCharge = Koha::Account::Line->new(
5511
        {
5512
            borrowernumber    => $patron->borrowernumber,
5513
            debit_type_code   => 'LOST',
5514
            status            => undef,
5515
            itemnumber        => $item->itemnumber,
5516
            amount            => 12,
5517
            amountoutstanding => 12,
5518
            interface         => 'something',
5519
        }
5520
    )->store();
5521
5522
    # Test for UpdateItemLostStatusWhenPaid
5523
    t::lib::Mocks::mock_preference('UpdateItemLostStatusWhenPaid', 0);
5524
5525
    my $paymentLine = Koha::Account::Line->new(
5526
        {
5527
            borrowernumber    => $patron->borrowernumber,
5528
            credit_type_code  => 'CREDIT',
5529
            status            => undef,
5530
            itemnumber        => $item->itemnumber,
5531
            amountoutstanding => 0 - 12,
5532
            amount            => 0 - 12,
5533
            interface         => 'something',
5534
        }
5535
    )->store();
5536
5537
    my $offset = Koha::Account::Offset->new(
5538
        {
5539
            credit_id => $paymentLine->id,
5540
            debit_id  => $debitCharge->id,
5541
            type      => 'APPLY',
5542
            amount    => 0
5543
        }
5544
    )->store();
5545
5546
    $paymentLine->apply( { debits => [$debitCharge] } );
5547
5548
    is(Koha::Items->find($item->itemnumber)->itemlost, 1,
5549
        "Payment should not change itemlost status when UpdateItemLostStatusWhenPaid is 0"
5550
    );
5551
5552
    # Test for UpdateItemLostStatusWhenWriteOff
5553
    t::lib::Mocks::mock_preference('UpdateItemLostStatusWhenWriteOff', 0);
5554
5555
    my $writeOffLine = Koha::Account::Line->new(
5556
        {
5557
            borrowernumber    => $patron->borrowernumber,
5558
            credit_type_code  => 'WRITEOFF',
5559
            status            => undef,
5560
            itemnumber        => $item->itemnumber,
5561
            amountoutstanding => 0 - 12,
5562
            amount            => 0 - 12,
5563
            interface => 'something',
5564
        }
5565
    )->store();
5566
5567
    $offset = Koha::Account::Offset->new(
5568
        {
5569
            credit_id => $writeOffLine->id,
5570
            debit_id  => $debitCharge->id,
5571
            type      => 'APPLY',
5572
            amount    => 0
5573
        }
5574
    )->store();
5575
5576
    $writeOffLine->apply( { debits => [$debitCharge] } );
5577
5578
    is(Koha::Items->find($item->itemnumber)->itemlost, 1,
5579
        "Write-off should not change itemlost status when UpdateItemLostStatusWhenWriteOff is 0"
5580
    );
5581
};
5582
5583
# Test for UpdateItemLostStatusWhenPaid
5584
subtest 'Update lost item to authorized value on payment of balance' => sub {
5585
    plan tests => 5;
5586
5587
    my $library = $builder->build_object( { class => "Koha::Libraries" } );
5588
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
5589
    t::lib::Mocks::mock_userenv({ patron => $manager,branchcode => $manager->branchcode });
5590
5591
    my $biblio = $builder->build_sample_biblio;
5592
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5593
5594
    for my $status (2..6) {
5595
        t::lib::Mocks::mock_preference('UpdateItemLostStatusWhenPaid', $status);
5596
5597
        my $item = $builder->build_sample_item(
5598
            {
5599
                biblionumber     => $biblio->biblionumber,
5600
                library          => $library->branchcode,
5601
                replacementprice => 99,
5602
                itype            => $itemtype,
5603
                itemlost         => 1,
5604
            }
5605
        );
5606
5607
        my $debitCharge = Koha::Account::Line->new(
5608
            {
5609
                borrowernumber    => $patron->borrowernumber,
5610
                debit_type_code   => 'LOST',
5611
                status            => undef,
5612
                itemnumber        => $item->itemnumber,
5613
                amount            => 12,
5614
                amountoutstanding => 12,
5615
                interface         => 'something',
5616
            }
5617
        )->store();
5618
5619
        my $paymentLine = Koha::Account::Line->new(
5620
            {
5621
                borrowernumber    => $patron->borrowernumber,
5622
                credit_type_code  => 'CREDIT',
5623
                status            => undef,
5624
                itemnumber        => $item->itemnumber,
5625
                amountoutstanding => 0 - 12,
5626
                amount            => 0 - 12,
5627
                interface         => 'something',
5628
            }
5629
        )->store();
5630
5631
        my $offset = Koha::Account::Offset->new(
5632
            {
5633
                credit_id => $paymentLine->id,
5634
                debit_id  => $debitCharge->id,
5635
                type      => 'APPLY',
5636
                amount    => 0
5637
            }
5638
        )->store();
5639
5640
        $paymentLine->apply( { debits => [$debitCharge] } );
5641
5642
        is(Koha::Items->find($item->itemnumber)->itemlost, $status,
5643
            "Payment should set itemlost to status $status"
5644
        );
5645
    }
5646
};
5647
5648
# Test for UpdateItemLostStatusWhenWriteOff
5649
subtest 'Update lost item to authorized value on write-off of balance' => sub {
5650
    plan tests => 5;
5651
5652
    my $library = $builder->build_object( { class => "Koha::Libraries" } );
5653
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
5654
    t::lib::Mocks::mock_userenv({ patron => $manager,branchcode => $manager->branchcode });
5655
5656
    my $biblio = $builder->build_sample_biblio;
5657
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
5658
5659
    for my $status (2..6) {
5660
        t::lib::Mocks::mock_preference('UpdateItemLostStatusWhenWriteOff', $status);
5661
5662
        my $item = $builder->build_sample_item(
5663
            {
5664
                biblionumber     => $biblio->biblionumber,
5665
                library          => $library->branchcode,
5666
                replacementprice => 99,
5667
                itype            => $itemtype,
5668
                itemlost         => 1,
5669
            }
5670
        );
5671
5672
        my $debitCharge = Koha::Account::Line->new(
5673
            {
5674
                borrowernumber    => $patron->borrowernumber,
5675
                debit_type_code   => 'LOST',
5676
                status            => undef,
5677
                itemnumber        => $item->itemnumber,
5678
                amount            => 12,
5679
                amountoutstanding => 12,
5680
                interface         => 'something',
5681
            }
5682
        )->store();
5683
5684
        my $writeOffLine = Koha::Account::Line->new(
5685
            {
5686
                borrowernumber    => $patron->borrowernumber,
5687
                credit_type_code  => 'WRITEOFF',
5688
                status            => undef,
5689
                itemnumber        => $item->itemnumber,
5690
                amountoutstanding => 0 - 12,
5691
                amount            => 0 - 12,
5692
                interface => 'something',
5693
            }
5694
        )->store();
5695
5696
        my $offset = Koha::Account::Offset->new(
5697
            {
5698
                credit_id => $writeOffLine->id,
5699
                debit_id  => $debitCharge->id,
5700
                type      => 'APPLY',
5701
                amount    => 0
5702
            }
5703
        )->store();
5704
5705
        $writeOffLine->apply( { debits => [$debitCharge] } );
5706
5707
        is(Koha::Items->find($item->itemnumber)->itemlost, $status,
5708
            "Write-off should set itemlost to status $status"
5709
        );
5710
    }
5711
};
5712
5490
subtest 'Filling a hold should cancel existing transfer' => sub {
5713
subtest 'Filling a hold should cancel existing transfer' => sub {
5491
    plan tests => 4;
5714
    plan tests => 4;
5492
5715
5493
- 

Return to bug 22740