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

(-)a/C4/HoldsQueue.pm (-4 / +17 lines)
Lines 67-79 sub TransportCostMatrix { Link Here
67
    my $dbh   = C4::Context->dbh;
67
    my $dbh   = C4::Context->dbh;
68
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
68
    my $transport_costs = $dbh->selectall_arrayref("SELECT * FROM transport_cost",{ Slice => {} });
69
69
70
    my $today = dt_from_string();
71
    my $calendars;
70
    my %transport_cost_matrix;
72
    my %transport_cost_matrix;
71
    foreach (@$transport_costs) {
73
    foreach (@$transport_costs) {
72
        my $from = $_->{frombranch};
74
        my $from     = $_->{frombranch};
73
        my $to = $_->{tobranch};
75
        my $to       = $_->{tobranch};
74
        my $cost = $_->{cost};
76
        my $cost     = $_->{cost};
75
        my $disabled = $_->{disable_transfer};
77
        my $disabled = $_->{disable_transfer};
76
        $transport_cost_matrix{$to}{$from} = { cost => $cost, disable_transfer => $disabled };
78
        $transport_cost_matrix{$to}{$from} = {
79
            cost             => $cost,
80
            disable_transfer => $disabled
81
        };
82
83
        if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
84
            $calendars->{$from} ||= C4::Calendar->new( branchcode => $from );
85
            $transport_cost_matrix{$to}{$from}{disable_transfer} ||=
86
              $calendars->{$from}
87
              ->isHoliday( $today->day(), $today->month(), $today->year() );
88
        }
89
77
    }
90
    }
78
    return \%transport_cost_matrix;
91
    return \%transport_cost_matrix;
79
}
92
}
(-)a/t/db_dependent/HoldsQueue.t (-11 / +23 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 22;
11
use Test::More tests => 23;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Context;
14
use C4::Context;
Lines 53-58 my $itemtype = grep { $_->{notforloan} == 1 } @item_types Link Here
53
53
54
#Set up the stage
54
#Set up the stage
55
# Sysprefs and cost matrix
55
# Sysprefs and cost matrix
56
my $HoldsQueueSkipClosed = C4::Context->preference('HoldsQueueSkipClosed');
57
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
56
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
58
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
57
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
59
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
58
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
60
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 289-294 ok( @$holds_queue == 2, "Holds queue filling correct number for default holds po Link Here
289
ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
291
ok( $holds_queue->[0]->{cardnumber} eq 'CARDNUMBER1', "Holds queue filling 1st correct hold for default holds policy 'from home library'");
290
ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
292
ok( $holds_queue->[1]->{cardnumber} eq 'CARDNUMBER2', "Holds queue filling 2nd correct hold for default holds policy 'from home library'");
291
293
294
# Test skipping hold picks for closed libraries.
295
# At this point in the test, we have 2 rows in the holds queue
296
# 1 of which is coming from MPL. Let's enable HoldsQueueSkipClosed
297
# and make today a holiday for MPL. When we run it again we should only
298
# have 1 row in the holds queue
299
C4::Context->set_preference('HoldsQueueSkipClosed', 1);
300
my $today = dt_from_string();
301
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
302
    day         => $today->day(),
303
    month       => $today->month(),
304
    year        => $today->year(),
305
    title       => "$today",
306
    description => "$today",
307
);
308
C4::HoldsQueue::CreateQueue();
309
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
310
ok( @$holds_queue == 1, "Holds not filled with items from closed libraries" );
311
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
312
292
$dbh->do("DELETE FROM default_circ_rules");
313
$dbh->do("DELETE FROM default_circ_rules");
293
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
314
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
294
C4::HoldsQueue::CreateQueue();
315
C4::HoldsQueue::CreateQueue();
Lines 296-315 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
296
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
317
ok( @$holds_queue == 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
297
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
318
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
298
319
299
# Test skipping hold picks for closed libraries.
320
# Test skipping hold picks for closed libraries without transport cost matrix
300
# At this point in the test, we have 3 rows in the holds queue
321
# At this point in the test, we have 3 rows in the holds queue
301
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
322
# one of which is coming from MPL. Let's enable HoldsQueueSkipClosed
302
# and make today a holiday for MPL. When we run it again we should only
323
# and make today a holiday for MPL. When we run it again we should only
303
# have 2 rows in the holds queue
324
# have 2 rows in the holds queue
304
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
325
C4::Context->set_preference( 'HoldsQueueSkipClosed', 1 );
305
my $today = dt_from_string();
306
C4::Calendar->new( branchcode => 'MPL' )->insert_single_holiday(
307
    day         => $today->day(),
308
    month       => $today->month(),
309
    year        => $today->year(),
310
    title       => "$today",
311
    description => "$today",
312
);
313
C4::HoldsQueue::CreateQueue();
326
C4::HoldsQueue::CreateQueue();
314
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
327
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
315
ok( @$holds_queue == 2, "Holds not filled with items from closed libraries" );
328
ok( @$holds_queue == 2, "Holds not filled with items from closed libraries" );
316
- 

Return to bug 12803