From edb1441d88fc7ae6adb6863ffd54bac964d8913a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 13 Feb 2026 17:13:02 +0000 Subject: [PATCH] Bug 40445: (follow-up) Set payment_type for CASHUP_SURPLUS and CASHUP_DEFICIT accountlines When creating CASHUP_SURPLUS and CASHUP_DEFICIT accountlines during cashup reconciliation, the payment_type was not being set. This resulted in accountlines with NULL payment_type values, which should be 'CASH' to properly indicate these are cash-related transactions. This patch: - Sets payment_type to 'CASH' for both CASHUP_SURPLUS and CASHUP_DEFICIT accountlines created during the reconciliation process - Adds test coverage to verify payment_type is correctly set - Adds preference mocking to prevent test failures in subtests that don't specifically test reconciliation note requirements All required fields are now properly set for reconciliation accountlines: - payment_type (CASH) - manager_id - branchcode (from earlier follow-up) - register_id Test plan: 1. Apply patch 2. Run prove t/db_dependent/Koha/Cash/Register.t 3. Verify all tests pass, including new payment_type checks 4. In the staff interface, perform a cashup with a surplus or deficit 5. Verify the created CASHUP_SURPLUS or CASHUP_DEFICIT accountline has payment_type set to 'CASH' Signed-off-by: Jackie Usher --- Koha/Cash/Register.pm | 2 ++ t/db_dependent/Koha/Cash/Register.t | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm index 1a02f23aa9b..db37537196a 100644 --- a/Koha/Cash/Register.pm +++ b/Koha/Cash/Register.pm @@ -455,6 +455,7 @@ sub add_cashup { interface => 'intranet', branchcode => $self->branch, register_id => $self->id, + payment_type => 'CASH', note => $reconciliation_note } )->store(); @@ -480,6 +481,7 @@ sub add_cashup { interface => 'intranet', branchcode => $self->branch, register_id => $self->id, + payment_type => 'CASH', note => $reconciliation_note } )->store(); diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t index 1cb83f7e3f3..43c23a682a2 100755 --- a/t/db_dependent/Koha/Cash/Register.t +++ b/t/db_dependent/Koha/Cash/Register.t @@ -174,6 +174,9 @@ subtest 'cashup' => sub { $schema->storage->txn_begin; + # Ensure reconciliation notes are not required for these tests + t::lib::Mocks::mock_preference( 'CashupReconciliationNoteRequired', 0 ); + my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } ); my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -343,6 +346,9 @@ subtest 'cashup_reconciliation' => sub { $schema->storage->txn_begin; + # Ensure reconciliation notes are not required for these tests + t::lib::Mocks::mock_preference( 'CashupReconciliationNoteRequired', 0 ); + my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } ); my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -417,7 +423,7 @@ subtest 'cashup_reconciliation' => sub { }; subtest 'surplus_cashup' => sub { - plan tests => 8; + plan tests => 9; $schema->storage->txn_begin; @@ -466,7 +472,8 @@ subtest 'cashup_reconciliation' => sub { sprintf( '%.0f', $surplus_line->amount ), sprintf( '%.0f', -$surplus ), 'Surplus amount is correct (negative for credit)' ); - is( $surplus_line->branchcode, $register2->branch, 'Surplus branchcode matches register branch' ); + is( $surplus_line->branchcode, $register2->branch, 'Surplus branchcode matches register branch' ); + is( $surplus_line->payment_type, 'CASH', 'Surplus payment_type is set to CASH' ); # Note should be undef for surplus without user note is( $surplus_line->note, undef, 'No note for surplus without user reconciliation note' ); @@ -515,7 +522,7 @@ subtest 'cashup_reconciliation' => sub { }; subtest 'deficit_cashup' => sub { - plan tests => 8; + plan tests => 9; $schema->storage->txn_begin; @@ -564,7 +571,8 @@ subtest 'cashup_reconciliation' => sub { sprintf( '%.0f', $deficit_line->amount ), sprintf( '%.0f', $deficit ), 'Deficit amount is correct (positive for debit)' ); - is( $deficit_line->branchcode, $register3->branch, 'Deficit branchcode matches register branch' ); + is( $deficit_line->branchcode, $register3->branch, 'Deficit branchcode matches register branch' ); + is( $deficit_line->payment_type, 'CASH', 'Deficit payment_type is set to CASH' ); # Note should be undef for deficit without user note is( $deficit_line->note, undef, 'No note for deficit without user reconciliation note' ); -- 2.53.0