Bug 17069: Koha::Patron::Category->store must default checkprevcheckout to 'inherit'
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 8 Aug 2016 09:48:36 +0000 (10:48 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 10 Aug 2016 13:12:34 +0000 (13:12 +0000)
Creating a new patron category raises an error "An error occurred when updating
this patron category. Perhaps it already exists."
DBIx::Class does not default to the value defined at the DB devel if the
key checkprevcheckout has been passed to the constructor.
We may need to provide a global fix for this kind of issue: if a column
is defined as "not null" but has a default value, the constructor
(Koha::Object->new) should not pass it to the DBIx::Class constructor
(even if assuming that null means default is a terrible mysqlism).

Test plan:
Create a new patron category.

Works as expected.
Signed-off-by: Marc <veron@veron.ch>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/Patron/Category.pm
t/db_dependent/Koha/Patron/Categories.t

index 7b17c8c..06012ec 100644 (file)
@@ -35,6 +35,13 @@ Koha::Patron;;Category - Koha Patron;;Category Object class
 
 =cut
 
+sub store {
+    my ( $self ) = @_;
+    $self->checkprevcheckout('inherit')
+        unless defined $self->checkprevcheckout;
+    return $self->SUPER::store;
+}
+
 =head3 default_messaging
 
 my $messaging = $category->default_messaging();
index 974b982..df0327c 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 5;
+use Test::More tests => 7;
 
 use Koha::Database;
 use Koha::Patron::Category;
@@ -40,6 +40,7 @@ $new_category_1->add_branch_limitation( $branch->{branchcode} );
 my $new_category_2 = Koha::Patron::Category->new({
     categorycode => 'mycatcodeY',
     description  => 'mycatdescY',
+    checkprevcheckout => undef,
 })->store;
 
 is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'The 2 patron categories should have been added' );
@@ -49,6 +50,10 @@ is( $retrieved_category_1->categorycode, $new_category_1->categorycode, 'Find a
 is_deeply( $retrieved_category_1->branch_limitations, [ $branch->{branchcode} ], 'The branch limitation should have been stored and retrieved' );
 is_deeply( $retrieved_category_1->default_messaging, [], 'By default there is not messaging option' );
 
+my $retrieved_category_2 = Koha::Patron::Categories->find( $new_category_2->categorycode );
+is( $retrieved_category_1->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' );
+is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' );
+
 $retrieved_category_1->delete;
 is( Koha::Patron::Categories->search->count, $nb_of_categories + 1, 'Delete should have deleted the patron category' );