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

(-)a/Koha/Account.pm (-2 lines)
Lines 102-109 sub pay { Link Here
102
        }
102
        }
103
    );
103
    );
104
104
105
    Koha::Patron::Debarments::DelDebarmentsAfterPayment({ borrowernumber => $self->{patron_id} });
106
107
    # NOTE: Pay historically always applied as much credit as it could to all
105
    # NOTE: Pay historically always applied as much credit as it could to all
108
    # existing outstanding debits, whether passed specific debits or otherwise.
106
    # existing outstanding debits, whether passed specific debits or otherwise.
109
    if ( $payment->amountoutstanding ) {
107
    if ( $payment->amountoutstanding ) {
(-)a/Koha/Account/Line.pm (+2 lines)
Lines 701-706 sub apply { Link Here
701
        }
701
        }
702
    });
702
    });
703
703
704
    Koha::Patron::Debarments::DelDebarmentsAfterPayment({ borrowernumber => $self->borrowernumber });
705
704
    return $self;
706
    return $self;
705
}
707
}
706
708
(-)a/t/db_dependent/Patron/Borrower_Debarments.t (-11 / +44 lines)
Lines 197-218 is( Koha::Patrons->find($borrowernumber3)->debarredcomment, Link Here
197
197
198
# Test removing debartments after payment
198
# Test removing debartments after payment
199
my $debarmentsRulesPref = C4::Context->preference("DebarmentsToLiftAfterPayment");
199
my $debarmentsRulesPref = C4::Context->preference("DebarmentsToLiftAfterPayment");
200
C4::Context->set_preference("DebarmentsToLiftAfterPayment", "Test debarment:\n  outstanding: 0\nTest debarment 2:");
200
C4::Context->set_preference("DebarmentsToLiftAfterPayment", "Test debarment:\n  outstanding: 0\nTest debarment 2:\n  outstanding: 2");
201
201
202
AddDebarment({
202
my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } );
203
    borrowernumber => $borrowernumber,
203
my $patron2  = $builder->build_object( { class => 'Koha::Patrons' } );
204
my $account = $patron2->account;
205
my $fine = $account->add_debit(
206
    {
207
        amount    => '5.00',
208
        type      => 'OVERDUE',
209
        interface => 'cron'
210
    }
211
);
212
213
Koha::Patron::Debarments::AddDebarment({
214
    borrowernumber => $patron2->borrowernumber,
204
    comment => 'Test debarment',
215
    comment => 'Test debarment',
205
});
216
});
206
AddDebarment({
217
Koha::Patron::Debarments::AddDebarment({
207
    borrowernumber => $borrowernumber,
218
    borrowernumber => $patron2->borrowernumber,
208
    comment => 'Test debarment 2',
219
    comment => 'Test debarment 2',
209
});
220
});
210
221
211
$debarments = GetDebarments({ borrowernumber => $borrowernumber });
222
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron2->borrowernumber });
212
is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" );
223
is( @$debarments, 2, "GetDebarments returns 2 debarments before payment" );
213
224
214
DelDebarmentsAfterPayment({ borrowernumber => $borrowernumber });
225
my $payment1 = $account->pay(
215
C4::Context->set_preference("DebarmentsToLiftAfterPayment", $debarmentsRulesPref);
226
    {
227
        cash_register => $register->id,
228
        amount        => '4.00',
229
        credit_type   => 'PAYMENT',
230
        lines         => [$fine]
231
    }
232
);
233
234
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron2->borrowernumber });
235
is( @$debarments, 1, "GetDebarments returns 1 debarment after first payment" );
236
my $debarment_comment;
237
foreach my $debarment (@$debarments){
238
    $debarment_comment = $debarment->{comment};
239
}
240
is( $debarment_comment, "Test debarment", "Returned debartments comment is 'Test debarment'" );
241
242
my $payment2 = $account->pay(
243
    {
244
        cash_register => $register->id,
245
        amount        => '1.00',
246
        credit_type   => 'PAYMENT',
247
        lines         => [$fine]
248
    }
249
);
216
250
217
$debarments = GetDebarments({ borrowernumber => $borrowernumber });
251
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron2->borrowernumber });
218
is( @$debarments, 0, "GetDebarments returns 0 debarments after payment" );
252
is( @$debarments, 0, "GetDebarments returns 0 debarments after second payment" );
219
- 

Return to bug 16223