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

(-)a/C4/HoldsQueue.pm (-5 / +8 lines)
Lines 32-37 use C4::Biblio; Link Here
32
use C4::Dates qw/format_date/;
32
use C4::Dates qw/format_date/;
33
33
34
use List::Util qw(shuffle);
34
use List::Util qw(shuffle);
35
use List::MoreUtils qw(any);
35
use Data::Dumper;
36
use Data::Dumper;
36
37
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Lines 361-368 sub MapItemsToHoldRequests { Link Here
361
    return unless scalar(@$hold_requests) > 0;
362
    return unless scalar(@$hold_requests) > 0;
362
    return unless scalar(@$available_items) > 0;
363
    return unless scalar(@$available_items) > 0;
363
364
364
    my $automatic_return = C4::Context->preference("AutomaticItemReturn");
365
366
    # identify item-level requests
365
    # identify item-level requests
367
    my %specific_items_requested = map { $_->{itemnumber} => 1 }
366
    my %specific_items_requested = map { $_->{itemnumber} => 1 }
368
                                   grep { defined($_->{itemnumber}) }
367
                                   grep { defined($_->{itemnumber}) }
Lines 426-432 sub MapItemsToHoldRequests { Link Here
426
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
425
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
427
        my ($itemnumber, $holdingbranch);
426
        my ($itemnumber, $holdingbranch);
428
427
429
        my $holding_branch_items = $automatic_return ? undef : $items_by_branch{$pickup_branch};
428
        my $holding_branch_items = $items_by_branch{$pickup_branch};
430
        if ( $holding_branch_items ) {
429
        if ( $holding_branch_items ) {
431
            foreach my $item (@$holding_branch_items) {
430
            foreach my $item (@$holding_branch_items) {
432
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
431
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
Lines 594-603 sub least_cost_branch { Link Here
594
    #$from - arrayref
593
    #$from - arrayref
595
    my ($to, $from, $transport_cost_matrix) = @_;
594
    my ($to, $from, $transport_cost_matrix) = @_;
596
595
597
# Nothing really spectacular: supply to branch, a list of potential from branches
596
    # Nothing really spectacular: supply to branch, a list of potential from branches
598
# and find the minimum from - to value from the transport_cost_matrix
597
    # and find the minimum from - to value from the transport_cost_matrix
599
    return $from->[0] if @$from == 1;
598
    return $from->[0] if @$from == 1;
600
599
600
    # If the pickup library is in the list of libraries to pull from,
601
    # return that library right away, it is obviously the least costly
602
    return ($to) if any { $_ eq $to } @$from;
603
601
    my ($least_cost, @branch);
604
    my ($least_cost, @branch);
602
    foreach (@$from) {
605
    foreach (@$from) {
603
        my $cell = $transport_cost_matrix->{$to}{$_};
606
        my $cell = $transport_cost_matrix->{$to}{$_};
(-)a/t/db_dependent/HoldsQueue.t (-5 / +8 lines)
Lines 12-18 use C4::Context; Link Here
12
12
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use Test::More tests => 19;
15
use Test::More tests => 17;
16
16
17
17
use C4::Branch;
18
use C4::Branch;
18
use C4::ItemType;
19
use C4::ItemType;
Lines 100-106 my $priority = 1; Link Here
100
# Make a reserve
101
# Make a reserve
101
AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority );
102
AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority );
102
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
103
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
103
$dbh->do("UPDATE reserves SET reservedate = reservedate - 1");
104
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
104
105
105
# Tests
106
# Tests
106
my $use_cost_matrix_sth = $dbh->prepare("UPDATE systempreferences SET value = ? WHERE variable = 'UseTransportCostMatrix'");
107
my $use_cost_matrix_sth = $dbh->prepare("UPDATE systempreferences SET value = ? WHERE variable = 'UseTransportCostMatrix'");
Lines 121-128 $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdin Link Here
121
# test_queue will flush
122
# test_queue will flush
122
C4::Context->set_preference('AutomaticItemReturn', 1);
123
C4::Context->set_preference('AutomaticItemReturn', 1);
123
# Not sure how to make this test more difficult - holding branch does not matter
124
# Not sure how to make this test more difficult - holding branch does not matter
124
test_queue ('take from holdingbranch AutomaticItemReturn on', 0, $borrower_branchcode, undef);
125
test_queue ('take from holdingbranch AutomaticItemReturn on', 1, $borrower_branchcode, $least_cost_branch_code);
126
125
127
$dbh->do("DELETE FROM tmp_holdsqueue");
126
$dbh->do("DELETE FROM tmp_holdsqueue");
128
$dbh->do("DELETE FROM hold_fill_targets");
127
$dbh->do("DELETE FROM hold_fill_targets");
Lines 149-154 ok( $queue_item Link Here
149
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item) );
148
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item) );
150
ok( exists($queue_item->{itype}), 'item type included in queued items list (bug 5825)' );
149
ok( exists($queue_item->{itype}), 'item type included in queued items list (bug 5825)' );
151
150
151
ok(
152
    C4::HoldsQueue::least_cost_branch( 'B', [ 'A', 'B', 'C' ] ) eq 'B',
153
    'C4::HoldsQueue::least_cost_branch returns the local branch if it is in the list of branches to pull from'
154
);
155
152
# XXX All this tests are for borrower branch pick-up.
156
# XXX All this tests are for borrower branch pick-up.
153
# Maybe needs expanding to homebranch or holdingbranch pick-up.
157
# Maybe needs expanding to homebranch or holdingbranch pick-up.
154
158
155
- 

Return to bug 10628