@@ -, +, @@ --- t/db_dependent/Koha/Account.t | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/Account.t +++ a/t/db_dependent/Koha/Account.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Account; use Koha::Account::Lines; @@ -192,3 +192,44 @@ subtest 'add_credit() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'accountlines branchcode' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my $account = $patron->account; + my $credit1 = $account->add_credit({ + amount => 13, + description => 'Payment of 13', + note => 'some note', + }); + my $line1 = Koha::Account::Lines->find( $credit1->id ); + is($line1->branchcode, undef, "No branchcode without userenv and no library set"); + + C4::Context->_new_userenv('my_session1'); + C4::Context->set_userenv(0,0,0,'firstname','surname', $library1->branchcode, $library1->branchname, '', '', ''); + my $credit2 = $account->add_credit({ + amount => 14, + description => 'Payment of 14', + note => 'some note', + }); + my $line2 = Koha::Account::Lines->find( $credit2->id ); + is($line2->branchcode, $library1->branchcode, "Branchcode should be taken from userenv"); + + my $line3 = Koha::Account::Line->new({ + amount => 15, + accounttype => 'Payment', + branchcode => $library2->branchcode, + borrowernumber => $patron->id, + })->store; + my $line3_from_db = Koha::Account::Lines->find( $line3->id ); + is($line3_from_db->branchcode, $library2->branchcode, "Branchcode should be set when creating line with branchcode"); + + $schema->storage->txn_rollback; +}; --