View | Details | Raw Unified | Return to bug 22899
Collapse All | Expand All

(-)a/Koha/Item.pm (+14 lines)
Lines 354-359 sub add_to_rota { Link Here
354
    return $self;
354
    return $self;
355
}
355
}
356
356
357
=head3 pending_hold
358
359
  my $is_pending_hold = $item->pending_hold();
360
361
This method checks the tmp_holdsqueue to see if this item has been selected for a hold, but not filled yet and returns true or false
362
363
=cut
364
365
sub pending_hold {
366
    my ( $self ) = @_;
367
    my $pending_hold = $self->_result->tmp_holdsqueues;
368
    return !C4::Context->preference('AllowItemsOnHoldCheckout') && $pending_hold->count ? 1: 0;
369
}
370
357
=head2 Internal methods
371
=head2 Internal methods
358
372
359
=head3 _type
373
=head3 _type
(-)a/t/db_dependent/Koha/Item.t (-2 / +22 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use Koha::Items;
24
use Koha::Items;
25
use Koha::Database;
25
use Koha::Database;
Lines 61-63 subtest 'hidden_in_opac() tests' => sub { Link Here
61
61
62
    $schema->storage->txn_rollback;
62
    $schema->storage->txn_rollback;
63
};
63
};
64
- 
64
65
subtest 'pending_hold() tests' => sub {
66
67
    plan tests => 3;
68
69
    $schema->storage->txn_begin;
70
71
    my $dbh = C4::Context->dbh;
72
    my $item  = $builder->build_sample_item({ itemlost => 0 });
73
    my $itemnumber = $item->itemnumber;
74
75
    # disable AllowItemsOnHoldCheckout as it ignores pending holds
76
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 );
77
    $dbh->do("INSERT INTO tmp_holdsqueue (surname,borrowernumber,itemnumber) VALUES ('Clamp',42,$itemnumber)");
78
    ok( $item->pending_hold, "Yes, we have a pending hold");
79
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 1 );
80
    ok( !$item->pending_hold, "We don't consider a pending hold if hold items can be checked out");
81
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 );
82
    $dbh->do("DELETE FROM tmp_holdsqueue WHERE itemnumber=$itemnumber");
83
    ok( !$item->pending_hold, "We don't have a pending hold if nothing in the tmp_holdsqueue");
84
};

Return to bug 22899