Bugzilla – Attachment 186643 Details for
Bug 40445
Point of Sale reconciliation input during daily summaries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40445: Use centralized exception handling in Cash Register methods
Bug-40445-Use-centralized-exception-handling-in-Ca.patch (text/plain), 4.28 KB, created by
Martin Renvoize (ashimema)
on 2025-09-21 11:55:10 UTC
(
hide
)
Description:
Bug 40445: Use centralized exception handling in Cash Register methods
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-09-21 11:55:10 UTC
Size:
4.28 KB
patch
obsolete
>From bd2b530aeed74d0fec1fb4490b82d2046699f470 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Sun, 21 Sep 2025 12:42:50 +0100 >Subject: [PATCH] Bug 40445: Use centralized exception handling in Cash > Register methods > >Update start_cashup and add_cashup methods to use the new centralized >exception translation system instead of letting raw DBIx::Class exceptions >bubble up. This provides consistent Koha-specific exceptions across the API. > >Also update the corresponding unit tests to expect proper >Koha::Exceptions::Object::FKConstraint exceptions instead of generic errors >when invalid manager_id values are provided. >--- > Koha/Cash/Register.pm | 37 ++++++++++++++++++----------- > t/db_dependent/Koha/Cash/Register.t | 13 ++++++---- > 2 files changed, 31 insertions(+), 19 deletions(-) > >diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm >index 293021b0ef9..6651bedaf39 100644 >--- a/Koha/Cash/Register.pm >+++ b/Koha/Cash/Register.pm >@@ -291,14 +291,19 @@ sub start_cashup { > > my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) ); > >- # Create the CASHUP_START action >- my $rs = $self->_result->add_to_cash_register_actions( >- { >- code => 'CASHUP_START', >- manager_id => $manager_id, >- amount => $expected_amount >+ # Create the CASHUP_START action using centralized exception handling >+ my $schema = $self->_result->result_source->schema; >+ my $rs = $schema->safe_do( >+ sub { >+ return $self->_result->add_to_cash_register_actions( >+ { >+ code => 'CASHUP_START', >+ manager_id => $manager_id, >+ amount => $expected_amount >+ } >+ )->discard_changes; > } >- )->discard_changes; >+ ); > > return Koha::Cash::Register::Cashup->_new_from_dbic($rs); > } >@@ -387,14 +392,18 @@ sub add_cashup { > > $schema->txn_do( > sub { >- # Create the cashup action with actual amount >- my $rs = $self->_result->add_to_cash_register_actions( >- { >- code => 'CASHUP', >- manager_id => $manager_id, >- amount => $amount >+ # Create the cashup action with actual amount using centralized exception handling >+ my $rs = $schema->safe_do( >+ sub { >+ return $self->_result->add_to_cash_register_actions( >+ { >+ code => 'CASHUP', >+ manager_id => $manager_id, >+ amount => $amount >+ } >+ )->discard_changes; > } >- )->discard_changes; >+ ); > > $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs); > >diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t >index e227fb9777c..0b9fd35717f 100755 >--- a/t/db_dependent/Koha/Cash/Register.t >+++ b/t/db_dependent/Koha/Cash/Register.t >@@ -1071,8 +1071,10 @@ subtest 'start_cashup_parameter_validation' => sub { > > my $register3 = $builder->build_object( { class => 'Koha::Cash::Registers' } ); > >- eval { $register3->start_cashup( { manager_id => 99999999 } ); }; >- ok( $@, 'start_cashup fails with invalid manager_id' ); >+ throws_ok { >+ $register3->start_cashup( { manager_id => 99999999 } ); >+ } >+ 'Koha::Exceptions::Object::FKConstraint', 'start_cashup throws FK constraint exception with invalid manager_id'; > }; > > # Test 4: Duplicate start_cashup prevention >@@ -1377,9 +1379,10 @@ subtest 'add_cashup' => sub { > > my $register9 = $builder->build_object( { class => 'Koha::Cash::Registers' } ); > >- eval { $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } ); }; >- ok( $@, 'add_cashup fails with invalid manager_id' ); >- diag($@); >+ throws_ok { >+ $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } ); >+ } >+ 'Koha::Exceptions::Object::FKConstraint', 'add_cashup throws FK constraint exception with invalid manager_id'; > }; > > $schema->storage->txn_rollback; >-- >2.51.0
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 40445
:
185289
|
185290
|
185291
|
185292
|
185809
|
186636
|
186637
|
186638
|
186639
|
186640
|
186641
|
186642
| 186643