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

(-)a/C4/Circulation.pm (-31 / +20 lines)
Lines 1358-1364 sub CanBookBeIssued { Link Here
1358
1358
1359
=head2 CanBookBeReturned
1359
=head2 CanBookBeReturned
1360
1360
1361
  ($returnallowed, $message) = CanBookBeReturned($item, $branch)
1361
  ($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch])
1362
1362
1363
Check whether the item can be returned to the provided branch
1363
Check whether the item can be returned to the provided branch
1364
1364
Lines 1383-1431 Returns: Link Here
1383
=cut
1383
=cut
1384
1384
1385
sub CanBookBeReturned {
1385
sub CanBookBeReturned {
1386
    my ( $item, $branch ) = @_;
1386
    my ( $item, $returnbranch, $transferbranch ) = @_;
1387
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1387
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1388
1388
1389
    # assume return is allowed to start
1389
    # assume return is allowed to start
1390
    my $allowed   = 1;
1390
    my $allowed = 1;
1391
    my $to_branch = $branch;
1392
    my $message;
1391
    my $message;
1393
1392
1394
    # identify all cases where return is forbidden
1393
    # identify all cases where return is forbidden
1395
    if ( $allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch ) {
1394
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1396
        $allowed = 0;
1395
        $allowed = 0;
1397
        $message = $to_branch = $item->homebranch;
1396
        $message = $item->homebranch;
1398
    } elsif ( $allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch ) {
1397
    } elsif ( $allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch ) {
1399
        $allowed = 0;
1398
        $allowed = 0;
1400
        $message = $to_branch = $item->holdingbranch;
1399
        $message = $item->holdingbranch;
1401
    } elsif ( $allowreturntobranch eq 'homeorholdingbranch'
1400
    } elsif ( $allowreturntobranch eq 'homeorholdingbranch'
1402
        && $branch ne $item->homebranch
1401
        && $returnbranch ne $item->homebranch
1403
        && $branch ne $item->holdingbranch )
1402
        && $returnbranch ne $item->holdingbranch )
1404
    {
1403
    {
1405
        $allowed = 0;
1404
        $allowed = 0;
1406
        $message = $to_branch = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1405
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1407
    }
1406
    }
1408
1407
1409
    return ( $allowed, $message ) unless $allowed;
1408
    # identify cases where transfer rules prohibit return
1410
1409
    if ( defined($transferbranch) && $allowed ) {
1411
    # Make sure there are no branch transfer limits between item's current
1410
        my $from_library = Koha::Libraries->find($returnbranch);
1412
    # branch (holdinbranch) and the return branch
1411
        my $to_library   = Koha::Libraries->find($transferbranch);
1413
    my $return_library = Koha::Libraries->find($to_branch);
1412
        if ( !$item->can_be_transferred( { from => $from_library, to => $to_library } ) ) {
1414
    if ( !$item->can_be_transferred( { to => $return_library } ) ) {
1413
            $allowed = 0;
1415
        return ( 0, $item->homebranch );
1414
            $message = $transferbranch;
1416
    }
1415
        }
1417
1418
    # Make sure there are no branch transfer limits between
1419
    # either homebranch and holdinbranch and the return branch
1420
    my $home_library    = Koha::Libraries->find( $item->homebranch );
1421
    my $holding_library = Koha::Libraries->find( $item->holdingbranch );
1422
    if (   $item->can_be_transferred( { from => $return_library, to => $holding_library } )
1423
        or $item->can_be_transferred( { from => $return_library, to => $home_library } ) )
1424
    {
1425
        return ( 1, undef );
1426
    }
1416
    }
1427
1417
1428
    return ( 0, $item->homebranch );
1418
    return ( $allowed, $message );
1429
}
1419
}
1430
1420
1431
=head2 CheckHighHolds
1421
=head2 CheckHighHolds
Lines 2308-2314 sub AddReturn { Link Here
2308
    }
2298
    }
2309
2299
2310
    # check if the return is allowed at this branch
2300
    # check if the return is allowed at this branch
2311
    my ( $returnallowed, $message ) = CanBookBeReturned( $item, $branch );
2301
    my ( $returnallowed, $message ) = CanBookBeReturned( $item, $branch, $returnbranch );
2312
2302
2313
    unless ($returnallowed) {
2303
    unless ($returnallowed) {
2314
        $messages->{'Wrongbranch'} = {
2304
        $messages->{'Wrongbranch'} = {
2315
- 

Return to bug 7376