Bug 31692: Tidy and rebase fix
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
889853bc9d
commit
a45e79c1f4
4 changed files with 57 additions and 43 deletions
22
Koha/Hold.pm
22
Koha/Hold.pm
|
@ -866,21 +866,25 @@ a patron on a record to be alike.
|
||||||
sub change_type {
|
sub change_type {
|
||||||
my ( $self, $itemnumber ) = @_;
|
my ( $self, $itemnumber ) = @_;
|
||||||
|
|
||||||
my $record_holds_per_patron = Koha::Holds->search( {
|
my $record_holds_per_patron = Koha::Holds->search(
|
||||||
borrowernumber => $self->borrowernumber,
|
{
|
||||||
biblionumber => $self->biblionumber,
|
borrowernumber => $self->borrowernumber,
|
||||||
} );
|
biblionumber => $self->biblionumber,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if ( $itemnumber && $self->itemnumber ) {
|
if ( $itemnumber && $self->itemnumber ) {
|
||||||
$self->itemnumber( $itemnumber )->store;
|
$self->itemnumber($itemnumber)->store;
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $record_holds_per_patron->count == 1 ) {
|
if ( $record_holds_per_patron->count == 1 ) {
|
||||||
$self->set({
|
$self->set(
|
||||||
itemnumber => $itemnumber ? $itemnumber : undef,
|
{
|
||||||
item_level_hold => $itemnumber ? 1 : 0,
|
itemnumber => $itemnumber ? $itemnumber : undef,
|
||||||
})->store;
|
item_level_hold => $itemnumber ? 1 : 0,
|
||||||
|
}
|
||||||
|
)->store;
|
||||||
} else {
|
} else {
|
||||||
Koha::Exceptions::Hold::CannotChangeHoldType->throw();
|
Koha::Exceptions::Hold::CannotChangeHoldType->throw();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,13 +96,13 @@ else {
|
||||||
try {
|
try {
|
||||||
$hold->change_type;
|
$hold->change_type;
|
||||||
} catch {
|
} catch {
|
||||||
if ($_->isa('Koha::Exceptions::Hold::CannotChangeHoldType')){
|
if ( $_->isa('Koha::Exceptions::Hold::CannotChangeHoldType') ) {
|
||||||
warn $_;
|
warn $_;
|
||||||
} else {
|
} else {
|
||||||
$_->rethrow;
|
$_->rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
my @biblio_ids = uniq @biblionumber;
|
my @biblio_ids = uniq @biblionumber;
|
||||||
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
|
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
|
||||||
|
|
|
@ -579,13 +579,17 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
|
||||||
$template->param( always_show_holds => $always_show_holds );
|
$template->param( always_show_holds => $always_show_holds );
|
||||||
my $show_holds_now = $input->param('show_holds_now');
|
my $show_holds_now = $input->param('show_holds_now');
|
||||||
unless( (defined $always_show_holds && $always_show_holds eq 'DONT') && !$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} }
|
my $holds_count_per_patron = {
|
||||||
@{ Koha::Holds->search( { biblionumber=> $biblionumber }, {
|
map { $_->{borrowernumber} => $_->{hold_count} } @{ Koha::Holds->search(
|
||||||
select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ],
|
{ biblionumber => $biblionumber },
|
||||||
as => [ qw( borrowernumber hold_count ) ],
|
{
|
||||||
group_by => [ qw( borrowernumber ) ] }
|
select => [ "borrowernumber", { count => { distinct => "reserve_id" } } ],
|
||||||
)->unblessed
|
as => [qw( borrowernumber hold_count )],
|
||||||
} };
|
group_by => [qw( borrowernumber )]
|
||||||
|
}
|
||||||
|
)->unblessed
|
||||||
|
}
|
||||||
|
};
|
||||||
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list;
|
my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list;
|
||||||
foreach my $res (
|
foreach my $res (
|
||||||
sort {
|
sort {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
|
|
||||||
use Test::More tests => 12;
|
use Test::More tests => 13;
|
||||||
|
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
use Test::MockModule;
|
use Test::MockModule;
|
||||||
|
@ -998,33 +998,37 @@ subtest 'Koha::Hold::item_group tests' => sub {
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'change_type tests' => sub {
|
subtest 'change_type() tests' => sub {
|
||||||
|
|
||||||
plan tests => 13;
|
plan tests => 13;
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
my $item = $builder->build_object( { class => 'Koha::Items', } );
|
my $item = $builder->build_object( { class => 'Koha::Items', } );
|
||||||
my $hold = $builder->build_object( {
|
my $hold = $builder->build_object(
|
||||||
class => 'Koha::Holds',
|
{
|
||||||
value => {
|
class => 'Koha::Holds',
|
||||||
itemnumber => undef,
|
value => {
|
||||||
item_level_hold => 0,
|
itemnumber => undef,
|
||||||
|
item_level_hold => 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
);
|
||||||
|
|
||||||
my $hold2 = $builder->build_object( {
|
my $hold2 = $builder->build_object(
|
||||||
class => 'Koha::Holds',
|
{
|
||||||
value => {
|
class => 'Koha::Holds',
|
||||||
borrowernumber => $hold->borrowernumber,
|
value => {
|
||||||
|
borrowernumber => $hold->borrowernumber,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
);
|
||||||
|
|
||||||
ok( $hold->change_type );
|
ok( $hold->change_type );
|
||||||
|
|
||||||
$hold->discard_changes;
|
$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' );
|
is( $hold->item_level_hold, 0, 'item_level_hold=0' );
|
||||||
|
|
||||||
|
@ -1032,7 +1036,7 @@ subtest 'change_type tests' => sub {
|
||||||
|
|
||||||
$hold->discard_changes;
|
$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' );
|
is( $hold->item_level_hold, 1, 'item_level_hold=1' );
|
||||||
|
|
||||||
|
@ -1040,7 +1044,7 @@ subtest 'change_type tests' => sub {
|
||||||
|
|
||||||
$hold->discard_changes;
|
$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' );
|
is( $hold->item_level_hold, 1, 'item_level_hold=1' );
|
||||||
|
|
||||||
|
@ -1048,21 +1052,23 @@ subtest 'change_type tests' => sub {
|
||||||
|
|
||||||
$hold->discard_changes;
|
$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' );
|
is( $hold->item_level_hold, 0, 'item_level_hold=0' );
|
||||||
|
|
||||||
my $hold3 = $builder->build_object( {
|
my $hold3 = $builder->build_object(
|
||||||
class => 'Koha::Holds',
|
{
|
||||||
value => {
|
class => 'Koha::Holds',
|
||||||
biblionumber => $hold->biblionumber,
|
value => {
|
||||||
borrowernumber => $hold->borrowernumber,
|
biblionumber => $hold->biblionumber,
|
||||||
|
borrowernumber => $hold->borrowernumber,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
);
|
||||||
|
|
||||||
throws_ok { $hold->change_type }
|
throws_ok { $hold->change_type }
|
||||||
'Koha::Exceptions::Hold::CannotChangeHoldType',
|
'Koha::Exceptions::Hold::CannotChangeHoldType',
|
||||||
'Exception thrown because more than one hold per record';
|
'Exception thrown because more than one hold per record';
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue