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

(-)a/Koha/Account.pm (-1 lines)
Lines 81-87 sub pay { Link Here
81
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
81
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
82
82
83
    my $userenv = C4::Context->userenv;
83
    my $userenv = C4::Context->userenv;
84
    $library_id ||= $userenv ? $userenv->{branch} : undef;
85
84
86
    my $patron = Koha::Patrons->find( $self->{patron_id} );
85
    my $patron = Koha::Patrons->find( $self->{patron_id} );
87
86
(-)a/t/db_dependent/Accounts.t (-1 / +1 lines)
Lines 292-298 subtest "Koha::Account::pay tests" => sub { Link Here
292
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
292
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
293
    $line3 = Koha::Account::Lines->find( $line3->id );
293
    $line3 = Koha::Account::Lines->find( $line3->id );
294
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
294
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
295
    is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' );
295
    is( $payment->branchcode, undef, 'branchcode passed, then undef' );
296
};
296
};
297
297
298
subtest "Koha::Account::pay particular line tests" => sub {
298
subtest "Koha::Account::pay particular line tests" => sub {
(-)a/t/db_dependent/Koha/Account.t (-2 / +28 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::MockModule;
23
24
24
use Koha::Account;
25
use Koha::Account;
25
use Koha::Account::Lines;
26
use Koha::Account::Lines;
Lines 396-398 subtest 'reconcile_balance' => sub { Link Here
396
        $schema->storage->txn_rollback;
397
        $schema->storage->txn_rollback;
397
    };
398
    };
398
};
399
};
399
- 
400
401
subtest 'pay() tests' => sub {
402
403
    plan tests => 2;
404
405
    $schema->storage->txn_begin;
406
407
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
408
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
409
    my $account = $patron->account;
410
411
    my $context = Test::MockModule->new('C4::Context');
412
    $context->mock( 'userenv', { branch => $library->id } );
413
414
    my $credit_1_id = $account->pay({ amount => 200 });
415
    my $credit_1    = Koha::Account::Lines->find( $credit_1_id );
416
417
    is( $credit_1->branchcode, undef, 'No branchcode is set if library_id was not passed' );
418
419
    my $credit_2_id = $account->pay({ amount => 150, library_id => $library->id });
420
    my $credit_2    = Koha::Account::Lines->find( $credit_2_id );
421
422
    is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
423
424
    $schema->storage->txn_rollback;
425
};

Return to bug 19066