From 56419590cb58bf8f2dd40460e33cde46cddbaa61 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 17 Oct 2023 13:40:09 -0300 Subject: [PATCH] Bug 30719: Rename `batch` for `ill_batch` in Koha::Illrequest Signed-off-by: Tomas Cohen Arazi --- Koha/Illrequest.pm | 14 +++--- Koha/Schema/Result/Illrequest.pm | 12 +++++ api/v1/swagger/definitions/ill_request.yaml | 2 +- api/v1/swagger/paths/ill_requests.yaml | 2 +- t/db_dependent/Koha/Illbatch.t | 49 +++++++++++++++++++++ 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100755 t/db_dependent/Koha/Illbatch.t diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 5059e8989d..aa5e16b8ba 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -147,18 +147,20 @@ sub push_processor { push @{$self->{processors}}, $processor; } -=head3 batch +=head3 ill_batch - my $batch = $request->batch; + my $ill_batch = $request->ill_batch; -Returns the batch associated with a request +Returns the I associated with the request =cut -sub batch { - my ( $self ) = @_; +sub ill_batch { + my ($self) = @_; - return Koha::Illbatches->find($self->_result->batch_id); + my $ill_batch = $self->_result->ill_batch; + return unless $ill_batch; + return Koha::Illbatch->_new_from_dbic($ill_batch); } =head3 statusalias diff --git a/Koha/Schema/Result/Illrequest.pm b/Koha/Schema/Result/Illrequest.pm index e1c29012bc..ccfbe880ee 100644 --- a/Koha/Schema/Result/Illrequest.pm +++ b/Koha/Schema/Result/Illrequest.pm @@ -408,6 +408,18 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->belongs_to( + "ill_batch", + "Koha::Schema::Result::Illbatch", + { ill_batch_id => "batch_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + __PACKAGE__->belongs_to( "library", "Koha::Schema::Result::Branch", diff --git a/api/v1/swagger/definitions/ill_request.yaml b/api/v1/swagger/definitions/ill_request.yaml index e25fc6f416..9c6459b915 100644 --- a/api/v1/swagger/definitions/ill_request.yaml +++ b/api/v1/swagger/definitions/ill_request.yaml @@ -120,7 +120,7 @@ properties: - array - "null" description: The linked extended ill request attributes (x-koha-embed) - batch: + ill_batch: type: - object - "null" diff --git a/api/v1/swagger/paths/ill_requests.yaml b/api/v1/swagger/paths/ill_requests.yaml index 3f7b82b75f..03d58ebdf9 100644 --- a/api/v1/swagger/paths/ill_requests.yaml +++ b/api/v1/swagger/paths/ill_requests.yaml @@ -27,7 +27,7 @@ - comments - comments+count - extended_attributes - - batch + - ill_batch - library - id_prefix - patron diff --git a/t/db_dependent/Koha/Illbatch.t b/t/db_dependent/Koha/Illbatch.t new file mode 100755 index 0000000000..c18b686386 --- /dev/null +++ b/t/db_dependent/Koha/Illbatch.t @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +# Copyright 2023 Koha Development team +# +# 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, see . + +use Modern::Perl; + +use Test::More tests => 1; + +use Koha::Database; + +use t::lib::TestBuilder; + +my $builder = t::lib::TestBuilder->new; +my $schema = Koha::Database->new->schema; + +subtest 'ill_batch() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $batch = $builder->build_object( { class => 'Koha::Illbatches' } ); + my $request = $builder->build_object( { class => 'Koha::Illrequests', value => { batch_id => undef } } ); + + is( $request->ill_batch, undef, 'Not having a linked batch makes the method return undef' ); + + $request->batch_id( $batch->id )->store; + + my $linked_batch = $request->ill_batch; + is( ref($linked_batch), 'Koha::Illbatch' ); + is( $linked_batch->id, $batch->id, 'Correct batch linked' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5