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

(-)a/C4/Reserves.pm (+14 lines)
Lines 192-197 sub AddReserve { Link Here
192
    my $found          = $params->{found};
192
    my $found          = $params->{found};
193
    my $itemtype       = $params->{itemtype};
193
    my $itemtype       = $params->{itemtype};
194
    my $non_priority   = $params->{non_priority};
194
    my $non_priority   = $params->{non_priority};
195
    my $hold_group_id  = $params->{hold_group_id};
195
196
196
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
197
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
197
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
198
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
Lines 256-261 sub AddReserve { Link Here
256
            itemtype       => $itemtype,
257
            itemtype       => $itemtype,
257
            item_level_hold => $checkitem ? 1 : 0,
258
            item_level_hold => $checkitem ? 1 : 0,
258
            non_priority   => $non_priority ? 1 : 0,
259
            non_priority   => $non_priority ? 1 : 0,
260
            hold_group_id  => $hold_group_id,
259
        }
261
        }
260
    )->store();
262
    )->store();
261
    $hold->set_waiting() if $found && $found eq 'W';
263
    $hold->set_waiting() if $found && $found eq 'W';
Lines 1124-1129 sub ModReserveFill { Link Here
1124
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
1126
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
1125
        if C4::Context->preference('HoldsLog');
1127
        if C4::Context->preference('HoldsLog');
1126
1128
1129
    # if this hold was part of a group, cancel other holds in the group
1130
    my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1131
    foreach my $h ( @holds ) {
1132
        $h->cancel unless $h->reserve_id == $hold->reserve_id;
1133
    }
1134
1127
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1135
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1128
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1136
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1129
1137
Lines 1227-1232 sub ModReserveAffect { Link Here
1227
        # Complete transfer if one exists
1235
        # Complete transfer if one exists
1228
        my $transfer = $hold->item->get_transfer;
1236
        my $transfer = $hold->item->get_transfer;
1229
        $transfer->receive if $transfer;
1237
        $transfer->receive if $transfer;
1238
1239
        # if this hold was part of a group, cancel other holds in the group
1240
        my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1241
        foreach my $h ( @holds ) {
1242
            $h->cancel unless $h->reserve_id == $hold->reserve_id;
1243
        }
1230
    }
1244
    }
1231
1245
1232
    _FixPriority( { biblionumber => $biblionumber } );
1246
    _FixPriority( { biblionumber => $biblionumber } );
(-)a/Koha/Hold.pm (-1 / +20 lines)
Lines 34-40 use Koha::Items; Link Here
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::Old::Holds;
35
use Koha::Old::Holds;
36
use Koha::Calendar;
36
use Koha::Calendar;
37
37
use Koha::HoldGroups;
38
use Koha::Exceptions::Hold;
38
use Koha::Exceptions::Hold;
39
39
40
use base qw(Koha::Object);
40
use base qw(Koha::Object);
Lines 626-631 sub _set_default_expirationdate { Link Here
626
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
626
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
627
}
627
}
628
628
629
=head3 hold_group
630
631
    my $hold_group = $hold->hold_group;
632
    my $hold_group_id = $hold_group->id if $hold_group;
633
634
Return the Koha::HoldGroup object of a hold if part of a hold group
635
636
=cut
637
638
sub hold_group {
639
    my ( $self ) = @_;
640
641
    if ( $self->hold_group_id ) {
642
        return Koha::HoldGroups->find( $self->hold_group_id );
643
    }
644
645
    return undef;
646
}
647
629
=head3 _move_to_old
648
=head3 _move_to_old
630
649
631
my $is_moved = $hold->_move_to_old;
650
my $is_moved = $hold->_move_to_old;
(-)a/Koha/HoldGroup.pm (+63 lines)
Line 0 Link Here
1
package Koha::HoldGroup;
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::HoldGroup - Koha Hold Group object class
27
28
=head1 API
29
30
=head2 Class Methods
31
32
=cut
33
34
=head3 holds
35
36
    $holds = $hold_group->holds
37
38
Return all holds associated with this group
39
40
=cut
41
42
sub holds {
43
    my ($self) = @_;
44
45
    my $holds_rs = $self->_result->reserves->search;
46
    return Koha::Holds->_new_from_dbic($holds_rs);
47
}
48
49
=head3 _type
50
51
=cut
52
53
sub _type {
54
    return 'HoldGroup';
55
}
56
57
=head1 AUTHORS
58
59
Josef Moravec <josef.moravec@gmail.com>
60
61
=cut
62
63
1;
(-)a/Koha/HoldGroups.pm (+60 lines)
Line 0 Link Here
1
package Koha::HoldGroups;
2
3
# Copyright Koha Development team 2020
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use Koha::HoldGroup;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::HoldGroups - Koha Hold Group object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 _type
39
40
=cut
41
42
sub _type {
43
    return 'HoldGroup';
44
}
45
46
=head3 object_class
47
48
=cut
49
50
sub object_class {
51
    return 'Koha::HoldGroup';
52
}
53
54
=head1 AUTHOR
55
56
Josef Moravec <josef.moravec@gmail.com>
57
58
=cut
59
60
1;
(-)a/Koha/Holds.pm (+15 lines)
Lines 139-144 sub get_items_that_can_fill { Link Here
139
    )->filter_by_for_hold();
139
    )->filter_by_for_hold();
140
}
140
}
141
141
142
=head3 count_grouped
143
144
    $holds->count_grouped();
145
146
Return number of hold, where hold group is counted as one hold
147
148
=cut
149
150
sub count_grouped {
151
    my ($self) = @_;
152
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
153
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
154
    return $holds_without_group_count + $hold_groups_count;
155
}
156
142
=head3 type
157
=head3 type
143
158
144
=cut
159
=cut
(-)a/t/db_dependent/Koha/Holds.t (-1 / +72 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation qw( AddIssue );
25
use C4::Circulation qw( AddIssue );
Lines 500-505 subtest 'get_items_that_can_fill' => sub { Link Here
500
500
501
};
501
};
502
502
503
subtest 'count_grouped' => sub {
504
    plan tests => 3;
505
    $schema->storage->txn_begin;
506
507
    my $patron = $builder->build_object({
508
        class => 'Koha::Patrons',
509
    });
510
    my $patron_id = $patron->borrowernumber;
511
512
    my $hold1 = $builder->build_object({
513
            class => 'Koha::Holds',
514
            value => {
515
                borrowernumber => $patron_id,
516
                hold_group_id => undef,
517
            },
518
        });
519
520
    is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.');
521
522
    my $hold_group = $builder->build_object({
523
        class => 'Koha::HoldGroups',
524
    });
525
526
    my $hold2 = $builder->build_object({
527
        class => 'Koha::Holds',
528
        value => {
529
            borrowernumber => $patron_id,
530
            hold_group_id => $hold_group->hold_group_id,
531
        }
532
    });
533
    my $hold3 = $builder->build_object({
534
        class => 'Koha::Holds',
535
        value => {
536
            borrowernumber => $patron_id,
537
            hold_group_id => $hold_group->hold_group_id,
538
        }
539
    });
540
541
    is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.');
542
543
    my $hold_group2 = $builder->build_object({
544
        class => 'Koha::HoldGroups',
545
    });
546
547
    my $hold4 = $builder->build_object({
548
        class => 'Koha::Holds',
549
        value => {
550
            borrowernumber => $patron_id,
551
            hold_group_id => $hold_group2->hold_group_id,
552
        }
553
    });
554
    my $hold5 = $builder->build_object({
555
        class => 'Koha::Holds',
556
        value => {
557
            borrowernumber => $patron_id,
558
            hold_group_id => $hold_group2->hold_group_id,
559
        }
560
    });
561
    my $hold6 = $builder->build_object({
562
        class => 'Koha::Holds',
563
        value => {
564
            borrowernumber => $patron_id,
565
            hold_group_id => $hold_group2->hold_group_id,
566
        }
567
    });
568
569
    is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.');
570
571
    $schema->storage->txn_rollback;
572
};
573
503
$schema->storage->txn_rollback;
574
$schema->storage->txn_rollback;
504
575
505
1;
576
1;
(-)a/t/db_dependent/Reserves/HoldGroup.t (-1 / +53 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use t::lib::TestBuilder;
25
26
my $schema  = Koha::Database->new->schema;
27
my $builder = t::lib::TestBuilder->new;
28
29
subtest 'holds tests' => sub {
30
31
    plan tests => 2;
32
33
    $schema->storage->txn_begin;
34
35
    my $patron     = $builder->build_object({ class => 'Koha::Patrons' });
36
    my $hold_group = $builder->build_object({ class => 'Koha::HoldGroups' });
37
    my $hold       = $builder->build_object(
38
        {
39
            class => 'Koha::Holds',
40
            value => {
41
                borrowernumber => $patron->borrowernumber,
42
                hold_group_id  => $hold_group->hold_group_id,
43
            }
44
        }
45
    );
46
47
    my $holds = $hold_group->holds;
48
    is( ref($holds), 'Koha::Holds', 'Right type' );
49
    my $hold_from_group = $holds->next;
50
    is( $hold_from_group->id, $hold->id, 'Right object' );
51
52
    $schema->storage->txn_rollback;
53
};

Return to bug 15516