From c267716e6bdbe6858a78380b49cccf5f81e1ed4c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 May 2018 13:32:47 -0300 Subject: [PATCH] Bug 20366: Add new method Koha::Acquisition::Basket->basket_group Can be moved to a separate bug report. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Josef Moravec Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- Koha/Acquisition/Basket.pm | 13 +++++++ Koha/Acquisition/BasketGroup.pm | 44 +++++++++++++++++++++ Koha/Acquisition/BasketGroups.pm | 49 ++++++++++++++++++++++++ t/db_dependent/Koha/Acquisition/Basket.t | 33 +++++++++++++++- 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Koha/Acquisition/BasketGroup.pm create mode 100644 Koha/Acquisition/BasketGroups.pm diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 98e4bd45b5..d5e6b8ccb1 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -20,6 +20,7 @@ package Koha::Acquisition::Basket; use Modern::Perl; use Koha::Database; +use Koha::Acquisition::BasketGroups; use base qw( Koha::Object ); @@ -45,6 +46,18 @@ sub bookseller { return Koha::Acquisition::Bookseller->_new_from_dbic( $bookseller_rs ); } +=head3 basket_group + +Returns the basket group associated to this basket + +=cut + +sub basket_group { + my ($self) = @_; + my $basket_group_rs = $self->_result->basketgroupid; + return unless $basket_group_rs; + return Koha::Acquisition::BasketGroup->_new_from_dbic( $basket_group_rs ); +} =head3 effective_create_items diff --git a/Koha/Acquisition/BasketGroup.pm b/Koha/Acquisition/BasketGroup.pm new file mode 100644 index 0000000000..a63d8299c4 --- /dev/null +++ b/Koha/Acquisition/BasketGroup.pm @@ -0,0 +1,44 @@ +package Koha::Acquisition::BasketGroup; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw( Koha::Object ); + +=head1 NAME + +Koha::Acquisition::BasketGroup - Koha Basket group Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'Aqbasketgroup'; +} + +1; diff --git a/Koha/Acquisition/BasketGroups.pm b/Koha/Acquisition/BasketGroups.pm new file mode 100644 index 0000000000..186c5fbd74 --- /dev/null +++ b/Koha/Acquisition/BasketGroups.pm @@ -0,0 +1,49 @@ +package Koha::Acquisition::BasketGroups; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Acquisition::BasketGroup; + +use base qw( Koha::Objects ); + +=head1 NAME + +Koha::Acquisition::BasketGroups - Koha Basket groups object set class + +=head1 API + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'Aqbasketgroup'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Acquisition::BasketGroup'; +} + +1; diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t index 8965c891b0..e262e2d1f2 100644 --- a/t/db_dependent/Koha/Acquisition/Basket.t +++ b/t/db_dependent/Koha/Acquisition/Basket.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright 2017 Koha Development team +# Copyright 2018 Koha Development team # # This file is part of Koha # @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use t::lib::TestBuilder; use t::lib::Mocks; @@ -78,3 +78,32 @@ subtest 'create_items + effective_create_items tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'basket_group' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + my $b = $builder->build_object( + { + class => 'Koha::Acquisition::Baskets', + value => { basketgroupid => undef }, # not linked to a basketgroupid + } + ); + + my $basket = Koha::Acquisition::Baskets->find( $b->basketno ); + is( $basket->basket_group, undef, + '->basket_group should return undef if not linked to a basket group'); + + $b = $builder->build_object( + { + class => 'Koha::Acquisition::Baskets', + # Will be linked to a basket group by TestBuilder + } + ); + + $basket = Koha::Acquisition::Baskets->find( $b->basketno ); + is( ref( $basket->basket_group ), 'Koha::Acquisition::BasketGroup', + '->basket_group should return a Koha::Acquisition::BasketGroup object if linked to a basket group'); + + $schema->storage->txn_rollback; +}; -- 2.39.5