Bugzilla – Attachment 189340 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.70 KB, created by
Martin Renvoize (ashimema)
on 2025-11-07 14:44:15 UTC
(
hide
)
Description:
Bug 40445: Use centralized exception handling in Cash Register methods
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-11-07 14:44:15 UTC
Size:
4.70 KB
patch
obsolete
>From 75ca0c240c572658b068e1c6d870c19c77d9242e 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 | 49 +++++++++++++++++++---------- > t/db_dependent/Koha/Cash/Register.t | 13 +++++--- > 2 files changed, 40 insertions(+), 22 deletions(-) > >diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm >index b54f9712143..11e73d8af25 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,16 +392,26 @@ 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 >- } >- )->discard_changes; >- >- $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs); >+ try { >+ # 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; >+ } >+ ); >+ >+ $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs); >+ } catch { >+ >+ # Propagate any exception (already translated by safe_do if needed) >+ $_->rethrow(); >+ }; > > # Create reconciliation accountline if there's a difference > if ( $difference != 0 ) { >diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t >index 64618dfdc8b..078cb70ca7f 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.1
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
|
189333
|
189334
|
189335
|
189336
|
189337
|
189338
|
189339
|
189340
|
189341
|
189353
|
189354
|
189355
|
189356
|
189357
|
189358
|
189359
|
189360
|
189361
|
189362
|
189363
|
189364
|
189410
|
189411
|
189412
|
189413
|
189414
|
189415
|
189420
|
189421
|
189422
|
189423
|
189424
|
189425
|
189426
|
189427
|
189428
|
189429
|
189430
|
189476
|
189477
|
189478
|
189479
|
189480
|
189481
|
189482