Bug 31692: Tidy and rebase fix

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2023-10-10 09:53:19 -03:00
parent 889853bc9d
commit a45e79c1f4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 57 additions and 43 deletions

View file

@ -866,21 +866,25 @@ a patron on a record to be alike.
sub change_type {
my ( $self, $itemnumber ) = @_;
my $record_holds_per_patron = Koha::Holds->search( {
borrowernumber => $self->borrowernumber,
biblionumber => $self->biblionumber,
} );
my $record_holds_per_patron = Koha::Holds->search(
{
borrowernumber => $self->borrowernumber,
biblionumber => $self->biblionumber,
}
);
if ( $itemnumber && $self->itemnumber ) {
$self->itemnumber( $itemnumber )->store;
$self->itemnumber($itemnumber)->store;
return $self;
}
if ( $record_holds_per_patron->count == 1 ) {
$self->set({
itemnumber => $itemnumber ? $itemnumber : undef,
item_level_hold => $itemnumber ? 1 : 0,
})->store;
$self->set(
{
itemnumber => $itemnumber ? $itemnumber : undef,
item_level_hold => $itemnumber ? 1 : 0,
}
)->store;
} else {
Koha::Exceptions::Hold::CannotChangeHoldType->throw();
}

View file

@ -96,13 +96,13 @@ else {
try {
$hold->change_type;
} catch {
if ($_->isa('Koha::Exceptions::Hold::CannotChangeHoldType')){
if ( $_->isa('Koha::Exceptions::Hold::CannotChangeHoldType') ) {
warn $_;
} else {
$_->rethrow;
}
}
};
}
}
my @biblio_ids = uniq @biblionumber;
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(

View file

@ -579,13 +579,17 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
$template->param( always_show_holds => $always_show_holds );
my $show_holds_now = $input->param('show_holds_now');
unless( (defined $always_show_holds && $always_show_holds eq 'DONT') && !$show_holds_now ){
my $holds_count_per_patron = { map { $_->{borrowernumber} => $_->{hold_count} }
@{ Koha::Holds->search( { biblionumber=> $biblionumber }, {
select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ],
as => [ qw( borrowernumber hold_count ) ],
group_by => [ qw( borrowernumber ) ] }
)->unblessed
} };
my $holds_count_per_patron = {
map { $_->{borrowernumber} => $_->{hold_count} } @{ Koha::Holds->search(
{ biblionumber => $biblionumber },
{
select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ],
as => [qw( borrowernumber hold_count )],
group_by => [qw( borrowernumber )]
}
)->unblessed
}
};
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list;
foreach my $res (
sort {

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 12;
use Test::More tests => 13;
use Test::Exception;
use Test::MockModule;
@ -998,33 +998,37 @@ subtest 'Koha::Hold::item_group tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'change_type tests' => sub {
subtest 'change_type() tests' => sub {
plan tests => 13;
$schema->storage->txn_begin;
my $item = $builder->build_object( { class => 'Koha::Items', } );
my $hold = $builder->build_object( {
class => 'Koha::Holds',
value => {
itemnumber => undef,
item_level_hold => 0,
my $hold = $builder->build_object(
{
class => 'Koha::Holds',
value => {
itemnumber => undef,
item_level_hold => 0,
}
}
} );
);
my $hold2 = $builder->build_object( {
class => 'Koha::Holds',
value => {
borrowernumber => $hold->borrowernumber,
my $hold2 = $builder->build_object(
{
class => 'Koha::Holds',
value => {
borrowernumber => $hold->borrowernumber,
}
}
} );
);
ok( $hold->change_type );
$hold->discard_changes;
is( $hold->itemnumber, undef, 'record hold to record hold, no changes');
is( $hold->itemnumber, undef, 'record hold to record hold, no changes' );
is( $hold->item_level_hold, 0, 'item_level_hold=0' );
@ -1032,7 +1036,7 @@ subtest 'change_type tests' => sub {
$hold->discard_changes;
is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold');
is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold' );
is( $hold->item_level_hold, 1, 'item_level_hold=1' );
@ -1040,7 +1044,7 @@ subtest 'change_type tests' => sub {
$hold->discard_changes;
is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes');
is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes' );
is( $hold->item_level_hold, 1, 'item_level_hold=1' );
@ -1048,21 +1052,23 @@ subtest 'change_type tests' => sub {
$hold->discard_changes;
is( $hold->itemnumber, undef, 'item hold to record hold');
is( $hold->itemnumber, undef, 'item hold to record hold' );
is( $hold->item_level_hold, 0, 'item_level_hold=0' );
my $hold3 = $builder->build_object( {
class => 'Koha::Holds',
value => {
biblionumber => $hold->biblionumber,
borrowernumber => $hold->borrowernumber,
my $hold3 = $builder->build_object(
{
class => 'Koha::Holds',
value => {
biblionumber => $hold->biblionumber,
borrowernumber => $hold->borrowernumber,
}
}
} );
);
throws_ok { $hold->change_type }
'Koha::Exceptions::Hold::CannotChangeHoldType',
'Exception thrown because more than one hold per record';
'Koha::Exceptions::Hold::CannotChangeHoldType',
'Exception thrown because more than one hold per record';
$schema->storage->txn_rollback;
};