Bugzilla – Attachment 80864 Details for
Bug 13098
Item lost multiple times by the same patron will create only be charged once
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13098: Make _FixAccountForLostAndReturned refund the right thing
Bug-13098-Make-FixAccountForLostAndReturned-refund.patch (text/plain), 3.80 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-10-18 16:24:07 UTC
(
hide
)
Description:
Bug 13098: Make _FixAccountForLostAndReturned refund the right thing
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-10-18 16:24:07 UTC
Size:
3.80 KB
patch
obsolete
>From 8d4d414825122f20c393d06ef613fb243057121d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 18 Oct 2018 13:08:42 -0300 >Subject: [PATCH] Bug 13098: Make _FixAccountForLostAndReturned refund the > right thing > >This patch changes the logic inside the method, to make it match the >behaviour described on the tests. > >It uses the existing offsets on the account_offsets table to gather >information about the right things to refund. > >To test: >- Run: > $ kshell > k$ prove t/db_dependent/Circulation.t >=> FAIL: Tests don't pass! >- Apply this patch >- Run > k$ prove t/db_dependent/Circulation.t >=> SUCCESS: Tests pass! >- Sign off :-D >--- > C4/Circulation.pm | 60 ++++++++++++++++++++++++++++++++--------------- > 1 file changed, 41 insertions(+), 19 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 9c8d5ba13e..f439d6c186 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2392,8 +2392,10 @@ sub _FixAccountForLostAndReturned { > my $borrowernumber = @_ ? shift : undef; > my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description > >+ my $credit; >+ > # check for charge made for lost book >- my $accountline = Koha::Account::Lines->search( >+ my $accountlines = Koha::Account::Lines->search( > { > itemnumber => $itemnumber, > accounttype => { -in => [ 'L', 'Rep', 'W' ] }, >@@ -2401,29 +2403,49 @@ sub _FixAccountForLostAndReturned { > { > order_by => { -desc => [ 'date', 'accountno' ] } > } >- )->next(); >+ ); >+ >+ return unless $accountlines->count > 0; >+ my $accountline = $accountlines->next; >+ >+ # Use cases >+ if ( $accountline->amount > $accountline->amountoutstanding ) { >+ # some amount has been cancelled. collect the offsets that are not writeoffs >+ # this works because the only way to subtract from a debt is >+ # using the UI buttons 'Pay' and 'Write off' >+ my $credits_offsets = Koha::Account::Offsets->search({ >+ debit_id => $accountline->id, >+ credit_id => { '!=' => undef }, # it is not the debit itself >+ type => { '!=' => 'Writeoff' }, >+ amount => { '<' => 0 } # credits are negative on the DB >+ }); >+ >+ my $total_to_refund = ( $credits_offsets->count > 0 ) >+ ? $credits_offsets->total * -1 # credits are negative on the DB >+ : 0; >+ >+ if ( $total_to_refund > 0 ) { >+ my $account = Koha::Patrons->find( $accountline->borrowernumber )->account; >+ $credit = $account->add_credit( >+ { >+ amount => $total_to_refund, >+ description => 'Item Returned ' . $item_id, >+ type => 'lost_item_return' >+ } >+ ); >+ } > >- return unless $accountline; >- return if $accountline->accounttype eq 'W'; # Written off >+ ModItem( { paidfor => '' }, undef, $itemnumber, { log_action => 0 } ); >+ } >+ # else { >+ # $accountline->amount == $accountline->amountoutstanding >+ #} > > $accountline->accounttype('LR'); >+ $accountline->amountoutstanding(0); > $accountline->store(); > >- my $account = Koha::Account->new( { patron_id => $accountline->borrowernumber } ); >- my $credit_id = $account->pay( >- { >- amount => $accountline->amount, >- description => "Item Returned " . $item_id, >- account_type => 'CR', >- offset_type => 'Lost Item Return', >- lines => [$accountline], >- >- } >- ); >- >- ModItem( { paidfor => '' }, undef, $itemnumber, { log_action => 0 } ); >- >- return $credit_id; >+ return ($credit) ? $credit->id : undef; > } > > =head2 _GetCircControlBranch >-- >2.19.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 13098
:
80507
|
80678
|
80862
|
80863
|
80864
|
81105
|
81106
|
81107
|
81194
|
81195
|
81354
|
81538
|
81539
|
81540
|
81541
|
81542
|
81543