From 26f20d64cb6336b4911f91befa736539946a0a0c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Aug 2016 10:48:36 +0100 Subject: [PATCH] Bug 17069: Koha::Patron::Category->store must default checkprevcheckout to 'inherit' 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 Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- Koha/Patron/Category.pm | 7 +++++++ t/db_dependent/Koha/Patron/Categories.t | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index 7b17c8c084..06012ec90b 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -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(); diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index 974b982559..df0327cc82 100644 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -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' ); -- 2.39.5