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 (-4 / +114 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 => 86;
22
use Test::More tests => 87;
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 3012-3017 subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub Link Here
3012
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
3012
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
3013
};
3013
};
3014
3014
3015
subtest 'AddReturn + TransferLimits' => sub {
3016
    plan tests => 3;
3017
3018
    ########################################################################
3019
    #
3020
    # Prepare test
3021
    #
3022
    ########################################################################
3023
3024
    my $patron        = $builder->build_object( { class => 'Koha::Patrons' } );
3025
    my $homebranch    = $builder->build( { source => 'Branch' } );
3026
    my $holdingbranch = $builder->build( { source => 'Branch' } );
3027
    my $returnbranch  = $builder->build( { source => 'Branch' } );
3028
    my $item          = $builder->build_sample_item(
3029
        {
3030
            homebranch    => $homebranch->{branchcode},
3031
            holdingbranch => $holdingbranch->{branchcode},
3032
        }
3033
    );
3034
3035
    # Default circulation rules
3036
    Koha::CirculationRules->set_rules(
3037
        {
3038
            categorycode => undef,
3039
            branchcode   => undef,
3040
            itemtype     => $item->itype,
3041
            rules        => {
3042
                maxissueqty     => 1,
3043
                reservesallowed => 25,
3044
                issuelength     => 7,
3045
                lengthunit      => 'days',
3046
                renewalsallowed => 5,
3047
                renewalperiod   => 7,
3048
                norenewalbefore => undef,
3049
                auto_renew      => 0,
3050
                fine            => .10,
3051
                chargeperiod    => 1,
3052
            }
3053
        }
3054
    );
3055
    t::lib::Mocks::mock_userenv( { branchcode => $holdingbranch->{branchcode} } );
3056
3057
    # Each transfer from returnbranch is forbidden
3058
    my $limit = Koha::Item::Transfer::Limit->new(
3059
        {
3060
            fromBranch => $returnbranch->{branchcode},
3061
            toBranch   => $holdingbranch->{branchcode},
3062
            itemtype   => $item->effective_itemtype,
3063
        }
3064
    )->store();
3065
    my $limit2 = Koha::Item::Transfer::Limit->new(
3066
        {
3067
            fromBranch => $returnbranch->{branchcode},
3068
            toBranch   => $homebranch->{branchcode},
3069
            itemtype   => $item->effective_itemtype,
3070
        }
3071
    )->store();
3072
3073
    ########################################################################
3074
    #
3075
    # Begin test
3076
    #
3077
    # Each transfer is forbidden by transfer limits
3078
    # Checkin must be forbidden except if there is no transfer to perform
3079
    #
3080
    ########################################################################
3081
3082
    # Case 1: There is a transfer to to do homebranch
3083
    Koha::CirculationRules->set_rules(
3084
        {
3085
            branchcode => undef,
3086
            itemtype   => undef,
3087
            rules      => {
3088
                returnbranch => 'homebranch',
3089
            },
3090
        }
3091
    );
3092
    my $issue = AddIssue( $patron, $item->barcode );
3093
    my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3094
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do" );
3095
3096
    # Case 2: There is a transfer to do to holdingbranch
3097
    Koha::CirculationRules->set_rules(
3098
        {
3099
            branchcode => undef,
3100
            itemtype   => undef,
3101
            rules      => {
3102
                returnbranch => 'holdingbranch',
3103
            },
3104
        }
3105
    );
3106
    $issue->delete;
3107
    $item->holdingbranch( $holdingbranch->{branchcode} )->store();
3108
    $issue = AddIssue( $patron, $item->barcode );
3109
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3110
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do (item is floating)" );
3111
3112
    # Case 3: There is no transfer to do
3113
    Koha::CirculationRules->set_rules(
3114
        {
3115
            branchcode => undef,
3116
            itemtype   => undef,
3117
            rules      => {
3118
                returnbranch => 'noreturn',
3119
            },
3120
        }
3121
    );
3122
    $issue->delete;
3123
    $issue = AddIssue( $patron, $item->barcode );
3124
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3125
    is( $doreturn, 1, "Item cannot be returned if there is a transfer to do" );
3126
};
3127
3015
subtest 'Statistic patrons "X"' => sub {
3128
subtest 'Statistic patrons "X"' => sub {
3016
    plan tests => 15;
3129
    plan tests => 15;
3017
3130
Lines 3099-3106 subtest 'Statistic patrons "X"' => sub { Link Here
3099
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3212
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3100
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3213
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3101
    );
3214
    );
3102
3103
    # TODO There are other tests to provide here
3104
};
3215
};
3105
3216
3106
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
3217
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
3107
- 

Return to bug 7376