Bug 30719: Rename `batch` for `ill_batch` in Koha::Illrequest

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2023-10-17 13:40:09 -03:00
parent e6de47e9ec
commit 56419590cb
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
5 changed files with 71 additions and 8 deletions

View File

@ -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<Koha::Illbatch> 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

View File

@ -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",

View File

@ -120,7 +120,7 @@ properties:
- array
- "null"
description: The linked extended ill request attributes (x-koha-embed)
batch:
ill_batch:
type:
- object
- "null"

View File

@ -27,7 +27,7 @@
- comments
- comments+count
- extended_attributes
- batch
- ill_batch
- library
- id_prefix
- patron

49
t/db_dependent/Koha/Illbatch.t Executable file
View File

@ -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 <http://www.gnu.org/licenses>.
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;
};