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

(-)a/C4/ILSDI/Services.pm (-2 / +2 lines)
Lines 531-540 sub GetPatronInfo { Link Here
531
            delete $issue->{'more_subfields_xml'};
531
            delete $issue->{'more_subfields_xml'};
532
532
533
            # Is the item already on hold by another user?
533
            # Is the item already on hold by another user?
534
            $issue->{'holds_on_item'} = Koha::Holds->search({ itemnumber => $issue->{'itemnumber'} })->count;
534
            $issue->{'holds_on_item'} = Koha::Holds->search( { itemnumber => $issue->{'itemnumber'} } )->count;
535
535
536
            # Is the record (next available item) on hold by another user?
536
            # Is the record (next available item) on hold by another user?
537
            $issue->{'holds_on_record'} = Koha::Holds->search({ biblionumber => $issue->{'biblionumber'} })->count;
537
            $issue->{'holds_on_record'} = Koha::Holds->search( { biblionumber => $issue->{'biblionumber'} } )->count;
538
538
539
            push @checkouts, $issue
539
            push @checkouts, $issue
540
        }
540
        }
(-)a/t/db_dependent/ILSDI_Services.t (-55 / +76 lines)
Lines 127-219 subtest 'GetPatronInfo test for holds' => sub { Link Here
127
    plan tests => 8;
127
    plan tests => 8;
128
128
129
    $schema->storage->txn_begin;
129
    $schema->storage->txn_begin;
130
    $schema->resultset( 'Issue' )->delete_all;
130
    $schema->resultset('Issue')->delete_all;
131
    $schema->resultset( 'Reserve' )->delete_all;
131
    $schema->resultset('Reserve')->delete_all;
132
    $schema->resultset( 'Borrower' )->delete_all;
132
    $schema->resultset('Borrower')->delete_all;
133
    $schema->resultset( 'Category' )->delete_all;
133
    $schema->resultset('Category')->delete_all;
134
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
134
    $schema->resultset('Item')->delete_all;    # 'Branch' deps. on this
135
    $schema->resultset( 'Branch' )->delete_all;
135
    $schema->resultset('Branch')->delete_all;
136
136
137
    # Configure Koha to enable ILS-DI server
137
    # Configure Koha to enable ILS-DI server
138
    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
138
    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
139
139
140
    my $library = $builder->build_object({
140
    my $library = $builder->build_object(
141
        class => 'Koha::Libraries',
141
        {
142
    });
142
            class => 'Koha::Libraries',
143
        }
144
    );
143
145
144
    # Create new users:
146
    # Create new users:
145
    my $brwr = $builder->build_object( {
147
    my $brwr = $builder->build_object(
146
        class => 'Koha::Patrons',
148
        {
147
        value  => {
149
            class => 'Koha::Patrons',
148
            branchcode   => $library->branchcode,
150
            value => {
151
                branchcode => $library->branchcode,
152
            }
149
        }
153
        }
150
    } );
154
    );
151
    my $brwr2 = $builder->build_object( {
155
    my $brwr2 = $builder->build_object(
152
        class => 'Koha::Patrons',
156
        {
153
        value  => {
157
            class => 'Koha::Patrons',
154
            branchcode   => $library->branchcode,
158
            value => {
159
                branchcode => $library->branchcode,
160
            }
155
        }
161
        }
156
    } );
162
    );
157
    my $brwr3 = $builder->build_object( {
163
    my $brwr3 = $builder->build_object(
158
        class => 'Koha::Patrons',
164
        {
159
        value  => {
165
            class => 'Koha::Patrons',
160
            branchcode   => $library->branchcode,
166
            value => {
167
                branchcode => $library->branchcode,
168
            }
161
        }
169
        }
162
    } );
170
    );
163
171
164
    my $module = Test::MockModule->new('C4::Context');
172
    my $module = Test::MockModule->new('C4::Context');
165
    $module->mock('userenv', sub { { branch => $library->branchcode } });
173
    $module->mock( 'userenv', sub { { branch => $library->branchcode } } );
166
174
167
    # Place a loan
175
    # Place a loan
168
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
176
    my $biblio   = $builder->build_object( { class => 'Koha::Biblios' } );
169
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
177
    my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } );
170
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } );
178
    my $biblioitem =
171
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype });
179
        $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } );
172
    my $issue = AddIssue($brwr, $item->barcode);
180
    my $item = $builder->build_sample_item(
181
        { biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype } );
182
    my $issue = AddIssue( $brwr, $item->barcode );
173
183
174
    # Prepare and send web request for IL-SDI server:
184
    # Prepare and send web request for IL-SDI server:
175
    my $query = new CGI;
185
    my $query = CGI->new();
176
    $query->param( 'service', 'GetPatronInfo' );
186
    $query->param( 'service',    'GetPatronInfo' );
177
    $query->param( 'patron_id', $brwr->borrowernumber );
187
    $query->param( 'patron_id',  $brwr->borrowernumber );
178
    $query->param( 'show_loans', '1' );
188
    $query->param( 'show_loans', '1' );
179
    my $reply = C4::ILSDI::Services::GetPatronInfo( $query );
189
    my $reply = C4::ILSDI::Services::GetPatronInfo($query);
180
190
181
    # Check that this loan is not on hold
191
    # Check that this loan is not on hold
182
    is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "0", "Record is not on hold");
192
    is( $reply->{loans}->{loan}[0]->{holds_on_record}, "0", "Record is not on hold" );
183
    is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is not on hold");
193
    is( $reply->{loans}->{loan}[0]->{holds_on_item},   "0", "Item is not on hold" );
184
194
185
    # Place a loan
195
    # Place a loan
186
    # Add a hold on the biblio
196
    # Add a hold on the biblio
187
    my $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr2->borrowernumber, biblionumber => $biblio->biblionumber });
197
    my $biblioreserve = AddReserve(
198
        {
199
            branchcode   => $library->branchcode, borrowernumber => $brwr2->borrowernumber,
200
            biblionumber => $biblio->biblionumber
201
        }
202
    );
188
203
189
    # Check that it is on hold on biblio level
204
    # Check that it is on hold on biblio level
190
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
205
    $reply = C4::ILSDI::Services::GetPatronInfo($query);
191
    is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold");
206
    is( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold" );
192
    is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "0", "Item is on hold");
207
    is( $reply->{loans}->{loan}[0]->{holds_on_item},   "0", "Item is on hold" );
193
208
194
    # Delete holds
209
    # Delete holds
195
    $schema->resultset( 'Reserve' )->delete_all;
210
    $schema->resultset('Reserve')->delete_all;
196
211
197
    # Add a hold on the item
212
    # Add a hold on the item
198
    my $itemreserve = AddReserve({
213
    my $itemreserve = AddReserve(
199
             branchcode => $library->branchcode,
214
        {
200
             borrowernumber => $brwr2->borrowernumber,
215
            branchcode     => $library->branchcode,
201
             biblionumber => $biblio->biblionumber,
216
            borrowernumber => $brwr2->borrowernumber,
202
             itemnumber => $item->itemnumber
217
            biblionumber   => $biblio->biblionumber,
203
     });
218
            itemnumber     => $item->itemnumber
219
        }
220
    );
204
221
205
    # When a specific item has a reserve, the item is on hold as well as the record
222
    # When a specific item has a reserve, the item is on hold as well as the record
206
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
223
    $reply = C4::ILSDI::Services::GetPatronInfo($query);
207
    is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold");
224
    is( $reply->{loans}->{loan}[0]->{holds_on_record}, "1", "Record is on hold" );
208
    is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold");
225
    is( $reply->{loans}->{loan}[0]->{holds_on_item},   "1", "Item is on hold" );
209
226
210
    # Add another hold on the biblio
227
    # Add another hold on the biblio
211
    $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr3->borrowernumber, biblionumber => $biblio->biblionumber });
228
    $biblioreserve = AddReserve(
229
        {
230
            branchcode   => $library->branchcode, borrowernumber => $brwr3->borrowernumber,
231
            biblionumber => $biblio->biblionumber
232
        }
233
    );
212
234
213
    # Check that there are 2 holds on the biblio and 1 on this specific item
235
    # Check that there are 2 holds on the biblio and 1 on this specific item
214
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
236
    $reply = C4::ILSDI::Services::GetPatronInfo($query);
215
    is ( $reply->{loans}->{loan}[0]->{holds_on_record}, "2", "Record is on hold twice");
237
    is( $reply->{loans}->{loan}[0]->{holds_on_record}, "2", "Record is on hold twice" );
216
    is ( $reply->{loans}->{loan}[0]->{holds_on_item}, "1", "Item is on hold");
238
    is( $reply->{loans}->{loan}[0]->{holds_on_item},   "1", "Item is on hold" );
217
239
218
    # Cleanup
240
    # Cleanup
219
    $schema->storage->txn_rollback;
241
    $schema->storage->txn_rollback;
220
- 

Return to bug 21284