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

(-)a/C4/Circulation.pm (-3 / +4 lines)
Lines 1368-1373 Check whether the item can be returned to the provided branch Link Here
1368
1368
1369
=item C<$branch> is the branchcode where the return is taking place
1369
=item C<$branch> is the branchcode where the return is taking place
1370
1370
1371
=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.
1372
1371
=back
1373
=back
1372
1374
1373
Returns:
1375
Returns:
Lines 1386-1396 sub CanBookBeReturned { Link Here
1386
    my ( $item, $returnbranch, $transferbranch ) = @_;
1388
    my ( $item, $returnbranch, $transferbranch ) = @_;
1387
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1389
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1388
1390
1389
    # assume return is allowed to start
1390
    my $allowed = 1;
1391
    my $allowed = 1;
1391
    my $message;
1392
    my $message;
1392
1393
1393
    # identify all cases where return is forbidden
1394
    # Refuse check-in if it does not respect AllowReturnToBranch rules
1394
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1395
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1395
        $allowed = 0;
1396
        $allowed = 0;
1396
        $message = $item->homebranch;
1397
        $message = $item->homebranch;
Lines 1405-1411 sub CanBookBeReturned { Link Here
1405
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1406
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1406
    }
1407
    }
1407
1408
1408
    # identify cases where transfer rules prohibit return
1409
    # Refuse check-in if book cannot be transferred to $transferbranch due to transfer limits
1409
    if ( defined($transferbranch) && $allowed ) {
1410
    if ( defined($transferbranch) && $allowed ) {
1410
        my $from_library = Koha::Libraries->find($returnbranch);
1411
        my $from_library = Koha::Libraries->find($returnbranch);
1411
        my $to_library   = Koha::Libraries->find($transferbranch);
1412
        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 => 77;
22
use Test::More tests => 78;
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 2957-2962 subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub Link Here
2957
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2957
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2958
};
2958
};
2959
2959
2960
subtest 'AddReturn + TransferLimits' => sub {
2961
    plan tests => 3;
2962
2963
    ########################################################################
2964
    #
2965
    # Prepare test
2966
    #
2967
    ########################################################################
2968
2969
    my $patron        = $builder->build_object( { class => 'Koha::Patrons' } );
2970
    my $homebranch    = $builder->build( { source => 'Branch' } );
2971
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2972
    my $returnbranch  = $builder->build( { source => 'Branch' } );
2973
    my $item          = $builder->build_sample_item(
2974
        {
2975
            homebranch    => $homebranch->{branchcode},
2976
            holdingbranch => $holdingbranch->{branchcode},
2977
        }
2978
    );
2979
2980
    # Default circulation rules
2981
    Koha::CirculationRules->set_rules(
2982
        {
2983
            categorycode => undef,
2984
            branchcode   => undef,
2985
            itemtype     => $item->itype,
2986
            rules        => {
2987
                maxissueqty     => 1,
2988
                reservesallowed => 25,
2989
                issuelength     => 7,
2990
                lengthunit      => 'days',
2991
                renewalsallowed => 5,
2992
                renewalperiod   => 7,
2993
                norenewalbefore => undef,
2994
                auto_renew      => 0,
2995
                fine            => .10,
2996
                chargeperiod    => 1,
2997
            }
2998
        }
2999
    );
3000
    t::lib::Mocks::mock_userenv( { branchcode => $holdingbranch->{branchcode} } );
3001
3002
    # Each transfer from returnbranch is forbidden
3003
    my $limit = Koha::Item::Transfer::Limit->new(
3004
        {
3005
            fromBranch => $returnbranch->{branchcode},
3006
            toBranch   => $holdingbranch->{branchcode},
3007
            itemtype   => $item->effective_itemtype,
3008
        }
3009
    )->store();
3010
    my $limit2 = Koha::Item::Transfer::Limit->new(
3011
        {
3012
            fromBranch => $returnbranch->{branchcode},
3013
            toBranch   => $homebranch->{branchcode},
3014
            itemtype   => $item->effective_itemtype,
3015
        }
3016
    )->store();
3017
3018
    ########################################################################
3019
    #
3020
    # Begin test
3021
    #
3022
    # Each transfer is forbidden by transfer limits
3023
    # Checkin must be forbidden except if there is no transfer to perform
3024
    #
3025
    ########################################################################
3026
3027
    # Case 1: There is a transfer to to do homebranch
3028
    Koha::CirculationRules->set_rules(
3029
        {
3030
            branchcode => undef,
3031
            itemtype   => undef,
3032
            rules      => {
3033
                returnbranch => 'homebranch',
3034
            },
3035
        }
3036
    );
3037
    my $issue = AddIssue( $patron, $item->barcode );
3038
    my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3039
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do" );
3040
3041
    # Case 2: There is a transfer to do to holdingbranch
3042
    Koha::CirculationRules->set_rules(
3043
        {
3044
            branchcode => undef,
3045
            itemtype   => undef,
3046
            rules      => {
3047
                returnbranch => 'holdingbranch',
3048
            },
3049
        }
3050
    );
3051
    $issue->delete;
3052
    $item->holdingbranch( $holdingbranch->{branchcode} )->store();
3053
    $issue = AddIssue( $patron, $item->barcode );
3054
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3055
    is( $doreturn, 0, "Item cannot be returned if there is a transfer to do (item is floating)" );
3056
3057
    # Case 3: There is no transfer to do
3058
    Koha::CirculationRules->set_rules(
3059
        {
3060
            branchcode => undef,
3061
            itemtype   => undef,
3062
            rules      => {
3063
                returnbranch => 'noreturn',
3064
            },
3065
        }
3066
    );
3067
    $issue->delete;
3068
    $issue = AddIssue( $patron, $item->barcode );
3069
    ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item->barcode, $returnbranch->{branchcode} );
3070
    is( $doreturn, 1, "Item cannot be returned if there is a transfer to do" );
3071
};
3072
2960
subtest 'Statistic patrons "X"' => sub {
3073
subtest 'Statistic patrons "X"' => sub {
2961
    plan tests => 15;
3074
    plan tests => 15;
2962
3075
Lines 3044-3051 subtest 'Statistic patrons "X"' => sub { Link Here
3044
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3157
        Koha::Statistics->search( { itemnumber => $item_4->itemnumber } )->count, 3,
3045
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3158
        'Issue, return, and localuse should be recorded in statistics table for item 4.'
3046
    );
3159
    );
3047
3048
    # TODO There are other tests to provide here
3049
};
3160
};
3050
3161
3051
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
3162
subtest "Bug 27753 - Add AutoClaimReturnStatusOnCheckin" => sub {
3052
- 

Return to bug 7376