View | Details | Raw Unified | Return to bug 40445
Collapse All | Expand All

(-)a/Koha/Cash/Register.pm (-17 / +32 lines)
Lines 291-304 sub start_cashup { Link Here
291
291
292
    my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) );
292
    my $expected_amount = abs( $self->outstanding_accountlines->total( { payment_type => [ 'CASH', 'SIP00' ] } ) );
293
293
294
    # Create the CASHUP_START action
294
    # Create the CASHUP_START action using centralized exception handling
295
    my $rs = $self->_result->add_to_cash_register_actions(
295
    my $schema = $self->_result->result_source->schema;
296
        {
296
    my $rs     = $schema->safe_do(
297
            code       => 'CASHUP_START',
297
        sub {
298
            manager_id => $manager_id,
298
            return $self->_result->add_to_cash_register_actions(
299
            amount     => $expected_amount
299
                {
300
                    code       => 'CASHUP_START',
301
                    manager_id => $manager_id,
302
                    amount     => $expected_amount
303
                }
304
            )->discard_changes;
300
        }
305
        }
301
    )->discard_changes;
306
    );
302
307
303
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
308
    return Koha::Cash::Register::Cashup->_new_from_dbic($rs);
304
}
309
}
Lines 387-402 sub add_cashup { Link Here
387
392
388
    $schema->txn_do(
393
    $schema->txn_do(
389
        sub {
394
        sub {
390
            # Create the cashup action with actual amount
395
            try {
391
            my $rs = $self->_result->add_to_cash_register_actions(
396
                # Create the cashup action with actual amount using centralized exception handling
392
                {
397
                my $rs = $schema->safe_do(
393
                    code       => 'CASHUP',
398
                    sub {
394
                    manager_id => $manager_id,
399
                        return $self->_result->add_to_cash_register_actions(
395
                    amount     => $amount
400
                            {
396
                }
401
                                code       => 'CASHUP',
397
            )->discard_changes;
402
                                manager_id => $manager_id,
398
403
                                amount     => $amount
399
            $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
404
                            }
405
                        )->discard_changes;
406
                    }
407
                );
408
409
                $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
410
            } catch {
411
412
                # Propagate any exception (already translated by safe_do if needed)
413
                $_->rethrow();
414
            };
400
415
401
            # Create reconciliation accountline if there's a difference
416
            # Create reconciliation accountline if there's a difference
402
            if ( $difference != 0 ) {
417
            if ( $difference != 0 ) {
(-)a/t/db_dependent/Koha/Cash/Register.t (-6 / +8 lines)
Lines 1071-1078 subtest 'start_cashup_parameter_validation' => sub { Link Here
1071
1071
1072
        my $register3 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1072
        my $register3 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1073
1073
1074
        eval { $register3->start_cashup( { manager_id => 99999999 } ); };
1074
        throws_ok {
1075
        ok( $@, 'start_cashup fails with invalid manager_id' );
1075
            $register3->start_cashup( { manager_id => 99999999 } );
1076
        }
1077
        'Koha::Exceptions::Object::FKConstraint', 'start_cashup throws FK constraint exception with invalid manager_id';
1076
    };
1078
    };
1077
1079
1078
    # Test 4: Duplicate start_cashup prevention
1080
    # Test 4: Duplicate start_cashup prevention
Lines 1377-1385 subtest 'add_cashup' => sub { Link Here
1377
1379
1378
        my $register9 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1380
        my $register9 = $builder->build_object( { class => 'Koha::Cash::Registers' } );
1379
1381
1380
        eval { $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } ); };
1382
        throws_ok {
1381
        ok( $@, 'add_cashup fails with invalid manager_id' );
1383
            $register9->add_cashup( { manager_id => 99999999, amount => '10.00' } );
1382
        diag($@);
1384
        }
1385
        'Koha::Exceptions::Object::FKConstraint', 'add_cashup throws FK constraint exception with invalid manager_id';
1383
    };
1386
    };
1384
1387
1385
    $schema->storage->txn_rollback;
1388
    $schema->storage->txn_rollback;
1386
- 

Return to bug 40445