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

(-)a/C4/Circulation.pm (-3 / +4 lines)
Lines 1385-1390 Check whether the item can be returned to the provided branch Link Here
1385
1385
1386
=item C<$branch> is the branchcode where the return is taking place
1386
=item C<$branch> is the branchcode where the return is taking place
1387
1387
1388
=item C<$transferbranch> the branch where the book should be transferred after return, if the transfer is impossible, the book will be prevented from returning.
1389
1388
=back
1390
=back
1389
1391
1390
Returns:
1392
Returns:
Lines 1403-1413 sub CanBookBeReturned { Link Here
1403
    my ( $item, $returnbranch, $transferbranch ) = @_;
1405
    my ( $item, $returnbranch, $transferbranch ) = @_;
1404
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1406
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1405
1407
1406
    # assume return is allowed to start
1407
    my $allowed = 1;
1408
    my $allowed = 1;
1408
    my $message;
1409
    my $message;
1409
1410
1410
    # identify all cases where return is forbidden
1411
    # Refuse check-in if it does not respect AllowReturnToBranch rules
1411
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1412
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1412
        $allowed = 0;
1413
        $allowed = 0;
1413
        $message = $item->homebranch;
1414
        $message = $item->homebranch;
Lines 1422-1428 sub CanBookBeReturned { Link Here
1422
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1423
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1423
    }
1424
    }
1424
1425
1425
    # identify cases where transfer rules prohibit return
1426
    # Refuse check-in if book cannot be transferred to $transferbranch due to transfer limits
1426
    if ( defined($transferbranch) && $allowed ) {
1427
    if ( defined($transferbranch) && $allowed ) {
1427
        my $from_library = Koha::Libraries->find($returnbranch);
1428
        my $from_library = Koha::Libraries->find($returnbranch);
1428
        my $to_library   = Koha::Libraries->find($transferbranch);
1429
        my $to_library   = Koha::Libraries->find($transferbranch);
(-)a/t/db_dependent/Circulation.t (-14 / +124 lines)
Lines 19-25 use Modern::Perl; Link Here
19
use utf8;
19
use utf8;
20
20
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 84;
22
use Test::More tests => 85;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Deep qw( cmp_deeply );
25
use Test::Deep qw( cmp_deeply );
Lines 1185-1191 subtest "CanBookBeRenewed tests" => sub { Link Here
1185
        );
1185
        );
1186
1186
1187
        my $ten_days_before = dt_from_string->add( days => -10 );
1187
        my $ten_days_before = dt_from_string->add( days => -10 );
1188
        my $ten_days_ahead  = dt_from_string->add( days =>  10 );
1188
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1189
        my $issue           = AddIssue(
1189
        my $issue           = AddIssue(
1190
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1190
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1191
            undef, { auto_renew => 1 }
1191
            undef, { auto_renew => 1 }
Lines 1335-1341 subtest "CanBookBeRenewed tests" => sub { Link Here
1335
        );
1335
        );
1336
1336
1337
        my $ten_days_before = dt_from_string->add( days => -10 );
1337
        my $ten_days_before = dt_from_string->add( days => -10 );
1338
        my $ten_days_ahead  = dt_from_string->add( days =>  10 );
1338
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1339
        my $issue           = AddIssue(
1339
        my $issue           = AddIssue(
1340
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1340
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1341
            undef, { auto_renew => 1 }
1341
            undef, { auto_renew => 1 }
Lines 1445-1451 subtest "CanBookBeRenewed tests" => sub { Link Here
1445
        );
1445
        );
1446
1446
1447
        my $ten_days_before = dt_from_string->add( days => -10 );
1447
        my $ten_days_before = dt_from_string->add( days => -10 );
1448
        my $ten_days_ahead  = dt_from_string->add( days =>  10 );
1448
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1449
1449
1450
        # Patron is expired and BlockExpiredPatronOpacActions=''
1450
        # Patron is expired and BlockExpiredPatronOpacActions=''
1451
        # => auto renew is allowed
1451
        # => auto renew is allowed
Lines 1497-1503 subtest "CanBookBeRenewed tests" => sub { Link Here
1497
        );
1497
        );
1498
1498
1499
        my $ten_days_before = dt_from_string->add( days => -10 );
1499
        my $ten_days_before = dt_from_string->add( days => -10 );
1500
        my $ten_days_ahead  = dt_from_string->add( days =>  10 );
1500
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1501
        my $issue           = AddIssue(
1501
        my $issue           = AddIssue(
1502
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1502
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1503
            undef, { auto_renew => 1 }
1503
            undef, { auto_renew => 1 }
Lines 1618-1624 subtest "CanBookBeRenewed tests" => sub { Link Here
1618
        );
1618
        );
1619
1619
1620
        my $ten_days_before = dt_from_string->add( days => -10 );
1620
        my $ten_days_before = dt_from_string->add( days => -10 );
1621
        my $ten_days_ahead  = dt_from_string->add( days =>  10 );
1621
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1622
        my $issue           = AddIssue(
1622
        my $issue           = AddIssue(
1623
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1623
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1624
            undef, { auto_renew => 1 }
1624
            undef, { auto_renew => 1 }
Lines 1969-1975 subtest "GetUpcomingDueIssues" => sub { Link Here
1969
    my $a_borrower                = Koha::Patrons->find($a_borrower_borrowernumber);
1969
    my $a_borrower                = Koha::Patrons->find($a_borrower_borrowernumber);
1970
1970
1971
    my $yesterday      = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1971
    my $yesterday      = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1972
    my $two_days_ahead = DateTime->today( time_zone => C4::Context->tz() )->add( days =>  2 );
1972
    my $two_days_ahead = DateTime->today( time_zone => C4::Context->tz() )->add( days => 2 );
1973
    my $today          = DateTime->today( time_zone => C4::Context->tz() );
1973
    my $today          = DateTime->today( time_zone => C4::Context->tz() );
1974
1974
1975
    my $issue    = AddIssue( $a_borrower, $item_1->barcode, $yesterday );
1975
    my $issue    = AddIssue( $a_borrower, $item_1->barcode, $yesterday );
Lines 2961-2966 subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub Link Here
2961
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2961
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2962
};
2962
};
2963
2963
2964
subtest 'AddReturn + TransferLimits' => sub {
2965
    plan tests => 3;
2966
2967
    ########################################################################
2968
    #
2969
    # Prepare test
2970
    #
2971
    ########################################################################
2972
2973
    my $patron        = $builder->build_object( { class => 'Koha::Patrons' } );
2974
    my $homebranch    = $builder->build( { source => 'Branch' } );
2975
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2976
    my $returnbranch  = $builder->build( { source => 'Branch' } );
2977
    my $item          = $builder->build_sample_item(
2978
        {
2979
            homebranch    => $homebranch->{branchcode},
2980
            holdingbranch => $holdingbranch->{branchcode},
2981
        }
2982
    );
2983
2984
    # Default circulation rules
2985
    Koha::CirculationRules->set_rules(
2986
        {
2987
            categorycode => undef,
2988
            branchcode   => undef,
2989
            itemtype     => $item->itype,
2990
            rules        => {
2991
                maxissueqty     => 1,
2992
                reservesallowed => 25,
2993
                issuelength     => 7,
2994
                lengthunit      => 'days',
2995
                renewalsallowed => 5,
2996
                renewalperiod   => 7,
2997
                norenewalbefore => undef,
2998
                auto_renew      => 0,
2999
                fine            => .10,
3000
                chargeperiod    => 1,
3001
            }
3002
        }
3003
    );
3004
    t::lib::Mocks::mock_userenv( { branchcode => $holdingbranch->{branchcode} } );
3005
3006
    # Each transfer from returnbranch is forbidden
3007
    my $limit = Koha::Item::Transfer::Limit->new(
3008
        {
3009
            fromBranch => $returnbranch->{branchcode},
3010
            toBranch   => $holdingbranch->{branchcode},
3011
            itemtype   => $item->effective_itemtype,
3012
        }
3013
    )->store();
3014
    my $limit2 = Koha::Item::Transfer::Limit->new(
3015
        {
3016
            fromBranch => $returnbranch->{branchcode},
3017
            toBranch   => $homebranch->{branchcode},
3018
            itemtype   => $item->effective_itemtype,
3019
        }
3020
    )->store();
3021
3022
    ########################################################################
3023
    #
3024
    # Begin test
3025
    #
3026
    # Each transfer is forbidden by transfer limits
3027
    # Checkin must be forbidden except if there is no transfer to perform
3028
    #
3029
    ########################################################################
3030
3031
    # Case 1: There is a transfer to to do homebranch
3032
    Koha::CirculationRules->set_rules(
3033
        {
3034
            branchcode => undef,
3035
            itemtype   => undef,
3036
            rules      => {
3037
                returnbranch => 'homebranch',
3038
            },
3039
        }
3040
    );
3041
    my $issue = AddIssue( $patron, $item->barcode );
3042
    my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3043
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do" );
3044
3045
    # Case 2: There is a transfer to do to holdingbranch
3046
    Koha::CirculationRules->set_rules(
3047
        {
3048
            branchcode => undef,
3049
            itemtype   => undef,
3050
            rules      => {
3051
                returnbranch => 'holdingbranch',
3052
            },
3053
        }
3054
    );
3055
    $issue->delete;
3056
    $item->holdingbranch( $holdingbranch->{branchcode} )->store();
3057
    $issue = AddIssue( $patron, $item->barcode );
3058
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3059
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do (item is floating)" );
3060
3061
    # Case 3: There is no transfer to do
3062
    Koha::CirculationRules->set_rules(
3063
        {
3064
            branchcode => undef,
3065
            itemtype   => undef,
3066
            rules      => {
3067
                returnbranch => 'noreturn',
3068
            },
3069
        }
3070
    );
3071
    $issue->delete;
3072
    $issue = AddIssue( $patron, $item->barcode );
3073
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3074
    is( $doreturn, 1, "Item cannot be returned if there is a transfer to do" );
3075
};
3076
2964
subtest 'Statistic patrons "X"' => sub {
3077
subtest 'Statistic patrons "X"' => sub {
2965
    plan tests => 15;
3078
    plan tests => 15;
2966
3079
Lines 3048-3055 subtest 'Statistic patrons "X"' => sub { Link Here
3048
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3161
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3049
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3162
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3050
    );
3163
    );
3051
3052
    # TODO There are other tests to provide here
3053
};
3164
};
3054
3165
3055
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
3166
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
Lines 3996-4002 subtest 'AddReturn | is_overdue' => sub { Link Here
3996
        is( $line->status,                'RETURNED', "Overdue fine is fixed" );
4107
        is( $line->status,                'RETURNED', "Overdue fine is fixed" );
3997
        $line = $lines->next;
4108
        $line = $lines->next;
3998
        is( $line->amount + 0,            -2, "Original payment amount remains as 2" );
4109
        is( $line->amount + 0,            -2, "Original payment amount remains as 2" );
3999
        is( $line->amountoutstanding + 0,  0, "Original payment remains applied" );
4110
        is( $line->amountoutstanding + 0, 0,  "Original payment remains applied" );
4000
        $line = $lines->next;
4111
        $line = $lines->next;
4001
        is( $line->amount + 0,            -1, "Refund amount correctly set to 1" );
4112
        is( $line->amount + 0,            -1, "Refund amount correctly set to 1" );
4002
        is( $line->amountoutstanding + 0, -1, "Refund amount outstanding unspent" );
4113
        is( $line->amountoutstanding + 0, -1, "Refund amount outstanding unspent" );
Lines 4950-4956 subtest '_FixOverduesOnReturn' => sub { Link Here
4950
    my $credit = $offset->credit;
5061
    my $credit = $offset->credit;
4951
    is( ref $credit,                    "Koha::Account::Line", "Found matching credit for fine forgiveness" );
5062
    is( ref $credit,                    "Koha::Account::Line", "Found matching credit for fine forgiveness" );
4952
    is( $credit->amount + 0,            -99,                   "Credit amount is set correctly" );
5063
    is( $credit->amount + 0,            -99,                   "Credit amount is set correctly" );
4953
    is( $credit->amountoutstanding + 0,  0,                    "Credit amountoutstanding is correctly set to 0" );
5064
    is( $credit->amountoutstanding + 0, 0,                     "Credit amountoutstanding is correctly set to 0" );
4954
5065
4955
    # Bug 25417 - Only forgive fines where there is an amount outstanding to forgive
5066
    # Bug 25417 - Only forgive fines where there is an amount outstanding to forgive
4956
    $accountline->set(
5067
    $accountline->set(
Lines 7701-7707 subtest 'NoRefundOnLostFinesPaidAge' => sub { Link Here
7701
        {
7812
        {
7702
            borrowernumber    => $patron->id,
7813
            borrowernumber    => $patron->id,
7703
            date              => '1970-01-01 14:00:01',
7814
            date              => '1970-01-01 14:00:01',
7704
            amountoutstanding =>  0,
7815
            amountoutstanding => 0,
7705
            amount            => -5,
7816
            amount            => -5,
7706
            interface         => 'commandline',
7817
            interface         => 'commandline',
7707
            credit_type_code  => 'PAYMENT'
7818
            credit_type_code  => 'PAYMENT'
Lines 7757-7763 subtest 'NoRefundOnLostFinesPaidAge' => sub { Link Here
7757
            borrowernumber    => $patron2->id,
7868
            borrowernumber    => $patron2->id,
7758
            date              => '1970-01-01 14:00:01',
7869
            date              => '1970-01-01 14:00:01',
7759
            amount            => -5,
7870
            amount            => -5,
7760
            amountoutstanding =>  0,
7871
            amountoutstanding => 0,
7761
            interface         => 'commandline',
7872
            interface         => 'commandline',
7762
            credit_type_code  => 'PAYMENT'
7873
            credit_type_code  => 'PAYMENT'
7763
        }
7874
        }
7764
- 

Return to bug 7376