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

(-)a/Koha/Cash/Register.pm (-14 / +23 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-400 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
            # Create the cashup action with actual amount using centralized exception handling
391
            my $rs = $self->_result->add_to_cash_register_actions(
396
            my $rs = $schema->safe_do(
392
                {
397
                sub {
393
                    code       => 'CASHUP',
398
                    return $self->_result->add_to_cash_register_actions(
394
                    manager_id => $manager_id,
399
                        {
395
                    amount     => $amount
400
                            code       => 'CASHUP',
401
                            manager_id => $manager_id,
402
                            amount     => $amount
403
                        }
404
                    )->discard_changes;
396
                }
405
                }
397
            )->discard_changes;
406
            );
398
407
399
            $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
408
            $cashup = Koha::Cash::Register::Cashup->_new_from_dbic($rs);
400
409
(-)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