Bugzilla – Attachment 106873 Details for
Bug 23091
Add options to charge new or restore forgiven overdues when a lost item is returned
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23091: Add handling for new lostreturn rules
Bug-23091-Add-handling-for-new-lostreturn-rules.patch (text/plain), 20.48 KB, created by
Martin Renvoize (ashimema)
on 2020-07-14 14:03:24 UTC
(
hide
)
Description:
Bug 23091: Add handling for new lostreturn rules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-07-14 14:03:24 UTC
Size:
20.48 KB
patch
obsolete
>From 1d2d9df910aafc1c0fb381a9e0670ad28703419b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 23 Oct 2019 11:32:28 +0100 >Subject: [PATCH] Bug 23091: Add handling for new lostreturn rules > >This patch adds handing for the new values available for the lostreturn >policy settings. > >* undef - Do nothing, leave fees and fines as they were at the point of > lose. >* refund - Refund the lost item fee only >* charge - Refund the lost item fee and charge a fresh overdue fine > dated for a return on the date the item is 'found' >* restore - Refund the lost item fee and restore the original overdue > fine (dated for a 'return' on the date the item was 'lost' > >Test plan >1/ apply patch >2/ updatedatabase, restart_all >3/ verify finesmode and CalculateFinesOnReturn and WhenLostChargeReplacementFee are on >4/ verify WhenLostForgiveFine is set to "Forgive" >5/ verify circ rules include fines >6/ set Default lost item fee refund on return policy to "Refund lost item charge" >7/ create 4 overdue checkouts that will incur fines >8/ run fines.pl >9/ confirm 4 items checked out with accruing fines >10/ confirm all 4 items have a replacement price > >Item 1 >11/ mark the first item lost >12/ verify that fine is gone and lost fee has been charged >13/ check item in >14/ verify that lost fee is gone and overdue charge has not returned > >Item 2 >15/ set Default lost item fee refund on return policy to "Refund lost item charge and charge new overdue fine" >16/ mark second item lost >17/ verify that fine is gone and lost fee has been charged >18/ check item in >19/ verify that lost fee is gone and a new overdue charge has been made > >Item 3 >20/ set Default lost item fee refund on return policy to "Refund lost item charge and restore overdue fine" >21/ mark third item lost >22/ verify that fine is gone and lost fee has been charged >23/ check item in >24/ verify that lost fee is gone and the old overdue charge has been restored > >Item 4 >25/ set Default lost item fee refund on return policy to "Leave lost item charge" >26/ mark fourth item lost >27/ verify that fine is gone and lost fee has been charged >28/ check item in >29/ verify that lost fee remains and the overdue charge is still gone >--- > C4/Circulation.pm | 143 +++++++++++++++--- > Koha/CirculationRules.pm | 19 ++- > admin/smart-rules.pl | 16 +- > .../prog/en/modules/admin/smart-rules.tt | 87 +++++++---- > 4 files changed, 199 insertions(+), 66 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 590288fb94..c049061832 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1453,19 +1453,35 @@ sub AddIssue { > UpdateTotalIssues( $item_object->biblionumber, 1 ); > } > >- ## If item was lost, it has now been found, reverse any list item charges if necessary. >+ ## If item was lost, it has now been found, reverse any lost item charges if necessary. > if ( $item_object->itemlost ) { >- if ( >- Koha::CirculationRules->get_lostreturn_policy( >- { >- return_branch => C4::Context->userenv->{branch}, >- item => $item_object >- } >- ) >- ) >- { >+ my $lostreturn_policy = >+ Koha::CirculationRules->get_lostreturn_policy( >+ { >+ return_branch => C4::Context->userenv->{branch}, >+ item => $item_object >+ } >+ ); >+ >+ if ($lostreturn_policy) { > _FixAccountForLostAndFound( $item_object->itemnumber, undef, > $item_object->barcode ); >+ >+ if ( $lostreturn_policy eq 'charge' ) { >+ _CalculateAndUpdateFine( >+ { >+ issue => $issue, >+ item => $item_unblessed, >+ borrower => $borrower >+ } >+ ); >+ _FixOverduesOnReturn( $borrower->{borrowernumber}, >+ $item_object->itemnumber, undef, 'RENEWED' ); >+ } >+ elsif ( $lostreturn_policy eq 'restore' ) { >+ _RestoreOverdueForLostAndFound( $item_object->itemnumber, >+ $borrower->{'borrowernumber'} ); >+ } > } > } > >@@ -2038,18 +2054,35 @@ sub AddReturn { > if ( $item->itemlost ) { > $messages->{'WasLost'} = 1; > unless ( C4::Context->preference("BlockReturnOfLostItems") ) { >- if ( >- Koha::CirculationRules->get_lostreturn_policy( >- { >- return_branch => C4::Context->userenv->{branch}, >- item => $item, >- } >- ) >- ) >- { >+ my $lostreturn_policy = >+ Koha::CirculationRules->get_lostreturn_policy( >+ { >+ return_branch => C4::Context->userenv->{branch}, >+ item => $item >+ } >+ ); >+ >+ if ($lostreturn_policy) { > _FixAccountForLostAndFound( $item->itemnumber, > $borrowernumber, $barcode ); > $messages->{'LostItemFeeRefunded'} = 1; >+ >+ if ( $lostreturn_policy eq 'charge' ) { >+ _CalculateAndUpdateFine( >+ { >+ issue => $issue, >+ item => $item->unblessed, >+ borrower => $patron_unblessed, >+ return_date => $return_date >+ } >+ ); >+ $messages->{'LostItemFeeCharged'} = 1; >+ } >+ elsif ( $lostreturn_policy eq 'restore' ) { >+ _RestoreOverdueForLostAndFound( $item->itemnumber, >+ $borrowernumber ); >+ $messages->{'LostItemFeeRestored'} = 1; >+ } > } > } > } >@@ -2454,15 +2487,12 @@ sub _FixOverduesOnReturn { > > $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); > >- $accountline->status('FORGIVEN'); >- > if (C4::Context->preference("FinesLog")) { > &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); > } >- } else { >- $accountline->status($status); > } > >+ $accountline->status($status); > return $accountline->store(); > } > ); >@@ -2559,6 +2589,73 @@ sub _FixAccountForLostAndFound { > return ($credit) ? $credit->id : undef; > } > >+=head2 _RestoreOverdueForLostAndFound >+ >+ &_RestoreOverdueForLostAndFound($borrowernumber, $itemnumber ); >+ >+C<$borrowernumber> borrowernumber >+ >+C<$itemnumber> itemnumber >+ >+Internal function >+ >+=cut >+ >+sub _RestoreOverdueForLostAndFound { >+ my ( $borrowernumber, $item ) = @_; >+ >+ unless( $borrowernumber ) { >+ warn "_RestoreOverdueForLostAndFound() not supplied valid borrowernumber"; >+ return; >+ } >+ unless( $item ) { >+ warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; >+ return; >+ } >+ >+ my $schema = Koha::Database->schema; >+ >+ my $result = $schema->txn_do( >+ sub { >+ # check for lost overdue fine >+ my $accountlines = Koha::Account::Lines->search( >+ { >+ borrowernumber => $borrowernumber, >+ itemnumber => $item, >+ debit_type_code => 'OVERDUE', >+ status => 'LOST' >+ }, >+ { >+ order_by => { '-desc' => 'date' }, >+ rows => 1 >+ } >+ ); >+ return 0 unless $accountlines->count; # no warning, there's just nothing to fix >+ >+ # Update status of fine >+ my $overdue = $accountlines->next; >+ $overdue->status('RETURNED')->store(); >+ >+ # Find related forgive credit >+ my $refunds = $overdue->credits( >+ { >+ credit_type_code => 'FORGIVEN', >+ itemnumber => $item, >+ status => [ { '!=' => 'VOID' }, undef ] >+ }, >+ { order_by => { '-desc' => 'date' }, rows => 1 } >+ ); >+ return 0 unless $refunds->count; # no warning, there's just nothing to fix >+ >+ # Revert the forgive credit >+ my $refund = $refunds->next; >+ return $refund->void(); >+ } >+ ); >+ >+ return $result; >+} >+ > =head2 _GetCircControlBranch > > my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index 9bf1ab860e..5e92674a60 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -46,7 +46,7 @@ Any attempt to set a rule with a nonsensical scope (for instance, setting the C< > =cut > > our $RULE_KINDS = { >- refund => { >+ lostreturn => { > scope => [ 'branchcode' ], > }, > >@@ -428,7 +428,18 @@ sub get_onshelfholds_policy { > > =head3 get_lostreturn_policy > >- my $refund = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } ); >+ my $lostrefund_policy = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } ); >+ >+Return values are: >+ >+=over 2 >+ >+=item 0 - Do not refund >+=item refund - Refund the lost item charge >+=item restore - Refund the lost item charge and restore the original overdue fine >+=item charge - Refund the lost item charge and charge a new overdue fine >+ >+=back > > =cut > >@@ -449,11 +460,11 @@ sub get_lostreturn_policy { > my $rule = Koha::CirculationRules->get_effective_rule( > { > branchcode => $branch, >- rule_name => 'refund', >+ rule_name => 'lostreturn', > } > ); > >- return $rule ? $rule->rule_value : 1; >+ return $rule ? $rule->rule_value : 'refund'; > } > > =head3 article_requestable_rules >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index 04ddb2698a..1c17758dc1 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -523,16 +523,16 @@ elsif ($op eq "add-branch-item") { > } > elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { > >- my $refund = $input->param('refund'); >+ my $lostreturn = $input->param('lostreturn'); > >- if ( $refund eq '*' ) { >+ if ( $lostreturn eq '*' ) { > if ( $branch ne '*' ) { >- # only do something for $refund eq '*' if branch-specific >+ # only do something for $lostreturn eq '*' if branch-specific > Koha::CirculationRules->set_rules( > { > branchcode => $branch, > rules => { >- refund => undef >+ lostreturn => undef > } > } > ); >@@ -542,18 +542,18 @@ elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { > { > branchcode => $branch, > rules => { >- refund => $refund >+ lostreturn => $lostreturn > } > } > ); > } > } > >-my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'refund' }); >-my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'refund' }); >+my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' }); >+my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' }); > $template->param( > refundLostItemFeeRule => $refundLostItemFeeRule, >- defaultRefundRule => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 1 >+ defaultRefundRule => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 'refund' > ); > > my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >index cfea9b6cec..c64838e3f0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >@@ -738,23 +738,35 @@ > </tr> > <tr> > <td> >- <select name="refund"> >+ <select name="lostreturn"> > [%# Default branch %] > [% IF ( current_branch == '*' ) %] >- [% IF ( defaultRefundRule ) %] >- <option value="1" selected="selected"> >+ [% IF ( defaultRefundRule == 'refund' ) %] >+ <option value="refund" selected="selected">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( defaultRefundRule == 'charge' ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( defaultRefundRule == 'restore' ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( defaultRefundRule == 0 ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0" selected="selected">Leave lost item charge</option> > [% ELSE %] >- <option value="1"> >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> > [% END %] >- Yes >- </option> >- [% IF ( not defaultRefundRule ) %] >- <option value="0" selected="selected"> >- [% ELSE %] >- <option value="0"> >- [% END %] >- No >- </option> > [% ELSE %] > [%# Branch-specific %] > [% IF ( not refundLostItemFeeRule ) %] >@@ -762,30 +774,43 @@ > [% ELSE %] > <option value="*"> > [% END %] >- [% IF defaultRefundRule %] >- Use default (Yes) >+ [% IF defaultRefundRule == 'refund' %] >+ Use default (Refund lost item charge) >+ [% ELSIF defaultRefundRule == 'charge' %] >+ Use default (Refund lost item charge and restore overdue fine) >+ [% ELSIF defaultRefundRule == 'restore' %] >+ Use default (Refund lost item charge and charge new overdue fine) > [% ELSE %] >- Use default (No) >+ Use default (Leave lost item charge) > [% END %] > </option> > [% IF ( not refundLostItemFeeRule ) %] >- <option value="1">Yes</option> >- <option value="0">No</option> >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> > [% ELSE %] >- [% IF ( refundLostItemFeeRule.rule_value ) %] >- <option value="1" selected="selected"> >- [% ELSE %] >- <option value="1"> >+ [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %] >+ <option value="refund" selected="selected">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option> >+ <option value="0">Leave lost item charge</option> >+ [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %] >+ <option value="refund">Refund lost item charge</option> >+ <option value="charge">Refund lost item charge and charge new overdue fine</option> >+ <option value="restore">Refund lost item charge and restore overdue fine</option> >+ <option value="0" selected="selected">Leave lost item charge</option> > [% END %] >- Yes >- </option> >- [% IF ( not refundLostItemFeeRule.rule_value ) %] >- <option value="0" selected="selected"> >- [% ELSE %] >- <option value="0"> >- [% END %] >- No >- </option> > [% END %] > [% END %] > </select> >-- >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 23091
:
96217
|
105529
|
105530
|
105531
|
105544
|
105545
|
105546
|
105547
|
105567
|
105649
|
106871
|
106872
|
106873
|
106874
|
106875
|
106876
|
106906
|
106907
|
106908
|
106909
|
106910
|
106911
|
106912
|
106961
|
107026
|
107027
|
107028
|
107029
|
107030
|
107031
|
107032
|
107033
|
107034
|
107100
|
107101
|
107102
|
107103
|
107104
|
107105
|
107106
|
107107
|
107108
|
107335
|
107336
|
107337
|
107338
|
107339
|
107340
|
107341
|
107342
|
107343
|
108718
|
108719
|
108720
|
108721
|
108722
|
108723
|
108724
|
109571
|
109572
|
109573
|
109574
|
109575
|
109576
|
109577
|
110660
|
110661
|
110662
|
110663
|
110664
|
110665
|
110666
|
110667
|
110720
|
110721
|
110722
|
110723
|
110724
|
110725
|
110726
|
110727
|
111501
|
111502
|
111503
|
111504
|
111505
|
111506
|
111507
|
111508
|
111935
|
111936
|
111965
|
111979
|
111980
|
111981
|
111982
|
111983
|
111984
|
111985
|
111986
|
111987
|
111988
|
111989
|
113081
|
113082
|
113083
|
113084
|
113085
|
113086
|
113087
|
113088
|
113089
|
113090
|
113091