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

(-)a/Koha/Item.pm (-2 / +8 lines)
Lines 599-609 sub pickup_locations { Link Here
599
    ) unless C4::Context->preference('UseBranchTransferLimits');
599
    ) unless C4::Context->preference('UseBranchTransferLimits');
600
600
601
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
601
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
602
    my $limiter = $limittype eq 'itemtype' ? $self->effective_itemtype : $self->ccode;
602
    my ($ccode, $itype) = (undef, undef);
603
    if( $limittype eq 'ccode' ){
604
        $ccode = $self->ccode;
605
    } else {
606
        $itype = $self->itype;
607
    }
603
    my $limits = Koha::Item::Transfer::Limits->search(
608
    my $limits = Koha::Item::Transfer::Limits->search(
604
        {
609
        {
605
            fromBranch => $self->holdingbranch,
610
            fromBranch => $self->holdingbranch,
606
            $limittype => $limiter
611
            ccode      => $ccode,
612
            itemtype   => $itype,
607
        },
613
        },
608
        { columns => ['toBranch'] }
614
        { columns => ['toBranch'] }
609
    );
615
    );
(-)a/t/db_dependent/Koha/Item.t (-7 / +18 lines)
Lines 178-184 subtest 'pickup_locations' => sub { Link Here
178
        {
178
        {
179
            homebranch    => $library1->branchcode,
179
            homebranch    => $library1->branchcode,
180
            holdingbranch => $library2->branchcode,
180
            holdingbranch => $library2->branchcode,
181
            barcode       => '1',
181
            copynumber    => 1,
182
            ccode         => 'Gollum'
182
            ccode         => 'Gollum'
183
        }
183
        }
184
    )->store;
184
    )->store;
Lines 187-193 subtest 'pickup_locations' => sub { Link Here
187
        {
187
        {
188
            homebranch    => $library3->branchcode,
188
            homebranch    => $library3->branchcode,
189
            holdingbranch => $library4->branchcode,
189
            holdingbranch => $library4->branchcode,
190
            barcode       => '3',
190
            copynumber    => 3,
191
            itype         => $item1->itype,
191
            itype         => $item1->itype,
192
        }
192
        }
193
    )->store;
193
    )->store;
Lines 208-214 subtest 'pickup_locations' => sub { Link Here
208
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
208
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
209
209
210
    my $all_count = Koha::Libraries->search({ pickup_location => 1})->count();
210
    my $all_count = Koha::Libraries->search({ pickup_location => 1})->count();
211
    plan tests => ($all_count +1) * 7 + 31 + 60;
211
    plan tests => ($all_count +1) * 7 + 31 + 61;
212
212
213
    my $results = {
213
    my $results = {
214
        "1-1-1-any"           => $all_count,
214
        "1-1-1-any"           => $all_count,
Lines 295-307 subtest 'pickup_locations' => sub { Link Here
295
        }
295
        }
296
        ok(
296
        ok(
297
            scalar(@pl) == $results->{
297
            scalar(@pl) == $results->{
298
                    $item->barcode . '-'
298
                    $item->copynumber . '-'
299
                  . $patron->firstname . '-'
299
                  . $patron->firstname . '-'
300
                  . $ha . '-'
300
                  . $ha . '-'
301
                  . $hfp
301
                  . $hfp
302
            },
302
            },
303
            'item'
303
            'item'
304
              . $item->barcode
304
              . $item->copynumber
305
              . ', patron'
305
              . ', patron'
306
              . $patron->firstname
306
              . $patron->firstname
307
              . ', holdallowed: '
307
              . ', holdallowed: '
Lines 310-316 subtest 'pickup_locations' => sub { Link Here
310
              . $hfp
310
              . $hfp
311
              . ' should return '
311
              . ' should return '
312
              . $results->{
312
              . $results->{
313
                    $item->barcode . '-'
313
                    $item->copynumber . '-'
314
                  . $patron->firstname . '-'
314
                  . $patron->firstname . '-'
315
                  . $ha . '-'
315
                  . $ha . '-'
316
                  . $hfp
316
                  . $hfp
Lines 334-339 subtest 'pickup_locations' => sub { Link Here
334
    }
334
    }
335
335
336
    # Now test that branchtransferlimits will further filter the pickup locations
336
    # Now test that branchtransferlimits will further filter the pickup locations
337
338
    my $item_no_ccode = $builder->build_sample_item(
339
        {
340
            homebranch    => $library1->branchcode,
341
            holdingbranch => $library2->branchcode,
342
            itype         => $item1->itype,
343
        }
344
    )->store;
345
337
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
346
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
338
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
347
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
339
    Koha::CirculationRules->set_rules(
348
    Koha::CirculationRules->set_rules(
Lines 381-386 subtest 'pickup_locations' => sub { Link Here
381
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
390
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
382
    is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
391
    is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
383
392
393
    $pickup_locations = $item_no_ccode->pickup_locations( { patron => $patron1 } )->as_list;
394
    is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode and an item with no ccode we get back the libraries that are pickup locations");
395
384
    $builder->build_object(
396
    $builder->build_object(
385
        {
397
        {
386
            class => 'Koha::Item::Transfer::Limits',
398
            class => 'Koha::Item::Transfer::Limits',
387
- 

Return to bug 26963