Bug 33608: (QA follow-up) Restore older gt zero tests

See the Bugzilla report. I have been asked to restore the former
tests although I definitely think that they are wrong. Will address
that on bug 34308 separately.

This currently has the side-effect of negative lost values being
interpreted as 'found'. (Do not use negative lost values!)
The added subtest still reflects that now. Added a few TODOs.

Test plan:
[1] Prove t/db_dependent/Koha/Items.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2023-07-20 06:04:46 +00:00 committed by Tomas Cohen Arazi
parent 043f358878
commit 9aa95001d4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 34 additions and 6 deletions

View file

@ -131,8 +131,9 @@ sub store {
$self->cn_sort($cn_sort);
}
if( $self->itemlost ) {
$self->_add_statistic('item_lost'); # should be quite rare when adding item
# should be quite rare when adding item
if ( $self->itemlost && $self->itemlost > 0 ) { # TODO BZ34308
$self->_add_statistic('item_lost');
}
} else { # ModItem
@ -190,10 +191,20 @@ sub store {
$self->permanent_location( $self->location );
}
if( exists $updated_columns{itemlost} && !$updated_columns{itemlost} && $pre_mod_item->itemlost ) { # item found again
$self->_set_found_trigger($pre_mod_item); # reverse any list item charges if necessary
# TODO BZ 34308 (gt zero checks)
if ( exists $updated_columns{itemlost}
&& ( !$updated_columns{itemlost} || $updated_columns{itemlost} <= 0 )
&& ( $pre_mod_item->itemlost && $pre_mod_item->itemlost > 0 ) )
{
# item found
# reverse any list item charges if necessary
$self->_set_found_trigger($pre_mod_item);
$self->_add_statistic('item_found');
} elsif( exists $updated_columns{itemlost} && $updated_columns{itemlost} && !$pre_mod_item->itemlost ) { # item lost
} elsif ( exists $updated_columns{itemlost}
&& ( $updated_columns{itemlost} && $updated_columns{itemlost} > 0 )
&& ( !$pre_mod_item->itemlost || $pre_mod_item->itemlost <= 0 ) )
{
# item lost
$self->_add_statistic('item_lost');
}
}

View file

@ -33,6 +33,7 @@ use Koha::Item::Transfer::Limits;
use Koha::Items;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Statistics;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -68,7 +69,7 @@ my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
subtest 'store' => sub {
plan tests => 7;
plan tests => 8;
my $biblio = $builder->build_sample_biblio;
my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
@ -1363,6 +1364,22 @@ subtest 'store' => sub {
"Item modification logged"
);
};
subtest 'itemlost / statistics' => sub { # TODO BZ 34308 (gt zero checks)
plan tests => 5;
my $item = $builder->build_sample_item;
$item->itemlost(-1)->store; # weird value; >0 test not triggered ?
is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 0, 'No statistics added' );
$item->itemlost(1)->store;
is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 1, 'statistics added' );
$item->itemlost(2)->store;
is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 1, 'No statistics added, already lost' );
$item->itemlost(-1)->store; # weird value; <=0 test triggered ?
is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 2, 'statistics added' );
$item->itemlost(-2)->store; # weird value, but no status change
is( Koha::Statistics->search( { itemnumber => $item->id } )->count, 2, 'No statistics added, already *found*' );
};
};
subtest 'get_transfer' => sub {