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

(-)a/Koha/Availability/Checks/Item.pm (-1 / +1 lines)
Lines 65-71 Returns Koha::Exceptions::Item::CheckedOut if item is checked out. Link Here
65
sub checked_out {
65
sub checked_out {
66
    my ($self, $issue) = @_;
66
    my ($self, $issue) = @_;
67
67
68
    $issue ||= C4::Circulation::GetItemIssue($self->item->itemnumber);
68
    $issue ||= $self->item->checkout;
69
    if (ref($issue) eq 'Koha::Checkout') {
69
    if (ref($issue) eq 'Koha::Checkout') {
70
        $issue = $issue->unblessed;
70
        $issue = $issue->unblessed;
71
        $issue->{date_due} = dt_from_string($issue->{date_due});
71
        $issue->{date_due} = dt_from_string($issue->{date_due});
(-)a/Koha/Availability/Checks/Patron.pm (-11 / +4 lines)
Lines 87-95 Koha::Exceptions::Patron::Debt additional fields: Link Here
87
sub debt_checkout {
87
sub debt_checkout {
88
    my ($self) = @_;
88
    my ($self) = @_;
89
89
90
    my ($amount) = C4::Members::GetMemberAccountRecords(
90
    my $amount = $self->patron->account->balance;
91
                        $self->patron->borrowernumber
92
    );
93
    my $maxoutstanding = C4::Context->preference("noissuescharge");
91
    my $maxoutstanding = C4::Context->preference("noissuescharge");
94
    if (C4::Context->preference('AllFinesNeedOverride') && $amount > 0) {
92
    if (C4::Context->preference('AllFinesNeedOverride') && $amount > 0) {
95
        # All fines need override, so return Koha::Exceptions::Patron::Debt.
93
        # All fines need override, so return Koha::Exceptions::Patron::Debt.
Lines 124-131 sub debt_checkout_guarantees { Link Here
124
    return unless scalar(@guarantees);
122
    return unless scalar(@guarantees);
125
    my $guarantees_non_issues_charges;
123
    my $guarantees_non_issues_charges;
126
    foreach my $g (@guarantees) {
124
    foreach my $g (@guarantees) {
127
        my ($b, $n, $o) = C4::Members::GetMemberAccountBalance($g->id);
125
        $guarantees_non_issues_charges += $g->account->non_issues_charges;
128
        $guarantees_non_issues_charges += $n;
129
    }
126
    }
130
    if ($guarantees_non_issues_charges > $max_charges) {
127
    if ($guarantees_non_issues_charges > $max_charges) {
131
        return Koha::Exceptions::Patron::DebtGuarantees->new(
128
        return Koha::Exceptions::Patron::DebtGuarantees->new(
Lines 150-158 Koha::Exceptions::Patron::Debt additional fields: Link Here
150
sub debt_hold {
147
sub debt_hold {
151
    my ($self) = @_;
148
    my ($self) = @_;
152
149
153
    my ($amount) = C4::Members::GetMemberAccountRecords(
150
    my $amount = $self->patron->account->balance;
154
                        $self->patron->borrowernumber
155
    );
156
    my $maxoutstanding = C4::Context->preference("maxoutstanding");
151
    my $maxoutstanding = C4::Context->preference("maxoutstanding");
157
    return $self->_debt($amount, $maxoutstanding);
152
    return $self->_debt($amount, $maxoutstanding);
158
}
153
}
Lines 171-179 Koha::Exceptions::Patron::Debt additional fields: Link Here
171
sub debt_renew_opac {
166
sub debt_renew_opac {
172
    my ($self) = @_;
167
    my ($self) = @_;
173
168
174
    my ($amount) = C4::Members::GetMemberAccountRecords(
169
    my $amount = $self->patron->account->balance;
175
                        $self->patron->borrowernumber
176
    );
177
    my $maxoutstanding = C4::Context->preference("OPACFineNoRenewals");
170
    my $maxoutstanding = C4::Context->preference("OPACFineNoRenewals");
178
    return $self->_debt($amount, $maxoutstanding);
171
    return $self->_debt($amount, $maxoutstanding);
179
}
172
}
(-)a/Koha/Biblio/Availability.pm (-2 / +6 lines)
Lines 22-30 use Scalar::Util qw(looks_like_number); Link Here
22
22
23
use base qw(Koha::Availability);
23
use base qw(Koha::Availability);
24
24
25
use Koha::Biblios;
25
use Koha::Exceptions;
26
use Koha::Exceptions;
26
use Koha::Exceptions::Biblio;
27
use Koha::Exceptions::Biblio;
27
use Koha::Exceptions::Patron;
28
use Koha::Exceptions::Patron;
29
use Koha::Patrons;
28
30
29
=head1 NAME
31
=head1 NAME
30
32
Lines 88-94 sub new { Link Here
88
                parameter => 'biblionumber',
90
                parameter => 'biblionumber',
89
            );
91
            );
90
        }
92
        }
91
        $self->biblio(Koha::Biblios->find($params->{'biblionumber'}));
93
        my $biblio = Koha::Biblios->find($params->{'biblionumber'});
94
        $self->biblio( $biblio );
92
        unless ($self->biblio) {
95
        unless ($self->biblio) {
93
            Koha::Exceptions::Biblio::NotFound->throw(
96
            Koha::Exceptions::Biblio::NotFound->throw(
94
                error => 'Biblio not found.',
97
                error => 'Biblio not found.',
Lines 117-123 sub new { Link Here
117
                parameter => 'borrowernumber',
120
                parameter => 'borrowernumber',
118
            );
121
            );
119
        }
122
        }
120
        $self->patron(Koha::Patrons->find($params->{'borrowernumber'}));
123
        my $patron = Koha::Patrons->find($params->{'borrowernumber'});
124
        $self->patron( $patron );
121
        unless ($self->patron) {
125
        unless ($self->patron) {
122
            Koha::Exceptions::Patron::NotFound->throw(
126
            Koha::Exceptions::Patron::NotFound->throw(
123
                error => 'Patron not found.',
127
                error => 'Patron not found.',
(-)a/Koha/Item/Availability.pm (-2 / +6 lines)
Lines 25-30 use base qw(Koha::Availability); Link Here
25
use Koha::Exceptions;
25
use Koha::Exceptions;
26
use Koha::Exceptions::Item;
26
use Koha::Exceptions::Item;
27
use Koha::Exceptions::Patron;
27
use Koha::Exceptions::Patron;
28
use Koha::Items;
29
use Koha::Patrons;
28
30
29
=head1 NAME
31
=head1 NAME
30
32
Lines 82-88 sub new { Link Here
82
                parameter => 'itemnumber',
84
                parameter => 'itemnumber',
83
            );
85
            );
84
        }
86
        }
85
        $self->item(Koha::Items->find($params->{'itemnumber'}));
87
        my $item = Koha::Items->find($params->{'itemnumber'});
88
        $self->item( $item );
86
        unless ($self->item) {
89
        unless ($self->item) {
87
            Koha::Exceptions::Item::NotFound->throw(
90
            Koha::Exceptions::Item::NotFound->throw(
88
                error => 'Item not found.',
91
                error => 'Item not found.',
Lines 111-117 sub new { Link Here
111
                parameter => 'borrowernumber',
114
                parameter => 'borrowernumber',
112
            );
115
            );
113
        }
116
        }
114
        $self->patron(Koha::Patrons->find($params->{'borrowernumber'}));
117
        my $patron = Koha::Patrons->find($params->{'borrowernumber'});
118
        $self->patron( $patron );
115
        unless ($self->patron) {
119
        unless ($self->patron) {
116
            Koha::Exceptions::Patron::NotFound->throw(
120
            Koha::Exceptions::Patron::NotFound->throw(
117
                error => 'Patron not found.',
121
                error => 'Patron not found.',
(-)a/t/db_dependent/Koha/Availability/Checks/Patron.t (-14 / +16 lines)
Lines 88-94 sub t_fines_checkout_less_than_max { Link Here
88
        borrowernumber => $patron->borrowernumber,
88
        borrowernumber => $patron->borrowernumber,
89
        amountoutstanding => 9000,
89
        amountoutstanding => 9000,
90
    })->store;
90
    })->store;
91
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
91
    my $outstanding = $patron->account->balance;
92
    my $maxoutstanding = C4::Context->preference('noissuescharge');
92
    my $maxoutstanding = C4::Context->preference('noissuescharge');
93
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
93
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
94
    my $debt = $patroncalc->debt_checkout;
94
    my $debt = $patroncalc->debt_checkout;
Lines 120-126 sub t_fines_checkout_more_than_max { Link Here
120
        borrowernumber => $patron->borrowernumber,
120
        borrowernumber => $patron->borrowernumber,
121
        amountoutstanding => 9001,
121
        amountoutstanding => 9001,
122
    })->store;
122
    })->store;
123
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
123
    my $outstanding = $patron->account->balance;
124
    my $maxoutstanding = C4::Context->preference('noissuescharge');
124
    my $maxoutstanding = C4::Context->preference('noissuescharge');
125
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
125
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
126
    my $debt = $patroncalc->debt_checkout;
126
    my $debt = $patroncalc->debt_checkout;
Lines 146-152 sub t_fines_hold_less_than_max { Link Here
146
        borrowernumber => $patron->borrowernumber,
146
        borrowernumber => $patron->borrowernumber,
147
        amountoutstanding => 9000,
147
        amountoutstanding => 9000,
148
    })->store;
148
    })->store;
149
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
149
    my $outstanding = $patron->account->balance;
150
    my $maxoutstanding = C4::Context->preference('maxoutstanding');
150
    my $maxoutstanding = C4::Context->preference('maxoutstanding');
151
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
151
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
152
    my $debt = $patroncalc->debt_hold;
152
    my $debt = $patroncalc->debt_hold;
Lines 167-173 sub t_fines_hold_more_than_max { Link Here
167
        borrowernumber => $patron->borrowernumber,
167
        borrowernumber => $patron->borrowernumber,
168
        amountoutstanding => 9001,
168
        amountoutstanding => 9001,
169
    })->store;
169
    })->store;
170
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
170
    my $outstanding = $patron->account->balance;
171
    my $maxoutstanding = C4::Context->preference('maxoutstanding');
171
    my $maxoutstanding = C4::Context->preference('maxoutstanding');
172
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
172
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
173
    my $debt = $patroncalc->debt_hold;
173
    my $debt = $patroncalc->debt_hold;
Lines 193-199 sub t_fines_renew_opac_less_than_max { Link Here
193
        borrowernumber => $patron->borrowernumber,
193
        borrowernumber => $patron->borrowernumber,
194
        amountoutstanding => 9000,
194
        amountoutstanding => 9000,
195
    })->store;
195
    })->store;
196
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
196
    my $outstanding = $patron->account->balance;
197
    my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals');
197
    my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals');
198
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
198
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
199
    my $debt = $patroncalc->debt_renew_opac;
199
    my $debt = $patroncalc->debt_renew_opac;
Lines 214-220 sub t_fines_renew_opac_more_than_max { Link Here
214
        borrowernumber => $patron->borrowernumber,
214
        borrowernumber => $patron->borrowernumber,
215
        amountoutstanding => 9001,
215
        amountoutstanding => 9001,
216
    })->store;
216
    })->store;
217
    my ($outstanding) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
217
    my $outstanding = $patron->account->balance;
218
    my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals');
218
    my $maxoutstanding = C4::Context->preference('OPACFineNoRenewals');
219
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
219
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
220
    my $debt = $patroncalc->debt_renew_opac;
220
    my $debt = $patroncalc->debt_renew_opac;
Lines 268-281 sub t_guarantees_fines_checkout_more_than_max { Link Here
268
    $guarantee1->guarantorid($patron->borrowernumber)->store;
268
    $guarantee1->guarantorid($patron->borrowernumber)->store;
269
    my $guarantee2 = build_a_test_patron();
269
    my $guarantee2 = build_a_test_patron();
270
    $guarantee2->guarantorid($patron->borrowernumber)->store;
270
    $guarantee2->guarantorid($patron->borrowernumber)->store;
271
    my $line1 = Koha::Account::Line->new({
271
272
        borrowernumber => $guarantee1->borrowernumber,
272
    my $line1 = $guarantee1->account->add_debit({
273
        amountoutstanding => 3,
273
        amount => 3,
274
    })->store;
274
        type => 'fine',
275
    my $line2 = Koha::Account::Line->new({
275
    });
276
        borrowernumber => $guarantee2->borrowernumber,
276
    my $line2 = $guarantee2->account->add_debit({
277
        amountoutstanding => 3,
277
        amount => 3,
278
    })->store;
278
        type => 'fine',
279
    });
280
279
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
281
    my $patroncalc = Koha::Availability::Checks::Patron->new($patron);
280
    my $debt = $patroncalc->debt_checkout_guarantees;
282
    my $debt = $patroncalc->debt_checkout_guarantees;
281
    my $expecting = 'Koha::Exceptions::Patron::DebtGuarantees';
283
    my $expecting = 'Koha::Exceptions::Patron::DebtGuarantees';
(-)a/t/db_dependent/Koha/Item/Availability/Checkout.t (-3 / +3 lines)
Lines 100-106 subtest 'Checkout held item' => sub { Link Here
100
    my $patron = build_a_test_patron();
100
    my $patron = build_a_test_patron();
101
    my $patron2 = build_a_test_patron();
101
    my $patron2 = build_a_test_patron();
102
    my $item = build_a_test_item();
102
    my $item = build_a_test_item();
103
    my $biblio = C4::Biblio::GetBiblio($item->biblionumber);
103
    my $biblio = $item->biblio;
104
    my $priority= C4::Reserves::CalculatePriority($item->biblionumber);
104
    my $priority= C4::Reserves::CalculatePriority($item->biblionumber);
105
    my $reserve_id = add_biblio_level_hold($item, $patron2, $item->homebranch);
105
    my $reserve_id = add_biblio_level_hold($item, $patron2, $item->homebranch);
106
106
Lines 114-120 subtest 'Checkout held item' => sub { Link Here
114
       .' then it is available.');
114
       .' then it is available.');
115
    is($availability->confirm, 1, 'Then there is one thing to be confirmed.');
115
    is($availability->confirm, 1, 'Then there is one thing to be confirmed.');
116
    ok($availability->confirmations->{$expected}, $expected);
116
    ok($availability->confirmations->{$expected}, $expected);
117
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
117
    my $hold = Koha::Holds->find( $reserve_id );
118
    $hold->cancel;
118
    ok($availability->in_intranet->available, 'Given I have cancelled the hold,'
119
    ok($availability->in_intranet->available, 'Given I have cancelled the hold,'
119
       .' then the item is still available.');
120
       .' then the item is still available.');
120
    ok(!$availability->confirm, 'Then there is no need to make confirmations.');
121
    ok(!$availability->confirm, 'Then there is no need to make confirmations.');
121
- 

Return to bug 17712