Bug 28432

Summary: When refunding lost fees we should not include voided payments [20.11 and below]
Product: Koha Reporter: Martin Renvoize <martin.renvoize>
Component: Fines and feesAssignee: Bugs List <koha-bugs>
Status: RESOLVED WONTFIX QA Contact: Testopia <testopia>
Severity: major    
Priority: P5 - low CC: martin.renvoize, nick, testopia
Version: 20.11   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28421
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29923
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 28432: Unit Tests

Description Martin Renvoize 2021-05-24 10:56:11 UTC
+++ This bug was initially created as a clone of Bug #28421 +++

To recreate:
1 - Mark an item lost
2 - Add a manual lost fee for that barcode to a patron 
    (or checkout before #1 and ensure a fine will be charged when marked lost)
3 - Pay the fee
4 - Void the fee
5 - Pay the fee
6 - Checkin the item
7 - The patron has a credit for twice the fee

The problematic code appears to be in _FixAccountForLostAndReturned:

        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
        });

We count both the payment and the voided payment
Comment 1 Martin Renvoize 2021-05-24 11:56:40 UTC
Created attachment 121323 [details] [review]
Bug 28432: Unit Tests

This patch adds test test cases for both a Voided Payment and Voided
Writeoff. These cases need special handling in the refund process.

Test plan
1/ Run t/db_dependent/Koha/Items.t
2/ Prior to this commit the test should pass
3/ After this commit the test should fail
4/ The subsequent commit should make the test pass again.
Comment 2 Martin Renvoize 2021-05-24 11:59:01 UTC
Pretty confident in the test.. but no idea how to resolve the actual bug..

I've tried using joins to look at the credit line status.. but for some reason that breaks all sorts..

>  my $credits_offsets = Koha::Account::Offsets->search(
>      {
>          debit_id  => $lost_charge->id,
>          credit_id => { '!=' => undef },     # it is not the debit itself
>          'credit.credit_type_code' => { '!=' => 'Writeoff' },
>          'credit.status'           => { '!=' => 'VOID' },
>      },
>      { join => 'credit' }
>  );
Comment 3 Nick Clemens 2021-05-26 14:42:01 UTC
Is this 20.05 and earlier? 20.11 does not appear to have _FixAccountForLostAndReturned?
Comment 4 Katrin Fischer 2023-07-01 09:30:27 UTC
As 20.11 is no longer maintained, I am moving this to WONTFIX.