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

(-)a/Koha/Item.pm (-80 / +36 lines)
Lines 553-619 sub can_be_transferred { Link Here
553
553
554
}
554
}
555
555
556
=head3 _can_pickup_locations
557
558
$item->_can_pickup_locations({ to => $to_libraries, from => $from_library })
559
Checks if an item can be transferred to given libraries.
560
561
This feature is controlled by two system preferences:
562
UseBranchTransferLimits to enable / disable the feature
563
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
564
                         for setting the limitations
565
566
Takes HASHref that can have the following parameters:
567
    MANDATORY PARAMETERS:
568
    $to   : Array of Koha::Libraries
569
    OPTIONAL PARAMETERS:
570
    $from : Koha::Library  # if not given, item holdingbranch
571
                           # will be used instead
572
573
Returns arry of Koha::Libraries that item can be transferred to $to_library and
574
are pickup_locations
575
576
If checking only one library please use $item->can_be_transferred.
577
578
=cut
579
580
sub _can_pickup_locations {
581
    my ($self, $params ) = @_;
582
583
    my $to   = $params->{to};
584
    my $from = $params->{from};
585
    $from = defined $from ? $from->branchcode : $self->holdingbranch;
586
587
    my @pickup_locations;
588
    my @destination_codes;
589
    foreach my $lib (@$to){
590
        next unless $lib->pickup_location;
591
        push @destination_codes, $lib->branchcode;
592
        push @pickup_locations, $lib;
593
    }
594
595
    return \@pickup_locations unless C4::Context->preference('UseBranchTransferLimits');
596
597
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
598
    my $limiter = $limittype eq 'itemtype' ? $self->effective_itemtype : $self->ccode;
599
600
    my $limits = Koha::Item::Transfer::Limits->search({
601
                fromBranch => $from,
602
                $limittype => $limiter
603
            });
604
    my @limits = $limits->get_column('toBranch');
605
    return \@pickup_locations unless @limits;
606
607
    my @can_transfer = Koha::Libraries->search({
608
        pickup_location => 1,
609
        branchcode => {
610
            -in => \@destination_codes,
611
            -not_in => \@limits,
612
        }
613
    });
614
    return \@can_transfer;
615
}
616
617
=head3 pickup_locations
556
=head3 pickup_locations
618
557
619
$pickup_locations = $item->pickup_locations( {patron => $patron } )
558
$pickup_locations = $item->pickup_locations( {patron => $patron } )
Lines 633-668 sub pickup_locations { Link Here
633
    my $branchitemrule =
572
    my $branchitemrule =
634
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
573
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
635
574
636
    my @libs;
637
    if(defined $patron) {
575
    if(defined $patron) {
638
        return \@libs if $branchitemrule->{holdallowed} == 3 && !$self->home_branch->validate_hold_sibling( {branchcode => $patron->branchcode} );
576
        return Koha::Libraries->new()->empty if $branchitemrule->{holdallowed} == 3 && !$self->home_branch->validate_hold_sibling( {branchcode => $patron->branchcode} );
639
        return \@libs if $branchitemrule->{holdallowed} == 1 && $self->home_branch->branchcode ne $patron->branchcode;
577
        return Koha::Libraries->new()->empty if $branchitemrule->{holdallowed} == 1 && $self->home_branch->branchcode ne $patron->branchcode;
640
    }
578
    }
641
579
 
580
    my $pickup_libraries = Koha::Libraries->search();
642
    if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
581
    if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
643
        @libs  = $self->home_branch->get_hold_libraries;
582
        $pickup_libraries = $self->home_branch->get_hold_libraries;
644
        push @libs, $self->home_branch unless scalar(@libs) > 0;
645
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup') {
583
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup') {
646
        my $plib = Koha::Libraries->find({ branchcode => $patron->branchcode});
584
        my $plib = Koha::Libraries->find({ branchcode => $patron->branchcode});
647
        @libs  = $plib->get_hold_libraries;
585
        $pickup_libraries = $plib->get_hold_libraries;
648
        push @libs, $self->home_branch unless scalar(@libs) > 0;
649
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
586
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
650
        push @libs, $self->home_branch;
587
        $pickup_libraries = Koha::Libraries->search({ branchcode => $self->homebranch });
651
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
588
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
652
        push @libs, $self->holding_branch;
589
        $pickup_libraries = Koha::Libraries->search({ branchcode => $self->holdingbranch });
653
    } else {
590
    };
654
        @libs = Koha::Libraries->search({
591
    
592
    return $pickup_libraries->search(
593
        {
655
            pickup_location => 1
594
            pickup_location => 1
656
        }, {
595
        },
596
        {
657
            order_by => ['branchname']
597
            order_by => ['branchname']
658
        })->as_list;
598
        }
659
    }
599
    ) unless C4::Context->preference('UseBranchTransferLimits');
660
600
661
    my $pickup_locations = $self->_can_pickup_locations({
601
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
662
        to => \@libs
602
    my $limiter = $limittype eq 'itemtype' ? $self->effective_itemtype : $self->ccode;
663
    });
603
    my $limits = Koha::Item::Transfer::Limits->search(
604
        {
605
            fromBranch => $self->holdingbranch,
606
            $limittype => $limiter
607
        },
608
        { columns => ['toBranch'] }
609
    );
664
610
665
    return $pickup_locations;
611
    return $pickup_libraries->search(
612
        {
613
            pickup_location => 1,
614
            branchcode      => {
615
                '-not_in' => $limits->_resultset->as_query
616
            }
617
        },
618
        {
619
            order_by => ['branchname']
620
        }
621
    );
666
}
622
}
667
623
668
=head3 article_request_type
624
=head3 article_request_type
(-)a/Koha/Library.pm (-1 / +1 lines)
Lines 210-216 sub get_hold_libraries { Link Here
210
    @hold_libraries =
210
    @hold_libraries =
211
      grep { !$seen{ $_->id }++ } @hold_libraries;
211
      grep { !$seen{ $_->id }++ } @hold_libraries;
212
212
213
    return @hold_libraries;
213
    return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
214
}
214
}
215
215
216
=head3 validate_hold_sibling
216
=head3 validate_hold_sibling
(-)a/t/db_dependent/Koha/Item.t (-2 / +1 lines)
Lines 290-296 subtest 'pickup_locations' => sub { Link Here
290
                }
290
                }
291
            }
291
            }
292
        );
292
        );
293
        my @pl = @{ $item->pickup_locations( { patron => $patron} ) };
293
        my @pl = $item->pickup_locations( { patron => $patron} )->as_list;
294
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
294
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
295
295
296
        foreach my $pickup_location (@pl) {
296
        foreach my $pickup_location (@pl) {
297
- 

Return to bug 26963