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 1102-1107 sub ModReserveFill { Link Here
1102
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
1104
    logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
1103
        if C4::Context->preference('HoldsLog');
1105
        if C4::Context->preference('HoldsLog');
1104
1106
1107
    # if this hold was part of a group, cancel other holds in the group
1108
    my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1109
    foreach my $h ( @holds ) {
1110
        $h->cancel unless $h->reserve_id == $hold->reserve_id;
1111
    }
1112
1105
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1113
    # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
1106
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1114
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1107
1115
Lines 1207-1212 sub ModReserveAffect { Link Here
1207
        while( my $transfer = $transfers->next ){
1215
        while( my $transfer = $transfers->next ){
1208
            $transfer->datearrived( dt_from_string() )->store;
1216
            $transfer->datearrived( dt_from_string() )->store;
1209
        };
1217
        };
1218
1219
        # if this hold was part of a group, cancel other holds in the group
1220
        my @holds = Koha::Holds->search({ hold_group_id => $hold->hold_group_id });
1221
        foreach my $h ( @holds ) {
1222
            $h->cancel unless $h->reserve_id == $hold->reserve_id;
1223
        }
1210
    }
1224
    }
1211
1225
1212
1226
(-)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 143-148 sub get_items_that_can_fill { Link Here
143
    );
143
    );
144
}
144
}
145
145
146
=head3 count_grouped
147
148
    $holds->count_grouped();
149
150
Return number of hold, where hold group is counted as one hold
151
152
=cut
153
154
sub count_grouped {
155
    my ($self) = @_;
156
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
157
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
158
    return $holds_without_group_count + $hold_groups_count;
159
}
160
146
=head3 type
161
=head3 type
147
162
148
=cut
163
=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 485-490 subtest 'get_items_that_can_fill' => sub { Link Here
485
        [ $item_2->itemnumber, $item_5->itemnumber ], 'Only item 2 and 5 are available for filling the hold' );
485
        [ $item_2->itemnumber, $item_5->itemnumber ], 'Only item 2 and 5 are available for filling the hold' );
486
};
486
};
487
487
488
subtest 'count_grouped' => sub {
489
    plan tests => 3;
490
    $schema->storage->txn_begin;
491
492
    my $patron = $builder->build_object({
493
        class => 'Koha::Patrons',
494
    });
495
    my $patron_id = $patron->borrowernumber;
496
497
    my $hold1 = $builder->build_object({
498
            class => 'Koha::Holds',
499
            value => {
500
                borrowernumber => $patron_id,
501
                hold_group_id => undef,
502
            },
503
        });
504
505
    is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.');
506
507
    my $hold_group = $builder->build_object({
508
        class => 'Koha::HoldGroups',
509
    });
510
511
    my $hold2 = $builder->build_object({
512
        class => 'Koha::Holds',
513
        value => {
514
            borrowernumber => $patron_id,
515
            hold_group_id => $hold_group->hold_group_id,
516
        }
517
    });
518
    my $hold3 = $builder->build_object({
519
        class => 'Koha::Holds',
520
        value => {
521
            borrowernumber => $patron_id,
522
            hold_group_id => $hold_group->hold_group_id,
523
        }
524
    });
525
526
    is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.');
527
528
    my $hold_group2 = $builder->build_object({
529
        class => 'Koha::HoldGroups',
530
    });
531
532
    my $hold4 = $builder->build_object({
533
        class => 'Koha::Holds',
534
        value => {
535
            borrowernumber => $patron_id,
536
            hold_group_id => $hold_group2->hold_group_id,
537
        }
538
    });
539
    my $hold5 = $builder->build_object({
540
        class => 'Koha::Holds',
541
        value => {
542
            borrowernumber => $patron_id,
543
            hold_group_id => $hold_group2->hold_group_id,
544
        }
545
    });
546
    my $hold6 = $builder->build_object({
547
        class => 'Koha::Holds',
548
        value => {
549
            borrowernumber => $patron_id,
550
            hold_group_id => $hold_group2->hold_group_id,
551
        }
552
    });
553
554
    is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.');
555
556
    $schema->storage->txn_rollback;
557
};
558
488
$schema->storage->txn_rollback;
559
$schema->storage->txn_rollback;
489
560
490
1;
561
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