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

(-)a/C4/Circulation.pm (-31 / +20 lines)
Lines 1375-1381 sub CanBookBeIssued { Link Here
1375
1375
1376
=head2 CanBookBeReturned
1376
=head2 CanBookBeReturned
1377
1377
1378
  ($returnallowed, $message) = CanBookBeReturned($item, $branch)
1378
  ($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch])
1379
1379
1380
Check whether the item can be returned to the provided branch
1380
Check whether the item can be returned to the provided branch
1381
1381
Lines 1400-1448 Returns: Link Here
1400
=cut
1400
=cut
1401
1401
1402
sub CanBookBeReturned {
1402
sub CanBookBeReturned {
1403
    my ( $item, $branch ) = @_;
1403
    my ( $item, $returnbranch, $transferbranch ) = @_;
1404
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1404
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1405
1405
1406
    # assume return is allowed to start
1406
    # assume return is allowed to start
1407
    my $allowed   = 1;
1407
    my $allowed = 1;
1408
    my $to_branch = $branch;
1409
    my $message;
1408
    my $message;
1410
1409
1411
    # identify all cases where return is forbidden
1410
    # identify all cases where return is forbidden
1412
    if ( $allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch ) {
1411
    if ( $allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch ) {
1413
        $allowed = 0;
1412
        $allowed = 0;
1414
        $message = $to_branch = $item->homebranch;
1413
        $message = $item->homebranch;
1415
    } elsif ( $allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch ) {
1414
    } elsif ( $allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch ) {
1416
        $allowed = 0;
1415
        $allowed = 0;
1417
        $message = $to_branch = $item->holdingbranch;
1416
        $message = $item->holdingbranch;
1418
    } elsif ( $allowreturntobranch eq 'homeorholdingbranch'
1417
    } elsif ( $allowreturntobranch eq 'homeorholdingbranch'
1419
        && $branch ne $item->homebranch
1418
        && $returnbranch ne $item->homebranch
1420
        && $branch ne $item->holdingbranch )
1419
        && $returnbranch ne $item->holdingbranch )
1421
    {
1420
    {
1422
        $allowed = 0;
1421
        $allowed = 0;
1423
        $message = $to_branch = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1422
        $message = $item->homebranch;    # FIXME: choice of homebranch is arbitrary
1424
    }
1423
    }
1425
1424
1426
    return ( $allowed, $message ) unless $allowed;
1425
    # identify cases where transfer rules prohibit return
1427
1426
    if ( defined($transferbranch) && $allowed ) {
1428
    # Make sure there are no branch transfer limits between item's current
1427
        my $from_library = Koha::Libraries->find($returnbranch);
1429
    # branch (holdinbranch) and the return branch
1428
        my $to_library   = Koha::Libraries->find($transferbranch);
1430
    my $return_library = Koha::Libraries->find($to_branch);
1429
        if ( !$item->can_be_transferred( { from => $from_library, to => $to_library } ) ) {
1431
    if ( !$item->can_be_transferred( { to => $return_library } ) ) {
1430
            $allowed = 0;
1432
        return ( 0, $item->homebranch );
1431
            $message = $transferbranch;
1433
    }
1432
        }
1434
1435
    # Make sure there are no branch transfer limits between
1436
    # either homebranch and holdinbranch and the return branch
1437
    my $home_library    = Koha::Libraries->find( $item->homebranch );
1438
    my $holding_library = Koha::Libraries->find( $item->holdingbranch );
1439
    if (   $item->can_be_transferred( { from => $return_library, to => $holding_library } )
1440
        or $item->can_be_transferred( { from => $return_library, to => $home_library } ) )
1441
    {
1442
        return ( 1, undef );
1443
    }
1433
    }
1444
1434
1445
    return ( 0, $item->homebranch );
1435
    return ( $allowed, $message );
1446
}
1436
}
1447
1437
1448
=head2 CheckHighHolds
1438
=head2 CheckHighHolds
Lines 2392-2398 sub AddReturn { Link Here
2392
    }
2382
    }
2393
2383
2394
    # check if the return is allowed at this branch
2384
    # check if the return is allowed at this branch
2395
    my ( $returnallowed, $message ) = CanBookBeReturned( $item, $branch );
2385
    my ( $returnallowed, $message ) = CanBookBeReturned( $item, $branch, $returnbranch );
2396
2386
2397
    unless ($returnallowed) {
2387
    unless ($returnallowed) {
2398
        $messages->{'Wrongbranch'} = {
2388
        $messages->{'Wrongbranch'} = {
2399
- 

Return to bug 7376