Bugzilla – Attachment 118545 Details for
Bug 22435
Clarify account_offset types by converting them to clear codes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22435: ->apply() should always use 'APPLY' for offset_type
Bug-22435--apply-should-always-use-APPLY-for-offse.patch (text/plain), 9.01 KB, created by
Martin Renvoize (ashimema)
on 2021-03-19 14:14:10 UTC
(
hide
)
Description:
Bug 22435: ->apply() should always use 'APPLY' for offset_type
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-03-19 14:14:10 UTC
Size:
9.01 KB
patch
obsolete
>From 60a5902686438091806e307b0edb95d31800984e Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 17 Mar 2021 14:11:20 +0000 >Subject: [PATCH] Bug 22435: ->apply() should always use 'APPLY' for > offset_type > >--- > C4/Circulation.pm | 2 +- > Koha/Account.pm | 16 +++---------- > Koha/Account/Line.pm | 40 +++++++++++---------------------- > Koha/REST/V1/Patrons/Account.pm | 4 ++-- > t/db_dependent/Circulation.t | 11 ++++----- > 5 files changed, 23 insertions(+), 50 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 03fe5c78f2..80273d04b1 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2616,7 +2616,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"); >diff --git a/Koha/Account.pm b/Koha/Account.pm >index 081e165a9c..bdbf5676bf 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -354,12 +354,7 @@ sub payin_amount { > > # Offset debts passed first > if ( exists( $params->{debits} ) ) { >- $credit = $credit->apply( >- { >- debits => $params->{debits}, >- offset_type => $params->{type} >- } >- ); >+ $credit = $credit->apply( { debits => $params->{debits} } ); > } > > # Offset against remaining balance if AutoReconcile >@@ -367,11 +362,7 @@ sub payin_amount { > && $credit->amountoutstanding != 0 ) > { > $credit = $credit->apply( >- { >- debits => [ $self->outstanding_debits->as_list ], >- offset_type => $params->{type} >- } >- ); >+ { debits => [ $self->outstanding_debits->as_list ], } ); > } > } > ); >@@ -613,8 +604,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; > } >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index fa22243772..5ced78fa07 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -289,6 +289,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 = >@@ -311,13 +318,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', >@@ -422,12 +422,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 >@@ -549,12 +544,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 { >@@ -565,7 +555,7 @@ sub reduce { > { > credit_id => $reduction->accountlines_id, > debit_id => $self->accountlines_id, >- type => uc( $params->{reduction_type} ), >+ type => 'APPLY', > amount => 0 > } > )->store(); >@@ -583,7 +573,7 @@ sub reduce { > =head3 apply > > my $debits = $account->outstanding_debits; >- my $outstanding_amount = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } ); >+ my $outstanding_amount = $credit->apply( { debits => $debits } ); > > Applies the credit to a given debits array reference. > >@@ -593,9 +583,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 >@@ -604,7 +591,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( >@@ -645,7 +631,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; > } > ); >diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm >index c75f91a1f7..b1341cdacf 100644 >--- a/Koha/REST/V1/Patrons/Account.pm >+++ b/Koha/REST/V1/Patrons/Account.pm >@@ -134,12 +134,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 ] }); > } > > return $c->render( status => 200, openapi => { account_line_id => $credit->id } ); >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index d0bfe6e207..27fc7cbbd3 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -2640,8 +2640,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" ); >@@ -2767,7 +2766,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' ); > >@@ -3104,8 +3103,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'); > >@@ -3202,8 +3200,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'); > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22435
:
118340
|
118341
|
118541
|
118542
|
118543
|
118544
|
118545
|
118546
|
118547
|
120040
|
120041
|
120042
|
120043
|
120044
|
120045
|
120046
|
120963
|
120964
|
120965
|
120966
|
120967
|
120968
|
120969
|
120970
|
120979
|
120980
|
120981
|
120982
|
120983
|
120984
|
120985
|
120986
|
120987
|
120988
|
120989
|
120990
|
120991
|
121004
|
121005
|
121006
|
121007
|
121008
|
121009
|
121010
|
121011
|
121012
|
121013
|
121014
|
121015
|
121016
|
121028
|
121757
|
121758
|
121759
|
121760
|
121761
|
121762
|
121763
|
121764
|
121765
|
121766
|
121767
|
121768
|
121769
|
121960
|
121961
|
121962
|
121963
|
121964
|
121965
|
121966
|
121967
|
121968
|
121969
|
121970
|
121971
|
121972
|
122148
|
122149
|
122150
|
122151
|
122152
|
122153
|
122154
|
122155
|
122156
|
122157
|
122158
|
122159
|
122160
|
122161
|
122235
|
122236
|
122237
|
122238
|
122239
|
122240
|
122241
|
122242
|
122243
|
122244
|
122245
|
122246
|
122247
|
122248
|
122249
|
122250
|
122251
|
122252
|
122253
|
122256
|
122257
|
122258
|
122259
|
122260
|
122261
|
122262
|
122263
|
122264
|
122265
|
122266
|
122267
|
122268
|
122269
|
122270
|
122271
|
122272
|
122273
|
122274
|
122553
|
122554
|
122555
|
122556
|
122557
|
122558
|
122559
|
122560
|
122561
|
122562
|
122563
|
122564
|
122565
|
122566
|
122567
|
122568
|
122569
|
122570
|
122571
|
122586
|
122899
|
122900
|
122901
|
122902
|
122903
|
122904
|
122905
|
122906
|
122907
|
122908
|
122909
|
122910
|
122911
|
122912
|
122913
|
122914
|
122915
|
122916
|
122917
|
122918
|
122937
|
123423
|
123424
|
123425
|
123426
|
123427
|
123428
|
123429
|
123430
|
123431
|
123432
|
123433
|
123434
|
123435
|
123436
|
123437
|
123438
|
123439
|
123440
|
123441
|
123442
|
123443