@@ -, +, @@ --- Koha/Library.pm | 12 ++++++++++++ t/db_dependent/Koha/Libraries.t | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) --- a/Koha/Library.pm +++ a/Koha/Library.pm @@ -77,6 +77,18 @@ sub library_groups { return Koha::Library::Groups->_new_from_dbic( $rs ); } +=head3 cash_registers + +Return Cash::Registers associated with this Library + +=cut + +sub cash_registers { + my ( $self ) = @_; + my $rs = $self->_result->cash_registers; + return Koha::Cash::Registers->_new_from_dbic( $rs ); +} + =head2 Internal methods =head3 _type --- a/t/db_dependent/Koha/Libraries.t +++ a/t/db_dependent/Koha/Libraries.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use C4::Biblio; use C4::Context; @@ -451,3 +451,38 @@ subtest '->get_effective_marcorgcode' => sub { $schema->storage->txn_rollback; }; + +subtest 'cash_registers' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $register1 = $builder->build_object( + { + class => 'Koha::Cash::Registers', + value => { branch => $library->branchcode }, + } + ); + my $register2 = $builder->build_object( + { + class => 'Koha::Cash::Registers', + value => { branch => $library->branchcode }, + } + ); + + my $registers = $library->cash_registers; + is( ref($registers), 'Koha::Cash::Registers', +'Koha::Library->cash_registers should return a set of Koha::Cash::Registers' + ); + is( $registers->count, 2, + 'Koha::Library->cash_registers should return the correct cash registers' + ); + + $register1->delete; + is( $library->cash_registers->next->id, $register2->id, + 'Koha::Library->cash_registers should return the correct cash registers' + ); + + $schema->storage->txn_rollback; +}; --