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

(-)a/C4/ILSDI/Services.pm (-6 / +20 lines)
Lines 733-739 sub HoldTitle { Link Here
733
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
733
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
734
    #    $title,      $checkitem, $found
734
    #    $title,      $checkitem, $found
735
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
735
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
736
    AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, undef, undef );
736
    AddReserve(
737
        {
738
            branch         => $branch,
739
            borrowernumber => $borrowernumber,
740
            biblionumber   => $biblionumber,
741
            priority       => $priority,
742
            title          => $title,
743
        }
744
    );
737
745
738
    # Hashref building
746
    # Hashref building
739
    my $out;
747
    my $out;
Lines 808-818 sub HoldItem { Link Here
808
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
816
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
809
817
810
    # Add the reserve
818
    # Add the reserve
811
    #    $branch,    $borrowernumber, $biblionumber,
819
    my $priority = C4::Reserves::CalculatePriority($biblionumber);
812
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
820
    AddReserve(
813
    #    $title,      $checkitem, $found
821
        {
814
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
822
            branch         => $branch,
815
    AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, $itemnumber, undef );
823
            borrowernumber => $borrowernumber,
824
            biblionumber   => $biblionumber,
825
            priority       => $priority,
826
            title          => $title,
827
            itemnumber     => $itemnumber,
828
        }
829
    );
816
830
817
    # Hashref building
831
    # Hashref building
818
    my $out;
832
    my $out;
(-)a/C4/Reserves.pm (-6 / +27 lines)
Lines 141-147 BEGIN { Link Here
141
141
142
=head2 AddReserve
142
=head2 AddReserve
143
143
144
    AddReserve($branch,$borrowernumber,$biblionumber,$bibitems,$priority,$resdate,$expdate,$notes,$title,$checkitem,$found)
144
    AddReserve(
145
        {
146
            branch           => $branchcode,
147
            borrowernumber   => $borrowernumber,
148
            biblionumber     => $biblionumber,
149
            priority         => $priority,
150
            reservation_date => $reservation_date,
151
            expiration_date  => $expiration_date,
152
            notes            => $notes,
153
            title            => $title,
154
            itemnumber       => $itemnumber,
155
            found            => $found,
156
            itemtype         => $itemtype,
157
        }
158
    );
145
159
146
Adds reserve and generates HOLDPLACED message.
160
Adds reserve and generates HOLDPLACED message.
147
161
Lines 157-167 The following tables are available witin the HOLDPLACED message: Link Here
157
=cut
171
=cut
158
172
159
sub AddReserve {
173
sub AddReserve {
160
    my (
174
    my ($params)       = @_;
161
        $branch,   $borrowernumber, $biblionumber, $bibitems,
175
    my $branch         = $params->{branchcode};
162
        $priority, $resdate,        $expdate,      $notes,
176
    my $borrowernumber = $params->{borrowernumber};
163
        $title,    $checkitem,      $found,        $itemtype
177
    my $biblionumber   = $params->{biblionumber};
164
    ) = @_;
178
    my $priority       = $params->{priority};
179
    my $resdate        = $params->{reservation_date};
180
    my $expdate        = $params->{expiration_date};
181
    my $notes          = $params->{notes};
182
    my $title          = $params->{title};
183
    my $checkitem      = $params->{itemnumber};
184
    my $found          = $params->{found};
185
    my $itemtype       = $params->{itemtype};
165
186
166
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
187
    $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
167
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
188
        or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
(-)a/C4/SIP/ILS/Transaction/Hold.pm (-1 / +7 lines)
Lines 66-72 sub do_hold { Link Here
66
        return $self;
66
        return $self;
67
    }
67
    }
68
68
69
    AddReserve( $branch, $patron->borrowernumber, $item->biblionumber );
69
    AddReserve(
70
        {
71
            branch         => $branch,
72
            borrowernumber => $patron->borrowernumber,
73
            biblionumber   => $item->biblionumber
74
        }
75
    );
70
76
71
    # unfortunately no meaningful return value
77
    # unfortunately no meaningful return value
72
    $self->ok(1);
78
    $self->ok(1);
(-)a/Koha/Club/Hold.pm (-12 / +12 lines)
Lines 91-108 sub add { Link Here
91
        my $priority = C4::Reserves::CalculatePriority($params->{biblio_id});
91
        my $priority = C4::Reserves::CalculatePriority($params->{biblio_id});
92
92
93
        my $hold_id = C4::Reserves::AddReserve(
93
        my $hold_id = C4::Reserves::AddReserve(
94
            $params->{pickup_library_id},
94
            {
95
            $patron_id,
95
                branchcode      => $params->{pickup_library_id},
96
            $params->{biblio_id},
96
                borrowernumber  => $patron_id,
97
            undef,    # $bibitems param is unused
97
                biblionumber    => $params->{biblio_id},
98
            $priority,
98
                priority        => $priority,
99
            undef,    # hold date, we don't allow it currently
99
                expiration_date => $params->{expiration_date},
100
            $params->{expiration_date},
100
                notes           => $params->{notes},
101
            $params->{notes},
101
                title           => $biblio->title,
102
            $biblio->title,
102
                itemnumber      => $params->{item_id},
103
            $params->{item_id},
103
                found           => undef,                       # TODO: Why not?
104
            undef,    # TODO: Why not?
104
                itemtype        => $params->{item_type},
105
            $params->{item_type}
105
            }
106
        );
106
        );
107
        if ($hold_id) {
107
        if ($hold_id) {
108
            Koha::Club::Hold::PatronHold->new({
108
            Koha::Club::Hold::PatronHold->new({
(-)a/Koha/REST/V1/Holds.pm (-12 / +13 lines)
Lines 161-178 sub add { Link Here
161
        }
161
        }
162
162
163
        my $hold_id = C4::Reserves::AddReserve(
163
        my $hold_id = C4::Reserves::AddReserve(
164
            $pickup_library_id,
164
            {
165
            $patron_id,
165
                branchcode       => $pickup_library_id,
166
            $biblio_id,
166
                borrowernumber   => $patron_id,
167
            undef,    # $bibitems param is unused
167
                biblionumber     => $biblio_id,
168
            $priority,
168
                priority         => $priority,
169
            $hold_date,
169
                reservation_date => $hold_date,
170
            $expiration_date,
170
                expiration_date  => $expiration_date,
171
            $notes,
171
                notes            => $notes,
172
            $biblio->title,
172
                title            => $biblio->title,
173
            $item_id,
173
                itemnumber       => $item_id,
174
            undef,    # TODO: Why not?
174
                found            => undef,                # TODO: Why not?
175
            $item_type
175
                itemtype         => $item_type,
176
            }
176
        );
177
        );
177
178
178
        unless ($hold_id) {
179
        unless ($hold_id) {
(-)a/opac/opac-reserve.pl (-4 / +13 lines)
Lines 309-318 if ( $query->param('place_reserve') ) { Link Here
309
        # Here we actually do the reserveration. Stage 3.
309
        # Here we actually do the reserveration. Stage 3.
310
        if ($canreserve) {
310
        if ($canreserve) {
311
            my $reserve_id = AddReserve(
311
            my $reserve_id = AddReserve(
312
                $branch,          $borrowernumber, $biblioNum,
312
                {
313
                [$biblioNum],     $rank,           $startdate,
313
                    branchcode       => $branch,
314
                $expiration_date, $notes,          $biblioData->{title},
314
                    borrowernumber   => $borrowernumber,
315
                $itemNum,         $found,          $itemtype,
315
                    biblionumber     => $biblioNum,
316
                    priority         => $rank,
317
                    reservation_date => $startdate,
318
                    expiration_date  => $expiration_date,
319
                    notes            => $notes,
320
                    title            => $biblioData->{title},
321
                    itemnumber       => $itemNum,
322
                    found            => $found,
323
                    itemtype         => $itemtype,
324
                }
316
            );
325
            );
317
            $failed_holds++ unless $reserve_id;
326
            $failed_holds++ unless $reserve_id;
318
            ++$reserve_cnt;
327
            ++$reserve_cnt;
(-)a/reserve/placerequest.pl (-8 / +46 lines)
Lines 100-123 if ( $type eq 'str8' && $borrower ) { Link Here
100
            my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $branch)->{status};
100
            my $can_item_be_reserved = CanItemBeReserved($borrower->{'borrowernumber'}, $item->itemnumber, $branch)->{status};
101
101
102
            if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
102
            if ( $can_item_be_reserved eq 'OK' || ( $can_item_be_reserved ne 'itemAlreadyOnHold' && $can_override ) ) {
103
                AddReserve( $branch, $borrower->{'borrowernumber'},
103
                AddReserve(
104
                    $biblionumber, \@realbi, $rank[0], $startdate, $expirationdate, $notes, $title,
104
                    {
105
                    $checkitem, $found, $itemtype );
105
                        branchcode       => $branch,
106
                        borrowernumber   => $borrower->{'borrowernumber'},
107
                        biblionumber     => $biblionumber,
108
                        priority         => $rank[0],
109
                        reservation_date => $startdate,
110
                        expiration_date  => $expirationdate,
111
                        notes            => $notes,
112
                        title            => $title,
113
                        itemnumber       => $checkitem,
114
                        found            => $found,
115
                        itemtype         => $itemtype,
116
                    }
117
                );
118
106
            }
119
            }
107
120
108
        } elsif ($multi_hold) {
121
        } elsif ($multi_hold) {
109
            my $bibinfo = $bibinfos{$biblionumber};
122
            my $bibinfo = $bibinfos{$biblionumber};
110
            if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
123
            if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
111
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,[$biblionumber],
124
                AddReserve(
112
                           $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
125
                    {
126
                        branchcode       => $branch,
127
                        borrowernumber   => $borrower->{'borrowernumber'},
128
                        biblionumber     => $biblionumber,
129
                        priority         => $bibinfo->{rank},
130
                        reservation_date => $startdate,
131
                        expiration_date  => $expirationdate,
132
                        notes            => $notes,
133
                        title            => $bibinfo->{title},
134
                        itemnumber       => $checkitem,
135
                        found            => $found,
136
                        itemtype         => $itemtype,
137
                    }
138
                );
113
            }
139
            }
114
        } else {
140
        } else {
115
            # place a request on 1st available
141
            # place a request on 1st available
116
            for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
142
            for ( my $i = 0 ; $i < $holds_to_place_count ; $i++ ) {
117
                if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
143
                if ( $can_override || CanBookBeReserved($borrower->{'borrowernumber'}, $biblionumber)->{status} eq 'OK' ) {
118
                    AddReserve( $branch, $borrower->{'borrowernumber'},
144
                    AddReserve(
119
                        $biblionumber, \@realbi, $rank[0], $startdate, $expirationdate, $notes, $title,
145
                        {
120
                        $checkitem, $found, $itemtype );
146
                            branchcode       => $branch,
147
                            borrowernumber   => $borrower->{'borrowernumber'},
148
                            biblionumber     => $biblionumber,
149
                            priority         => $rank[0],
150
                            reservation_date => $startdate,
151
                            expiration_date  => $expirationdate,
152
                            notes            => $notes,
153
                            title            => $title,
154
                            itemnumber       => $checkitem,
155
                            found            => $found,
156
                            itemtype         => $itemtype,
157
                        }
158
                    );
121
                }
159
                }
122
            }
160
            }
123
        }
161
        }
(-)a/serials/routing-preview.pl (-1 / +10 lines)
Lines 94-100 if($ok){ Link Here
94
                    branchcode     => $branch
94
                    branchcode     => $branch
95
                });
95
                });
96
            } else {
96
            } else {
97
                AddReserve($branch,$routing->{borrowernumber},$biblionumber,undef,$routing->{ranking}, undef, undef, $notes,$title);
97
                AddReserve(
98
                    {
99
                        branchcode     => $branch,
100
                        borrowernumber => $routing->{borrowernumber},
101
                        biblionumber   => $biblionumber,
102
                        priority       => $routing->{ranking},
103
                        notes          => $notes,
104
                        title          => $title,
105
                    }
106
                );
98
        }
107
        }
99
    }
108
    }
100
	}
109
	}
(-)a/t/db_dependent/Circulation.t (-18 / +64 lines)
Lines 385-393 subtest "CanBookBeRenewed tests" => sub { Link Here
385
385
386
    # Biblio-level hold, renewal test
386
    # Biblio-level hold, renewal test
387
    AddReserve(
387
    AddReserve(
388
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
388
        {
389
        $bibitems,  $priority, $resdate, $expdate, $notes,
389
            branchcode       => $branch,
390
        'a title', $checkitem, $found
390
            borrowernumber   => $reserving_borrowernumber,
391
            biblionumber     => $biblio->biblionumber,
392
            priority         => $priority,
393
            reservation_date => $resdate,
394
            expiration_date  => $expdate,
395
            notes            => $notes,
396
            itemnumber       => $checkitem,
397
            found            => $found,
398
        }
391
    );
399
    );
392
400
393
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
401
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
Lines 458-466 subtest "CanBookBeRenewed tests" => sub { Link Here
458
466
459
    # Item-level hold, renewal test
467
    # Item-level hold, renewal test
460
    AddReserve(
468
    AddReserve(
461
        $branch, $reserving_borrowernumber, $biblio->biblionumber,
469
        {
462
        $bibitems,  $priority, $resdate, $expdate, $notes,
470
            branchcode       => $branch,
463
        'a title', $item_1->itemnumber, $found
471
            borrowernumber   => $reserving_borrowernumber,
472
            biblionumber     => $biblio->biblionumber,
473
            priority         => $priority,
474
            reservation_date => $resdate,
475
            expiration_date  => $expdate,
476
            notes            => $notes,
477
            itemnumber       => $item_1->itemnumber,
478
            found            => $found,
479
        }
464
    );
480
    );
465
481
466
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
482
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
Lines 1378-1386 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1378
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1394
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' );
1379
1395
1380
    AddReserve(
1396
    AddReserve(
1381
        $library2->{branchcode}, $borrowernumber2, $biblio->biblionumber,
1397
        {
1382
        '',  1, undef, undef, '',
1398
            branchcode     => $library2->{branchcode},
1383
        undef, undef, undef
1399
            borrowernumber => $borrowernumber2,
1400
            biblionumber   => $biblio->biblionumber,
1401
            priority       => 1,
1402
        }
1384
    );
1403
    );
1385
1404
1386
    Koha::CirculationRules->set_rules(
1405
    Koha::CirculationRules->set_rules(
Lines 1799-1807 subtest 'MultipleReserves' => sub { Link Here
1799
    );
1818
    );
1800
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1819
    my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber;
1801
    AddReserve(
1820
    AddReserve(
1802
        $branch, $reserving_borrowernumber1, $biblio->biblionumber,
1821
        {
1803
        $bibitems,  $priority, $resdate, $expdate, $notes,
1822
            branchcode       => $branch,
1804
        'a title', $checkitem, $found
1823
            borrowernumber   => $reserving_borrowernumber1,
1824
            biblionumber     => $biblio->biblionumber,
1825
            priority         => $priority,
1826
            reservation_date => $resdate,
1827
            expiration_date  => $expdate,
1828
            notes            => $notes,
1829
            itemnumber       => $checkitem,
1830
            found            => $found,
1831
        }
1805
    );
1832
    );
1806
1833
1807
    my %reserving_borrower_data2 = (
1834
    my %reserving_borrower_data2 = (
Lines 1812-1820 subtest 'MultipleReserves' => sub { Link Here
1812
    );
1839
    );
1813
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1840
    my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber;
1814
    AddReserve(
1841
    AddReserve(
1815
        $branch, $reserving_borrowernumber2, $biblio->biblionumber,
1842
        {
1816
        $bibitems,  $priority, $resdate, $expdate, $notes,
1843
            branchcode       => $branch,
1817
        'a title', $checkitem, $found
1844
            borrowernumber   => $reserving_borrowernumber2,
1845
            biblionumber     => $biblio->biblionumber,
1846
            priority         => $priority,
1847
            reservation_date => $resdate,
1848
            expiration_date  => $expdate,
1849
            notes            => $notes,
1850
            itemnumber       => $checkitem,
1851
            found            => $found,
1852
        }
1818
    );
1853
    );
1819
1854
1820
    {
1855
    {
Lines 2861-2868 subtest 'Set waiting flag' => sub { Link Here
2861
2896
2862
    set_userenv( $library_2 );
2897
    set_userenv( $library_2 );
2863
    my $reserve_id = AddReserve(
2898
    my $reserve_id = AddReserve(
2864
        $library_2->{branchcode}, $patron_2->{borrowernumber}, $item->{biblionumber},
2899
        {
2865
        '', 1, undef, undef, '', undef, $item->{itemnumber},
2900
            branchcode     => $library_2->{branchcode},
2901
            borrowernumber => $patron_2->{borrowernumber},
2902
            biblionumber   => $item->{biblionumber},
2903
            priority       => 1,
2904
            itemnumber     => $item->{itemnumber},
2905
        }
2866
    );
2906
    );
2867
2907
2868
    set_userenv( $library_1 );
2908
    set_userenv( $library_1 );
Lines 2899-2905 subtest 'Cancel transfers on lost items' => sub { Link Here
2899
2939
2900
    set_userenv( $library_2 );
2940
    set_userenv( $library_2 );
2901
    my $reserve_id = AddReserve(
2941
    my $reserve_id = AddReserve(
2902
        $library_2->{branchcode}, $patron_2->{borrowernumber}, $item->biblionumber, '', 1, undef, undef, '', undef, $item->itemnumber,
2942
        {
2943
            branchcode     => $library_2->{branchcode},
2944
            borrowernumber => $patron_2->{borrowernumber},
2945
            biblionumber   => $item->biblionumber,
2946
            priority       => 1,
2947
            itemnumber     => $item->itemnumber,
2948
        }
2903
    );
2949
    );
2904
2950
2905
    #Return book and add transfer
2951
    #Return book and add transfer
(-)a/t/db_dependent/Circulation/issue.t (-2 / +10 lines)
Lines 433-440 ok( $item2->permanent_location eq '' , q{UpdateItemLocationOnCheckin does not up Link Here
433
433
434
434
435
# Bug 14640 - Cancel the hold on checking out if asked
435
# Bug 14640 - Cancel the hold on checking out if asked
436
my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
436
my $reserve_id = AddReserve(
437
    undef,  1, undef, undef, "a note", "a title", undef, '');
437
    {
438
        branchcode     => $branchcode_1,
439
        borrowernumber => $borrower_id1,
440
        biblionumber   => $biblionumber,
441
        priority       => 1,
442
        notes          => "a note",
443
        title          => "a title",
444
    }
445
);
438
ok( $reserve_id, 'The reserve should have been inserted' );
446
ok( $reserve_id, 'The reserve should have been inserted' );
439
AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
447
AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
440
my $hold = Koha::Holds->find( $reserve_id );
448
my $hold = Koha::Holds->find( $reserve_id );
(-)a/t/db_dependent/Holds.t (-41 / +108 lines)
Lines 76-92 foreach (1..$borrowers_count) { Link Here
76
# Create five item level holds
76
# Create five item level holds
77
foreach my $borrowernumber ( @borrowernumbers ) {
77
foreach my $borrowernumber ( @borrowernumbers ) {
78
    AddReserve(
78
    AddReserve(
79
        $branch_1,
79
        {
80
        $borrowernumber,
80
            branchcode     => $branch_1,
81
        $biblio->biblionumber,
81
            borrowernumber => $borrowernumber,
82
        my $bibitems = q{},
82
            biblionumber   => $biblio->biblionumber,
83
        my $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ),
83
            priority       => C4::Reserves::CalculatePriority( $biblio->biblionumber ),
84
        my $resdate,
84
            itemnumber     => $itemnumber,
85
        my $expdate,
85
        }
86
        my $notes = q{},
87
        'a title',
88
        my $checkitem = $itemnumber,
89
        my $found,
90
    );
86
    );
91
}
87
}
92
88
Lines 191-209 is( $hold->suspend, 0, "Test resuming with SuspendAll()" ); Link Here
191
is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have no suspend until date" );
187
is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have no suspend until date" );
192
188
193
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
189
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
194
AddReserve(
190
    AddReserve(
195
    $branch_1,
191
        {
196
    $borrowernumbers[0],
192
            branchcode     => $branch_1,
197
    $biblio->biblionumber,
193
            borrowernumber => $borrowernumbers[0],
198
    my $bibitems = q{},
194
            biblionumber   => $biblio->biblionumber,
199
    my $priority,
195
        }
200
    my $resdate,
196
    );
201
    my $expdate,
197
202
    my $notes = q{},
203
    'a title',
204
    my $checkitem,
205
    my $found,
206
);
207
$patron = Koha::Patrons->find( $borrowernumber );
198
$patron = Koha::Patrons->find( $borrowernumber );
208
$holds = $patron->holds;
199
$holds = $patron->holds;
209
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
200
my $reserveid = Koha::Holds->search({ biblionumber => $biblio->biblionumber, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
Lines 297-307 ok( Link Here
297
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
288
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
298
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
289
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
299
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
290
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
300
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
291
    my $reserveid1 = AddReserve(
292
        {
293
            branchcode     => $branch_1,
294
            borrowernumber => $borrowernumbers[0],
295
            biblionumber   => $biblio->biblionumber,
296
            priority       => 1
297
        }
298
    );
299
301
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
300
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
302
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
301
    my $reserveid2 = AddReserve(
302
        {
303
            branchcode     => $branch_1,
304
            borrowernumber => $borrowernumbers[1],
305
            biblionumber   => $biblio->biblionumber,
306
            priority       => 2
307
        }
308
    );
309
303
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
310
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
304
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
311
    my $reserveid3 = AddReserve(
312
        {
313
            branchcode     => $branch_1,
314
            borrowernumber => $borrowernumbers[2],
315
            biblionumber   => $biblio->biblionumber,
316
            priority       => 3
317
        }
318
    );
319
305
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
320
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
306
    my $hold3 = Koha::Holds->find( $reserveid3 );
321
    my $hold3 = Koha::Holds->find( $reserveid3 );
307
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
322
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
Lines 335-345 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
335
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
350
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
336
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
351
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
337
AddReserve(
352
AddReserve(
338
    $branch_1,
353
    {
339
    $borrowernumbers[0],
354
        branchcode     => $branch_1,
340
    $biblio->biblionumber,
355
        borrowernumber => $borrowernumbers[0],
341
    '',
356
        biblionumber   => $biblio->biblionumber,
342
    1,
357
        priority       => 1,
358
    }
343
);
359
);
344
is(
360
is(
345
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
361
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
Lines 442-448 Koha::CirculationRules->set_rules( Link Here
442
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
458
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
443
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
459
    'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
444
460
445
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
461
my $res_id = AddReserve(
462
    {
463
        branchcode     => $branch_1,
464
        borrowernumber => $borrowernumbers[0],
465
        biblionumber   => $biblio->biblionumber,
466
        priority       => 1,
467
    }
468
);
446
469
447
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
470
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
448
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
471
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
Lines 474-482 subtest 'Test max_holds per library/patron category' => sub { Link Here
474
            }
497
            }
475
        }
498
        }
476
    );
499
    );
477
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
500
478
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
501
    for ( 1 .. 3 ) {
479
    AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, );
502
        AddReserve(
503
            {
504
                branchcode     => $branch_1,
505
                borrowernumber => $borrowernumbers[0],
506
                biblionumber   => $biblio->biblionumber,
507
                priority       => 1,
508
            }
509
        );
510
    }
480
511
481
    my $count =
512
    my $count =
482
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
513
      Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
Lines 635-641 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
635
        'Patron can reserve item with hold limit of 1, no holds placed'
666
        'Patron can reserve item with hold limit of 1, no holds placed'
636
    );
667
    );
637
668
638
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
669
    AddReserve(
670
        {
671
            branchcode     => $library->branchcode,
672
            borrowernumber => $patron->borrowernumber,
673
            biblionumber   => $biblio_1->biblionumber,
674
            priority       => 1,
675
        }
676
    );
639
677
640
    is_deeply(
678
    is_deeply(
641
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
679
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ),
Lines 662-668 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
662
    );
700
    );
663
701
664
    # Add a second reserve
702
    # Add a second reserve
665
    my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
703
    my $res_id = AddReserve(
704
        {
705
            branchcode     => $library->branchcode,
706
            borrowernumber => $patron->borrowernumber,
707
            biblionumber   => $biblio_2->biblionumber,
708
            priority       => 1,
709
        }
710
    );
666
    is_deeply(
711
    is_deeply(
667
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
712
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
668
        { status => 'tooManyReservesToday', limit => 2 },
713
        { status => 'tooManyReservesToday', limit => 2 },
Lines 718-731 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
718
        { status => 'OK' },
763
        { status => 'OK' },
719
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
764
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
720
    );
765
    );
721
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_1->biblionumber, '', 1, );
766
    AddReserve(
722
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_2->biblionumber, '', 1, );
767
        {
768
            branchcode     => $library->branchcode,
769
            borrowernumber => $patron->borrowernumber,
770
            biblionumber   => $biblio_1->biblionumber,
771
            priority       => 1,
772
        }
773
    );
774
    AddReserve(
775
        {
776
            branchcode     => $library->branchcode,
777
            borrowernumber => $patron->borrowernumber,
778
            biblionumber   => $biblio_2->biblionumber,
779
            priority       => 1,
780
        }
781
    );
782
723
    is_deeply(
783
    is_deeply(
724
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
784
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
725
        { status => 'OK' },
785
        { status => 'OK' },
726
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
786
        'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)'
727
    );
787
    );
728
    AddReserve( $library->branchcode, $patron->borrowernumber, $biblio_3->biblionumber, '', 1, );
788
    AddReserve(
789
        {
790
            branchcode     => $library->branchcode,
791
            borrowernumber => $patron->borrowernumber,
792
            biblionumber   => $biblio_3->biblionumber,
793
            priority       => 1,
794
        }
795
    );
729
    is_deeply(
796
    is_deeply(
730
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
797
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ),
731
        { status => 'tooManyReserves', limit => 3 },
798
        { status => 'tooManyReserves', limit => 3 },
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-10 / +80 lines)
Lines 85-103 Koha::CirculationRules->set_rules( Link Here
85
);
85
);
86
86
87
# Home branch matches pickup branch
87
# Home branch matches pickup branch
88
my $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
88
my $reserve_id = AddReserve(
89
    {
90
        branchcode     => $library_A,
91
        borrowernumber => $borrowernumber,
92
        biblionumber   => $biblionumber,
93
        priority       => 1,
94
    }
95
);
89
my ( $status ) = CheckReserves($itemnumber);
96
my ( $status ) = CheckReserves($itemnumber);
90
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
97
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
91
Koha::Holds->find( $reserve_id )->cancel;
98
Koha::Holds->find( $reserve_id )->cancel;
92
99
93
# Holding branch matches pickup branch
100
# Holding branch matches pickup branch
94
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
101
$reserve_id = AddReserve(
102
    {
103
        branchcode     => $library_B,
104
        borrowernumber => $borrowernumber,
105
        biblionumber   => $biblionumber,
106
        priority       => 1,
107
    }
108
);
95
( $status ) = CheckReserves($itemnumber);
109
( $status ) = CheckReserves($itemnumber);
96
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
110
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
97
Koha::Holds->find( $reserve_id )->cancel;
111
Koha::Holds->find( $reserve_id )->cancel;
98
112
99
# Neither branch matches pickup branch
113
# Neither branch matches pickup branch
100
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
114
$reserve_id = AddReserve(
115
    {
116
        branchcode     => $library_C,
117
        borrowernumber => $borrowernumber,
118
        biblionumber   => $biblionumber,
119
        priority       => 1,
120
    }
121
);
101
( $status ) = CheckReserves($itemnumber);
122
( $status ) = CheckReserves($itemnumber);
102
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
123
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
103
Koha::Holds->find( $reserve_id )->cancel;
124
Koha::Holds->find( $reserve_id )->cancel;
Lines 116-134 Koha::CirculationRules->set_rules( Link Here
116
);
137
);
117
138
118
# Home branch matches pickup branch
139
# Home branch matches pickup branch
119
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
140
$reserve_id = AddReserve(
141
    {
142
        branchcode     => $library_A,
143
        borrowernumber => $borrowernumber,
144
        biblionumber   => $biblionumber,
145
        priority       => 1,
146
    }
147
);
120
( $status ) = CheckReserves($itemnumber);
148
( $status ) = CheckReserves($itemnumber);
121
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
149
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
122
Koha::Holds->find( $reserve_id )->cancel;
150
Koha::Holds->find( $reserve_id )->cancel;
123
151
124
# Holding branch matches pickup branch
152
# Holding branch matches pickup branch
125
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
153
$reserve_id = AddReserve(
154
    {
155
        branchcode     => $library_B,
156
        borrowernumber => $borrowernumber,
157
        biblionumber   => $biblionumber,
158
        priority       => 1,
159
    }
160
);
126
( $status ) = CheckReserves($itemnumber);
161
( $status ) = CheckReserves($itemnumber);
127
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
162
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
128
Koha::Holds->find( $reserve_id )->cancel;
163
Koha::Holds->find( $reserve_id )->cancel;
129
164
130
# Neither branch matches pickup branch
165
# Neither branch matches pickup branch
131
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
166
$reserve_id = AddReserve(
167
    {
168
        branchcode     => $library_C,
169
        borrowernumber => $borrowernumber,
170
        biblionumber   => $biblionumber,
171
        priority       => 1,
172
    }
173
);
132
( $status ) = CheckReserves($itemnumber);
174
( $status ) = CheckReserves($itemnumber);
133
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
175
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
134
Koha::Holds->find( $reserve_id )->cancel;
176
Koha::Holds->find( $reserve_id )->cancel;
Lines 147-165 Koha::CirculationRules->set_rules( Link Here
147
);
189
);
148
190
149
# Home branch matches pickup branch
191
# Home branch matches pickup branch
150
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
192
$reserve_id = AddReserve(
193
    {
194
        branchcode     => $library_A,
195
        borrowernumber => $borrowernumber,
196
        biblionumber   => $biblionumber,
197
        priority       => 1,
198
    }
199
);
151
( $status ) = CheckReserves($itemnumber);
200
( $status ) = CheckReserves($itemnumber);
152
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
201
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
153
Koha::Holds->find( $reserve_id )->cancel;
202
Koha::Holds->find( $reserve_id )->cancel;
154
203
155
# Holding branch matches pickup branch
204
# Holding branch matches pickup branch
156
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
205
$reserve_id = AddReserve(
206
    {
207
        branchcode     => $library_B,
208
        borrowernumber => $borrowernumber,
209
        biblionumber   => $biblionumber,
210
        priority       => 1,
211
    }
212
);
157
( $status ) = CheckReserves($itemnumber);
213
( $status ) = CheckReserves($itemnumber);
158
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
214
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
159
Koha::Holds->find( $reserve_id )->cancel;
215
Koha::Holds->find( $reserve_id )->cancel;
160
216
161
# Neither branch matches pickup branch
217
# Neither branch matches pickup branch
162
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
218
$reserve_id = AddReserve(
219
    {
220
        branchcode     => $library_C,
221
        borrowernumber => $borrowernumber,
222
        biblionumber   => $biblionumber,
223
        priority       => 1,
224
    }
225
);
163
( $status ) = CheckReserves($itemnumber);
226
( $status ) = CheckReserves($itemnumber);
164
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
227
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
165
Koha::Holds->find( $reserve_id )->cancel;
228
Koha::Holds->find( $reserve_id )->cancel;
Lines 176-182 my $limit = Koha::Item::Transfer::Limit->new( Link Here
176
        itemtype   => $item->effective_itemtype,
239
        itemtype   => $item->effective_itemtype,
177
    }
240
    }
178
)->store();
241
)->store();
179
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
242
$reserve_id = AddReserve(
243
    {
244
        branchcode     => $library_C,
245
        borrowernumber => $borrowernumber,
246
        biblionumber   => $biblionumber,
247
        priority       => 1
248
    }
249
);
180
($status) = CheckReserves($itemnumber);
250
($status) = CheckReserves($itemnumber);
181
is( $status, '',  "No hold where branch transfer is not allowed" );
251
is( $status, '',  "No hold where branch transfer is not allowed" );
182
Koha::Holds->find($reserve_id)->cancel;
252
Koha::Holds->find($reserve_id)->cancel;
(-)a/t/db_dependent/Holds/HoldItemtypeLimit.t (-3 / +27 lines)
Lines 99-117 Koha::CirculationRules->set_rules( Link Here
99
);
99
);
100
100
101
# Itemtypes match
101
# Itemtypes match
102
my $reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
102
my $reserve_id = AddReserve(
103
    {
104
        branchcode     => $branchcode,
105
        borrowernumber => $borrowernumber,
106
        biblionumber   => $biblionumber,
107
        priority       => 1,
108
        itemtype       => $right_itemtype,
109
    }
110
);
103
my ( $status ) = CheckReserves($itemnumber);
111
my ( $status ) = CheckReserves($itemnumber);
104
is( $status, 'Reserved', "Hold where itemtype matches item's itemtype targed" );
112
is( $status, 'Reserved', "Hold where itemtype matches item's itemtype targed" );
105
Koha::Holds->find( $reserve_id )->cancel;
113
Koha::Holds->find( $reserve_id )->cancel;
106
114
107
# Itemtypes don't match
115
# Itemtypes don't match
108
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype );
116
$reserve_id = AddReserve(
117
    {
118
        branchcode     => $branchcode,
119
        borrowernumber => $borrowernumber,
120
        biblionumber   => $biblionumber,
121
        priority       => 1,
122
        itemtype       => $wrong_itemtype,
123
    }
124
);
125
109
( $status ) = CheckReserves($itemnumber);
126
( $status ) = CheckReserves($itemnumber);
110
is($status, q{}, "Hold where itemtype does not match item's itemtype not targeted" );
127
is($status, q{}, "Hold where itemtype does not match item's itemtype not targeted" );
111
Koha::Holds->find( $reserve_id )->cancel;
128
Koha::Holds->find( $reserve_id )->cancel;
112
129
113
# No itemtype set
130
# No itemtype set
114
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
131
$reserve_id = AddReserve(
132
    {
133
        branchcode     => $branchcode,
134
        borrowernumber => $borrowernumber,
135
        biblionumber   => $biblionumber,
136
        priority       => 1,
137
    }
138
);
115
( $status ) = CheckReserves($itemnumber);
139
( $status ) = CheckReserves($itemnumber);
116
is( $status, 'Reserved', "Item targeted with no hold itemtype set" );
140
is( $status, 'Reserved', "Item targeted with no hold itemtype set" );
117
Koha::Holds->find( $reserve_id )->cancel;
141
Koha::Holds->find( $reserve_id )->cancel;
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-11 / +6 lines)
Lines 69-85 foreach ( 1 .. $borrowers_count ) { Link Here
69
my $i = 1;
69
my $i = 1;
70
foreach my $borrowernumber (@borrowernumbers) {
70
foreach my $borrowernumber (@borrowernumbers) {
71
    AddReserve(
71
    AddReserve(
72
        $branchcodes[$i],
72
        {
73
        $borrowernumber,
73
            branchcode     => $branchcodes[$i],
74
        $biblio->biblionumber,
74
            borrowernumber => $borrowernumber,
75
        my $bibitems   = q{},
75
            biblionumber   => $biblio->biblionumber,
76
        my $priority = $i,
76
            priority       => $i,
77
        my $resdate,
77
        }
78
        my $expdate,
79
        my $notes = q{},
80
        'a title',
81
        my $checkitem,
82
        my $found,
83
    );
78
    );
84
79
85
    $i++;
80
    $i++;
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-11 / +5 lines)
Lines 73-89 foreach my $i ( 1 .. $borrowers_count ) { Link Here
73
# Create five item level holds
73
# Create five item level holds
74
foreach my $borrowernumber (@borrowernumbers) {
74
foreach my $borrowernumber (@borrowernumbers) {
75
    AddReserve(
75
    AddReserve(
76
        $branchcode,
76
        {
77
        $borrowernumber,
77
            branchcode     => $branchcode,
78
        $biblio->biblionumber,
78
            borrowernumber => $borrowernumber,
79
        my $bibitems   = q{},
79
            biblionumber   => $biblio->biblionumber,
80
        my $priority,
80
        }
81
        my $resdate,
82
        my $expdate,
83
        my $notes = q{},
84
        'a title',
85
        my $checkitem,
86
        my $found,
87
    );
81
    );
88
}
82
}
89
83
(-)a/t/db_dependent/HoldsQueue.t (-36 / +195 lines)
Lines 114-120 $dbh->do("DELETE FROM reserves"); Link Here
114
my $bibitems = undef;
114
my $bibitems = undef;
115
my $priority = 1;
115
my $priority = 1;
116
# Make a reserve
116
# Make a reserve
117
AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $bibitems,  $priority );
117
AddReserve(
118
    {
119
        branchcode     => $borrower_branchcode,
120
        borrowernumber => $borrowernumber,
121
        biblionumber   => $biblionumber,
122
        priority       => $priority,
123
    }
124
);
118
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
125
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
119
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
126
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
120
127
Lines 533-539 $dbh->do( "UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQ Link Here
533
    undef, join( ',', $library_B, $library_A, $library_C ) );
540
    undef, join( ',', $library_B, $library_A, $library_C ) );
534
$dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHoldsQueueWeight'" );
541
$dbh->do( "UPDATE systempreferences SET value = 0 WHERE variable = 'RandomizeHoldsQueueWeight'" );
535
542
536
my $reserve_id = AddReserve ( $library_C, $borrowernumber, $biblionumber, '', 1 );
543
my $reserve_id = AddReserve(
544
    {
545
        branchcode     => $library_C,
546
        borrowernumber => $borrowernumber,
547
        biblionumber   => $biblionumber,
548
        priority       => 1,
549
    }
550
);
537
C4::HoldsQueue::CreateQueue();
551
C4::HoldsQueue::CreateQueue();
538
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
552
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
539
is( @$holds_queue, 1, "Bug 14297 - Holds Queue building ignoring holds where pickup & home branch don't match and item is not from le");
553
is( @$holds_queue, 1, "Bug 14297 - Holds Queue building ignoring holds where pickup & home branch don't match and item is not from le");
Lines 577-583 $dbh->do(" Link Here
577
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
591
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
578
");
592
");
579
593
580
$reserve_id = AddReserve ( $library_B, $borrowernumber, $biblionumber, '', 1 );
594
$reserve_id = AddReserve(
595
    {
596
        branchcode     => $library_B,
597
        borrowernumber => $borrowernumber,
598
        biblionumber   => $biblionumber,
599
        priority       => 1,
600
    }
601
);
602
581
C4::HoldsQueue::CreateQueue();
603
C4::HoldsQueue::CreateQueue();
582
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
604
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
583
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
605
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
Lines 628-648 Koha::CirculationRules->set_rules( Link Here
628
);
650
);
629
651
630
# Home branch matches pickup branch
652
# Home branch matches pickup branch
631
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
653
$reserve_id = AddReserve(
654
    {
655
        branchcode     => $library_A,
656
        borrowernumber => $borrowernumber,
657
        biblionumber   => $biblionumber,
658
        priority       => 1,
659
    }
660
);
661
632
C4::HoldsQueue::CreateQueue();
662
C4::HoldsQueue::CreateQueue();
633
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
663
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
634
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
664
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
635
Koha::Holds->find( $reserve_id )->cancel;
665
Koha::Holds->find( $reserve_id )->cancel;
636
666
637
# Holding branch matches pickup branch
667
# Holding branch matches pickup branch
638
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
668
$reserve_id = AddReserve(
669
    {
670
        branchcode     => $library_B,
671
        borrowernumber => $borrowernumber,
672
        biblionumber   => $biblionumber,
673
        priority       => 1,
674
    }
675
);
676
677
639
C4::HoldsQueue::CreateQueue();
678
C4::HoldsQueue::CreateQueue();
640
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
679
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
641
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
680
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
642
Koha::Holds->find( $reserve_id )->cancel;
681
Koha::Holds->find( $reserve_id )->cancel;
643
682
644
# Neither branch matches pickup branch
683
# Neither branch matches pickup branch
645
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
684
$reserve_id = AddReserve(
685
    {
686
        branchcode     => $library_C,
687
        borrowernumber => $borrowernumber,
688
        biblionumber   => $biblionumber,
689
        priority       => 1,
690
    }
691
);
692
646
C4::HoldsQueue::CreateQueue();
693
C4::HoldsQueue::CreateQueue();
647
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
694
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
648
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
695
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
Lines 662-682 Koha::CirculationRules->set_rules( Link Here
662
);
709
);
663
710
664
# Home branch matches pickup branch
711
# Home branch matches pickup branch
665
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
712
$reserve_id = AddReserve(
713
    {
714
        branchcode     => $library_A,
715
        borrowernumber => $borrowernumber,
716
        biblionumber   => $biblionumber,
717
        priority       => 1,
718
    }
719
);
720
666
C4::HoldsQueue::CreateQueue();
721
C4::HoldsQueue::CreateQueue();
667
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
722
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
668
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
723
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
669
Koha::Holds->find( $reserve_id )->cancel;
724
Koha::Holds->find( $reserve_id )->cancel;
670
725
671
# Holding branch matches pickup branch
726
# Holding branch matches pickup branch
672
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
727
$reserve_id = AddReserve(
728
    {
729
        branchcode     => $library_B,
730
        borrowernumber => $borrowernumber,
731
        biblionumber   => $biblionumber,
732
        priority       => 1,
733
    }
734
);
735
673
C4::HoldsQueue::CreateQueue();
736
C4::HoldsQueue::CreateQueue();
674
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
737
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
675
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
738
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
676
Koha::Holds->find( $reserve_id )->cancel;
739
Koha::Holds->find( $reserve_id )->cancel;
677
740
678
# Neither branch matches pickup branch
741
# Neither branch matches pickup branch
679
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
742
$reserve_id = AddReserve(
743
    {
744
        branchcode     => $library_C,
745
        borrowernumber => $borrowernumber,
746
        biblionumber   => $biblionumber,
747
        priority       => 1,
748
    }
749
);
750
680
C4::HoldsQueue::CreateQueue();
751
C4::HoldsQueue::CreateQueue();
681
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
752
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
682
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
753
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
Lines 696-716 Koha::CirculationRules->set_rules( Link Here
696
);
767
);
697
768
698
# Home branch matches pickup branch
769
# Home branch matches pickup branch
699
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
770
$reserve_id = AddReserve(
771
    {
772
        branchcode     => $library_A,
773
        borrowernumber => $borrowernumber,
774
        biblionumber   => $biblionumber,
775
        priority       => 1,
776
    }
777
);
778
700
C4::HoldsQueue::CreateQueue();
779
C4::HoldsQueue::CreateQueue();
701
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
780
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
702
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
781
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
703
Koha::Holds->find( $reserve_id )->cancel;
782
Koha::Holds->find( $reserve_id )->cancel;
704
783
705
# Holding branch matches pickup branch
784
# Holding branch matches pickup branch
706
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
785
$reserve_id = AddReserve(
786
    {
787
        branchcode     => $library_B,
788
        borrowernumber => $borrowernumber,
789
        biblionumber   => $biblionumber,
790
        priority       => 1,
791
    }
792
);
793
707
C4::HoldsQueue::CreateQueue();
794
C4::HoldsQueue::CreateQueue();
708
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
795
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
709
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
796
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
710
Koha::Holds->find( $reserve_id )->cancel;
797
Koha::Holds->find( $reserve_id )->cancel;
711
798
712
# Neither branch matches pickup branch
799
# Neither branch matches pickup branch
713
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
800
$reserve_id = AddReserve(
801
    {
802
        branchcode     => $library_C,
803
        borrowernumber => $borrowernumber,
804
        biblionumber   => $biblionumber,
805
        priority       => 1,
806
    }
807
);
808
714
C4::HoldsQueue::CreateQueue();
809
C4::HoldsQueue::CreateQueue();
715
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
810
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
716
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
811
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
Lines 763-783 Koha::CirculationRules->set_rules( Link Here
763
);
858
);
764
859
765
# Home branch matches pickup branch
860
# Home branch matches pickup branch
766
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype );
861
$reserve_id = AddReserve(
862
    {
863
        branchcode     => $library_A,
864
        borrowernumber => $borrowernumber,
865
        biblionumber   => $biblionumber,
866
        priority       => 1,
867
        itemtype       => $wrong_itemtype,
868
    }
869
);
870
767
C4::HoldsQueue::CreateQueue();
871
C4::HoldsQueue::CreateQueue();
768
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
872
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
769
is( @$holds_queue, 0, "Item with incorrect itemtype not targeted" );
873
is( @$holds_queue, 0, "Item with incorrect itemtype not targeted" );
770
Koha::Holds->find( $reserve_id )->cancel;
874
Koha::Holds->find( $reserve_id )->cancel;
771
875
772
# Holding branch matches pickup branch
876
# Holding branch matches pickup branch
773
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
877
$reserve_id = AddReserve(
878
    {
879
        branchcode     => $library_A,
880
        borrowernumber => $borrowernumber,
881
        biblionumber   => $biblionumber,
882
        priority       => 1,
883
        itemtype       => $right_itemtype,
884
    }
885
);
886
774
C4::HoldsQueue::CreateQueue();
887
C4::HoldsQueue::CreateQueue();
775
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
888
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
776
is( @$holds_queue, 1, "Item with matching itemtype is targeted" );
889
is( @$holds_queue, 1, "Item with matching itemtype is targeted" );
777
Koha::Holds->find( $reserve_id )->cancel;
890
Koha::Holds->find( $reserve_id )->cancel;
778
891
779
# Neither branch matches pickup branch
892
# Neither branch matches pickup branch
780
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
893
$reserve_id = AddReserve(
894
    {
895
        branchcode     => $library_A,
896
        borrowernumber => $borrowernumber,
897
        biblionumber   => $biblionumber,
898
        priority       => 1,
899
    }
900
);
901
781
C4::HoldsQueue::CreateQueue();
902
C4::HoldsQueue::CreateQueue();
782
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
903
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
783
is( @$holds_queue, 1, "Item targeted when hold itemtype is not set" );
904
is( @$holds_queue, 1, "Item targeted when hold itemtype is not set" );
Lines 819-830 subtest "Test Local Holds Priority - Bib level" => sub { Link Here
819
        }
940
        }
820
    );
941
    );
821
942
822
    my $reserve_id =
943
    my $reserve_id = AddReserve(
823
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
944
        {
824
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
945
            branchcode     => $branch2->branchcode,
825
    my $reserve_id2 =
946
            borrowernumber => $other_patron->borrowernumber,
826
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
947
            biblionumber   => $biblio->biblionumber,
827
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, undef, undef, undef );
948
            priority       => 1,
949
        }
950
    );
951
    my $reserve_id2 = AddReserve(
952
        {
953
            branchcode     => $item->homebranch,
954
            borrowernumber => $local_patron->borrowernumber,
955
            biblionumber   => $biblio->biblionumber,
956
            priority       => 2,
957
        }
958
    );
828
959
829
    C4::HoldsQueue::CreateQueue();
960
    C4::HoldsQueue::CreateQueue();
830
961
Lines 871-882 subtest "Test Local Holds Priority - Item level" => sub { Link Here
871
        }
1002
        }
872
    );
1003
    );
873
1004
874
    my $reserve_id =
1005
    my $reserve_id = AddReserve(
875
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
1006
        {
876
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, $item->id, undef, undef );
1007
            branchcode     => $branch2->branchcode,
877
    my $reserve_id2 =
1008
            borrowernumber => $other_patron->borrowernumber,
878
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
1009
            biblionumber   => $biblio->biblionumber,
879
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, $item->id, undef, undef );
1010
            priority       => 1,
1011
            itemnumber     => $item->id,
1012
        }
1013
    );
1014
    my $reserve_id2 = AddReserve(
1015
        {
1016
            branchcode     => $item->homebranch,
1017
            borrowernumber => $local_patron->borrowernumber,
1018
            biblionumber   => $biblio->biblionumber,
1019
            priority       => 2,
1020
            itemnumber     => $item->id,
1021
        }
1022
    );
880
1023
881
    C4::HoldsQueue::CreateQueue();
1024
    C4::HoldsQueue::CreateQueue();
882
1025
Lines 924-935 subtest "Test Local Holds Priority - Item level hold over Record level hold (Bug Link Here
924
        }
1067
        }
925
    );
1068
    );
926
1069
927
    my $reserve_id =
1070
    my $reserve_id = AddReserve(
928
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
1071
        {
929
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
1072
            branchcode     => $branch2->branchcode,
930
    my $reserve_id2 =
1073
            borrowernumber => $other_patron->borrowernumber,
931
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
1074
            biblionumber   => $biblio->biblionumber,
932
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, $item->id, undef, undef );
1075
            priority       => 1,
1076
        }
1077
    );
1078
    my $reserve_id2 = AddReserve(
1079
        {
1080
            branchcode     => $item->homebranch,
1081
            borrowernumber => $local_patron->borrowernumber,
1082
            biblionumber   => $biblio->biblionumber,
1083
            priority       => 2,
1084
            itemnumber     => $item->id,
1085
        }
1086
    );
933
1087
934
    C4::HoldsQueue::CreateQueue();
1088
    C4::HoldsQueue::CreateQueue();
935
1089
Lines 987-995 subtest "Test Local Holds Priority - Ensure no duplicate requests in holds queue Link Here
987
        }
1141
        }
988
    );
1142
    );
989
1143
990
    $reserve_id =
1144
    $reserve_id = AddReserve(
991
      AddReserve( $item1->homebranch, $patron->borrowernumber, $biblio->id, '',
1145
        {
992
        1, undef, undef, undef, undef, undef, undef, undef );
1146
            branchcode     => $item1->homebranch,
1147
            borrowernumber => $patron->borrowernumber,
1148
            biblionumber   => $biblio->id,
1149
            priority       => 1
1150
        }
1151
    );
993
1152
994
    C4::HoldsQueue::CreateQueue();
1153
    C4::HoldsQueue::CreateQueue();
995
1154
(-)a/t/db_dependent/Items/GetItemsForInventory.t (-9 / +28 lines)
Lines 100-114 subtest 'Skip items with waiting holds' => sub { Link Here
100
    is( $first_items_count + 2, $second_items_count, 'Two items added, count makes sense' );
100
    is( $first_items_count + 2, $second_items_count, 'Two items added, count makes sense' );
101
101
102
    # Add 2 waiting holds
102
    # Add 2 waiting holds
103
    C4::Reserves::AddReserve( $library->branchcode, $patron_1->borrowernumber,
103
    C4::Reserves::AddReserve(
104
        $item_1->biblionumber, '', 1, undef, undef, '', "title for fee",
104
        {
105
        $item_1->itemnumber, 'W' );
105
            branchcode     => $library->branchcode,
106
    C4::Reserves::AddReserve( $library->branchcode, $patron_1->borrowernumber,
106
            borrowernumber => $patron_1->borrowernumber,
107
        $item_2->biblionumber, '', 1, undef, undef, '', "title for fee",
107
            biblionumber   => $item_1->biblionumber,
108
        $item_2->itemnumber, undef );
108
            priority       => 1,
109
    C4::Reserves::AddReserve( $library->branchcode, $patron_2->borrowernumber,
109
            itemnumber     => $item_1->itemnumber,
110
        $item_2->biblionumber, '', 2, undef, undef, '', "title for fee",
110
            found          => 'W'
111
        $item_2->itemnumber, undef );
111
        }
112
    );
113
    C4::Reserves::AddReserve(
114
        {
115
            branchcode     => $library->branchcode,
116
            borrowernumber => $patron_1->borrowernumber,
117
            biblionumber   => $item_2->biblionumber,
118
            priority       => 1,
119
            itemnumber     => $item_2->itemnumber,
120
        }
121
    );
122
    C4::Reserves::AddReserve(
123
        {
124
            branchcode     => $library->branchcode,
125
            borrowernumber => $patron_2->borrowernumber,
126
            biblionumber   => $item_2->biblionumber,
127
            priority       => 2,
128
            itemnumber     => $item_2->itemnumber,
129
        }
130
    );
112
131
113
    my ( $new_items, $new_items_count ) = GetItemsForInventory( { ignore_waiting_holds => 1 } );
132
    my ( $new_items, $new_items_count ) = GetItemsForInventory( { ignore_waiting_holds => 1 } );
114
    is( $new_items_count, $first_items_count + 1, 'Item on hold skipped, count makes sense' );
133
    is( $new_items_count, $first_items_count + 1, 'Item on hold skipped, count makes sense' );
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-15 / +21 lines)
Lines 296-321 subtest 'current_item_level_holds() tests' => sub { Link Here
296
    my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
296
    my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
297
297
298
    C4::Reserves::AddReserve(
298
    C4::Reserves::AddReserve(
299
        $patron->branchcode,   $patron->borrowernumber,
299
        {
300
        $biblio->biblionumber, undef,
300
            branchcode       => $patron->branchcode,
301
        undef, dt_from_string->add( days => -2 ),
301
            borrowernumber   => $patron->borrowernumber,
302
        undef, undef,
302
            biblionumber     => $biblio->biblionumber,
303
        undef, $item_1->itemnumber
303
            reservation_date => dt_from_string->add( days => -2 ),
304
            itemnumber       => $item_1->itemnumber,
305
        }
304
    );
306
    );
305
    C4::Reserves::AddReserve(
307
    C4::Reserves::AddReserve(
306
        $patron->branchcode,   $patron->borrowernumber,
308
        {
307
        $biblio->biblionumber, undef,
309
            branchcode       => $patron->branchcode,
308
        undef, dt_from_string->add( days => -2 ),
310
            borrowernumber   => $patron->borrowernumber,
309
        undef, undef,
311
            biblionumber     => $biblio->biblionumber,
310
        undef, $item_2->itemnumber
312
            reservation_date => dt_from_string->add( days => -2 ),
313
            itemnumber       => $item_2->itemnumber,
314
        }
311
    );
315
    );
312
    # Add a hold in the future
316
    # Add a hold in the future
313
    C4::Reserves::AddReserve(
317
    C4::Reserves::AddReserve(
314
        $patron->branchcode,   $patron->borrowernumber,
318
        {
315
        $biblio->biblionumber, undef,
319
            branchcode       => $patron->branchcode,
316
        undef, dt_from_string->add( days => 2 ),
320
            borrowernumber   => $patron->borrowernumber,
317
        undef, undef,
321
            biblionumber     => $biblio->biblionumber,
318
        undef, $item_3->itemnumber
322
            reservation_date => dt_from_string->add( days => 2 ),
323
            itemnumber       => $item_3->itemnumber,
324
        }
319
    );
325
    );
320
326
321
    # Add an order with no biblionumber
327
    # Add an order with no biblionumber
(-)a/t/db_dependent/Koha/Biblios.t (-2 / +15 lines)
Lines 64-70 subtest 'store' => sub { Link Here
64
64
65
subtest 'holds + current_holds' => sub {
65
subtest 'holds + current_holds' => sub {
66
    plan tests => 5;
66
    plan tests => 5;
67
    C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber );
67
    C4::Reserves::AddReserve(
68
        {
69
            branchcode     => $patron->branchcode,
70
            borrowernumber => $patron->borrowernumber,
71
            biblionumber   => $biblio->biblionumber,
72
        }
73
    );
68
    my $holds = $biblio->holds;
74
    my $holds = $biblio->holds;
69
    is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' );
75
    is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' );
70
    is( $holds->count, 1, '->holds should only return 1 hold' );
76
    is( $holds->count, 1, '->holds should only return 1 hold' );
Lines 72-78 subtest 'holds + current_holds' => sub { Link Here
72
    $holds->delete;
78
    $holds->delete;
73
79
74
    # Add a hold in the future
80
    # Add a hold in the future
75
    C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber, undef, undef, dt_from_string->add( days => 2 ) );
81
    C4::Reserves::AddReserve(
82
        {
83
            branchcode       => $patron->branchcode,
84
            borrowernumber   => $patron->borrowernumber,
85
            biblionumber     => $biblio->biblionumber,
86
            reservation_date => dt_from_string->add( days => 2 ),
87
        }
88
    );
76
    $holds = $biblio->holds;
89
    $holds = $biblio->holds;
77
    is( $holds->count, 1, '->holds should return future holds' );
90
    is( $holds->count, 1, '->holds should return future holds' );
78
    $holds = $biblio->current_holds;
91
    $holds = $biblio->current_holds;
(-)a/t/db_dependent/Koha/Holds.t (-38 / +47 lines)
Lines 60-70 subtest 'cancel' => sub { Link Here
60
            }
60
            }
61
        );
61
        );
62
        my $reserve_id = C4::Reserves::AddReserve(
62
        my $reserve_id = C4::Reserves::AddReserve(
63
            $library->branchcode, $patron->borrowernumber,
63
            {
64
            $item->biblionumber,  '',
64
                branchcode     => $library->branchcode,
65
            $priority,            undef,
65
                borrowernumber => $patron->borrowernumber,
66
            undef,                '',
66
                biblionumber   => $item->biblionumber,
67
            "title for fee",      $item->itemnumber,
67
                priority       => $priority,
68
                title          => "title for fee",
69
                itemnumber     => $item->itemnumber,
70
            }
68
        );
71
        );
69
        my $hold = Koha::Holds->find($reserve_id);
72
        my $hold = Koha::Holds->find($reserve_id);
70
        push @patrons, $patron;
73
        push @patrons, $patron;
Lines 107-136 subtest 'cancel' => sub { Link Here
107
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $patron_category->categorycode } });
110
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $patron_category->categorycode } });
108
        is( $patron->account->balance, 0, 'A new patron does not have any charges' );
111
        is( $patron->account->balance, 0, 'A new patron does not have any charges' );
109
112
110
        my @hold_info = (
113
        my $hold_info = {
111
            $library->branchcode, $patron->borrowernumber,
114
            branchcode     => $library->branchcode,
112
            $item->biblionumber,  '',
115
            borrowernumber => $patron->borrowernumber,
113
            1,                    undef,
116
            biblionumber   => $item->biblionumber,
114
            undef,                '',
117
            priority       => 1,
115
            "title for fee",      $item->itemnumber,
118
            title          => "title for fee",
116
        );
119
            itemnumber     => $item->itemnumber,
120
        };
117
121
118
        # First, test cancelling a reserve when there's no charge configured.
122
        # First, test cancelling a reserve when there's no charge configured.
119
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
123
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
120
        my $reserve_id = C4::Reserves::AddReserve( @hold_info );
124
        my $reserve_id = C4::Reserves::AddReserve( $hold_info );
121
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
125
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
122
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=0 - The patron should not have been charged' );
126
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=0 - The patron should not have been charged' );
123
127
124
        # Then, test cancelling a reserve when there's no charge desired.
128
        # Then, test cancelling a reserve when there's no charge desired.
125
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
129
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
126
        $reserve_id = C4::Reserves::AddReserve( @hold_info );
130
        $reserve_id = C4::Reserves::AddReserve( $hold_info );
127
        Koha::Holds->find( $reserve_id )->cancel(); # charge_cancel_fee => 0
131
        Koha::Holds->find( $reserve_id )->cancel(); # charge_cancel_fee => 0
128
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=42, but charge_cancel_fee => 0, The patron should not have been charged' );
132
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=42, but charge_cancel_fee => 0, The patron should not have been charged' );
129
133
130
134
131
        # Finally, test cancelling a reserve when there's a charge desired and configured.
135
        # Finally, test cancelling a reserve when there's a charge desired and configured.
132
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
136
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
133
        $reserve_id = C4::Reserves::AddReserve( @hold_info );
137
        $reserve_id = C4::Reserves::AddReserve( $hold_info );
134
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
138
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
135
        is( int($patron->account->balance), 42, 'ExpireReservesMaxPickUpDelayCharge=42 and charge_cancel_fee => 1, The patron should have been charged!' );
139
        is( int($patron->account->balance), 42, 'ExpireReservesMaxPickUpDelayCharge=42 and charge_cancel_fee => 1, The patron should have been charged!' );
136
    };
140
    };
Lines 139-150 subtest 'cancel' => sub { Link Here
139
        plan tests => 1;
143
        plan tests => 1;
140
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
144
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
141
        my $reserve_id = C4::Reserves::AddReserve(
145
        my $reserve_id = C4::Reserves::AddReserve(
142
            $library->branchcode, $patron->borrowernumber,
146
            {
143
            $item->biblionumber,  '',
147
                branchcode     => $library->branchcode,
144
            1,                    undef,
148
                borrowernumber => $patron->borrowernumber,
145
            undef,                '',
149
                biblionumber   => $item->biblionumber,
146
            "title for fee",      $item->itemnumber,
150
                priority       => 1,
147
            'W',
151
                title          => "title for fee",
152
                itemnumber     => $item->itemnumber,
153
                found          => 'W',
154
            }
148
        );
155
        );
149
        Koha::Holds->find( $reserve_id )->cancel;
156
        Koha::Holds->find( $reserve_id )->cancel;
150
        my $hold_old = Koha::Old::Holds->find( $reserve_id );
157
        my $hold_old = Koha::Old::Holds->find( $reserve_id );
Lines 154-175 subtest 'cancel' => sub { Link Here
154
    subtest 'HoldsLog' => sub {
161
    subtest 'HoldsLog' => sub {
155
        plan tests => 2;
162
        plan tests => 2;
156
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
163
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
157
        my @hold_info = (
164
        my $hold_info = {
158
            $library->branchcode, $patron->borrowernumber,
165
            branchcode     => $library->branchcode,
159
            $item->biblionumber,  '',
166
            borrowernumber => $patron->borrowernumber,
160
            1,                    undef,
167
            biblionumber   => $item->biblionumber,
161
            undef,                '',
168
            priority       => 1,
162
            "title for fee",      $item->itemnumber,
169
            title          => "title for fee",
163
        );
170
            itemnumber     => $item->itemnumber,
171
        };
164
172
165
        t::lib::Mocks::mock_preference('HoldsLog', 0);
173
        t::lib::Mocks::mock_preference('HoldsLog', 0);
166
        my $reserve_id = C4::Reserves::AddReserve(@hold_info);
174
        my $reserve_id = C4::Reserves::AddReserve($hold_info);
167
        Koha::Holds->find( $reserve_id )->cancel;
175
        Koha::Holds->find( $reserve_id )->cancel;
168
        my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
176
        my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
169
        is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
177
        is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
170
178
171
        t::lib::Mocks::mock_preference('HoldsLog', 1);
179
        t::lib::Mocks::mock_preference('HoldsLog', 1);
172
        $reserve_id = C4::Reserves::AddReserve(@hold_info);
180
        $reserve_id = C4::Reserves::AddReserve($hold_info);
173
        Koha::Holds->find( $reserve_id )->cancel;
181
        Koha::Holds->find( $reserve_id )->cancel;
174
        $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
182
        $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
175
        is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
183
        is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
Lines 189-204 subtest 'cancel' => sub { Link Here
189
                value => { categorycode => $patron_category->categorycode }
197
                value => { categorycode => $patron_category->categorycode }
190
            }
198
            }
191
        );
199
        );
192
        my @hold_info = (
200
        my $hold_info = {
193
            $library->branchcode, $patron->borrowernumber,
201
            branchcode     => $library->branchcode,
194
            $item->biblionumber,  '',
202
            borrowernumber => $patron->borrowernumber,
195
            1,                    undef,
203
            biblionumber   => $item->biblionumber,
196
            undef,                '',
204
            priority       => 1,
197
            "title for fee",      $item->itemnumber,
205
            title          => "title for fee",
198
        );
206
            itemnumber     => $item->itemnumber,
207
        };
199
208
200
        t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',42 );
209
        t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',42 );
201
        my $reserve_id = C4::Reserves::AddReserve(@hold_info);
210
        my $reserve_id = C4::Reserves::AddReserve($hold_info);
202
        my $hold       = Koha::Holds->find($reserve_id);
211
        my $hold       = Koha::Holds->find($reserve_id);
203
212
204
        # Add a row with the same id to make the cancel fails
213
        # Add a row with the same id to make the cancel fails
(-)a/t/db_dependent/Koha/Patrons.t (-4 / +15 lines)
Lines 919-929 subtest 'holds and old_holds' => sub { Link Here
919
        'Koha::Patron->holds should return a Koha::Holds objects' );
919
        'Koha::Patron->holds should return a Koha::Holds objects' );
920
    is( $holds->count, 0, 'There should not be holds placed by this patron yet' );
920
    is( $holds->count, 0, 'There should not be holds placed by this patron yet' );
921
921
922
    C4::Reserves::AddReserve( $library->{branchcode},
922
    C4::Reserves::AddReserve(
923
        $patron->borrowernumber, $biblionumber_1 );
923
        {
924
            branchcode     => $library->{branchcode},
925
            borrowernumber => $patron->borrowernumber,
926
            biblionumber   => $biblionumber_1
927
        }
928
    );
924
    # In the future
929
    # In the future
925
    C4::Reserves::AddReserve( $library->{branchcode},
930
    C4::Reserves::AddReserve(
926
        $patron->borrowernumber, $biblionumber_2, undef, undef, dt_from_string->add( days => 2 ) );
931
        {
932
            branchcode      => $library->{branchcode},
933
            borrowernumber  => $patron->borrowernumber,
934
            biblionumber    => $biblionumber_2,
935
            expiration_date => dt_from_string->add( days => 2 )
936
        }
937
    );
927
938
928
    $holds = $patron->holds;
939
    $holds = $patron->holds;
929
    is( $holds->count, 2, 'There should be 2 holds placed by this patron' );
940
    is( $holds->count, 2, 'There should be 2 holds placed by this patron' );
(-)a/t/db_dependent/Letters/TemplateToolkit.t (-2 / +19 lines)
Lines 524-531 You have [% count %] items due Link Here
524
524
525
        my $code = 'HOLD_SLIP';
525
        my $code = 'HOLD_SLIP';
526
526
527
        C4::Reserves::AddReserve( $library->{branchcode}, $patron->{borrowernumber}, $biblio1->{biblionumber}, undef, undef, undef, undef, "a note", undef, $item1->{itemnumber}, 'W' );
527
        C4::Reserves::AddReserve(
528
        C4::Reserves::AddReserve( $library->{branchcode}, $patron->{borrowernumber}, $biblio2->{biblionumber}, undef, undef, undef, undef, "another note", undef, $item2->{itemnumber} );
528
            {
529
                branchcode     => $library->{branchcode},
530
                borrowernumber => $patron->{borrowernumber},
531
                biblionumber   => $biblio1->{biblionumber},
532
                notes          => "a note",
533
                itemnumber     => $item1->{itemnumber},
534
                found          => 'W'
535
            }
536
        );
537
        C4::Reserves::AddReserve(
538
            {
539
                branchcode     => $library->{branchcode},
540
                borrowernumber => $patron->{borrowernumber},
541
                biblionumber   => $biblio2->{biblionumber},
542
                notes          => "another note",
543
                itemnumber     => $item2->{itemnumber},
544
            }
545
        );
529
546
530
        my $template = <<EOF;
547
        my $template = <<EOF;
531
<h5>Date: <<today>></h5>
548
<h5>Date: <<today>></h5>
(-)a/t/db_dependent/Reserves.t (-91 / +248 lines)
Lines 116-134 my $borrower = $patron->unblessed; Link Here
116
my $biblionumber   = $bibnum;
116
my $biblionumber   = $bibnum;
117
my $barcode        = $testbarcode;
117
my $barcode        = $testbarcode;
118
118
119
my $bibitems       = '';
120
my $priority       = '1';
121
my $resdate        = undef;
122
my $expdate        = undef;
123
my $notes          = '';
124
my $checkitem      = undef;
125
my $found          = undef;
126
127
my $branchcode = Koha::Libraries->search->next->branchcode;
119
my $branchcode = Koha::Libraries->search->next->branchcode;
128
120
129
AddReserve($branchcode,    $borrowernumber, $biblionumber,
121
AddReserve(
130
        $bibitems,  $priority, $resdate, $expdate, $notes,
122
    {
131
        'a title',      $checkitem, $found);
123
        branchcode     => $branchcode,
124
        borrowernumber => $borrowernumber,
125
        biblionumber   => $biblionumber,
126
        priority       => 1,
127
    }
128
);
132
129
133
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
130
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
134
131
Lines 251-265 my ($itemnum_cpl, $itemnum_fpl); Link Here
251
# Ensure that priorities are numbered correcly when a hold is moved to waiting
248
# Ensure that priorities are numbered correcly when a hold is moved to waiting
252
# (bug 11947)
249
# (bug 11947)
253
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
250
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
254
AddReserve($branch_3,  $requesters{$branch_3}, $bibnum2,
251
AddReserve(
255
           $bibitems,  1, $resdate, $expdate, $notes,
252
    {
256
           'a title',      $checkitem, $found);
253
        branchcode     => $branch_3,
257
AddReserve($branch_2,  $requesters{$branch_2}, $bibnum2,
254
        borrowernumber => $requesters{$branch_3},
258
           $bibitems,  2, $resdate, $expdate, $notes,
255
        biblionumber   => $bibnum2,
259
           'a title',      $checkitem, $found);
256
        priority       => 1,
260
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum2,
257
    }
261
           $bibitems,  3, $resdate, $expdate, $notes,
258
);
262
           'a title',      $checkitem, $found);
259
AddReserve(
260
    {
261
        branchcode     => $branch_2,
262
        borrowernumber => $requesters{$branch_2},
263
        biblionumber   => $bibnum2,
264
        priority       => 2,
265
    }
266
);
267
AddReserve(
268
    {
269
        branchcode     => $branch_1,
270
        borrowernumber => $requesters{$branch_1},
271
        biblionumber   => $bibnum2,
272
        priority       => 3,
273
    }
274
);
263
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
275
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
264
276
265
# Now it should have different priorities.
277
# Now it should have different priorities.
Lines 275-289 is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the Link Here
275
287
276
288
277
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
289
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
278
AddReserve($branch_3,  $requesters{$branch_3}, $bibnum2,
290
AddReserve(
279
           $bibitems,  1, $resdate, $expdate, $notes,
291
    {
280
           'a title',      $checkitem, $found);
292
        branchcode     => $branch_3,
281
AddReserve($branch_2,  $requesters{$branch_2}, $bibnum2,
293
        borrowernumber => $requesters{$branch_3},
282
           $bibitems,  2, $resdate, $expdate, $notes,
294
        biblionumber   => $bibnum2,
283
           'a title',      $checkitem, $found);
295
        priority       => 1,
284
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum2,
296
    }
285
           $bibitems,  3, $resdate, $expdate, $notes,
297
);
286
           'a title',      $checkitem, $found);
298
AddReserve(
299
    {
300
        branchcode     => $branch_2,
301
        borrowernumber => $requesters{$branch_2},
302
        biblionumber   => $bibnum2,
303
        priority       => 2,
304
    }
305
);
306
307
AddReserve(
308
    {
309
        branchcode     => $branch_1,
310
        borrowernumber => $requesters{$branch_1},
311
        biblionumber   => $bibnum2,
312
        priority       => 3,
313
    }
314
);
287
315
288
# Ensure that the item's home library controls hold policy lookup
316
# Ensure that the item's home library controls hold policy lookup
289
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
317
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
Lines 317-328 my $reserve_id = $holds->next->reserve_id; Link Here
317
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
345
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
318
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
346
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
319
# Test 9761a: Add a reserve without date, CheckReserve should return it
347
# Test 9761a: Add a reserve without date, CheckReserve should return it
320
$resdate= undef; #defaults to today in AddReserve
321
$expdate= undef; #no expdate
322
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
348
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
323
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
349
AddReserve(
324
           $bibitems,  1, $resdate, $expdate, $notes,
350
    {
325
           'a title',      $checkitem, $found);
351
        branchcode     => $branch_1,
352
        borrowernumber => $requesters{$branch_1},
353
        biblionumber   => $bibnum,
354
        priority       => 1,
355
    }
356
);
326
($status)=CheckReserves($itemnumber,undef,undef);
357
($status)=CheckReserves($itemnumber,undef,undef);
327
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
358
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
328
($status)=CheckReserves($itemnumber,undef,7);
359
($status)=CheckReserves($itemnumber,undef,7);
Lines 331-343 is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead'); Link Here
331
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
362
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
332
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
363
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
333
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
364
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
334
$resdate= dt_from_string();
365
my $resdate= dt_from_string();
335
$resdate->add_duration(DateTime::Duration->new(days => 4));
366
$resdate->add_duration(DateTime::Duration->new(days => 4));
336
$resdate=output_pref($resdate);
367
$resdate=output_pref($resdate);
337
$expdate= undef; #no expdate
368
AddReserve(
338
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
369
    {
339
           $bibitems,  1, $resdate, $expdate, $notes,
370
        branchcode       => $branch_1,
340
           'a title',      $checkitem, $found);
371
        borrowernumber   => $requesters{$branch_1},
372
        biblionumber     => $bibnum,
373
        priority         => 1,
374
        reservation_date => $resdate,
375
    }
376
);
341
($status)=CheckReserves($itemnumber,undef,undef);
377
($status)=CheckReserves($itemnumber,undef,undef);
342
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
378
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
343
379
Lines 392-400 t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1); Link Here
392
$resdate= dt_from_string();
428
$resdate= dt_from_string();
393
$resdate->add_duration(DateTime::Duration->new(days => 2));
429
$resdate->add_duration(DateTime::Duration->new(days => 2));
394
$resdate=output_pref($resdate);
430
$resdate=output_pref($resdate);
395
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
431
AddReserve(
396
           $bibitems,  1, $resdate, $expdate, $notes,
432
    {
397
           'a title',      $checkitem, $found);
433
        branchcode       => $branch_1,
434
        borrowernumber   => $requesters{$branch_1},
435
        biblionumber     => $bibnum,
436
        priority         => 1,
437
        reservation_date => $resdate,
438
    }
439
);
440
398
my $item = Koha::Items->find( $itemnumber );
441
my $item = Koha::Items->find( $itemnumber );
399
$holds = $item->current_holds;
442
$holds = $item->current_holds;
400
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
443
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
Lines 402-410 my $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( d Link Here
402
is( $future_holds->count, 0, 'current_holds does not return a future next available hold');
445
is( $future_holds->count, 0, 'current_holds does not return a future next available hold');
403
# 9788b: current_holds does not return future item level hold
446
# 9788b: current_holds does not return future item level hold
404
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
447
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
405
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
448
AddReserve(
406
           $bibitems,  1, $resdate, $expdate, $notes,
449
    {
407
           'a title',      $itemnumber, $found); #item level hold
450
        branchcode       => $branch_1,
451
        borrowernumber   => $requesters{$branch_1},
452
        biblionumber     => $bibnum,
453
        priority         => 1,
454
        reservation_date => $resdate,
455
        itemnumber       => $itemnumber,
456
    }
457
); #item level hold
408
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
458
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
409
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
459
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
410
# 9788c: current_holds returns future wait (confirmed future hold)
460
# 9788c: current_holds returns future wait (confirmed future hold)
Lines 417-426 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
417
# Tests for CalculatePriority (bug 8918)
467
# Tests for CalculatePriority (bug 8918)
418
my $p = C4::Reserves::CalculatePriority($bibnum2);
468
my $p = C4::Reserves::CalculatePriority($bibnum2);
419
is($p, 4, 'CalculatePriority should now return priority 4');
469
is($p, 4, 'CalculatePriority should now return priority 4');
420
$resdate=undef;
470
AddReserve(
421
AddReserve($branch_1,  $requesters{'CPL2'}, $bibnum2,
471
    {
422
           $bibitems,  $p, $resdate, $expdate, $notes,
472
        branchcode     => $branch_1,
423
           'a title',      $checkitem, $found);
473
        borrowernumber => $requesters{'CPL2'},
474
        biblionumber   => $bibnum2,
475
        priority       => $p,
476
    }
477
);
424
$p = C4::Reserves::CalculatePriority($bibnum2);
478
$p = C4::Reserves::CalculatePriority($bibnum2);
425
is($p, 5, 'CalculatePriority should now return priority 5');
479
is($p, 5, 'CalculatePriority should now return priority 5');
426
#some tests on bibnum
480
#some tests on bibnum
Lines 428-454 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
428
$p = C4::Reserves::CalculatePriority($bibnum);
482
$p = C4::Reserves::CalculatePriority($bibnum);
429
is($p, 1, 'CalculatePriority should now return priority 1');
483
is($p, 1, 'CalculatePriority should now return priority 1');
430
#add a new reserve and confirm it to waiting
484
#add a new reserve and confirm it to waiting
431
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
485
AddReserve(
432
           $bibitems,  $p, $resdate, $expdate, $notes,
486
    {
433
           'a title',      $itemnumber, $found);
487
        branchcode     => $branch_1,
488
        borrowernumber => $requesters{$branch_1},
489
        biblionumber   => $bibnum,
490
        priority       => $p,
491
        itemnumber     => $itemnumber,
492
    }
493
);
434
$p = C4::Reserves::CalculatePriority($bibnum);
494
$p = C4::Reserves::CalculatePriority($bibnum);
435
is($p, 2, 'CalculatePriority should now return priority 2');
495
is($p, 2, 'CalculatePriority should now return priority 2');
436
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0);
496
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0);
437
$p = C4::Reserves::CalculatePriority($bibnum);
497
$p = C4::Reserves::CalculatePriority($bibnum);
438
is($p, 1, 'CalculatePriority should now return priority 1');
498
is($p, 1, 'CalculatePriority should now return priority 1');
439
#add another biblio hold, no resdate
499
#add another biblio hold, no resdate
440
AddReserve($branch_1,  $requesters{'CPL2'}, $bibnum,
500
AddReserve(
441
           $bibitems,  $p, $resdate, $expdate, $notes,
501
    {
442
           'a title',      $checkitem, $found);
502
        branchcode     => $branch_1,
503
        borrowernumber => $requesters{'CPL2'},
504
        biblionumber   => $bibnum,
505
        priority       => $p,
506
    }
507
);
443
$p = C4::Reserves::CalculatePriority($bibnum);
508
$p = C4::Reserves::CalculatePriority($bibnum);
444
is($p, 2, 'CalculatePriority should now return priority 2');
509
is($p, 2, 'CalculatePriority should now return priority 2');
445
#add another future hold
510
#add another future hold
446
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
511
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
447
$resdate= dt_from_string();
512
$resdate= dt_from_string();
448
$resdate->add_duration(DateTime::Duration->new(days => 1));
513
$resdate->add_duration(DateTime::Duration->new(days => 1));
449
AddReserve($branch_1,  $requesters{'CPL3'}, $bibnum,
514
AddReserve(
450
           $bibitems,  $p, output_pref($resdate), $expdate, $notes,
515
    {
451
           'a title',      $checkitem, $found);
516
        branchcode     => $branch_1,
517
        borrowernumber => $requesters{'CPL2'},
518
        biblionumber   => $bibnum,
519
        priority       => $p,
520
        reservation_date => output_pref($resdate),
521
    }
522
);
452
$p = C4::Reserves::CalculatePriority($bibnum);
523
$p = C4::Reserves::CalculatePriority($bibnum);
453
is($p, 2, 'CalculatePriority should now still return priority 2');
524
is($p, 2, 'CalculatePriority should now still return priority 2');
454
#calc priority with future resdate
525
#calc priority with future resdate
Lines 458-466 is($p, 3, 'CalculatePriority should now return priority 3'); Link Here
458
529
459
# Tests for cancel reserves by users from OPAC.
530
# Tests for cancel reserves by users from OPAC.
460
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
531
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
461
AddReserve($branch_1,  $requesters{$branch_1}, $item_bibnum,
532
AddReserve(
462
           $bibitems,  1, undef, $expdate, $notes,
533
    {
463
           'a title',      $checkitem, '');
534
        branchcode     => $branch_1,
535
        borrowernumber => $requesters{$branch_1},
536
        biblionumber   => $item_bibnum,
537
        priority       => 1,
538
    }
539
);
464
my (undef, $canres, undef) = CheckReserves($itemnumber);
540
my (undef, $canres, undef) = CheckReserves($itemnumber);
465
541
466
is( CanReserveBeCanceledFromOpac(), undef,
542
is( CanReserveBeCanceledFromOpac(), undef,
Lines 488-496 $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$br Link Here
488
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
564
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
489
565
490
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
566
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
491
AddReserve($branch_1,  $requesters{$branch_1}, $item_bibnum,
567
AddReserve(
492
           $bibitems,  1, undef, $expdate, $notes,
568
    {
493
           'a title',      $checkitem, '');
569
        branchcode     => $branch_1,
570
        borrowernumber => $requesters{$branch_1},
571
        biblionumber   => $item_bibnum,
572
        priority       => 1,
573
    }
574
);
494
(undef, $canres, undef) = CheckReserves($itemnumber);
575
(undef, $canres, undef) = CheckReserves($itemnumber);
495
576
496
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
577
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
Lines 568-581 Koha::CirculationRules->set_rules( Link Here
568
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
649
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
569
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0);
650
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0);
570
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
651
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
571
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
652
AddReserve(
572
    $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, '');
653
    {
654
        branchcode     => $branch_1,
655
        borrowernumber => $borrowernumber,
656
        biblionumber   => $item_bibnum,
657
        priority       => 1,
658
    }
659
);
573
MoveReserve( $itemnumber, $borrowernumber );
660
MoveReserve( $itemnumber, $borrowernumber );
574
($status)=CheckReserves( $itemnumber );
661
($status)=CheckReserves( $itemnumber );
575
is( $status, '', 'MoveReserve filled hold');
662
is( $status, '', 'MoveReserve filled hold');
576
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
663
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
577
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
664
AddReserve(
578
   $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, 'W');
665
    {
666
        branchcode     => $branch_1,
667
        borrowernumber => $borrowernumber,
668
        biblionumber   => $item_bibnum,
669
        priority       => 1,
670
        found          => 'W',
671
    }
672
);
579
MoveReserve( $itemnumber, $borrowernumber );
673
MoveReserve( $itemnumber, $borrowernumber );
580
($status)=CheckReserves( $itemnumber );
674
($status)=CheckReserves( $itemnumber );
581
is( $status, '', 'MoveReserve filled waiting hold');
675
is( $status, '', 'MoveReserve filled waiting hold');
Lines 583-604 is( $status, '', 'MoveReserve filled waiting hold'); Link Here
583
$resdate= dt_from_string();
677
$resdate= dt_from_string();
584
$resdate->add_duration(DateTime::Duration->new(days => 1));
678
$resdate->add_duration(DateTime::Duration->new(days => 1));
585
$resdate=output_pref($resdate);
679
$resdate=output_pref($resdate);
586
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
680
AddReserve(
587
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
681
    {
682
        branchcode     => $branch_1,
683
        borrowernumber => $borrowernumber,
684
        biblionumber   => $item_bibnum,
685
        priority       => 1,
686
        reservation_date => $resdate,
687
    }
688
);
588
MoveReserve( $itemnumber, $borrowernumber );
689
MoveReserve( $itemnumber, $borrowernumber );
589
($status)=CheckReserves( $itemnumber, undef, 1 );
690
($status)=CheckReserves( $itemnumber, undef, 1 );
590
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
691
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
591
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
692
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
592
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
693
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
593
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
694
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
594
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
695
AddReserve(
595
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
696
    {
697
        branchcode     => $branch_1,
698
        borrowernumber => $borrowernumber,
699
        biblionumber   => $item_bibnum,
700
        priority       => 1,
701
        reservation_date => $resdate,
702
    }
703
);
596
MoveReserve( $itemnumber, $borrowernumber );
704
MoveReserve( $itemnumber, $borrowernumber );
597
($status)=CheckReserves( $itemnumber, undef, 2 );
705
($status)=CheckReserves( $itemnumber, undef, 2 );
598
is( $status, '', 'MoveReserve filled future hold now');
706
is( $status, '', 'MoveReserve filled future hold now');
599
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
707
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
600
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
708
AddReserve(
601
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, 'W');
709
    {
710
        branchcode     => $branch_1,
711
        borrowernumber => $borrowernumber,
712
        biblionumber   => $item_bibnum,
713
        priority       => 1,
714
        reservation_date => $resdate,
715
    }
716
);
602
MoveReserve( $itemnumber, $borrowernumber );
717
MoveReserve( $itemnumber, $borrowernumber );
603
($status)=CheckReserves( $itemnumber, undef, 2 );
718
($status)=CheckReserves( $itemnumber, undef, 2 );
604
is( $status, '', 'MoveReserve filled future waiting hold now');
719
is( $status, '', 'MoveReserve filled future waiting hold now');
Lines 606-613 is( $status, '', 'MoveReserve filled future waiting hold now'); Link Here
606
$resdate= dt_from_string();
721
$resdate= dt_from_string();
607
$resdate->add_duration(DateTime::Duration->new(days => 3));
722
$resdate->add_duration(DateTime::Duration->new(days => 3));
608
$resdate=output_pref($resdate);
723
$resdate=output_pref($resdate);
609
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
724
AddReserve(
610
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
725
    {
726
        branchcode     => $branch_1,
727
        borrowernumber => $borrowernumber,
728
        biblionumber   => $item_bibnum,
729
        priority       => 1,
730
        reservation_date => $resdate,
731
    }
732
);
611
MoveReserve( $itemnumber, $borrowernumber );
733
MoveReserve( $itemnumber, $borrowernumber );
612
($status)=CheckReserves( $itemnumber, undef, 3 );
734
($status)=CheckReserves( $itemnumber, undef, 3 );
613
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
735
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
Lines 668-675 subtest '_koha_notify_reserve() tests' => sub { Link Here
668
        })->{borrowernumber};
790
        })->{borrowernumber};
669
791
670
    C4::Reserves::AddReserve(
792
    C4::Reserves::AddReserve(
671
        $item->homebranch, $hold_borrower,
793
        {
672
        $item->biblionumber );
794
            branchcode     => $item->homebranch,
795
            borrowernumber => $hold_borrower,
796
            biblionumber   => $item->biblionumber,
797
        }
798
    );
673
799
674
    ModReserveAffect($item->itemnumber, $hold_borrower, 0);
800
    ModReserveAffect($item->itemnumber, $hold_borrower, 0);
675
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
801
    my $sms_message_address = $schema->resultset('MessageQueue')->search({
Lines 817-826 subtest 'reserves.item_level_hold' => sub { Link Here
817
943
818
    subtest 'item level hold' => sub {
944
    subtest 'item level hold' => sub {
819
        plan tests => 2;
945
        plan tests => 2;
820
        my $reserve_id =
946
        my $reserve_id = AddReserve(
821
          AddReserve( $item->homebranch, $patron->borrowernumber,
947
            {
822
            $item->biblionumber, undef, 1, undef, undef, '', '',
948
                branchcode     => $item->homebranch,
823
            $item->itemnumber );
949
                borrowernumber => $patron->borrowernumber,
950
                biblionumber   => $item->biblionumber,
951
                priority       => 1,
952
                itemnumber     => $item->itemnumber,
953
            }
954
        );
824
955
825
        my $hold = Koha::Holds->find($reserve_id);
956
        my $hold = Koha::Holds->find($reserve_id);
826
        is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' );
957
        is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' );
Lines 841-848 subtest 'reserves.item_level_hold' => sub { Link Here
841
972
842
    subtest 'biblio level hold' => sub {
973
    subtest 'biblio level hold' => sub {
843
        plan tests => 3;
974
        plan tests => 3;
844
        my $reserve_id = AddReserve( $item->homebranch, $patron->borrowernumber,
975
        my $reserve_id = AddReserve(
845
            $item->biblionumber, undef, 1 );
976
            {
977
                branchcode     => $item->homebranch,
978
                borrowernumber => $patron->borrowernumber,
979
                biblionumber   => $item->biblionumber,
980
                priority       => 1,
981
            }
982
        );
846
983
847
        my $hold = Koha::Holds->find($reserve_id);
984
        my $hold = Koha::Holds->find($reserve_id);
848
        is( $hold->item_level_hold, 0, 'item_level_hold should not be set when AddReserve is called without a specific item' );
985
        is( $hold->item_level_hold, 0, 'item_level_hold should not be set when AddReserve is called without a specific item' );
Lines 877-884 subtest 'MoveReserve additional test' => sub { Link Here
877
    my $patron_2 = $builder->build_object({ class => "Koha::Patrons" });
1014
    my $patron_2 = $builder->build_object({ class => "Koha::Patrons" });
878
1015
879
    # Place a hold on the title for both patrons
1016
    # Place a hold on the title for both patrons
880
    my $reserve_1 = AddReserve( $item_1->homebranch, $patron_1->borrowernumber, $biblio->biblionumber, undef, 1 );
1017
    my $reserve_1 = AddReserve(
881
    my $reserve_2 = AddReserve( $item_2->homebranch, $patron_2->borrowernumber, $biblio->biblionumber, undef, 1 );
1018
        {
1019
            branchcode     => $item_1->homebranch,
1020
            borrowernumber => $patron_1->borrowernumber,
1021
            biblionumber   => $biblio->biblionumber,
1022
            priority       => 1,
1023
            itemnumber     => $item_1->itemnumber,
1024
        }
1025
    );
1026
    my $reserve_2 = AddReserve(
1027
        {
1028
            branchcode     => $item_2->homebranch,
1029
            borrowernumber => $patron_2->borrowernumber,
1030
            biblionumber   => $biblio->biblionumber,
1031
            priority       => 1,
1032
            itemnumber     => $item_1->itemnumber,
1033
        }
1034
    );
882
    is($patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold");
1035
    is($patron_1->holds->next()->reserve_id, $reserve_1, "The 1st patron has a hold");
883
    is($patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold");
1036
    is($patron_2->holds->next()->reserve_id, $reserve_2, "The 2nd patron has a hold");
884
1037
Lines 906-917 sub place_item_hold { Link Here
906
    my ($patron,$item,$library,$priority) = @_;
1059
    my ($patron,$item,$library,$priority) = @_;
907
1060
908
    my $hold_id = C4::Reserves::AddReserve(
1061
    my $hold_id = C4::Reserves::AddReserve(
909
        $library->branchcode, $patron->borrowernumber,
1062
        {
910
        $item->biblionumber,  '',
1063
            branchcode     => $library->branchcode,
911
        $priority,            undef,
1064
            borrowernumber => $patron->borrowernumber,
912
        undef,                '',
1065
            biblionumber   => $item->biblionumber,
913
        "title for fee",      $item->itemnumber,
1066
            priority       => $priority,
1067
            title          => "title for fee",
1068
            itemnumber     => $item->itemnumber,
1069
        }
914
    );
1070
    );
1071
915
    my $hold = Koha::Holds->find($hold_id);
1072
    my $hold = Koha::Holds->find($hold_id);
916
    return $hold;
1073
    return $hold;
917
}
1074
}
(-)a/t/db_dependent/Reserves/GetReserveFee.t (-11 / +7 lines)
Lines 205-221 sub acctlines { #calculate number of accountlines for a patron Link Here
205
205
206
sub addreserve {
206
sub addreserve {
207
    return AddReserve(
207
    return AddReserve(
208
        $library->{branchcode},
208
        {
209
        $_[0],
209
            branchcode     => $library->{branchcode},
210
        $biblio->{biblionumber},
210
            borrowernumber => $_[0],
211
        undef,
211
            biblionumber   => $biblio->{biblionumber},
212
        '1',
212
            priority       => '1',
213
        undef,
213
            title          => $biblio->{title},
214
        undef,
214
        }
215
        '',
216
        $biblio->{title},
217
        undef,
218
        ''
219
    );
215
    );
220
}
216
}
221
217
(-)a/t/db_dependent/Reserves/MultiplePerRecord.t (-2 / +16 lines)
Lines 285-296 Koha::CirculationRules->set_rules( Link Here
285
285
286
my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
286
my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
287
is( $can->{status}, 'OK', 'Hold can be placed with 0 holds' );
287
is( $can->{status}, 'OK', 'Hold can be placed with 0 holds' );
288
my $hold_id = AddReserve( $library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber}, '', 1 );
288
my $hold_id = AddReserve(
289
    {
290
        branchcode     => $library->{branchcode},
291
        borrowernumber => $patron->{borrowernumber},
292
        biblionumber   => $biblio->{biblionumber},
293
        priority       => 1
294
    }
295
);
289
ok( $hold_id, 'First hold was placed' );
296
ok( $hold_id, 'First hold was placed' );
290
297
291
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
298
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
292
is( $can->{status}, 'OK', 'Hold can be placed with 1 hold' );
299
is( $can->{status}, 'OK', 'Hold can be placed with 1 hold' );
293
$hold_id = AddReserve( $library->{branchcode}, $patron->{borrowernumber}, $biblio->{biblionumber}, '', 1 );
300
$hold_id = AddReserve(
301
    {
302
        branchcode     => $library->{branchcode},
303
        borrowernumber => $patron->{borrowernumber},
304
        biblionumber   => $biblio->{biblionumber},
305
        priority       => 1
306
    }
307
);
294
ok( $hold_id, 'Second hold was placed' );
308
ok( $hold_id, 'Second hold was placed' );
295
309
296
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
310
$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber});
(-)a/t/db_dependent/SIP/Transaction.t (-6 / +23 lines)
Lines 81-88 subtest fill_holds_at_checkout => sub { Link Here
81
        }
81
        }
82
    );
82
    );
83
83
84
    my $reserve1 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
84
    my $reserve1 = AddReserve(
85
    my $reserve2 = AddReserve($branch->{branchcode},$borrower->{borrowernumber},$biblio->{biblionumber});
85
        {
86
            branchcode     => $branch->{branchcode},
87
            borrowernumber => $borrower->{borrowernumber},
88
            biblionumber   => $biblio->{biblionumber}
89
        }
90
    );
91
    my $reserve2 = AddReserve(
92
        {
93
            branchcode     => $branch->{branchcode},
94
            borrowernumber => $borrower->{borrowernumber},
95
            biblionumber   => $biblio->{biblionumber}
96
        }
97
    );
98
86
    my $bib = Koha::Biblios->find( $biblio->{biblionumber} );
99
    my $bib = Koha::Biblios->find( $biblio->{biblionumber} );
87
    is( $bib->holds->count(), 2, "Bib has 2 holds");
100
    is( $bib->holds->count(), 2, "Bib has 2 holds");
88
101
Lines 174-183 subtest cancel_hold => sub { Link Here
174
        }
187
        }
175
    );
188
    );
176
189
177
    my $reserve1 =
190
    my $reserve1 = AddReserve(
178
      AddReserve( $library->branchcode, $patron->borrowernumber,
191
        {
179
        $item->biblio->biblionumber,
192
            branchcode     => $library->branchcode,
180
        undef, undef, undef, undef, undef, undef, $item->itemnumber );
193
            borrowernumber => $patron->borrowernumber,
194
            biblionumber   => $item->biblio->biblionumber,
195
            itemnumber     => $item->itemnumber,
196
        }
197
    );
181
    is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
198
    is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
182
    is( $item->holds->count(),1,"Hold was placed on specific item");
199
    is( $item->holds->count(),1,"Hold was placed on specific item");
183
200
(-)a/t/db_dependent/UsageStats.t (-1 / +9 lines)
Lines 301-307 sub construct_objects_needed { Link Here
301
    my $issue_id1 = $dbh->last_insert_id( undef, undef, 'old_issues', undef );
301
    my $issue_id1 = $dbh->last_insert_id( undef, undef, 'old_issues', undef );
302
302
303
    # ---------- Add 1 old_reserves
303
    # ---------- Add 1 old_reserves
304
    AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
304
    AddReserve(
305
        {
306
            branchcode     => $branchcode,
307
            borrowernumber => $borrowernumber1,
308
            biblionumber   => $biblionumber1,
309
            priority       => 1,
310
            title          => 'Title',
311
        }
312
    );
305
    my $biblio = Koha::Biblios->find( $biblionumber1 );
313
    my $biblio = Koha::Biblios->find( $biblionumber1 );
306
    my $holds = $biblio->holds;
314
    my $holds = $biblio->holds;
307
    $holds->next->cancel if $holds->count;
315
    $holds->next->cancel if $holds->count;
(-)a/t/db_dependent/api/v1/holds.t (-14 / +36 lines)
Lines 127-138 Koha::CirculationRules->set_rules( Link Here
127
    }
127
    }
128
);
128
);
129
129
130
my $reserve_id = C4::Reserves::AddReserve($branchcode, $patron_1->borrowernumber,
130
my $reserve_id = C4::Reserves::AddReserve(
131
    $biblio_1->biblionumber, undef, 1, undef, undef, undef, '', $item_1->itemnumber);
131
    {
132
        branchcode     => $branchcode,
133
        borrowernumber => $patron_1->borrowernumber,
134
        biblionumber   => $biblio_1->biblionumber,
135
        priority       => 1,
136
        itemnumber     => $item_1->itemnumber,
137
    }
138
);
132
139
133
# Add another reserve to be able to change first reserve's rank
140
# Add another reserve to be able to change first reserve's rank
134
my $reserve_id2 = C4::Reserves::AddReserve($branchcode, $patron_2->borrowernumber,
141
my $reserve_id2 = C4::Reserves::AddReserve(
135
    $biblio_1->biblionumber, undef, 2, undef, undef, undef, '', $item_1->itemnumber);
142
    {
143
        branchcode     => $branchcode,
144
        borrowernumber => $patron_2->borrowernumber,
145
        biblionumber   => $biblio_1->biblionumber,
146
        priority       => 2,
147
        itemnumber     => $item_1->itemnumber,
148
    }
149
);
136
150
137
my $suspended_until = DateTime->now->add(days => 10)->truncate( to => 'day' );
151
my $suspended_until = DateTime->now->add(days => 10)->truncate( to => 'day' );
138
my $expiration_date = DateTime->now->add(days => 10)->truncate( to => 'day' );
152
my $expiration_date = DateTime->now->add(days => 10)->truncate( to => 'day' );
Lines 469-491 subtest 'PUT /holds/{hold_id}/priority tests' => sub { Link Here
469
483
470
    my $hold_1 = Koha::Holds->find(
484
    my $hold_1 = Koha::Holds->find(
471
        AddReserve(
485
        AddReserve(
472
            $library->branchcode,  $patron_1->borrowernumber,
486
            {
473
            $biblio->biblionumber, undef,
487
                branchcode     => $library->branchcode,
474
            1
488
                borrowernumber => $patron_1->borrowernumber,
489
                biblionumber   => $biblio->biblionumber,
490
                priority       => 1,
491
            }
475
        )
492
        )
476
    );
493
    );
477
    my $hold_2 = Koha::Holds->find(
494
    my $hold_2 = Koha::Holds->find(
478
        AddReserve(
495
        AddReserve(
479
            $library->branchcode,  $patron_2->borrowernumber,
496
            {
480
            $biblio->biblionumber, undef,
497
                branchcode     => $library->branchcode,
481
            2
498
                borrowernumber => $patron_2->borrowernumber,
499
                biblionumber   => $biblio->biblionumber,
500
                priority       => 2,
501
            }
482
        )
502
        )
483
    );
503
    );
484
    my $hold_3 = Koha::Holds->find(
504
    my $hold_3 = Koha::Holds->find(
485
        AddReserve(
505
        AddReserve(
486
            $library->branchcode,  $patron_3->borrowernumber,
506
            {
487
            $biblio->biblionumber, undef,
507
                branchcode     => $library->branchcode,
488
            3
508
                borrowernumber => $patron_3->borrowernumber,
509
                biblionumber   => $biblio->biblionumber,
510
                priority       => 3,
511
            }
489
        )
512
        )
490
    );
513
    );
491
514
492
- 

Return to bug 14711