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

(-)a/C4/HoldsQueue.pm (-86 / +47 lines)
Lines 452-465 sub MapItemsToHoldRequests { Link Here
452
            foreach my $item (@$available_items) {
452
            foreach my $item (@$available_items) {
453
                next if $item->{_object}->exclude_from_local_holds_priority;
453
                next if $item->{_object}->exclude_from_local_holds_priority;
454
454
455
                next unless _checkHoldPolicy($item, $request);
455
                next unless _can_item_fill_request( $item, $request, $libraries );
456
456
457
                next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber};
457
                next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber};
458
458
459
                next if $request->{item_group_id} && $item->{_object}->item_group && $item->{_object}->item_group->id ne $request->{item_group_id};
460
461
                next unless $item->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
462
463
                my $local_holds_priority_item_branchcode =
459
                my $local_holds_priority_item_branchcode =
464
                  $item->{$LocalHoldsPriorityItemControl};
460
                  $item->{$LocalHoldsPriorityItemControl};
465
461
Lines 506-523 sub MapItemsToHoldRequests { Link Here
506
        # is this an item-level request?
502
        # is this an item-level request?
507
        if (defined($request->{itemnumber})) {
503
        if (defined($request->{itemnumber})) {
508
            # fill it if possible; if not skip it
504
            # fill it if possible; if not skip it
509
            if (
505
            if (    exists $items_by_itemnumber{ $request->{itemnumber} }
510
                    exists $items_by_itemnumber{ $request->{itemnumber} }
511
                and not exists $allocated_items{ $request->{itemnumber} }
506
                and not exists $allocated_items{ $request->{itemnumber} }
512
                and  _checkHoldPolicy($items_by_itemnumber{ $request->{itemnumber} }, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
507
                and _can_item_fill_request( $items_by_itemnumber{ $request->{itemnumber} }, $request, $libraries ) )
513
                and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
514
                    || $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} )
515
                and ( !$request->{item_group_id} # If hold item_group is set, item's item_group must match
516
                      || ( $items_by_itemnumber{ $request->{itemnumber} }->{_object}->item_group
517
                        && $items_by_itemnumber{ $request->{itemnumber} }->{_object}->item_group->id eq $request->{item_group_id} ) )
518
                and $items_by_itemnumber{ $request->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } )
519
520
              )
521
            {
508
            {
522
509
523
                $item_map{ $request->{itemnumber} } = {
510
                $item_map{ $request->{itemnumber} } = {
Lines 568-586 sub MapItemsToHoldRequests { Link Here
568
555
569
        my $holding_branch_items = $items_by_branch{$pickup_branch};
556
        my $holding_branch_items = $items_by_branch{$pickup_branch};
570
        my $priority_branch = C4::Context->preference('HoldsQueuePrioritizeBranch') // 'homebranch';
557
        my $priority_branch = C4::Context->preference('HoldsQueuePrioritizeBranch') // 'homebranch';
571
        if ( $holding_branch_items ) {
558
        if ($holding_branch_items) {
572
            foreach my $item (@$holding_branch_items) {
559
            foreach my $item (@$holding_branch_items) {
573
                next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
560
                next unless _can_item_fill_request( $item, $request, $libraries );
574
561
575
                if (
562
                if ( $request->{borrowerbranch} eq $item->{$priority_branch} ) {
576
                    $request->{borrowerbranch} eq $item->{$priority_branch}
577
                    && _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
578
                    && ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
579
                        || ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) )
580
                    && ( !$request->{item_group_id} # If hold item_group is set, item's item_group must match
581
                        || ( $item->{_object}->item_group && $item->{_object}->item_group->id eq $request->{item_group_id} ) )
582
                  )
583
                {
584
                    $itemnumber = $item->{itemnumber};
563
                    $itemnumber = $item->{itemnumber};
585
                    last;
564
                    last;
586
                }
565
                }
Lines 595-615 sub MapItemsToHoldRequests { Link Here
595
                my $holding_branch_items = $items_by_branch{$holdingbranch};
574
                my $holding_branch_items = $items_by_branch{$holdingbranch};
596
                foreach my $item (@$holding_branch_items) {
575
                foreach my $item (@$holding_branch_items) {
597
                    next if $request->{borrowerbranch} ne $item->{$priority_branch};
576
                    next if $request->{borrowerbranch} ne $item->{$priority_branch};
598
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
577
                    next unless _can_item_fill_request( $item, $request, $libraries );
599
600
                    # Don't fill item level holds that contravene the hold pickup policy at this time
601
                    next unless _checkHoldPolicy($item, $request);
602
603
                    # If hold itemtype is set, item's itemtype must match
604
                    next unless ( !$request->{itemtype}
605
                        || $item->{itype} eq $request->{itemtype} );
606
607
                    # If hold item_group is set, item's item_group must match
608
                    next unless (
609
                        !$request->{item_group_id}
610
                        || (   $item->{_object}->item_group
611
                            && $item->{_object}->item_group->id eq $request->{item_group_id} )
612
                    );
613
578
614
                    $itemnumber = $item->{itemnumber};
579
                    $itemnumber = $item->{itemnumber};
615
                    last;
580
                    last;
Lines 642-660 sub MapItemsToHoldRequests { Link Here
642
                # FIXME: The itention is to follow StaticHoldsQueueWeight, but we don't check that pref
607
                # FIXME: The itention is to follow StaticHoldsQueueWeight, but we don't check that pref
643
                foreach my $item (@$holding_branch_items) {
608
                foreach my $item (@$holding_branch_items) {
644
                    next if $pickup_branch ne $item->{homebranch};
609
                    next if $pickup_branch ne $item->{homebranch};
645
                    next unless _checkHoldPolicy($item, $request);
610
                    next unless _can_item_fill_request( $item, $request, $libraries );
646
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
647
648
                    # If hold itemtype is set, item's itemtype must match
649
                    next unless ( !$request->{itemtype}
650
                        || $item->{itype} eq $request->{itemtype} );
651
652
                    # If hold item_group is set, item's item_group must match
653
                    next unless (
654
                        !$request->{item_group_id}
655
                        || (   $item->{_object}->item_group
656
                            && $item->{_object}->item_group->id eq $request->{item_group_id} )
657
                    );
658
611
659
                    $itemnumber = $item->{itemnumber};
612
                    $itemnumber = $item->{itemnumber};
660
                    $holdingbranch = $branch;
613
                    $holdingbranch = $branch;
Lines 665-685 sub MapItemsToHoldRequests { Link Here
665
            # Now try items from the least cost branch based on the transport cost matrix or StaticHoldsQueueWeight
618
            # Now try items from the least cost branch based on the transport cost matrix or StaticHoldsQueueWeight
666
            unless ( $itemnumber || !$holdingbranch) {
619
            unless ( $itemnumber || !$holdingbranch) {
667
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
620
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
668
                    next unless _checkHoldPolicy($current_item, $request); # Don't fill item level holds that contravene the hold pickup policy at this time
621
                    next unless _can_item_fill_request( $current_item, $request, $libraries );
669
670
                    # If hold itemtype is set, item's itemtype must match
671
                    next unless ( !$request->{itemtype}
672
                        || $current_item->{itype} eq $request->{itemtype} );
673
674
                    next unless $items_by_itemnumber{ $current_item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
675
676
                    # If hold item_group is set, item's item_group must match
677
                    next unless (
678
                        !$request->{item_group_id}
679
                        || (   $current_item->{_object}->item_group
680
                            && $current_item->{_object}->item_group->id eq $request->{item_group_id} )
681
                    );
682
683
622
684
                    $itemnumber = $current_item->{itemnumber};
623
                    $itemnumber = $current_item->{itemnumber};
685
                    last; # quit this loop as soon as we have a suitable item
624
                    last; # quit this loop as soon as we have a suitable item
Lines 694-714 sub MapItemsToHoldRequests { Link Here
694
                      or next;
633
                      or next;
695
634
696
                    foreach my $item (@$holding_branch_items) {
635
                    foreach my $item (@$holding_branch_items) {
697
                        # Don't fill item level holds that contravene the hold pickup policy at this time
698
                        next unless _checkHoldPolicy($item, $request);
699
700
                        # If hold itemtype is set, item's itemtype must match
701
                        next unless ( !$request->{itemtype}
702
                            || $item->{itype} eq $request->{itemtype} );
703
636
704
                        # If hold item_group is set, item's item_group must match
637
                        next unless _can_item_fill_request( $item, $request, $libraries );
705
                        next unless (
706
                            !$request->{item_group_id}
707
                            || (   $item->{_object}->item_group
708
                                && $item->{_object}->item_group->id eq $request->{item_group_id} )
709
                        );
710
711
                        next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
712
638
713
                        $itemnumber = $item->{itemnumber};
639
                        $itemnumber = $item->{itemnumber};
714
                        $holdingbranch = $branch;
640
                        $holdingbranch = $branch;
Lines 740-745 sub MapItemsToHoldRequests { Link Here
740
    return \%item_map;
666
    return \%item_map;
741
}
667
}
742
668
669
670
=head2 _can_item_fill_request
671
672
  my $bool = _can_item_fill_request( $item, $request, $libraries );
673
674
  This is an internal function of MapItemsToHoldRequests for checking an item against a hold. It uses the custom hashes for item and hold information
675
  used by thta routine
676
677
=cut
678
679
sub _can_item_fill_request {
680
    my ( $item, $request, $libraries ) = @_;
681
682
    # Don't fill item level holds that contravene the hold pickup policy at this time
683
    return unless _checkHoldPolicy( $item, $request );
684
685
    # If hold itemtype is set, item's itemtype must match
686
    return unless ( !$request->{itemtype}
687
        || $item->{itype} eq $request->{itemtype} );
688
689
    # If hold item_group is set, item's item_group must match
690
    return
691
        unless (
692
        !$request->{item_group_id}
693
        || (   $item->{_object}->item_group
694
            && $item->{_object}->item_group->id eq $request->{item_group_id} )
695
        );
696
697
    return
698
        unless $item->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
699
700
    return 1;
701
}
702
703
704
743
=head2 CreatePickListFromItemMap
705
=head2 CreatePickListFromItemMap
744
706
745
=cut
707
=cut
746
- 

Return to bug 35432