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

(-)a/Koha/Biblio.pm (-3 / +20 lines)
Lines 24-29 use Carp; Link Here
24
use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode );
24
use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode );
25
25
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
27
28
28
use base qw(Koha::Object);
29
use base qw(Koha::Object);
29
30
Lines 258-267 return the current holds placed on this record Link Here
258
=cut
259
=cut
259
260
260
sub holds {
261
sub holds {
261
    my ( $self ) = @_;
262
    my ( $self, $params, $attributes ) = @_;
263
    $attributes->{order_by} = 'priority' unless exists $attributes->{order_by};
264
    my $hold_rs = $self->_result->reserves->search( $params, $attributes );
265
    return Koha::Holds->_new_from_dbic($hold_rs);
266
}
267
268
=head3 holds_placed_before_today
269
270
my $holds = $biblio->holds_placed_before_today
262
271
263
    my $holds_rs = $self->_result->reserves;
272
Return the holds placed on this bibliographic record.
264
    return Koha::Holds->_new_from_dbic( $holds_rs );
273
It does not include future holds.
274
275
=cut
276
277
sub holds_placed_before_today {
278
    my ($self) = @_;
279
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
280
    return $self->holds(
281
        { reservedate => { '<=' => $dtf->format_date(dt_from_string) } } );
265
}
282
}
266
283
267
=head3 biblioitem
284
=head3 biblioitem
(-)a/t/db_dependent/Koha/Biblios.t (-3 / +13 lines)
Lines 23-28 use Test::More tests => 1; Link Here
23
23
24
use C4::Reserves;
24
use C4::Reserves;
25
25
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Biblios;
27
use Koha::Biblios;
27
use Koha::Patrons;
28
use Koha::Patrons;
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
Lines 43-55 my $biblioitem = $schema->resultset('Biblioitem')->new( Link Here
43
    }
44
    }
44
)->insert();
45
)->insert();
45
46
46
subtest 'holds' => sub {
47
subtest 'holds + holds_placed_before_today' => sub {
47
    plan tests => 3;
48
    plan tests => 5;
48
    C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber );
49
    C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber );
49
    my $holds = $biblio->holds;
50
    my $holds = $biblio->holds;
50
    is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' );
51
    is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' );
51
    is( $holds->count, 1, '->holds should only return 1 hold' );
52
    is( $holds->count, 1, '->holds should only return 1 hold' );
52
    is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' );
53
    is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' );
54
    $holds->delete;
55
56
    # Add a hold in the future
57
    C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber, undef, undef, dt_from_string->add( days => 2 ) );
58
    $holds = $biblio->holds;
59
    is( $holds->count, 1, '->holds should return future holds' );
60
    $holds = $biblio->holds_placed_before_today;
61
    is( $holds->count, 0, '->holds_placed_before_today should not return future holds' );
62
    $holds->delete;
63
53
};
64
};
54
65
55
$schema->storage->txn_rollback;
66
$schema->storage->txn_rollback;
56
- 

Return to bug 17736