Bug 22435: ->apply() should always use 'APPLY' for offset_type
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
990c023b42
commit
b5a09e4654
|
|
@ -2608,7 +2608,7 @@ sub _FixOverduesOnReturn {
|
|||
}
|
||||
);
|
||||
|
||||
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
|
||||
$credit->apply({ debits => [ $accountline ] });
|
||||
|
||||
if (C4::Context->preference("FinesLog")) {
|
||||
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
|
||||
|
|
|
|||
|
|
@ -360,8 +360,7 @@ sub payin_amount {
|
|||
if ( exists( $params->{debits} ) ) {
|
||||
$credit = $credit->apply(
|
||||
{
|
||||
debits => $params->{debits},
|
||||
offset_type => $Koha::Account::offset_type->{$params->{type}}
|
||||
debits => $params->{debits}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -372,8 +371,7 @@ sub payin_amount {
|
|||
{
|
||||
$credit = $credit->apply(
|
||||
{
|
||||
debits => [ $self->outstanding_debits->as_list ],
|
||||
offset_type => $Koha::Account::offset_type->{$params->{type}}
|
||||
debits => [ $self->outstanding_debits->as_list ]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -617,8 +615,7 @@ sub payout_amount {
|
|||
|
||||
# Offset against credits
|
||||
for my $credit ( @{$outstanding_credits} ) {
|
||||
$credit->apply(
|
||||
{ debits => [$payout], offset_type => 'PAYOUT' } );
|
||||
$credit->apply( { debits => [$payout] } );
|
||||
$payout->discard_changes;
|
||||
last if $payout->amountoutstanding == 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,6 +288,13 @@ sub void {
|
|||
}
|
||||
)->store();
|
||||
|
||||
# Link void to payment
|
||||
$self->set({
|
||||
amountoutstanding => $self->amount,
|
||||
status => 'VOID'
|
||||
})->store();
|
||||
$self->apply( { debits => [$void] } );
|
||||
|
||||
# Reverse any applied payments
|
||||
foreach my $account_offset (@account_offsets) {
|
||||
my $fee_paid =
|
||||
|
|
@ -310,13 +317,6 @@ sub void {
|
|||
)->store();
|
||||
}
|
||||
|
||||
# Link void to payment
|
||||
$self->set({
|
||||
amountoutstanding => $self->amount,
|
||||
status => 'VOID'
|
||||
})->store();
|
||||
$self->apply({ debits => [$void]});
|
||||
|
||||
if ( C4::Context->preference("FinesLog") ) {
|
||||
logaction(
|
||||
"FINES", 'VOID',
|
||||
|
|
@ -421,12 +421,7 @@ sub cancel {
|
|||
)->store();
|
||||
|
||||
# Link cancellation to charge
|
||||
$cancellation->apply(
|
||||
{
|
||||
debits => [$self],
|
||||
offset_type => 'CANCELLATION'
|
||||
}
|
||||
);
|
||||
$cancellation->apply( { debits => [$self] } );
|
||||
$cancellation->status('APPLIED')->store();
|
||||
|
||||
# Update status of original debit
|
||||
|
|
@ -548,12 +543,7 @@ sub reduce {
|
|||
my $debit_outstanding = $self->amountoutstanding;
|
||||
if ( $debit_outstanding >= $params->{amount} ) {
|
||||
|
||||
$reduction->apply(
|
||||
{
|
||||
debits => [$self],
|
||||
offset_type => uc( $params->{reduction_type} )
|
||||
}
|
||||
);
|
||||
$reduction->apply( { debits => [$self] } );
|
||||
$reduction->status('APPLIED')->store();
|
||||
}
|
||||
else {
|
||||
|
|
@ -564,7 +554,7 @@ sub reduce {
|
|||
{
|
||||
credit_id => $reduction->accountlines_id,
|
||||
debit_id => $self->accountlines_id,
|
||||
type => uc( $params->{reduction_type} ),
|
||||
type => 'APPLY',
|
||||
amount => 0
|
||||
}
|
||||
)->store();
|
||||
|
|
@ -582,7 +572,7 @@ sub reduce {
|
|||
=head3 apply
|
||||
|
||||
my $debits = $account->outstanding_debits;
|
||||
my $credit = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } );
|
||||
my $credit = $credit->apply( { debits => $debits } );
|
||||
|
||||
Applies the credit to a given debits array reference.
|
||||
|
||||
|
|
@ -592,9 +582,6 @@ Applies the credit to a given debits array reference.
|
|||
|
||||
=item debits - Koha::Account::Lines object set of debits
|
||||
|
||||
=item offset_type (optional) - a string indicating the offset type (valid values are those from
|
||||
the 'account_offset_types' table)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
@ -603,7 +590,6 @@ sub apply {
|
|||
my ( $self, $params ) = @_;
|
||||
|
||||
my $debits = $params->{debits};
|
||||
my $offset_type = $params->{offset_type} // 'Credit Applied';
|
||||
|
||||
unless ( $self->is_credit ) {
|
||||
Koha::Exceptions::Account::IsNotCredit->throw(
|
||||
|
|
@ -644,7 +630,7 @@ sub apply {
|
|||
{ credit_id => $self->id,
|
||||
debit_id => $debit->id,
|
||||
amount => $amount_to_cancel * -1,
|
||||
type => $offset_type,
|
||||
type => 'APPLY'
|
||||
}
|
||||
)->store();
|
||||
|
||||
|
|
@ -777,7 +763,7 @@ sub payout {
|
|||
}
|
||||
)->store();
|
||||
|
||||
$self->apply( { debits => [$payout], offset_type => 'PAYOUT' } );
|
||||
$self->apply( { debits => [$payout] } );
|
||||
$self->status('PAID')->store;
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -133,12 +133,12 @@ sub add_credit {
|
|||
|
||||
if ($debits) {
|
||||
# pay them!
|
||||
$credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' });
|
||||
$credit = $credit->apply({ debits => [ $debits->as_list ] });
|
||||
}
|
||||
|
||||
if ($credit->amountoutstanding != 0) {
|
||||
my $outstanding_debits = $account->outstanding_debits;
|
||||
$credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' });
|
||||
$credit->apply({ debits => [ $outstanding_debits->as_list ] });
|
||||
}
|
||||
|
||||
$credit->discard_changes;
|
||||
|
|
|
|||
|
|
@ -2729,8 +2729,7 @@ subtest 'AddReturn | is_overdue' => sub {
|
|||
interface => 'test',
|
||||
}
|
||||
);
|
||||
$credit->apply(
|
||||
{ debits => [ $debit ], offset_type => 'Payment' } );
|
||||
$credit->apply( { debits => [$debit] } );
|
||||
|
||||
is( int( $patron->account->balance() ),
|
||||
0, "Overdue fine should be paid off" );
|
||||
|
|
@ -2856,7 +2855,7 @@ subtest 'AddReturn | is_overdue' => sub {
|
|||
interface => 'test',
|
||||
}
|
||||
);
|
||||
$credit->apply( { debits => [$debit], offset_type => 'Payment' } );
|
||||
$credit->apply( { debits => [$debit] } );
|
||||
|
||||
is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
|
||||
|
||||
|
|
@ -3193,8 +3192,7 @@ subtest 'AddReturn | is_overdue' => sub {
|
|||
item_id => $item->itemnumber
|
||||
}
|
||||
);
|
||||
$overdue_forgive->apply(
|
||||
{ debits => [$overdue_fee], offset_type => 'Forgiven' } );
|
||||
$overdue_forgive->apply( { debits => [$overdue_fee] } );
|
||||
$overdue_fee->discard_changes;
|
||||
is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
|
||||
|
||||
|
|
@ -3291,8 +3289,7 @@ subtest 'AddReturn | is_overdue' => sub {
|
|||
item_id => $item->itemnumber
|
||||
}
|
||||
);
|
||||
$overdue_forgive->apply(
|
||||
{ debits => [$overdue_fee], offset_type => 'Forgiven' } );
|
||||
$overdue_forgive->apply( { debits => [$overdue_fee] } );
|
||||
$overdue_fee->discard_changes;
|
||||
is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue