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

(-)a/t/db_dependent/Circulation.t (-2 / +153 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 => 74;
21
use Test::More tests => 75;
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 6739-6744 subtest 'Test CanBookBeIssued param ignore_reserves (Bug 35322)' => sub { Link Here
6739
6739
6740
};
6740
};
6741
6741
6742
subtest 'NoRefundOnLostFinesPaidAge' => sub {
6743
    plan tests => 2;
6744
6745
    t::lib::Mocks::mock_preference( 'BlockReturnOfLostItems', 0 );
6746
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
6747
    my $patron  = $builder->build_object(
6748
        {
6749
            class => 'Koha::Patrons',
6750
            value => { categorycode => $patron_category->{categorycode} }
6751
        }
6752
    );
6753
6754
    my $biblionumber = $builder->build_sample_biblio(
6755
        {
6756
            branchcode => $library->branchcode,
6757
        }
6758
    )->biblionumber;
6759
6760
    Koha::CirculationRules->search->delete;
6761
    Koha::CirculationRules->set_rules(
6762
        {
6763
            categorycode => undef,
6764
            itemtype     => undef,
6765
            branchcode   => undef,
6766
            rules        => {
6767
                issuelength => 14,
6768
                lengthunit  => 'days',
6769
            }
6770
        }
6771
    );
6772
    $builder->build(
6773
        {
6774
            source => 'CirculationRule',
6775
            value  => {
6776
                branchcode   => undef,
6777
                categorycode => undef,
6778
                itemtype     => undef,
6779
                rule_name    => 'lostreturn',
6780
                rule_value   => 'refund'
6781
            }
6782
        }
6783
    );
6784
6785
    my $item = $builder->build_sample_item(
6786
        {
6787
            biblionumber => $biblionumber,
6788
            library      => $library->branchcode,
6789
        }
6790
    );
6791
    my $lost_on = dt_from_string->subtract( days => 5 )->date;
6792
    my $issue   = AddIssue( $patron, $item->barcode );
6793
    LostItem( $item->itemnumber, 'cli', 0 );
6794
    $item->_result->itemlost(1);
6795
    $item->_result->itemlost_on($lost_on);
6796
    $item->_result->update();
6797
6798
    my $debit = Koha::Account::Line->new(
6799
        {
6800
            borrowernumber    => $patron->id,
6801
            date              => '1970-01-01 14:00:01',
6802
            amount            => 5,
6803
            amountoutstanding => 0,
6804
            interface         => 'commandline',
6805
            debit_type_code   => 'LOST',
6806
            itemnumber        => $item->itemnumber
6807
        }
6808
    )->store();
6809
    my $credit = Koha::Account::Line->new(
6810
        {
6811
            borrowernumber    => $patron->id,
6812
            date              => '1970-01-01 14:00:01',
6813
            amountoutstanding => 0,
6814
            amount            => -5,
6815
6816
            interface        => 'commandline',
6817
            credit_type_code => 'PAYMENT'
6818
        }
6819
    )->store();
6820
    my $offset = Koha::Account::Offset->new(
6821
        {
6822
            credit_id  => $credit->id,
6823
            debit_id   => $debit->id,
6824
            type       => 'APPLY',
6825
            amount     => -5,
6826
            created_on => '1971-01-01 14:00:01'
6827
        }
6828
    )->store();
6829
6830
    t::lib::Mocks::mock_preference( 'NoRefundOnLostFinesPaidAge', undef );
6831
    my ( $return, $messages ) = AddReturn( $item->barcode, $library->branchcode, undef, dt_from_string );
6832
6833
    is( $patron->account->balance, -5, 'Lost fine has been refunded' );
6834
6835
    my $patron2 = $builder->build_object(
6836
        {
6837
            class => 'Koha::Patrons',
6838
            value => { categorycode => $patron_category->{categorycode} }
6839
        }
6840
    );
6841
    my $item2 = $builder->build_sample_item(
6842
        {
6843
            biblionumber => $biblionumber,
6844
            library      => $library->branchcode,
6845
        }
6846
    );
6847
    my $lost_on2 = dt_from_string->subtract( days => 5 )->date;
6848
    my $issue2   = AddIssue( $patron2, $item2->barcode );
6849
    LostItem( $item2->itemnumber, 'cli', 0 );
6850
    $item2->_result->itemlost(1);
6851
    $item2->_result->itemlost_on($lost_on2);
6852
    $item2->_result->update();
6853
6854
    my $debit2 = Koha::Account::Line->new(
6855
        {
6856
            borrowernumber    => $patron2->id,
6857
            date              => '1970-01-01 14:00:01',
6858
            amount            => 5,
6859
            amountoutstanding => 0,
6860
            interface         => 'commandline',
6861
            debit_type_code   => 'LOST',
6862
            itemnumber        => $item2->itemnumber
6863
        }
6864
    )->store();
6865
    my $credit2 = Koha::Account::Line->new(
6866
        {
6867
            borrowernumber    => $patron2->id,
6868
            date              => '1970-01-01 14:00:01',
6869
            amount            => -5,
6870
            amountoutstanding => 0,
6871
            interface         => 'commandline',
6872
            credit_type_code  => 'PAYMENT'
6873
        }
6874
    )->store();
6875
    my $offset2 = Koha::Account::Offset->new(
6876
        {
6877
            credit_id  => $credit2->id,
6878
            debit_id   => $debit2->id,
6879
            type       => 'APPLY',
6880
            amount     => -5,
6881
            created_on => '1971-01-01 14:00:01'
6882
        }
6883
    )->store();
6884
6885
    t::lib::Mocks::mock_preference( 'NoRefundOnLostFinesPaidAge', 5 );
6886
    my ( $return2, $messages2 ) = AddReturn( $item2->barcode, $library->branchcode, undef, dt_from_string );
6887
6888
    is(
6889
        $patron2->account->balance, 0,
6890
        'Lost fine has not been refunded as it is older than NoRefundOnLostFinesPaidAge'
6891
    );
6892
};
6893
6742
6894
6743
$schema->storage->txn_rollback;
6895
$schema->storage->txn_rollback;
6744
C4::Context->clear_syspref_cache();
6896
C4::Context->clear_syspref_cache();
6745
- 

Return to bug 28575