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

(-)a/C4/Circulation.pm (-17 / +9 lines)
Lines 2992-3002 sub GetSoonestRenewDate { Link Here
2992
    my $item   = $params->{item}   or return;
2992
    my $item   = $params->{item}   or return;
2993
    my $issue  = $params->{issue}  or return;
2993
    my $issue  = $params->{issue}  or return;
2994
2994
2995
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2995
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2996
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2996
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2997
        {   categorycode => $patron->categorycode,
2997
        {   categorycode => $patron->categorycode,
2998
2998
            itemtype     => $item->effective_itemtype,
2999
            itemtype     => $item->{itype},
3000
            branchcode   => $branchcode
2999
            branchcode   => $branchcode
3001
        }
3000
        }
3002
    );
3001
    );
Lines 3023-3029 sub GetSoonestRenewDate { Link Here
3023
3022
3024
=head2 GetLatestAutoRenewDate
3023
=head2 GetLatestAutoRenewDate
3025
3024
3026
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate({ patron => $patron, issue => $issue, item => $item });
3025
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate({ patron => $patron, checkout => $checkout, item => $item });
3027
3026
3028
Find out the latest possible auto renew date of a borrowed item.
3027
Find out the latest possible auto renew date of a borrowed item.
3029
3028
Lines 3031-3037 C<$borrower> is the patron who currencly has the item on loan. Link Here
3031
3030
3032
C<$item> is the item to renew.
3031
C<$item> is the item to renew.
3033
3032
3034
C<$issue> is the issue to renew.
3033
C<$checkout> is the checkout to renew.
3035
3034
3036
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3035
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3037
auto renew date, based on the value "No auto renewal after" and the "No auto
3036
auto renew date, based on the value "No auto renewal after" and the "No auto
Lines 3044-3064 or item cannot be found. Link Here
3044
sub GetLatestAutoRenewDate {
3043
sub GetLatestAutoRenewDate {
3045
    my ( $params ) = @_;
3044
    my ( $params ) = @_;
3046
3045
3047
    my $patron   = $params->{patron} or return;
3046
    my $patron   = $params->{patron}   or return;
3048
    my $item     = $params->{item}     or return;
3047
    my $item     = $params->{item}     or return;
3049
    my $issue    = $params->{issue}    or return;
3048
    my $checkout = $params->{checkout} or return;
3050
3051
    my $item      = GetItem($itemnumber)      or return;
3052
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3053
3049
3054
    $borrowernumber ||= $itemissue->borrowernumber;
3050
    my $branchcode = _GetCircControlBranch( $item->unblessed, { branchcode => $patron->branchcode } );
3055
    my $patron = Koha::Patrons->find( $borrowernumber )
3056
      or return;
3057
3058
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3059
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3051
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3060
        {   categorycode => $patron->categorycode,
3052
        {   categorycode => $patron->categorycode,
3061
            itemtype     => $item->{itype},
3053
            itemtype     => $item->effective_itemtype,
3062
            branchcode   => $branchcode
3054
            branchcode   => $branchcode
3063
        }
3055
        }
3064
    );
3056
    );
Lines 3072-3078 sub GetLatestAutoRenewDate { Link Here
3072
3064
3073
    my $maximum_renewal_date;
3065
    my $maximum_renewal_date;
3074
    if ( $issuing_rule->no_auto_renewal_after ) {
3066
    if ( $issuing_rule->no_auto_renewal_after ) {
3075
        $maximum_renewal_date = dt_from_string($itemissue->issuedate);
3067
        $maximum_renewal_date = dt_from_string($checkout->issuedate);
3076
        $maximum_renewal_date->add(
3068
        $maximum_renewal_date->add(
3077
            $issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after
3069
            $issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after
3078
        );
3070
        );
(-)a/circ/renew.pl (-3 / +3 lines)
Lines 90-98 if ($barcode) { Link Here
90
                if ( $error && ( $error eq 'auto_too_late' ) ) {
90
                if ( $error && ( $error eq 'auto_too_late' ) ) {
91
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
91
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
92
                        {
92
                        {
93
                            patron   => $borrower->unblessed,
93
                            patron   => $borrower,
94
                            item     => $item->unblessed,
94
                            item     => $item,
95
                            issue    => $issue->unblessed,
95
                            issue    => $issue,
96
                        }
96
                        }
97
                    );
97
                    );
98
                }
98
                }
(-)a/t/db_dependent/Circulation.t (-8 / +10 lines)
Lines 694-729 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
694
            }
694
            }
695
        );
695
        );
696
696
697
        my $renewing_borrower_obj = Koha::Patrons->find( $renewing_borrowernumber );
698
        my $item_to_auto_renew_obj = Koha::Items->find( $item_to_auto_renew->{itemnumber} );
699
697
        my $ten_days_before = dt_from_string->add( days => -10 );
700
        my $ten_days_before = dt_from_string->add( days => -10 );
698
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
701
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
699
        my $issue = AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
702
        my $issue = AddIssue( $renewing_borrower, $item_to_auto_renew_obj->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
700
        $issue->result_class('DBIx::Class::ResultClass::HashRefInflator');
703
        $issue = Koha::Checkouts->find( $issue->issue_id );
701
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL');
704
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = NULL');
702
        my $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } );
705
        my $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue, } );
703
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' );
706
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' );
704
        my $five_days_before = dt_from_string->add( days => -5 );
707
        my $five_days_before = dt_from_string->add( days => -5 );
705
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL');
708
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL');
706
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } );
709
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, );
707
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
710
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
708
            $five_days_before->truncate( to => 'minute' ),
711
            $five_days_before->truncate( to => 'minute' ),
709
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
712
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
710
        );
713
        );
711
        my $five_days_ahead = dt_from_string->add( days => 5 );
714
        my $five_days_ahead = dt_from_string->add( days => 5 );
712
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL');
715
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL');
713
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } );
716
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, );
714
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
717
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
715
            $five_days_ahead->truncate( to => 'minute' ),
718
            $five_days_ahead->truncate( to => 'minute' ),
716
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
719
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
717
        );
720
        );
718
        my $two_days_ahead = dt_from_string->add( days => 2 );
721
        my $two_days_ahead = dt_from_string->add( days => 2 );
719
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
722
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = "", no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
720
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } );
723
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, );
721
        is( $latest_auto_renew_date->truncate( to => 'day' ),
724
        is( $latest_auto_renew_date->truncate( to => 'day' ),
722
            $two_days_ahead->truncate( to => 'day' ),
725
            $two_days_ahead->truncate( to => 'day' ),
723
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after'
726
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after'
724
        );
727
        );
725
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
728
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) );
726
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower, item => $item_to_auto_renew, issue => { issuedate => $issue->issuedate }, } );
729
        $latest_auto_renew_date = GetLatestAutoRenewDate( { patron => $renewing_borrower_obj, item => $item_to_auto_renew_obj, checkout => $issue }, );
727
        is( $latest_auto_renew_date->truncate( to => 'day' ),
730
        is( $latest_auto_renew_date->truncate( to => 'day' ),
728
            $two_days_ahead->truncate( to => 'day' ),
731
            $two_days_ahead->truncate( to => 'day' ),
729
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after'
732
            'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is < no_auto_renewal_after'
730
- 

Return to bug 16413