From 84e2d7fe98aaab47a7c5e0d44fddf94e3ca6b78f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 13 Feb 2026 17:12:02 +0000 Subject: [PATCH] Bug 40445: (follow-up) Set branchcode for CASHUP_SURPLUS and CASHUP_DEFICIT accountlines When creating CASHUP_SURPLUS and CASHUP_DEFICIT accountlines during cashup reconciliation, the branchcode was not being set. This resulted in accountlines with NULL branchcode values, which violates the expectation that all accountlines should have an associated branch. This patch: - Sets branchcode from the cash register's branch for both CASHUP_SURPLUS and CASHUP_DEFICIT accountlines - Adds test coverage to verify branchcode is correctly set Test plan: 1. Apply patch 2. Run prove t/db_dependent/Koha/Cash/Register.t 3. Verify all tests pass, including new branchcode checks 4. In the staff interface, perform a cashup with a surplus or deficit 5. Verify the created accountline has the correct branchcode matching the cash register's branch Signed-off-by: Jackie Usher --- Koha/Cash/Register.pm | 2 ++ t/db_dependent/Koha/Cash/Register.t | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm index aa9168b541e..1a02f23aa9b 100644 --- a/Koha/Cash/Register.pm +++ b/Koha/Cash/Register.pm @@ -453,6 +453,7 @@ sub add_cashup { credit_type_code => 'CASHUP_SURPLUS', manager_id => $manager_id, interface => 'intranet', + branchcode => $self->branch, register_id => $self->id, note => $reconciliation_note } @@ -477,6 +478,7 @@ sub add_cashup { debit_type_code => 'CASHUP_DEFICIT', manager_id => $manager_id, interface => 'intranet', + branchcode => $self->branch, register_id => $self->id, note => $reconciliation_note } diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t index 99684617a6e..1cb83f7e3f3 100755 --- a/t/db_dependent/Koha/Cash/Register.t +++ b/t/db_dependent/Koha/Cash/Register.t @@ -417,7 +417,7 @@ subtest 'cashup_reconciliation' => sub { }; subtest 'surplus_cashup' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -466,6 +466,7 @@ 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' ); # Note should be undef for surplus without user note is( $surplus_line->note, undef, 'No note for surplus without user reconciliation note' ); @@ -514,7 +515,7 @@ subtest 'cashup_reconciliation' => sub { }; subtest 'deficit_cashup' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -563,6 +564,7 @@ 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' ); # Note should be undef for deficit without user note is( $deficit_line->note, undef, 'No note for deficit without user reconciliation note' ); @@ -894,7 +896,7 @@ subtest 'two_phase_cashup_workflow' => sub { # Test 9: outstanding_accountlines now includes new transaction $outstanding = $register->outstanding_accountlines; - is( $outstanding->count, 1, 'outstanding_accountlines includes transaction after completion' ); + is( $outstanding->count, 1, 'outstanding_accountlines includes transaction after completion' ); is( $outstanding->total, -8.00, 'outstanding_accountlines total is correct after completion' ); $schema->storage->txn_rollback; -- 2.53.0