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

(-)a/C4/Reserves.pm (+14 lines)
Lines 189-194 sub AddReserve { Link Here
189
    my $found          = $params->{found};
189
    my $found          = $params->{found};
190
    my $itemtype       = $params->{itemtype};
190
    my $itemtype       = $params->{itemtype};
191
    my $non_priority   = $params->{non_priority};
191
    my $non_priority   = $params->{non_priority};
192
    my $hold_group_id  = $params->{hold_group_id};
192
193
193
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
194
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
194
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
195
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
Lines 253-258 sub AddReserve { Link Here
253
            itemtype       => $itemtype,
254
            itemtype       => $itemtype,
254
            item_level_hold => $checkitem ? 1 : 0,
255
            item_level_hold => $checkitem ? 1 : 0,
255
            non_priority   => $non_priority ? 1 : 0,
256
            non_priority   => $non_priority ? 1 : 0,
257
            hold_group_id  => $hold_group_id,
256
        }
258
        }
257
    )->store();
259
    )->store();
258
    $hold->set_waiting() if $found && $found eq 'W';
260
    $hold->set_waiting() if $found && $found eq 'W';
Lines 1100-1105 sub ModReserveFill { Link Here
1100
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
1102
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
1101
        if C4::Context->preference('HoldsLog');
1103
        if C4::Context->preference('HoldsLog');
1102
1104
1105
    # if this hold was part of a group, cancel other holds in the group
1106
    my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1107
    foreach my $h ( @holds ) {
1108
        $h->cancel unless $h->reserve_id == $hold->reserve_id;
1109
    }
1110
1103
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1111
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1104
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1112
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1105
1113
Lines 1203-1208 sub ModReserveAffect { Link Here
1203
        # Complete transfer if one exists
1211
        # Complete transfer if one exists
1204
        my $transfer = $hold->item->get_transfer;
1212
        my $transfer = $hold->item->get_transfer;
1205
        $transfer->receive if $transfer;
1213
        $transfer->receive if $transfer;
1214
1215
        # if this hold was part of a group, cancel other holds in the group
1216
        my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1217
        foreach my $h ( @holds ) {
1218
            $h->cancel unless $h->reserve_id == $hold->reserve_id;
1219
        }
1206
    }
1220
    }
1207
1221
1208
    _FixPriority( { biblionumber => $biblionumber } );
1222
    _FixPriority( { biblionumber => $biblionumber } );
(-)a/Koha/Hold.pm (-1 / +20 lines)
Lines 36-42 use Koha::Items; Link Here
36
use Koha::Libraries;
36
use Koha::Libraries;
37
use Koha::Old::Holds;
37
use Koha::Old::Holds;
38
use Koha::Calendar;
38
use Koha::Calendar;
39
39
use Koha::HoldGroups;
40
use Koha::Exceptions::Hold;
40
use Koha::Exceptions::Hold;
41
41
42
use base qw(Koha::Object);
42
use base qw(Koha::Object);
Lines 562-567 sub cancel { Link Here
562
    return $self;
562
    return $self;
563
}
563
}
564
564
565
=head3 hold_group
566
567
    my $hold_group = $hold->hold_group;
568
    my $hold_group_id = $hold_group->id if $hold_group;
569
570
Return the Koha::HoldGroup object of a hold if part of a hold group
571
572
=cut
573
574
sub hold_group {
575
    my ( $self ) = @_;
576
577
    if ( $self->hold_group_id ) {
578
        return Koha::HoldGroups->find( $self->hold_group_id );
579
    }
580
581
    return undef;
582
}
583
565
=head3 _move_to_old
584
=head3 _move_to_old
566
585
567
my $is_moved = $hold->_move_to_old;
586
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 153-158 sub get_items_that_can_fill { Link Here
153
    );
153
    );
154
}
154
}
155
155
156
=head3 count_grouped
157
158
    $holds->count_grouped();
159
160
Return number of hold, where hold group is counted as one hold
161
162
=cut
163
164
sub count_grouped {
165
    my ($self) = @_;
166
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
167
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
168
    return $holds_without_group_count + $hold_groups_count;
169
}
170
156
=head3 type
171
=head3 type
157
172
158
=cut
173
=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;
25
use C4::Circulation;
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