Browse Source

Bug 24254: Compare itemlost with 0

On C4::Search and C4::Circulation the uses of the items.itemlost field
highlight the fact that the comparisson itemlost <= 0 was wrong, as it
is evaluated as a Perl boolean.

The column can only be an int and NOT NULL, so we need to check if it is
0 to ponder if not hidden.

This patch changes the tests to reflect this, and adjust the
Koha::Items->filter_by_visible_in_opac implementation to adapt to this.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Items.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomás Cohen Arazi 3 years ago
committed by Jonathan Druart
parent
commit
a592ebb3bb
  1. 17
      Koha/Items.pm
  2. 14
      t/db_dependent/Koha/Items.t

17
Koha/Items.pm

@ -65,14 +65,25 @@ sub filter_by_visible_in_opac {
my $rules = $params->{rules} // {};
my $search_params;
my $rules_params;
foreach my $field (keys %$rules){
$search_params->{$field}->{'-not_in'} = $rules->{$field};
$rules_params->{$field}->{'-not_in'} = $rules->{$field};
}
$search_params->{itemlost}->{'<='} = 0
my $itemlost_params;
$itemlost_params = { itemlost => 0 }
if C4::Context->preference('hidelostitems');
my $search_params;
if ( $rules_params and $itemlost_params ) {
$search_params = {
'-and' => [ $rules_params, $itemlost_params ]
};
}
else {
$search_params = $rules_params // $itemlost_params;
}
return $self->search( $search_params );
}

14
t/db_dependent/Koha/Items.t

@ -1366,7 +1366,15 @@ subtest 'filter_by_visible_in_opac() tests' => sub {
my $item_5 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
itemlost => undef,
itemlost => 0,
itype => $itype_1->itemtype,
withdrawn => 5
}
);
my $item_6 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
itemlost => 2,
itype => $itype_1->itemtype,
withdrawn => 5
}
@ -1376,12 +1384,12 @@ subtest 'filter_by_visible_in_opac() tests' => sub {
t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
is( $biblio->items->filter_by_visible_in_opac->count,
5, 'No rules passed, hidelostitems unset' );
6, 'No rules passed, hidelostitems unset' );
t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
is(
$biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
4,
3,
'No rules passed, hidelostitems set'
);

Loading…
Cancel
Save