Bug 41819: POS refunds with 'AC' type incorrectly create PAYOUT accountlines

When processing a refund through the POS register with refund type 'AC'
(Account Credit), the system was incorrectly creating both a REFUND credit
and a PAYOUT debit with payment_type = 'AC'.

When 'AC' is selected, the refund should remain as a credit on the patron's
account without creating a payout. This behavior was already correct in the
member account refund workflow (members/boraccount.pl) but was missing
from the POS refund workflow.

This patch:
1. Adds the same check to pos/register.pl that exists in members/boraccount.pl
   to skip payout creation when refund_type is 'AC', making both workflows
   consistent.

2. Fixes the JavaScript in register.tt to properly hide the 'AC' option for
   anonymous transactions. The original check only tested for empty string,
   but borrowernumber can be undefined/null, which needs to be handled.

Test plan:
Part 1: Test patron transaction refund with Account Credit (AC)
1. Find or create a test patron
2. On the patron's Accounting tab, manually add a charge (e.g., Manual fee)
3. Pay the fee off from the patron's Accounting tab
4. Navigate to Point of Sale > Transaction History
5. Find the payment transaction you just created
6. Click "Issue refund" on the payment line item
7. Verify that "Account credit" appears as an option in the "Transaction type"
   dropdown
8. Select "Account credit" as the transaction type
9. Enter the refund amount and click "Confirm"
10. Navigate back to the patron's Accounting tab
11. Verify that a REFUND credit appears on their account
12. Verify that NO PAYOUT debit was created
13. Verify the credit remains on the patron's account (positive balance)

Part 2: Test patron transaction refund with Cash payout
16. Using the same patron, create another manual fee and payment
17. Navigate to Point of Sale > Transaction History
18. Click "Issue refund" on the new payment
19. Select "Cash" (or another payment type) as the transaction type
20. Enter the refund amount and click "Confirm"
21. Navigate back to the patron's Accounting tab
22. Verify both a REFUND credit and a PAYOUT debit appear
23. Verify the PAYOUT has the correct payment_type (e.g., CASH)

Part 3: Test anonymous transaction (no Account Credit option)
24. Navigate to Point of Sale
25. Add an item to sell and complete the payment
27. Navigate to Point of Sale > Transaction History
28. Find the anonymous payment you just created
29. Click "Issue refund" on the payment line item
30. Verify that "Account credit" does NOT appear in the "Transaction type"
   dropdown (only payment types like Cash, Check, etc. should appear)
31. This confirms anonymous transactions cannot have account credits since
    there's no patron account to credit

Expected results:
- Patron transactions show "Account credit" option in refund dropdown
- Anonymous transactions do NOT show "Account credit" option
- AC refunds create only REFUND credit (no PAYOUT debit)
- Non-AC refunds create both REFUND credit and PAYOUT debit
- Run: prove t/db_dependent/Koha/Cash/Register/Cashup.t

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 39eae27a42)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
This commit is contained in:
Martin Renvoize 2026-02-11 14:28:43 +00:00 committed by Baptiste Wojtkowski
parent 5427ec07f9
commit ea059ce833
No known key found for this signature in database
GPG Key ID: 47A8A13E10BC0D40
2 changed files with 8 additions and 4 deletions

View File

@ -505,9 +505,10 @@
var amountoutstanding = button.data('amountoutstanding') || 0;
var paid = amount - amountoutstanding;
$("#paid + span").text(paid.format_price());
$("#returned").attr({ "value": paid.format_price(), "max": paid });
var member = button.data('member');
if ( member === '' ) {
$("#returned").attr({ "value": paid.format_price(), "max": paid });
var member = button.data("member");
// Hide AC option for anonymous transactions (no borrowernumber)
if (!member || member === "") {
$("#refund_type option[value='AC']").remove();
} else if ( $("#refund_type option[value='AC']").length == 0 ) {
$("#refund_type").prepend('<option value="AC" selected="selected">Account credit</option>');

View File

@ -137,13 +137,16 @@ if ( !$registers->count ) {
amount => $amount
}
);
# Only create a payout if refund_type is not 'AC' (Account Credit)
# When 'AC' is selected, the refund stays as credit on the patron's account
unless ( $refund_type eq 'AC' ) {
my $payout = $refund->payout(
{
payout_type => $refund_type,
branch => $library_id,
staff_id => $logged_in_user->id,
cash_register => $registerid,
cash_register => $cash_register->id,
interface => 'intranet',
amount => $amount
}