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

(-)a/C4/Circulation.pm (-5 / +1 lines)
Lines 3049-3062 sub AddRenewal { Link Here
3049
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3049
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3050
        }
3050
        }
3051
3051
3052
        unless ( C4::Context->interface eq 'opac' ) { #if from opac we are obeying OpacRenewalBranch as calculated in opac-renew.pl
3053
            $branch = ( C4::Context->userenv && defined C4::Context->userenv->{branch} ) ? C4::Context->userenv->{branch} : $branch;
3054
        }
3055
3056
        # Add the renewal to stats
3052
        # Add the renewal to stats
3057
        UpdateStats(
3053
        UpdateStats(
3058
            {
3054
            {
3059
                branch         => $branch,
3055
                branch         => $item_object->renewalbranch({branch => $branch}),
3060
                type           => 'renew',
3056
                type           => 'renew',
3061
                amount         => $charge,
3057
                amount         => $charge,
3062
                itemnumber     => $itemnumber,
3058
                itemnumber     => $itemnumber,
(-)a/Koha/Item.pm (+39 lines)
Lines 490-495 sub as_marc_field { Link Here
490
    return $field;
490
    return $field;
491
}
491
}
492
492
493
=head3 renewalbranch
494
495
Returns the branch to be recorded in statistics renewal of the item
496
497
=cut
498
499
sub renewalbranch {
500
501
    my ($self, $params ) = @_;
502
503
    my $interface = C4::Context->interface;
504
    my $branchcode;
505
    if ( $interface eq 'opac' ){
506
        my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
507
        if( !defined $renewalbranch ){
508
            $branchcode = 'OPACRenew';
509
        }
510
        elsif ( $renewalbranch eq 'itemhomebranch' ) {
511
            $branchcode = $self->homebranch;
512
        }
513
        elsif ( $renewalbranch eq 'patronhomebranch' ) {
514
            $branchcode = $self->checkout->patron->branchcode;
515
        }
516
        elsif ( $renewalbranch eq 'checkoutbranch' ) {
517
            $branchcode = $self->checkout->branchcode;
518
        }
519
        elsif ( $renewalbranch eq 'NULL' ) {
520
            $branchcode = '';
521
        }
522
        else {
523
            $branchcode = 'OPACRenew';
524
        }
525
    } else {
526
        $branchcode = ( C4::Context->userenv && defined C4::Context->userenv->{branch} )
527
            ? C4::Context->userenv->{branch} : $params->{branch};
528
    }
529
    return $branchcode;
530
}
531
493
=head3 to_api_mapping
532
=head3 to_api_mapping
494
533
495
This method returns the mapping for representing a Koha::Item object
534
This method returns the mapping for representing a Koha::Item object
(-)a/opac/opac-renew.pl (-20 / +1 lines)
Lines 63-88 else { Link Here
63
        my ( $status, $error ) =
63
        my ( $status, $error ) =
64
          CanBookBeRenewed( $borrowernumber, $itemnumber );
64
          CanBookBeRenewed( $borrowernumber, $itemnumber );
65
        if ( $status == 1 && $opacrenew == 1 ) {
65
        if ( $status == 1 && $opacrenew == 1 ) {
66
            my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
66
            AddRenewal( $borrowernumber, $itemnumber, undef, undef, undef );
67
            my $branchcode;
68
            if ( $renewalbranch eq 'itemhomebranch' ) {
69
                my $item = Koha::Items->find($itemnumber);
70
                $branchcode = $item->homebranch;
71
            }
72
            elsif ( $renewalbranch eq 'patronhomebranch' ) {
73
                $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
74
            }
75
            elsif ( $renewalbranch eq 'checkoutbranch' ) {
76
                my $issue = GetOpenIssue($itemnumber); # FIXME Should not be $item->checkout?
77
                $branchcode = $issue->{'branchcode'};
78
            }
79
            elsif ( $renewalbranch eq 'NULL' ) {
80
                $branchcode = '';
81
            }
82
            else {
83
                $branchcode = 'OPACRenew';
84
            }
85
            AddRenewal( $borrowernumber, $itemnumber, $branchcode, undef, undef );
86
            push( @renewed, $itemnumber );
67
            push( @renewed, $itemnumber );
87
        }
68
        }
88
        else {
69
        else {
(-)a/t/db_dependent/Koha/Item.t (-2 / +52 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
25
Lines 329-331 subtest 'pickup_locations' => sub { Link Here
329
329
330
    $schema->storage->txn_rollback;
330
    $schema->storage->txn_rollback;
331
};
331
};
332
- 
332
333
subtest 'renewalbranch' => sub {
334
    plan tests => 15;
335
336
    $schema->storage->txn_begin;
337
338
    my $item = $builder->build_sample_item();
339
    my $branch = $builder->build_object({ class => 'Koha::Libraries' });
340
    my $checkout = $builder->build_object({
341
        class => 'Koha::Checkouts',
342
        value => {
343
            itemnumber => $item->itemnumber,
344
        }
345
    });
346
347
348
    C4::Context->interface( 'intranet' );
349
    t::lib::Mocks::mock_userenv({ branchcode => $branch->branchcode });
350
351
    is( $item->renewalbranch, $branch->branchcode, "If interface not opac, we get the branch from context");
352
    is( $item->renewalbranch({ branch => "PANDA"}), $branch->branchcode, "If interface not opac, we get the branch from context even if we pass one in");
353
    C4::Context->set_userenv(51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ); #mock userenv doesn't let us set null branch
354
    is( $item->renewalbranch({ branch => "PANDA"}), "PANDA", "If interface not opac, we get the branch we pass one in if context not set");
355
356
    C4::Context->interface( 'opac' );
357
358
    t::lib::Mocks::mock_preference('OpacRenewalBranch', '');
359
    is( $item->renewalbranch, 'OPACRenew', "If interface opac and OpacRenewalBranch blank, we get the OPACRenew");
360
    is( $item->renewalbranch({branch=>'CHICKEN'}), 'OPACRenew', "If interface opac and OpacRenewalBranch blank, we get the OPACRenew even if branch passes");
361
362
    t::lib::Mocks::mock_preference('OpacRenewalBranch', undef);
363
    is( $item->renewalbranch, 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew");
364
    is( $item->renewalbranch({branch=>'COW'}), 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew even if branch passed");
365
366
    t::lib::Mocks::mock_preference('OpacRenewalBranch', 'NULL');
367
    is( $item->renewalbranch, '', "If interface opac and OpacRenewalBranch is string 'NULL', we get blank string");
368
    is( $item->renewalbranch({branch=>'COW'}), '', "If interface opac and OpacRenewalBranch is string 'NULL', we get blank string even if branch passed");
369
370
    t::lib::Mocks::mock_preference('OpacRenewalBranch', 'checkoutbranch');
371
    is( $item->renewalbranch, $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout");
372
    is( $item->renewalbranch({branch=>'MONKEY'}), $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed");
373
374
    t::lib::Mocks::mock_preference('OpacRenewalBranch','patronhomebranch');
375
    is( $item->renewalbranch, $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron");
376
    is( $item->renewalbranch({branch=>'TURKEY'}), $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron even if branch passed");
377
378
    t::lib::Mocks::mock_preference('OpacRenewalBranch','itemhomebranch');
379
    is( $item->renewalbranch, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item");
380
    is( $item->renewalbranch({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed");
381
382
};

Return to bug 24759