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

(-)a/Koha/Biblio.pm (+27 lines)
Lines 188-193 sub can_be_transferred { Link Here
188
    return 0;
188
    return 0;
189
}
189
}
190
190
191
192
=head3 pickup_locations
193
194
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
195
196
Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
197
and if item can be transfered to each pickup location.
198
199
=cut
200
201
sub pickup_locations {
202
    my ($self, $params) = @_;
203
204
    my $patron = $params->{patron};
205
206
    my @pickup_locations;
207
    foreach my $item_of_bib ($self->items) {
208
        push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} );
209
    }
210
211
    my %seen;
212
    @pickup_locations =
213
      grep { !$seen{ $_->{branchcode} }++ } @pickup_locations;
214
215
    return wantarray ? @pickup_locations : \@pickup_locations;
216
}
217
191
=head3 hidden_in_opac
218
=head3 hidden_in_opac
192
219
193
my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
220
my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
(-)a/Koha/Item.pm (+56 lines)
Lines 26-31 use Koha::Database; Link Here
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
27
27
28
use C4::Context;
28
use C4::Context;
29
use C4::Circulation;
29
use Koha::Checkouts;
30
use Koha::Checkouts;
30
use Koha::IssuingRules;
31
use Koha::IssuingRules;
31
use Koha::Item::Transfer::Limits;
32
use Koha::Item::Transfer::Limits;
Lines 37-42 use Koha::StockRotationRotas; Link Here
37
38
38
use base qw(Koha::Object);
39
use base qw(Koha::Object);
39
40
41
use Data::Dumper;
42
40
=head1 NAME
43
=head1 NAME
41
44
42
Koha::Item - Koha Item object class
45
Koha::Item - Koha Item object class
Lines 277-282 sub can_be_transferred { Link Here
277
    })->count ? 0 : 1;
280
    })->count ? 0 : 1;
278
}
281
}
279
282
283
=head3 pickup_locations
284
285
@pickup_locations = $item->pickup_locations( {patron => $patron } )
286
287
Returns possible pickup locations for this item, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
288
and if item can be transfered to each pickup location.
289
290
=cut
291
292
sub pickup_locations {
293
    my ($self, $params) = @_;
294
295
    my $patron = $params->{patron};
296
297
    my $circ_control_branch =
298
      C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron );
299
    my $branchitemrule =
300
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
301
302
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
303
    my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch;
304
305
    #warn $branch_control.' '.$branchitemrule->{holdallowed}.' '.$library->branchcode.' '.$patron->branchcode;
306
307
    my @libs;
308
    if(defined $patron) {
309
        return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} );
310
        return @libs if $branchitemrule->{holdallowed} == 1 && $library->branchcode ne $patron->branchcode;
311
    }
312
313
    if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
314
        @libs  = $library->get_hold_libraries;
315
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
316
        push @libs, $self->home_branch;
317
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
318
        push @libs, $self->holding_branch;
319
    } else {
320
        @libs = Koha::Libraries->search({
321
            pickup_location => 1
322
        }, {
323
            order_by => ['branchname']
324
        })->as_list;
325
    }
326
327
    my @pickup_locations;
328
    foreach my $library (@libs) {
329
        if ($library->pickup_location && $self->can_be_transferred({ to => $library })) {
330
            push @pickup_locations, $library->unblessed;
331
        }
332
    }
333
    return wantarray ? @pickup_locations : \@pickup_locations;
334
}
335
280
=head3 article_request_type
336
=head3 article_request_type
281
337
282
my $type = $item->article_request_type( $borrower )
338
my $type = $item->article_request_type( $borrower )
(-)a/Koha/Libraries.pm (-16 / +8 lines)
Lines 66-77 sub pickup_locations { Link Here
66
66
67
    my $item = $params->{'item'};
67
    my $item = $params->{'item'};
68
    my $biblio = $params->{'biblio'};
68
    my $biblio = $params->{'biblio'};
69
    my $patron = $params->{'patron'};
70
69
    if ($biblio && $item) {
71
    if ($biblio && $item) {
70
        Koha::Exceptions::BadParameter->throw(
72
        Koha::Exceptions::BadParameter->throw(
71
            error => "Koha::Libraries->pickup_locations takes either 'biblio' or "
73
            error => "Koha::Libraries->pickup_locations takes either 'biblio' or "
72
            ." 'item' as parameter, but not both."
74
            ." 'item' as parameter, but not both."
73
        );
75
        );
74
    }
76
    }
77
    unless (! defined $patron || ref($patron) eq 'Koha::Patron') {
78
        $patron = Koha::Items->find($patron);
79
    }
75
80
76
    # Select libraries that are configured as pickup locations
81
    # Select libraries that are configured as pickup locations
77
    my $libraries = $self->search({
82
    my $libraries = $self->search({
Lines 81-112 sub pickup_locations { Link Here
81
    });
86
    });
82
87
83
    return $libraries->unblessed unless $item or $biblio;
88
    return $libraries->unblessed unless $item or $biblio;
84
    return $libraries->unblessed
89
    if($item) {
85
        unless C4::Context->preference('UseBranchTransferLimits');
86
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
87
88
    if ($item) {
89
        unless (ref($item) eq 'Koha::Item') {
90
        unless (ref($item) eq 'Koha::Item') {
90
            $item = Koha::Items->find($item);
91
            $item = Koha::Items->find($item);
91
            return $libraries->unblessed unless $item;
92
            return $libraries->unblessed unless $item;
92
        }
93
        }
94
        return $item->pickup_locations( {patron => $patron} );
93
    } else {
95
    } else {
94
        unless (ref($biblio) eq 'Koha::Biblio') {
96
        unless (ref($biblio) eq 'Koha::Biblio') {
95
            $biblio = Koha::Biblios->find($biblio);
97
            $biblio = Koha::Biblios->find($biblio);
96
            return $libraries->unblessed unless $biblio;
98
            return $libraries->unblessed unless $biblio;
97
        }
99
        }
100
        return $biblio->pickup_locations( {patron => $patron} );
98
    }
101
    }
99
100
    my @pickup_locations;
101
    foreach my $library ($libraries->as_list) {
102
        if ($item && $item->can_be_transferred({ to => $library })) {
103
            push @pickup_locations, $library->unblessed;
104
        } elsif ($biblio && $biblio->can_be_transferred({ to => $library })) {
105
            push @pickup_locations, $library->unblessed;
106
        }
107
    }
108
109
    return wantarray ? @pickup_locations : \@pickup_locations;
110
}
102
}
111
103
112
=head3 search_filtered
104
=head3 search_filtered
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt (-2 / +2 lines)
Lines 233-244 Link Here
233
                                                        <label for="branch_[% bibitemloo.biblionumber | html %]">Pick up location:</label>
233
                                                        <label for="branch_[% bibitemloo.biblionumber | html %]">Pick up location:</label>
234
                                                        [% UNLESS ( bibitemloo.holdable ) %]
234
                                                        [% UNLESS ( bibitemloo.holdable ) %]
235
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]" disabled="disabled">
235
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]" disabled="disabled">
236
                                                                [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber }, selected => branch }) %]
236
                                                                [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber, patron => logged_in_user }, selected => branch }) %]
237
                                                            </select>
237
                                                            </select>
238
                                                        [% ELSE %]
238
                                                        [% ELSE %]
239
                                                            [% SET at_least_one_library_not_available_for_pickup = 0 %]
239
                                                            [% SET at_least_one_library_not_available_for_pickup = 0 %]
240
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]">
240
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]">
241
                                                                [% FOREACH library IN Branches.all({ search_params => { pickup_location => 1 }, selected => branch }) %]
241
                                                                [% FOREACH library IN Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber, patron => logged_in_user }, selected => branch }) %]
242
                                                                    [% SET pickup_available_at = bibitemloo.not_available_at.grep(library.branchcode).size ? 0 : 1 %]
242
                                                                    [% SET pickup_available_at = bibitemloo.not_available_at.grep(library.branchcode).size ? 0 : 1 %]
243
                                                                    [% IF library.selected AND pickup_available_at %]
243
                                                                    [% IF library.selected AND pickup_available_at %]
244
                                                                        <option value="[% library.branchcode | html %]" selected="selected" >[% library.branchname | html %]</option>
244
                                                                        <option value="[% library.branchcode | html %]" selected="selected" >[% library.branchname | html %]</option>
(-)a/t/db_dependent/Koha/Biblios.t (-1 / +343 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Items;
25
use C4::Items;
Lines 36-41 use t::lib::Mocks; Link Here
36
my $schema = Koha::Database->new->schema;
36
my $schema = Koha::Database->new->schema;
37
$schema->storage->txn_begin;
37
$schema->storage->txn_begin;
38
38
39
my $dbh     = C4::Context->dbh;
40
39
my $builder = t::lib::TestBuilder->new;
41
my $builder = t::lib::TestBuilder->new;
40
my $patron = $builder->build( { source => 'Borrower' } );
42
my $patron = $builder->build( { source => 'Borrower' } );
41
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
43
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
Lines 187-189 subtest 'can_be_transferred' => sub { Link Here
187
};
189
};
188
190
189
$schema->storage->txn_rollback;
191
$schema->storage->txn_rollback;
192
193
194
subtest 'pickup_locations' => sub {
195
    plan tests => 25;
196
197
    $schema->storage->txn_begin;
198
199
    # Cleanup database
200
    Koha::Holds->search->delete;
201
    Koha::Patrons->search->delete;
202
    Koha::Items->search->delete;
203
    Koha::Libraries->search->delete;
204
    $dbh->do('DELETE FROM issues');
205
    $dbh->do('DELETE FROM issuingrules');
206
    $dbh->do(
207
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
208
        VALUES (?, ?, ?, ?)},
209
        {},
210
        '*', '*', '*', 25
211
    );
212
    $dbh->do('DELETE FROM branch_item_rules');
213
    $dbh->do('DELETE FROM default_branch_circ_rules');
214
    $dbh->do('DELETE FROM default_branch_item_rules');
215
    $dbh->do('DELETE FROM default_circ_rules');
216
217
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
218
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
219
    my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
220
221
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
222
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
223
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
224
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
225
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
226
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
227
228
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
229
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
230
231
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
232
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
233
234
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
235
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
236
237
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios' } );
238
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
239
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios' } );
240
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
241
242
    my $item1_1  = Koha::Item->new({
243
        biblionumber     => $biblio1->biblionumber,
244
        biblioitemnumber => $biblioitem1->biblioitemnumber,
245
        homebranch       => $library1->branchcode,
246
        holdingbranch    => $library2->branchcode,
247
        itype            => 'test',
248
        barcode          => "item11barcode",
249
    })->store;
250
251
    my $item1_3  = Koha::Item->new({
252
        biblionumber     => $biblio1->biblionumber,
253
        biblioitemnumber => $biblioitem1->biblioitemnumber,
254
        homebranch       => $library3->branchcode,
255
        holdingbranch    => $library4->branchcode,
256
        itype            => 'test',
257
        barcode          => "item13barcode",
258
    })->store;
259
260
    my $item2_2  = Koha::Item->new({
261
        biblionumber     => $biblio2->biblionumber,
262
        biblioitemnumber => $biblioitem2->biblioitemnumber,
263
        homebranch       => $library2->branchcode,
264
        holdingbranch    => $library1->branchcode,
265
        itype            => 'test',
266
        barcode          => "item22barcode",
267
    })->store;
268
269
    my $item2_3  = Koha::Item->new({
270
        biblionumber     => $biblio2->biblionumber,
271
        biblioitemnumber => $biblioitem2->biblioitemnumber,
272
        homebranch       => $library3->branchcode,
273
        holdingbranch    => $library3->branchcode,
274
        itype            => 'test',
275
        barcode          => "item23barcode",
276
    })->store;
277
278
    my $item2_4  = Koha::Item->new({
279
        biblionumber     => $biblio2->biblionumber,
280
        biblioitemnumber => $biblioitem2->biblioitemnumber,
281
        homebranch       => $library4->branchcode,
282
        holdingbranch    => $library4->branchcode,
283
        itype            => 'test',
284
        barcode          => "item24barcode",
285
    })->store;
286
287
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
288
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
289
290
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
291
292
    #Case 1: holdallowed any, hold_fulfillment_policy any
293
    $dbh->do(
294
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
295
        VALUES (?,?,?)},
296
        {},
297
        2, 'any', 'any'
298
    );
299
300
    my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
301
    my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
302
    my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
303
    my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
304
305
306
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations');
307
308
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
309
    $dbh->do(
310
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
311
        {},
312
        1, 'any'
313
    );
314
315
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
316
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
317
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
318
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
319
320
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations, when item\'s hombebranch equals patron\' homebranch');
321
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
322
323
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
324
    $dbh->do(
325
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
326
        {},
327
        3, 'any'
328
    );
329
330
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
331
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
332
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
333
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
334
335
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup');
336
337
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
338
    $dbh->do(
339
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
340
        {},
341
        2, 'holdgroup'
342
    );
343
344
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
345
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
346
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
347
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
348
349
    ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations');
350
351
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
352
    $dbh->do(
353
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
354
        {},
355
        1, 'holdgroup'
356
    );
357
358
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
359
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
360
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
361
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
362
363
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations');
364
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
365
366
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
367
    $dbh->do(
368
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
369
        {},
370
        3, 'holdgroup'
371
    );
372
373
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
374
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
375
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
376
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
377
378
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations');
379
380
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
381
    $dbh->do(
382
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
383
        {},
384
        2, 'homebranch'
385
    );
386
387
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
388
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
389
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
390
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
391
392
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations');
393
394
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
395
    $dbh->do(
396
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
397
        {},
398
        1, 'homebranch'
399
    );
400
401
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
402
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
403
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
404
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
405
406
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Returns homebranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
407
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
408
409
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
410
    $dbh->do(
411
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
412
        {},
413
        3, 'homebranch'
414
    );
415
416
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
417
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
418
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
419
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
420
421
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio that are within patron\'s holdgroup, and that are pickup_locations');
422
    ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
423
424
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
425
    $dbh->do(
426
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
427
        {},
428
        2, 'holdingbranch'
429
    );
430
431
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
432
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
433
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
434
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
435
436
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations');
437
438
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
439
    $dbh->do(
440
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
441
        {},
442
        1, 'holdingbranch'
443
    );
444
445
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
446
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
447
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
448
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
449
450
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio, whose homebranch equals patron\'s, and that are pickup_locations');
451
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
452
453
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
454
    $dbh->do(
455
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
456
        {},
457
        3, 'holdingbranch'
458
    );
459
460
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
461
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
462
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
463
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
464
465
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1, 'Returns holdingbranch of items in biblio, whose homebranch are within patron\'s holdgroup, and that are pickup_locations');
466
467
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
468
469
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
470
    $dbh->do(
471
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
472
        {},
473
        1, 'any'
474
    );
475
476
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
477
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
478
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
479
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
480
481
    ok(scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries when item\'s holdingbranch equals patron\'s homebranch, and that are pickup_locations');
482
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
483
484
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
485
    $dbh->do(
486
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
487
        {},
488
        1, 'holdgroup'
489
    );
490
491
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
492
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
493
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
494
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
495
496
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
497
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
498
499
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
500
    $dbh->do(
501
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
502
        {},
503
        1, 'homebranch'
504
    );
505
506
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
507
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
508
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
509
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
510
511
    #ok(scalar(@pl_2_4) == 1 && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
512
    ok(scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
513
    ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
514
515
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
516
    $dbh->do(
517
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
518
        {},
519
        1, 'holdingbranch'
520
    );
521
522
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
523
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
524
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
525
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
526
527
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
528
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
529
530
    $schema->storage->txn_rollback;
531
};
(-)a/t/db_dependent/Koha/Items.t (-2 / +314 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
26
use C4::Context;
26
use Koha::Item;
27
use Koha::Item;
27
use Koha::Item::Transfer::Limits;
28
use Koha::Item::Transfer::Limits;
28
use Koha::Items;
29
use Koha::Items;
Lines 34-39 use t::lib::Mocks; Link Here
34
my $schema = Koha::Database->new->schema;
35
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
36
$schema->storage->txn_begin;
36
37
38
my $dbh     = C4::Context->dbh;
39
37
my $builder     = t::lib::TestBuilder->new;
40
my $builder     = t::lib::TestBuilder->new;
38
my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
41
my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
39
my $library     = $builder->build( { source => 'Branch' } );
42
my $library     = $builder->build( { source => 'Branch' } );
Lines 165-167 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
165
168
166
$schema->storage->txn_rollback;
169
$schema->storage->txn_rollback;
167
170
168
- 
171
subtest 'pickup_locations' => sub {
172
    plan tests => 33;
173
174
    $schema->storage->txn_begin;
175
176
    # Cleanup database
177
    Koha::Holds->search->delete;
178
    Koha::Patrons->search->delete;
179
    Koha::Items->search->delete;
180
    Koha::Libraries->search->delete;
181
    $dbh->do('DELETE FROM issues');
182
    $dbh->do('DELETE FROM issuingrules');
183
    $dbh->do(
184
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
185
        VALUES (?, ?, ?, ?)},
186
        {},
187
        '*', '*', '*', 25
188
    );
189
    $dbh->do('DELETE FROM branch_item_rules');
190
    $dbh->do('DELETE FROM default_branch_circ_rules');
191
    $dbh->do('DELETE FROM default_branch_item_rules');
192
    $dbh->do('DELETE FROM default_circ_rules');
193
194
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
195
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
196
197
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
198
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
199
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
200
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
201
202
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
203
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
204
205
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
206
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
207
208
    my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
209
210
    my $item1  = Koha::Item->new({
211
        biblionumber     => $biblioitem->{biblionumber},
212
        biblioitemnumber => $biblioitem->{biblioitemnumber},
213
        homebranch       => $library1->branchcode,
214
        holdingbranch    => $library2->branchcode,
215
        itype            => 'test',
216
        barcode          => "item1barcode",
217
    })->store;
218
219
    my $item3  = Koha::Item->new({
220
        biblionumber     => $biblioitem->{biblionumber},
221
        biblioitemnumber => $biblioitem->{biblioitemnumber},
222
        homebranch       => $library3->branchcode,
223
        holdingbranch    => $library4->branchcode,
224
        itype            => 'test',
225
        barcode          => "item3barcode",
226
    })->store;
227
228
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
229
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
230
231
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
232
233
    #Case 1: holdallowed any, hold_fulfillment_policy any
234
    $dbh->do(
235
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
236
        VALUES (?,?,?)},
237
        {},
238
        2, 'any', 'any'
239
    );
240
241
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
242
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
243
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
244
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
245
246
    ok(scalar(@pl_1_1) == scalar(@pl_1_4) && scalar(@pl_1_1) == scalar(@pl_3_1) && scalar(@pl_1_1) == scalar(@pl_3_4), 'All combinations of patron/item renders the same number of locations');
247
248
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
249
    $dbh->do(
250
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
251
        {},
252
        1, 'any'
253
    );
254
255
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
256
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
257
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
258
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
259
260
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
261
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
262
263
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
264
    $dbh->do(
265
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
266
        {},
267
        3, 'any'
268
    );
269
270
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
271
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
272
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
273
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
274
275
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
276
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
277
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
278
279
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
280
    $dbh->do(
281
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
282
        {},
283
        2, 'holdgroup'
284
    );
285
286
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
287
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
288
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
289
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
290
291
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2, 'Pickup locations for item 1 renders all libraries in items\'s holdgroup that are pickup_locations');
292
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1, 'Pickup locations for item 3 renders all libraries in items\'s holdgroup that are pickup_locations');
293
294
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
295
    $dbh->do(
296
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
297
        {},
298
        1, 'holdgroup'
299
    );
300
301
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
302
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
303
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
304
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
305
306
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
307
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
308
309
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
310
    $dbh->do(
311
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
312
        {},
313
        3, 'holdgroup'
314
    );
315
316
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
317
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
318
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
319
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
320
321
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
322
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
323
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
324
325
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
326
    $dbh->do(
327
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
328
        {},
329
        2, 'homebranch'
330
    );
331
332
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
333
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
334
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
335
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
336
337
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_1_4[0]->{branchcode} eq $library1->id, 'Pickup locations for item 1 renders item\'s homelibrary');
338
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
339
340
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
341
    $dbh->do(
342
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
343
        {},
344
        1, 'homebranch'
345
    );
346
347
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
348
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
349
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
350
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
351
352
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
353
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
354
355
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
356
    $dbh->do(
357
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
358
        {},
359
        3, 'homebranch'
360
    );
361
362
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
363
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
364
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
365
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
366
367
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
368
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
369
370
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
371
    $dbh->do(
372
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
373
        {},
374
        2, 'holdingbranch'
375
    );
376
377
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
378
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
379
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
380
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
381
382
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode && $pl_1_4[0]->{branchcode} eq $library2->branchcode, 'Pickup locations for item 1 renders item\'s holding branch');
383
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1 && $pl_3_1[0]->{branchcode} eq $library4->branchcode && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup locations for item 3 renders item\'s holding branch');
384
385
386
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
387
    $dbh->do(
388
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
389
        {},
390
        1, 'holdingbranch'
391
    );
392
393
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
394
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
395
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
396
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
397
398
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
399
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
400
401
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
402
    $dbh->do(
403
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
404
        {},
405
        3, 'holdingbranch'
406
    );
407
408
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
409
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
410
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
411
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
412
413
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
414
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
415
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
416
417
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
418
419
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
420
    $dbh->do(
421
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
422
        {},
423
        1, 'any'
424
    );
425
426
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
427
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
428
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
429
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
430
431
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
432
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
433
434
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
435
    $dbh->do(
436
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
437
        {},
438
        1, 'holdgroup'
439
    );
440
441
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
442
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
443
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
444
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
445
446
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
447
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
448
449
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
450
    $dbh->do(
451
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
452
        {},
453
        1, 'homebranch'
454
    );
455
456
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
457
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
458
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
459
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
460
461
    #ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
462
    ok(scalar(@pl_3_4) == 0 && scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any combination of patron/item renders no locations');
463
464
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
465
    $dbh->do(
466
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
467
        {},
468
        1, 'holdingbranch'
469
    );
470
471
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
472
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
473
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
474
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
475
476
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
477
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
478
479
    $schema->storage->txn_rollback;
480
};

Return to bug 22284