Bugzilla – Attachment 97156 Details for
Bug 23442
Add a 'refund' process to accounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23442: Prevent payouts from being reduced
Bug-23442-Prevent-payouts-from-being-reduced.patch (text/plain), 7.14 KB, created by
Josef Moravec
on 2020-01-10 07:46:24 UTC
(
hide
)
Description:
Bug 23442: Prevent payouts from being reduced
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2020-01-10 07:46:24 UTC
Size:
7.14 KB
patch
obsolete
>From fe18951fb8f92564abc836252e09a898fb1594ad Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 9 Jan 2020 11:59:43 +0000 >Subject: [PATCH] Bug 23442: Prevent payouts from being reduced > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Account/Line.pm | 8 +++- > .../prog/en/modules/members/boraccount.tt | 2 +- > t/db_dependent/Koha/Account/Lines.t | 47 ++++++++++++++++------ > 3 files changed, 42 insertions(+), 15 deletions(-) > >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index cecf0c26f0..bd86317bb4 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -304,6 +304,10 @@ sub reduce { > Koha::Exceptions::Account::IsNotDebit->throw( > error => 'Account line ' . $self->id . 'is not a debit' ); > } >+ if ( $self->debit_type_code eq 'PAYOUT' ) { >+ Koha::Exceptions::Account::IsNotDebit->throw( >+ error => 'Account line ' . $self->id . 'is a payout' ); >+ } > > # Check for mandatory parameters > my @mandatory = ( 'interface', 'reduction_type', 'amount' ); >@@ -401,7 +405,8 @@ sub reduce { > } > ); > >- return $reduction->discard_changes; >+ $reduction->discard_changes; >+ return $reduction; > } > > =head3 apply >@@ -583,6 +588,7 @@ sub payout { > } > ); > >+ $payout->discard_changes; > return $payout; > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >index 195db37642..7427d41e38 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt >@@ -87,7 +87,7 @@ > [% IF CAN_user_updatecharges_payout && account.is_credit && ( account.amountoutstanding < 0 ) %] > <button type="button" data-toggle="modal" data-target="#issuePayoutModal" data-account="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue payout</button> > [% END %] >- [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED' ) %] >+ [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED') && !(account.debit_type_code == 'PAYOUT') %] > <button type="button" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amount | $Price %]" data-amountoutstanding="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue refund</button> > [% END %] > </td> >diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t >index 873cb38739..a2a12c16f0 100755 >--- a/t/db_dependent/Koha/Account/Lines.t >+++ b/t/db_dependent/Koha/Account/Lines.t >@@ -895,7 +895,7 @@ subtest "void() tests" => sub { > > subtest "payout() tests" => sub { > >- plan tests => 17; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -948,9 +948,9 @@ subtest "payout() tests" => sub { > )->store(); > > is( $account->balance(), -10, "Account balance is -10" ); >- is( $debit1->amountoutstanding, >+ is( $debit1->amountoutstanding + 0, > 10, 'Overdue fee has an amount outstanding of 10' ); >- is( $credit1->amountoutstanding, >+ is( $credit1->amountoutstanding + 0, > -20, 'Credit has an amount outstanding of -20' ); > > my $pay_params = { >@@ -1017,12 +1017,14 @@ subtest "payout() tests" => sub { > } > ); > >- is( $payout->amount(), 10, "Payout amount is 10" ); >- is( $payout->amountoutstanding(), 0, "Payout amountoutstanding is 0" ); >- is( $account->balance(), 0, "Account balance is 0" ); >- is( $debit1->amountoutstanding, >+ is( ref($payout), 'Koha::Account::Line', >+ '->payout() returns a Koha::Account::Line' ); >+ is( $payout->amount() + 0, 10, "Payout amount is 10" ); >+ is( $payout->amountoutstanding() + 0, 0, "Payout amountoutstanding is 0" ); >+ is( $account->balance() + 0, 0, "Account balance is 0" ); >+ is( $debit1->amountoutstanding + 0, > 10, 'Overdue fee still has an amount outstanding of 10' ); >- is( $credit1->amountoutstanding, >+ is( $credit1->amountoutstanding + 0, > -10, 'Credit has an new amount outstanding of -10' ); > is( $credit1->status(), 'PAID', "Credit has a new status of PAID" ); > >@@ -1031,7 +1033,7 @@ subtest "payout() tests" => sub { > > subtest "reduce() tests" => sub { > >- plan tests => 25; >+ plan tests => 27; > > $schema->storage->txn_begin; > >@@ -1142,12 +1144,14 @@ subtest "reduce() tests" => sub { > # (Refund 5 on debt of 20) > my $reduction = $debit1->reduce($reduce_params); > >+ is( ref($reduction), 'Koha::Account::Line', >+ '->reduce() returns a Koha::Account::Line' ); > is( $reduction->amount() * 1, -5, "Reduce amount is -5" ); > is( $reduction->amountoutstanding() * 1, > 0, "Reduce amountoutstanding is 0" ); > is( $debit1->amountoutstanding() * 1, > 15, "Debit amountoutstanding reduced by 5 to 15" ); >- is( $account->balance() * 1, -5, "Account balance is -5" ); >+ is( $account->balance() * 1, -5, "Account balance is -5" ); > is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); > > my $offsets = Koha::Account::Offsets->search( >@@ -1160,8 +1164,9 @@ subtest "reduce() tests" => sub { > > # Zero offset created when zero outstanding > # (Refund another 5 on paid debt of 20) >- $credit1->apply( { debits => [ $debit1 ] } ); >- is($debit1->amountoutstanding + 0, 0, 'Debit1 amountoutstanding reduced to 0'); >+ $credit1->apply( { debits => [$debit1] } ); >+ is( $debit1->amountoutstanding + 0, >+ 0, 'Debit1 amountoutstanding reduced to 0' ); > $reduction = $debit1->reduce($reduce_params); > is( $reduction->amount() * 1, -5, "Reduce amount is -5" ); > is( $reduction->amountoutstanding() * 1, >@@ -1182,7 +1187,23 @@ subtest "reduce() tests" => sub { > $debit1->reduce($reduce_params); > } > 'Koha::Exceptions::ParameterTooHigh', >-'->reduce cannot reduce mor than the original amount (combined reductions test)'; >+'->reduce cannot reduce more than the original amount (combined reductions test)'; >+ >+ # Throw exception if attempting to reduce a payout >+ my $payout = $reduction->payout( >+ { >+ interface => 'intranet', >+ staff_id => $staff->borrowernumber, >+ branch => $branchcode, >+ payout_type => 'CASH', >+ amount => 5 >+ } >+ ); >+ throws_ok { >+ $payout->reduce($reduce_params); >+ } >+ 'Koha::Exceptions::Account::IsNotDebit', >+ '->reduce() cannot be used on a payout debit'; > > $schema->storage->txn_rollback; > }; >-- >2.11.0
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 23442
:
92954
|
92955
|
92956
|
95674
|
95675
|
95676
|
95677
|
96400
|
96401
|
96402
|
96403
|
96414
|
96415
|
96416
|
96417
|
97008
|
97009
|
97010
|
97011
|
97012
|
97062
|
97063
|
97064
|
97065
|
97066
|
97067
|
97151
|
97152
|
97153
|
97154
|
97155
| 97156