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

(-)a/t/db_dependent/SIP/Transaction.t (-263 / +328 lines)
Lines 26-70 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
26
my $schema = Koha::Database->new->schema;
26
my $schema = Koha::Database->new->schema;
27
$schema->storage->txn_begin;
27
$schema->storage->txn_begin;
28
28
29
my $builder = t::lib::TestBuilder->new();
29
my $builder    = t::lib::TestBuilder->new();
30
my $borr1 = $builder->build({ source => 'Borrower' });
30
my $borr1      = $builder->build( { source => 'Borrower' } );
31
my $card = $borr1->{cardnumber};
31
my $card       = $borr1->{cardnumber};
32
my $sip_patron = C4::SIP::ILS::Patron->new( $card );
32
my $sip_patron = C4::SIP::ILS::Patron->new($card);
33
33
34
# Create transaction RenewAll, assign patron, and run (no items)
34
# Create transaction RenewAll, assign patron, and run (no items)
35
my $transaction = C4::SIP::ILS::Transaction::RenewAll->new();
35
my $transaction = C4::SIP::ILS::Transaction::RenewAll->new();
36
is( ref $transaction, "C4::SIP::ILS::Transaction::RenewAll", "New transaction created" );
36
is( ref $transaction,                  "C4::SIP::ILS::Transaction::RenewAll", "New transaction created" );
37
is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" );
37
is( $transaction->patron($sip_patron), $sip_patron,                           "Patron assigned to transaction" );
38
isnt( $transaction->do_renew_all, undef, "RenewAll on zero items" );
38
isnt( $transaction->do_renew_all, undef, "RenewAll on zero items" );
39
39
40
subtest fill_holds_at_checkout => sub {
40
subtest fill_holds_at_checkout => sub {
41
    plan tests => 6;
41
    plan tests => 6;
42
42
43
    my $category = $builder->build( { source => 'Category', value => { category_type => 'A' } } );
44
    my $branch   = $builder->build( { source => 'Branch' } );
45
    my $borrower = $builder->build(
46
        {
47
            source => 'Borrower',
48
            value  => {
49
                branchcode   => $branch->{branchcode},
50
                categorycode => $category->{categorycode}
51
            }
52
        }
53
    );
54
    t::lib::Mocks::mock_userenv( { branchcode => $branch->{branchcode}, flags => 1 } );
43
55
44
    my $category = $builder->build({ source => 'Category', value => { category_type => 'A' }});
56
    my $itype = $builder->build( { source => 'Itemtype', value => { notforloan => 0 } } );
45
    my $branch   = $builder->build({ source => 'Branch' });
57
    my $item1 = $builder->build_sample_item(
46
    my $borrower = $builder->build({ source => 'Borrower', value =>{
58
        {
47
        branchcode => $branch->{branchcode},
59
            barcode       => 'barcode4test',
48
        categorycode=>$category->{categorycode}
60
            homebranch    => $branch->{branchcode},
61
            holdingbranch => $branch->{branchcode},
62
            itype         => $itype->{itemtype},
63
            notforloan    => 0,
49
        }
64
        }
50
    });
65
    )->unblessed;
51
    t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode}, flags => 1 });
66
    my $item2 = $builder->build_sample_item(
52
67
        {
53
    my $itype = $builder->build({ source => 'Itemtype', value =>{notforloan=>0} });
68
            homebranch    => $branch->{branchcode},
54
    my $item1 = $builder->build_sample_item({
69
            holdingbranch => $branch->{branchcode},
55
        barcode       => 'barcode4test',
70
            biblionumber  => $item1->{biblionumber},
56
        homebranch    => $branch->{branchcode},
71
            itype         => $itype->{itemtype},
57
        holdingbranch => $branch->{branchcode},
72
            notforloan    => 0,
58
        itype         => $itype->{itemtype},
73
        }
59
        notforloan       => 0,
74
    )->unblessed;
60
    })->unblessed;
61
    my $item2 = $builder->build_sample_item({
62
        homebranch    => $branch->{branchcode},
63
        holdingbranch => $branch->{branchcode},
64
        biblionumber  => $item1->{biblionumber},
65
        itype         => $itype->{itemtype},
66
        notforloan       => 0,
67
    })->unblessed;
68
75
69
    Koha::CirculationRules->set_rules(
76
    Koha::CirculationRules->set_rules(
70
        {
77
        {
Lines 97-116 subtest fill_holds_at_checkout => sub { Link Here
97
    );
104
    );
98
105
99
    my $bib = Koha::Biblios->find( $item1->{biblionumber} );
106
    my $bib = Koha::Biblios->find( $item1->{biblionumber} );
100
    is( $bib->holds->count(), 2, "Bib has 2 holds");
107
    is( $bib->holds->count(), 2, "Bib has 2 holds" );
101
108
102
    my $sip_patron = C4::SIP::ILS::Patron->new( $borrower->{cardnumber} );
109
    my $sip_patron  = C4::SIP::ILS::Patron->new( $borrower->{cardnumber} );
103
    my $sip_item   = C4::SIP::ILS::Item->new( $item1->{barcode} );
110
    my $sip_item    = C4::SIP::ILS::Item->new( $item1->{barcode} );
104
    my $transaction = C4::SIP::ILS::Transaction::Checkout->new();
111
    my $transaction = C4::SIP::ILS::Transaction::Checkout->new();
105
    is( ref $transaction, "C4::SIP::ILS::Transaction::Checkout", "New transaction created" );
112
    is( ref $transaction,                  "C4::SIP::ILS::Transaction::Checkout", "New transaction created" );
106
    is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" );
113
    is( $transaction->patron($sip_patron), $sip_patron,                           "Patron assigned to transaction" );
107
    is( $transaction->item( $sip_item ), $sip_item, "Item assigned to transaction" );
114
    is( $transaction->item($sip_item),     $sip_item,                             "Item assigned to transaction" );
108
    my $checkout = $transaction->do_checkout();
115
    my $checkout = $transaction->do_checkout();
109
    use Data::Dumper; # Temporary debug statement
116
    use Data::Dumper;    # Temporary debug statement
110
    is( $bib->holds->count(), 1, "Bib has 1 holds remaining") or diag Dumper $checkout;
117
    is( $bib->holds->count(), 1, "Bib has 1 holds remaining" ) or diag Dumper $checkout;
111
118
112
    t::lib::Mocks::mock_preference('itemBarcodeInputFilter', 'whitespace');
119
    t::lib::Mocks::mock_preference( 'itemBarcodeInputFilter', 'whitespace' );
113
    $sip_item   = C4::SIP::ILS::Item->new( ' barcode 4 test ');
120
    $sip_item    = C4::SIP::ILS::Item->new(' barcode 4 test ');
114
    $transaction = C4::SIP::ILS::Transaction::Checkout->new();
121
    $transaction = C4::SIP::ILS::Transaction::Checkout->new();
115
    is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" );
122
    is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" );
116
};
123
};
Lines 122-132 subtest "FeePayment->pay tests" => sub { Link Here
122
    # Create a borrower and add some outstanding debts to their account
129
    # Create a borrower and add some outstanding debts to their account
123
    my $patron = $builder->build( { source => 'Borrower' } );
130
    my $patron = $builder->build( { source => 'Borrower' } );
124
    my $account =
131
    my $account =
125
      Koha::Account->new( { patron_id => $patron->{borrowernumber} } );
132
        Koha::Account->new( { patron_id => $patron->{borrowernumber} } );
126
    my $debt1 = $account->add_debit(
133
    my $debt1 = $account->add_debit( { type => 'ACCOUNT', amount => 100, interface => 'commandline' } );
127
        { type => 'ACCOUNT', amount => 100, interface => 'commandline' } );
134
    my $debt2 = $account->add_debit( { type => 'ACCOUNT', amount => 200, interface => 'commandline' } );
128
    my $debt2 = $account->add_debit(
129
        { type => 'ACCOUNT', amount => 200, interface => 'commandline' } );
130
135
131
    # Instantiate a new FeePayment transaction object
136
    # Instantiate a new FeePayment transaction object
132
    my $trans = C4::SIP::ILS::Transaction::FeePayment->new();
137
    my $trans = C4::SIP::ILS::Transaction::FeePayment->new();
Lines 139-154 subtest "FeePayment->pay tests" => sub { Link Here
139
    # Test the 'pay' method
144
    # Test the 'pay' method
140
    # FIXME: pay should not require a borrowernumber
145
    # FIXME: pay should not require a borrowernumber
141
    # (we should reach out to the transaction which should contain a patron object)
146
    # (we should reach out to the transaction which should contain a patron object)
142
    my $pay_type = '00';    # 00 - Cash, 01 - VISA, 02 - Creditcard
147
    my $pay_type = '00';          # 00 - Cash, 01 - VISA, 02 - Creditcard
143
    my $ok =
148
    my $ok       = $trans->pay(
144
      $trans->pay( $patron->{borrowernumber}, 100, $pay_type, $debt1->id, 0,
149
        $patron->{borrowernumber}, 100, $pay_type, $debt1->id, 0,
145
        0 );
150
        0
151
    );
146
    ok( $ok, "FeePayment transaction succeeded" );
152
    ok( $ok, "FeePayment transaction succeeded" );
147
    $debt1->discard_changes;
153
    $debt1->discard_changes;
148
    is( $debt1->amountoutstanding + 0, 0,
154
    is(
149
        "Debt1 was reduced to 0 as expected" );
155
        $debt1->amountoutstanding + 0, 0,
150
    my $offsets = Koha::Account::Offsets->search(
156
        "Debt1 was reduced to 0 as expected"
151
        { debit_id => $debt1->id, credit_id => { '!=' => undef } } );
157
    );
158
    my $offsets = Koha::Account::Offsets->search( { debit_id => $debt1->id, credit_id => { '!=' => undef } } );
152
    is( $offsets->count, 1, "FeePayment produced an offset line correctly" );
159
    is( $offsets->count, 1, "FeePayment produced an offset line correctly" );
153
    my $credit = $offsets->next->credit;
160
    my $credit = $offsets->next->credit;
154
    is( $credit->payment_type, 'SIP00', "Payment type was set correctly" );
161
    is( $credit->payment_type, 'SIP00', "Payment type was set correctly" );
Lines 157-164 subtest "FeePayment->pay tests" => sub { Link Here
157
subtest cancel_hold => sub {
164
subtest cancel_hold => sub {
158
    plan tests => 7;
165
    plan tests => 7;
159
166
160
    my $library = $builder->build_object ({ class => 'Koha::Libraries' });
167
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
161
    my $patron = $builder->build_object(
168
    my $patron  = $builder->build_object(
162
        {
169
        {
163
            class => 'Koha::Patrons',
170
            class => 'Koha::Patrons',
164
            value => {
171
            value => {
Lines 166-176 subtest cancel_hold => sub { Link Here
166
            }
173
            }
167
        }
174
        }
168
    );
175
    );
169
    t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
176
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
170
177
171
    my $item = $builder->build_sample_item({
178
    my $item = $builder->build_sample_item(
172
        library       => $library->branchcode,
179
        {
173
    });
180
            library => $library->branchcode,
181
        }
182
    );
174
183
175
    Koha::CirculationRules->set_rules(
184
    Koha::CirculationRules->set_rules(
176
        {
185
        {
Lines 195-212 subtest cancel_hold => sub { Link Here
195
            itemnumber     => $item->itemnumber,
204
            itemnumber     => $item->itemnumber,
196
        }
205
        }
197
    );
206
    );
198
    is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
207
    is( $item->biblio->holds->count(), 1, "Hold was placed on bib" );
199
    is( $item->holds->count(),1,"Hold was placed on specific item");
208
    is( $item->holds->count(),         1, "Hold was placed on specific item" );
200
209
201
    my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
210
    my $sip_patron  = C4::SIP::ILS::Patron->new( $patron->cardnumber );
202
    my $sip_item   = C4::SIP::ILS::Item->new( $item->barcode );
211
    my $sip_item    = C4::SIP::ILS::Item->new( $item->barcode );
203
    my $transaction = C4::SIP::ILS::Transaction::Hold->new();
212
    my $transaction = C4::SIP::ILS::Transaction::Hold->new();
204
    is( ref $transaction, "C4::SIP::ILS::Transaction::Hold", "New transaction created" );
213
    is( ref $transaction,                  "C4::SIP::ILS::Transaction::Hold", "New transaction created" );
205
    is( $transaction->patron( $sip_patron ), $sip_patron, "Patron assigned to transaction" );
214
    is( $transaction->patron($sip_patron), $sip_patron,                       "Patron assigned to transaction" );
206
    is( $transaction->item( $sip_item ), $sip_item, "Item assigned to transaction" );
215
    is( $transaction->item($sip_item),     $sip_item,                         "Item assigned to transaction" );
207
    my $hold = $transaction->drop_hold();
216
    my $hold = $transaction->drop_hold();
208
    is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining");
217
    is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining" );
209
    is( $item->holds->count(), 0,  "Item has 0 holds remaining");
218
    is( $item->holds->count(),         0, "Item has 0 holds remaining" );
210
};
219
};
211
220
212
subtest do_hold => sub {
221
subtest do_hold => sub {
Lines 215-223 subtest do_hold => sub { Link Here
215
    my $library = $builder->build_object(
224
    my $library = $builder->build_object(
216
        {
225
        {
217
            class => 'Koha::Libraries',
226
            class => 'Koha::Libraries',
218
            value => {
227
            value => { pickup_location => 1 }
219
                pickup_location => 1
220
            }
221
        }
228
        }
222
    );
229
    );
223
    my $patron_1 = $builder->build_object(
230
    my $patron_1 = $builder->build_object(
Lines 238-245 subtest do_hold => sub { Link Here
238
        }
245
        }
239
    );
246
    );
240
247
241
    t::lib::Mocks::mock_userenv(
248
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
242
        { branchcode => $library->branchcode, flags => 1 } );
243
249
244
    my $item = $builder->build_sample_item(
250
    my $item = $builder->build_sample_item(
245
        {
251
        {
Lines 266-280 subtest do_hold => sub { Link Here
266
        "C4::SIP::ILS::Transaction::Hold",
272
        "C4::SIP::ILS::Transaction::Hold",
267
        "New transaction created"
273
        "New transaction created"
268
    );
274
    );
269
    is( $transaction->patron($sip_patron),
275
    is(
270
        $sip_patron, "Patron assigned to transaction" );
276
        $transaction->patron($sip_patron),
271
    is( $transaction->item($sip_item),
277
        $sip_patron, "Patron assigned to transaction"
272
        $sip_item, "Item assigned to transaction" );
278
    );
279
    is(
280
        $transaction->item($sip_item),
281
        $sip_item, "Item assigned to transaction"
282
    );
273
    my $hold = $transaction->do_hold();
283
    my $hold = $transaction->do_hold();
274
    is( $item->biblio->holds->count(), 2, "Bib has 2 holds" );
284
    is( $item->biblio->holds->count(), 2, "Bib has 2 holds" );
275
285
276
    my $THE_hold = $patron_2->holds->next;
286
    my $THE_hold = $patron_2->holds->next;
277
    is( $THE_hold->priority, 2, 'Hold placed from SIP should have a correct priority of 2');
287
    is( $THE_hold->priority,   2,                     'Hold placed from SIP should have a correct priority of 2' );
278
    is( $THE_hold->branchcode, $patron_2->branchcode, 'Hold placed from SIP should have the branchcode set' );
288
    is( $THE_hold->branchcode, $patron_2->branchcode, 'Hold placed from SIP should have the branchcode set' );
279
};
289
};
280
290
Lines 284-292 subtest "Placing holds via SIP check CanItemBeReserved" => sub { Link Here
284
    my $library = $builder->build_object(
294
    my $library = $builder->build_object(
285
        {
295
        {
286
            class => 'Koha::Libraries',
296
            class => 'Koha::Libraries',
287
            value => {
297
            value => { pickup_location => 0 }
288
                pickup_location => 0
289
            }
290
        }
298
        }
291
    );
299
    );
292
    my $patron_1 = $builder->build_object(
300
    my $patron_1 = $builder->build_object(
Lines 307-314 subtest "Placing holds via SIP check CanItemBeReserved" => sub { Link Here
307
        }
315
        }
308
    );
316
    );
309
317
310
    t::lib::Mocks::mock_userenv(
318
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
311
        { branchcode => $library->branchcode, flags => 1 } );
312
319
313
    my $item = $builder->build_sample_item(
320
    my $item = $builder->build_sample_item(
314
        {
321
        {
Lines 324-333 subtest "Placing holds via SIP check CanItemBeReserved" => sub { Link Here
324
        "C4::SIP::ILS::Transaction::Hold",
331
        "C4::SIP::ILS::Transaction::Hold",
325
        "New transaction created"
332
        "New transaction created"
326
    );
333
    );
327
    is( $transaction->patron($sip_patron),
334
    is(
328
        $sip_patron, "Patron assigned to transaction" );
335
        $transaction->patron($sip_patron),
329
    is( $transaction->item($sip_item),
336
        $sip_patron, "Patron assigned to transaction"
330
        $sip_item, "Item assigned to transaction" );
337
    );
338
    is(
339
        $transaction->item($sip_item),
340
        $sip_item, "Item assigned to transaction"
341
    );
331
    my $hold = $transaction->do_hold();
342
    my $hold = $transaction->do_hold();
332
343
333
    is( $transaction->ok, 0, "Hold was not allowed" );
344
    is( $transaction->ok, 0, "Hold was not allowed" );
Lines 336-346 subtest "Placing holds via SIP check CanItemBeReserved" => sub { Link Here
336
subtest do_checkin => sub {
347
subtest do_checkin => sub {
337
    plan tests => 13;
348
    plan tests => 13;
338
349
339
    my $mockILS = Test::MockObject->new;
350
    my $mockILS  = Test::MockObject->new;
340
    my $server = { ils => $mockILS };
351
    my $server   = { ils => $mockILS };
341
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
352
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
342
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
353
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
343
    my $patron = $builder->build_object(
354
    my $patron   = $builder->build_object(
344
        {
355
        {
345
            class => 'Koha::Patrons',
356
            class => 'Koha::Patrons',
346
            value => {
357
            value => {
Lines 349-356 subtest do_checkin => sub { Link Here
349
        }
360
        }
350
    );
361
    );
351
362
352
    t::lib::Mocks::mock_userenv(
363
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
353
        { branchcode => $library->branchcode, flags => 1 } );
354
364
355
    my $item = $builder->build_sample_item(
365
    my $item = $builder->build_sample_item(
356
        {
366
        {
Lines 358-393 subtest do_checkin => sub { Link Here
358
        }
368
        }
359
    );
369
    );
360
370
361
362
    # Checkout
371
    # Checkout
363
    my $sip_patron  = C4::SIP::ILS::Patron->new( $patron->cardnumber );
372
    my $sip_patron     = C4::SIP::ILS::Patron->new( $patron->cardnumber );
364
    my $sip_item    = C4::SIP::ILS::Item->new( $item->barcode );
373
    my $sip_item       = C4::SIP::ILS::Item->new( $item->barcode );
365
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
374
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
366
    is( $co_transaction->patron($sip_patron),
375
    is(
367
        $sip_patron, "Patron assigned to transaction" );
376
        $co_transaction->patron($sip_patron),
368
    is( $co_transaction->item($sip_item),
377
        $sip_patron, "Patron assigned to transaction"
369
        $sip_item, "Item assigned to transaction" );
378
    );
379
    is(
380
        $co_transaction->item($sip_item),
381
        $sip_item, "Item assigned to transaction"
382
    );
370
    my $checkout = $co_transaction->do_checkout();
383
    my $checkout = $co_transaction->do_checkout();
371
    is( $patron->checkouts->count, 1, 'Checkout should have been done successfully');
384
    is( $patron->checkouts->count, 1, 'Checkout should have been done successfully' );
372
385
373
    # Checkin
386
    # Checkin
374
    my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new();
387
    my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new();
375
    is( $ci_transaction->patron($sip_patron),
388
    is(
376
        $sip_patron, "Patron assigned to transaction" );
389
        $ci_transaction->patron($sip_patron),
377
    is( $ci_transaction->item($sip_item),
390
        $sip_patron, "Patron assigned to transaction"
378
        $sip_item, "Item assigned to transaction" );
391
    );
392
    is(
393
        $ci_transaction->item($sip_item),
394
        $sip_item, "Item assigned to transaction"
395
    );
379
396
380
    my $checkin = $ci_transaction->do_checkin($library->branchcode, C4::SIP::Sip::timestamp);
397
    my $checkin = $ci_transaction->do_checkin( $library->branchcode, C4::SIP::Sip::timestamp );
381
    is( $patron->checkouts->count, 0, 'Checkin should have been done successfully');
398
    is( $patron->checkouts->count, 0, 'Checkin should have been done successfully' );
382
399
383
    # Test checkin without return date
400
    # Test checkin without return date
384
    $co_transaction->do_checkout;
401
    $co_transaction->do_checkout;
385
    is( $patron->checkouts->count, 1, 'Checkout should have been done successfully');
402
    is( $patron->checkouts->count, 1, 'Checkout should have been done successfully' );
386
    $ci_transaction->do_checkin($library->branchcode, undef);
403
    $ci_transaction->do_checkin( $library->branchcode, undef );
387
    is( $patron->checkouts->count, 0, 'Checkin should have been done successfully');
404
    is( $patron->checkouts->count, 0, 'Checkin should have been done successfully' );
388
405
389
    my $result  = $ci_transaction->do_checkin($library2->branchcode, undef);
406
    my $result = $ci_transaction->do_checkin( $library2->branchcode, undef );
390
    is($ci_transaction->alert_type,'04',"Checkin of item no issued at another branch succeeds");
407
    is( $ci_transaction->alert_type, '04', "Checkin of item no issued at another branch succeeds" );
391
    is_deeply(
408
    is_deeply(
392
        $result,
409
        $result,
393
        {
410
        {
Lines 399-420 subtest do_checkin => sub { Link Here
399
        },
416
        },
400
        "Messages show not issued and transferred"
417
        "Messages show not issued and transferred"
401
    );
418
    );
402
    is( $ci_transaction->item->destination_loc,$library->branchcode,"Item destination correctly set");
419
    is( $ci_transaction->item->destination_loc, $library->branchcode, "Item destination correctly set" );
403
420
404
    subtest 'Checkin an in transit item' => sub {
421
    subtest 'Checkin an in transit item' => sub {
405
422
406
        plan tests => 5;
423
        plan tests => 5;
407
424
408
        my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
425
        my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } );
409
        my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
426
        my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } );
410
427
411
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $library_1->branchcode, }});
428
        my $patron =
429
            $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library_1->branchcode, } } );
412
        my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
430
        my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
413
        my $item = $builder->build_sample_item({ library => $library_1->branchcode });
431
        my $item       = $builder->build_sample_item( { library => $library_1->branchcode } );
414
        my $sip_item   = C4::SIP::ILS::Item->new( $item->barcode );
432
        my $sip_item   = C4::SIP::ILS::Item->new( $item->barcode );
415
433
416
        t::lib::Mocks::mock_userenv(
434
        t::lib::Mocks::mock_userenv( { branchcode => $library_1->branchcode, flags => 1 } );
417
            { branchcode => $library_1->branchcode, flags => 1 } );
418
435
419
        my $reserve = AddReserve(
436
        my $reserve = AddReserve(
420
            {
437
            {
Lines 424-451 subtest do_checkin => sub { Link Here
424
            }
441
            }
425
        );
442
        );
426
443
427
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber ); # Mark waiting
444
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber );    # Mark waiting
428
445
429
        my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new();
446
        my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new();
430
        is( $ci_transaction->patron($sip_patron),
447
        is(
431
            $sip_patron, "Patron assigned to transaction" );
448
            $ci_transaction->patron($sip_patron),
432
        is( $ci_transaction->item($sip_item),
449
            $sip_patron, "Patron assigned to transaction"
433
            $sip_item, "Item assigned to transaction" );
450
        );
451
        is(
452
            $ci_transaction->item($sip_item),
453
            $sip_item, "Item assigned to transaction"
454
        );
434
455
435
        my $checkin = $ci_transaction->do_checkin($library_2->branchcode, C4::SIP::Sip::timestamp);
456
        my $checkin = $ci_transaction->do_checkin( $library_2->branchcode, C4::SIP::Sip::timestamp );
436
457
437
        my $hold = Koha::Holds->find($reserve);
458
        my $hold = Koha::Holds->find($reserve);
438
        is( $hold->found, 'T', );
459
        is( $hold->found,                                                          'T', );
439
        is( $hold->itemnumber, $item->itemnumber, );
460
        is( $hold->itemnumber,                                                     $item->itemnumber, );
440
        is( Koha::Checkouts->search({itemnumber => $item->itemnumber})->count, 0, );
461
        is( Koha::Checkouts->search( { itemnumber => $item->itemnumber } )->count, 0, );
441
    };
462
    };
442
463
443
    subtest 'Checkin with fines' => sub {
464
    subtest 'Checkin with fines' => sub {
444
        plan tests => 2;
465
        plan tests => 2;
445
466
446
        my $mockILS = Test::MockObject->new;
467
        my $mockILS     = Test::MockObject->new;
447
        my $server = { ils => $mockILS };
468
        my $server      = { ils => $mockILS };
448
        my $library = $builder->build_object( { class => 'Koha::Libraries' } );
469
        my $library     = $builder->build_object( { class => 'Koha::Libraries' } );
449
        my $institution = {
470
        my $institution = {
450
            id             => $library->id,
471
            id             => $library->id,
451
            implementation => "ILS",
472
            implementation => "ILS",
Lines 457-463 subtest do_checkin => sub { Link Here
457
                retries  => 5,
478
                retries  => 5,
458
            }
479
            }
459
        };
480
        };
460
        my $ils = C4::SIP::ILS->new($institution);
481
        my $ils  = C4::SIP::ILS->new($institution);
461
        my $item = $builder->build_sample_item(
482
        my $item = $builder->build_sample_item(
462
            {
483
            {
463
                library => $library->branchcode,
484
                library => $library->branchcode,
Lines 473-491 subtest do_checkin => sub { Link Here
473
                }
494
                }
474
            }
495
            }
475
        );
496
        );
476
        my $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
497
        my $circ = $ils->checkout( $patron->cardnumber, $item->barcode, undef, undef, $server->{account} );
477
        my $fee1 = $builder->build(
498
        my $fee1 = $builder->build(
478
            {
499
            {
479
                source => 'Accountline',
500
                source => 'Accountline',
480
                value  => {
501
                value  => {
481
                    borrowernumber => $patron->borrowernumber,
502
                    borrowernumber    => $patron->borrowernumber,
482
                    amountoutstanding => 12,
503
                    amountoutstanding => 12,
483
                    debit_type_code   => 'OVERDUE',
504
                    debit_type_code   => 'OVERDUE',
484
                    itemnumber        => $item->itemnumber
505
                    itemnumber        => $item->itemnumber
485
                }
506
                }
486
            }
507
            }
487
        );
508
        );
488
        $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef, $server->{account} );
509
        $circ = $ils->checkin(
510
            $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef,
511
            $server->{account}
512
        );
489
        is( $circ->{screen_msg}, '', "The fine is not displayed on checkin when show_outstanding_amount is disabled" );
513
        is( $circ->{screen_msg}, '', "The fine is not displayed on checkin when show_outstanding_amount is disabled" );
490
514
491
        # show_outstanding_amount enabled
515
        # show_outstanding_amount enabled
Lines 497-509 subtest do_checkin => sub { Link Here
497
                }
521
                }
498
            }
522
            }
499
        );
523
        );
500
        $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
524
        $circ = $ils->checkout( $patron->cardnumber, $item->barcode, undef, undef, $server->{account} );
501
525
502
        $fee1 = $builder->build(
526
        $fee1 = $builder->build(
503
            {
527
            {
504
                source => 'Accountline',
528
                source => 'Accountline',
505
                value  => {
529
                value  => {
506
                    borrowernumber => $patron->borrowernumber,
530
                    borrowernumber    => $patron->borrowernumber,
507
                    amountoutstanding => 12,
531
                    amountoutstanding => 12,
508
                    debit_type_code   => 'OVERDUE',
532
                    debit_type_code   => 'OVERDUE',
509
                    itemnumber        => $item->itemnumber
533
                    itemnumber        => $item->itemnumber
Lines 512-521 subtest do_checkin => sub { Link Here
512
        );
536
        );
513
537
514
        $server->{account}->{show_outstanding_amount} = 1;
538
        $server->{account}->{show_outstanding_amount} = 1;
515
        $circ = $ils->checkout($patron->cardnumber, $item->barcode, undef, undef, $server->{account});
539
        $circ = $ils->checkout( $patron->cardnumber, $item->barcode, undef, undef, $server->{account} );
516
540
517
        $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef, $server->{account} );
541
        $circ = $ils->checkin(
518
        is( $circ->{screen_msg}, 'You owe $12.00 for this item.', "The fine is displayed on checkin when show_outstanding_amount is enabled" );
542
            $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode, undef, undef,
543
            $server->{account}
544
        );
545
        is(
546
            $circ->{screen_msg}, 'You owe $12.00 for this item.',
547
            "The fine is displayed on checkin when show_outstanding_amount is enabled"
548
        );
519
549
520
    };
550
    };
521
};
551
};
Lines 523-531 subtest do_checkin => sub { Link Here
523
subtest do_checkout_with_sysprefs_override => sub {
553
subtest do_checkout_with_sysprefs_override => sub {
524
    plan tests => 8;
554
    plan tests => 8;
525
555
526
    my $mockILS = Test::MockObject->new;
556
    my $mockILS     = Test::MockObject->new;
527
    my $server = { ils => $mockILS };
557
    my $server      = { ils => $mockILS };
528
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
558
    my $library     = $builder->build_object( { class => 'Koha::Libraries' } );
529
    my $institution = {
559
    my $institution = {
530
        id             => $library->id,
560
        id             => $library->id,
531
        implementation => "ILS",
561
        implementation => "ILS",
Lines 537-543 subtest do_checkout_with_sysprefs_override => sub { Link Here
537
            retries  => 5,
567
            retries  => 5,
538
        }
568
        }
539
    };
569
    };
540
    my $ils = C4::SIP::ILS->new($institution);
570
    my $ils  = C4::SIP::ILS->new($institution);
541
    my $item = $builder->build_sample_item(
571
    my $item = $builder->build_sample_item(
542
        {
572
        {
543
            library => $library->branchcode,
573
            library => $library->branchcode,
Lines 557-563 subtest do_checkout_with_sysprefs_override => sub { Link Here
557
        {
587
        {
558
            source => 'Accountline',
588
            source => 'Accountline',
559
            value  => {
589
            value  => {
560
                borrowernumber => $patron_under_noissuescharge->borrowernumber,
590
                borrowernumber    => $patron_under_noissuescharge->borrowernumber,
561
                amountoutstanding => 4,
591
                amountoutstanding => 4,
562
                debit_type_code   => 'OVERDUE',
592
                debit_type_code   => 'OVERDUE',
563
            }
593
            }
Lines 578-640 subtest do_checkout_with_sysprefs_override => sub { Link Here
578
        {
608
        {
579
            source => 'Accountline',
609
            source => 'Accountline',
580
            value  => {
610
            value  => {
581
                borrowernumber => $patron_over_noissuescharge->borrowernumber,
611
                borrowernumber    => $patron_over_noissuescharge->borrowernumber,
582
                amountoutstanding => 6,
612
                amountoutstanding => 6,
583
                debit_type_code   => 'OVERDUE',
613
                debit_type_code   => 'OVERDUE',
584
            }
614
            }
585
        }
615
        }
586
    );
616
    );
587
617
588
589
    $server->{account}->{override_fine_on_checkout} = 0;
618
    $server->{account}->{override_fine_on_checkout} = 0;
590
619
591
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '0' );
620
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '0' );
592
    t::lib::Mocks::mock_preference( 'AllowFineOverride', '0' );
621
    t::lib::Mocks::mock_preference( 'AllowFineOverride',    '0' );
593
    my $circ = $ils->checkout($patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
622
    my $circ =
594
    is( $patron_under_noissuescharge->checkouts->count, 1, 'Checkout is allowed when the amount is under noissuecharge, AllFinesNeedOverride and AllowFineOverride disabled');
623
        $ils->checkout( $patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
624
    is(
625
        $patron_under_noissuescharge->checkouts->count, 1,
626
        'Checkout is allowed when the amount is under noissuecharge, AllFinesNeedOverride and AllowFineOverride disabled'
627
    );
595
628
596
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
629
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
597
630
598
    $circ = $ils->checkout($patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
631
    $circ = $ils->checkout( $patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
599
    is( $patron_over_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride and AllowFineOverride disabled');
632
    is(
633
        $patron_over_noissuescharge->checkouts->count, 0,
634
        'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride and AllowFineOverride disabled'
635
    );
600
636
601
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '0' );
637
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '0' );
602
    t::lib::Mocks::mock_preference( 'AllowFineOverride', '1' );
638
    t::lib::Mocks::mock_preference( 'AllowFineOverride',    '1' );
603
639
604
    $circ = $ils->checkout($patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
640
    $circ =
605
    is( $patron_under_noissuescharge->checkouts->count, 1, 'Checkout is allowed when the amount is under noissuecharge, AllFinesNeedOverride disabled and AllowFineOverride enabled');
641
        $ils->checkout( $patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
642
    is(
643
        $patron_under_noissuescharge->checkouts->count, 1,
644
        'Checkout is allowed when the amount is under noissuecharge, AllFinesNeedOverride disabled and AllowFineOverride enabled'
645
    );
606
646
607
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
647
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
608
648
609
    $circ = $ils->checkout($patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
649
    $circ = $ils->checkout( $patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
610
    is( $patron_over_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride disabled and AllowFineOverride enabled');
650
    is(
651
        $patron_over_noissuescharge->checkouts->count, 0,
652
        'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride disabled and AllowFineOverride enabled'
653
    );
611
654
612
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '1' );
655
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '1' );
613
    t::lib::Mocks::mock_preference( 'AllowFineOverride', '0' );
656
    t::lib::Mocks::mock_preference( 'AllowFineOverride',    '0' );
614
657
615
    $circ = $ils->checkout($patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
658
    $circ =
616
    is( $patron_under_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is under noissuecharge, AllFinesNeedOverride enabled and AllowFineOverride disabled');
659
        $ils->checkout( $patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
660
    is(
661
        $patron_under_noissuescharge->checkouts->count, 0,
662
        'Checkout is blocked when the amount is under noissuecharge, AllFinesNeedOverride enabled and AllowFineOverride disabled'
663
    );
617
664
618
    $circ = $ils->checkout($patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
665
    $circ = $ils->checkout( $patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
619
    is( $patron_over_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride enabled and AllowFineOverride disabled');
666
    is(
667
        $patron_over_noissuescharge->checkouts->count, 0,
668
        'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride enabled and AllowFineOverride disabled'
669
    );
620
670
621
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '1' );
671
    t::lib::Mocks::mock_preference( 'AllFinesNeedOverride', '1' );
622
    t::lib::Mocks::mock_preference( 'AllowFineOverride', '1' );
672
    t::lib::Mocks::mock_preference( 'AllowFineOverride',    '1' );
623
673
624
    $circ = $ils->checkout($patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
674
    $circ =
625
    is( $patron_under_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is under noissuecharge, AllFinesNeedOverride and AllowFineOverride enabled');
675
        $ils->checkout( $patron_under_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
676
    is(
677
        $patron_under_noissuescharge->checkouts->count, 0,
678
        'Checkout is blocked when the amount is under noissuecharge, AllFinesNeedOverride and AllowFineOverride enabled'
679
    );
626
680
627
    $circ = $ils->checkout($patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account});
681
    $circ = $ils->checkout( $patron_over_noissuescharge->cardnumber, $item->barcode, undef, undef, $server->{account} );
628
    is( $patron_over_noissuescharge->checkouts->count, 0, 'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride and AllowFineOverride enabled');
682
    is(
683
        $patron_over_noissuescharge->checkouts->count, 0,
684
        'Checkout is blocked when the amount is over noissuecharge, AllFinesNeedOverride and AllowFineOverride enabled'
685
    );
629
};
686
};
630
687
631
632
subtest do_checkout_with_patron_blocked => sub {
688
subtest do_checkout_with_patron_blocked => sub {
633
    plan tests => 5;
689
    plan tests => 5;
634
690
635
    my $mockILS = Test::MockObject->new;
691
    my $mockILS     = Test::MockObject->new;
636
    my $server = { ils => $mockILS };
692
    my $server      = { ils => $mockILS };
637
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
693
    my $library     = $builder->build_object( { class => 'Koha::Libraries' } );
638
    my $institution = {
694
    my $institution = {
639
        id             => $library->id,
695
        id             => $library->id,
640
        implementation => "ILS",
696
        implementation => "ILS",
Lines 646-652 subtest do_checkout_with_patron_blocked => sub { Link Here
646
            retries  => 5,
702
            retries  => 5,
647
        }
703
        }
648
    };
704
    };
649
    my $ils = C4::SIP::ILS->new($institution);
705
    my $ils  = C4::SIP::ILS->new($institution);
650
    my $item = $builder->build_sample_item(
706
    my $item = $builder->build_sample_item(
651
        {
707
        {
652
            library => $library->branchcode,
708
            library => $library->branchcode,
Lines 662-668 subtest do_checkout_with_patron_blocked => sub { Link Here
662
            }
718
            }
663
        }
719
        }
664
    );
720
    );
665
    my $circ = $ils->checkout($expired_patron->cardnumber, $item->barcode);
721
    my $circ = $ils->checkout( $expired_patron->cardnumber, $item->barcode );
666
    is( $circ->{screen_msg}, 'Patron expired on 01/03/2020', "Got correct expired screen message" );
722
    is( $circ->{screen_msg}, 'Patron expired on 01/03/2020', "Got correct expired screen message" );
667
723
668
    my $fines_patron = $builder->build_object(
724
    my $fines_patron = $builder->build_object(
Lines 677-708 subtest do_checkout_with_patron_blocked => sub { Link Here
677
        {
733
        {
678
            source => 'Accountline',
734
            source => 'Accountline',
679
            value  => {
735
            value  => {
680
                borrowernumber => $fines_patron->borrowernumber,
736
                borrowernumber    => $fines_patron->borrowernumber,
681
                amountoutstanding => 10,
737
                amountoutstanding => 10,
682
                debit_type_code   => 'OVERDUE',
738
                debit_type_code   => 'OVERDUE',
683
            }
739
            }
684
        }
740
        }
685
    );
741
    );
686
742
687
    my $fines_sip_patron  = C4::SIP::ILS::Patron->new( $fines_patron->cardnumber );
743
    my $fines_sip_patron = C4::SIP::ILS::Patron->new( $fines_patron->cardnumber );
688
744
689
    $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account});
745
    $circ = $ils->checkout( $fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account} );
690
    is( $circ->{screen_msg}, 'Patron has fines', "Got correct fines screen message" );
746
    is( $circ->{screen_msg}, 'Patron has fines', "Got correct fines screen message" );
691
747
692
    $server->{account}->{show_outstanding_amount} = 1;
748
    $server->{account}->{show_outstanding_amount} = 1;
693
    $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account});
749
    $circ = $ils->checkout( $fines_patron->cardnumber, $item->barcode, undef, undef, $server->{account} );
694
    is( $circ->{screen_msg}, 'Patron has fines - You owe $10.00.', "Got correct fines with amount screen message" );
750
    is( $circ->{screen_msg}, 'Patron has fines - You owe $10.00.', "Got correct fines with amount screen message" );
695
    my $debarred_patron = $builder->build_object(
751
    my $debarred_patron = $builder->build_object(
696
        {
752
        {
697
            class => 'Koha::Patrons',
753
            class => 'Koha::Patrons',
698
            value => {
754
            value => {
699
                branchcode => $library->branchcode,
755
                branchcode => $library->branchcode,
700
                debarred => '9999/01/01',
756
                debarred   => '9999/01/01',
701
            }
757
            }
702
        }
758
        }
703
    );
759
    );
704
    my $debarred_sip_patron  = C4::SIP::ILS::Patron->new( $debarred_patron->cardnumber );
760
    my $debarred_sip_patron = C4::SIP::ILS::Patron->new( $debarred_patron->cardnumber );
705
    $circ = $ils->checkout($debarred_patron->cardnumber, $item->barcode);
761
    $circ = $ils->checkout( $debarred_patron->cardnumber, $item->barcode );
706
    is( $circ->{screen_msg}, 'Patron debarred', "Got correct debarred screen message" );
762
    is( $circ->{screen_msg}, 'Patron debarred', "Got correct debarred screen message" );
707
763
708
    my $overdue_patron = $builder->build_object(
764
    my $overdue_patron = $builder->build_object(
Lines 714-727 subtest do_checkout_with_patron_blocked => sub { Link Here
714
        }
770
        }
715
    );
771
    );
716
772
717
    my $odue = $builder->build({ source => 'Issue', value => {
773
    my $odue = $builder->build(
718
            borrowernumber => $overdue_patron->borrowernumber,
774
        {
719
            date_due => '2017-01-01',
775
            source => 'Issue',
776
            value  => {
777
                borrowernumber => $overdue_patron->borrowernumber,
778
                date_due       => '2017-01-01',
779
            }
720
        }
780
        }
721
    });
781
    );
722
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
782
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' );
723
    my $overdue_sip_patron  = C4::SIP::ILS::Patron->new( $overdue_patron->cardnumber );
783
    my $overdue_sip_patron = C4::SIP::ILS::Patron->new( $overdue_patron->cardnumber );
724
    $circ = $ils->checkout($overdue_patron->cardnumber, $item->barcode);
784
    $circ = $ils->checkout( $overdue_patron->cardnumber, $item->barcode );
725
    is( $circ->{screen_msg}, 'Patron blocked', "Got correct blocked screen message" );
785
    is( $circ->{screen_msg}, 'Patron blocked', "Got correct blocked screen message" );
726
786
727
};
787
};
Lines 730-747 subtest do_checkout_with_noblock => sub { Link Here
730
    plan tests => 3;
790
    plan tests => 3;
731
791
732
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
792
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
733
    my $patron = $builder->build_object(
793
    my $patron  = $builder->build_object(
734
        {
794
        {
735
            class => 'Koha::Patrons',
795
            class => 'Koha::Patrons',
736
            value => {
796
            value => {
737
                branchcode => $library->branchcode,
797
                branchcode => $library->branchcode,
738
                debarred => '9999/01/01',
798
                debarred   => '9999/01/01',
739
            },
799
            },
740
        }
800
        }
741
    );
801
    );
742
802
743
    t::lib::Mocks::mock_userenv(
803
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
744
        { branchcode => $library->branchcode, flags => 1 } );
745
804
746
    my $item = $builder->build_sample_item(
805
    my $item = $builder->build_sample_item(
747
        {
806
        {
Lines 749-773 subtest do_checkout_with_noblock => sub { Link Here
749
        }
808
        }
750
    );
809
    );
751
810
752
811
    my $sip_patron     = C4::SIP::ILS::Patron->new( $patron->cardnumber );
753
    my $sip_patron  = C4::SIP::ILS::Patron->new( $patron->cardnumber );
812
    my $sip_item       = C4::SIP::ILS::Item->new( $item->barcode );
754
    my $sip_item    = C4::SIP::ILS::Item->new( $item->barcode );
755
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
813
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
756
    is( $co_transaction->patron($sip_patron),
814
    is(
757
        $sip_patron, "Patron assigned to transaction" );
815
        $co_transaction->patron($sip_patron),
758
    is( $co_transaction->item($sip_item),
816
        $sip_patron, "Patron assigned to transaction"
759
        $sip_item, "Item assigned to transaction" );
817
    );
818
    is(
819
        $co_transaction->item($sip_item),
820
        $sip_item, "Item assigned to transaction"
821
    );
760
822
761
    $co_transaction->do_checkout(undef, '19990102    030405');
823
    $co_transaction->do_checkout( undef, '19990102    030405' );
762
824
763
    is( $patron->checkouts->count, 1, 'No Block checkout was performed for debarred patron');
825
    is( $patron->checkouts->count, 1, 'No Block checkout was performed for debarred patron' );
764
};
826
};
765
827
766
subtest do_checkout_with_holds => sub {
828
subtest do_checkout_with_holds => sub {
767
    plan tests => 7;
829
    plan tests => 7;
768
830
769
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
831
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
770
    my $patron = $builder->build_object(
832
    my $patron  = $builder->build_object(
771
        {
833
        {
772
            class => 'Koha::Patrons',
834
            class => 'Koha::Patrons',
773
            value => {
835
            value => {
Lines 784-791 subtest do_checkout_with_holds => sub { Link Here
784
        }
846
        }
785
    );
847
    );
786
848
787
    t::lib::Mocks::mock_userenv(
849
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
788
        { branchcode => $library->branchcode, flags => 1 } );
789
850
790
    my $item = $builder->build_sample_item(
851
    my $item = $builder->build_sample_item(
791
        {
852
        {
Lines 795-837 subtest do_checkout_with_holds => sub { Link Here
795
856
796
    my $reserve = AddReserve(
857
    my $reserve = AddReserve(
797
        {
858
        {
798
                branchcode     => $library->branchcode,
859
            branchcode     => $library->branchcode,
799
                borrowernumber => $patron2->borrowernumber,
860
            borrowernumber => $patron2->borrowernumber,
800
                biblionumber   => $item->biblionumber,
861
            biblionumber   => $item->biblionumber,
801
        }
862
        }
802
    );
863
    );
803
864
804
    my $sip_patron  = C4::SIP::ILS::Patron->new( $patron->cardnumber );
865
    my $sip_patron     = C4::SIP::ILS::Patron->new( $patron->cardnumber );
805
    my $sip_item    = C4::SIP::ILS::Item->new( $item->barcode );
866
    my $sip_item       = C4::SIP::ILS::Item->new( $item->barcode );
806
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
867
    my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new();
807
    is( $co_transaction->patron($sip_patron),
868
    is(
808
        $sip_patron, "Patron assigned to transaction" );
869
        $co_transaction->patron($sip_patron),
809
    is( $co_transaction->item($sip_item),
870
        $sip_patron, "Patron assigned to transaction"
810
        $sip_item, "Item assigned to transaction" );
871
    );
872
    is(
873
        $co_transaction->item($sip_item),
874
        $sip_item, "Item assigned to transaction"
875
    );
811
876
812
    # Test attached holds
877
    # Test attached holds
813
    ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve ); # Mark waiting (W)
878
    ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve );    # Mark waiting (W)
814
    my $hold = Koha::Holds->find($reserve);
879
    my $hold = Koha::Holds->find($reserve);
815
    $co_transaction->do_checkout();
880
    $co_transaction->do_checkout();
816
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (W)');
881
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (W)' );
817
882
818
    $hold->set_transfer;
883
    $hold->set_transfer;
819
    $co_transaction->do_checkout();
884
    $co_transaction->do_checkout();
820
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (T)');
885
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (T)' );
821
886
822
    $hold->set_processing;
887
    $hold->set_processing;
823
    $co_transaction->do_checkout();
888
    $co_transaction->do_checkout();
824
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)');
889
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' );
825
890
826
    # Test non-attached holds
891
    # Test non-attached holds
827
    C4::Reserves::RevertWaitingStatus({ itemnumber => $hold->itemnumber });
892
    C4::Reserves::RevertWaitingStatus( { itemnumber => $hold->itemnumber } );
828
    t::lib::Mocks::mock_preference('AllowItemsOnHoldCheckoutSIP', '0');
893
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' );
829
    $co_transaction->do_checkout();
894
    $co_transaction->do_checkout();
830
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP');
895
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' );
831
896
832
    t::lib::Mocks::mock_preference('AllowItemsOnHoldCheckoutSIP', '1');
897
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '1' );
833
    $co_transaction->do_checkout();
898
    $co_transaction->do_checkout();
834
    is( $patron->checkouts->count, 1, 'Checkout allowed due to hold and AllowItemsOnHoldCheckoutSIP');
899
    is( $patron->checkouts->count, 1, 'Checkout allowed due to hold and AllowItemsOnHoldCheckoutSIP' );
835
};
900
};
836
901
837
subtest checkin_lost => sub {
902
subtest checkin_lost => sub {
Lines 839-850 subtest checkin_lost => sub { Link Here
839
904
840
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
905
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
841
906
842
    t::lib::Mocks::mock_userenv(
907
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
843
        { branchcode => $library->branchcode, flags => 1 } );
844
908
845
    my $item = $builder->build_sample_item(
909
    my $item = $builder->build_sample_item(
846
        {
910
        {
847
            library     => $library->branchcode,
911
            library => $library->branchcode,
848
        }
912
        }
849
    );
913
    );
850
914
Lines 861-873 subtest checkin_lost => sub { Link Here
861
            retries  => 5,
925
            retries  => 5,
862
        }
926
        }
863
    };
927
    };
864
    my $ils = C4::SIP::ILS->new( $instituation );
928
    my $ils = C4::SIP::ILS->new($instituation);
865
929
866
    t::lib::Mocks::mock_preference('BlockReturnOfLostItems', '1');
930
    t::lib::Mocks::mock_preference( 'BlockReturnOfLostItems', '1' );
867
    my $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
931
    my $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
868
    is( $circ->{screen_msg}, 'Item lost, return not allowed', "Got correct screen message" );
932
    is( $circ->{screen_msg}, 'Item lost, return not allowed', "Got correct screen message" );
869
933
870
    t::lib::Mocks::mock_preference('BlockReturnOfLostItems', '0');
934
    t::lib::Mocks::mock_preference( 'BlockReturnOfLostItems', '0' );
871
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
935
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
872
    is( $circ->{screen_msg}, 'Item not checked out', "Got 'Item not checked out' screen message" );
936
    is( $circ->{screen_msg}, 'Item not checked out', "Got 'Item not checked out' screen message" );
873
};
937
};
Lines 877-888 subtest checkin_withdrawn => sub { Link Here
877
941
878
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
942
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
879
943
880
    t::lib::Mocks::mock_userenv(
944
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
881
        { branchcode => $library->branchcode, flags => 1 } );
882
945
883
    my $item = $builder->build_sample_item(
946
    my $item = $builder->build_sample_item(
884
        {
947
        {
885
            library     => $library->branchcode,
948
            library => $library->branchcode,
886
        }
949
        }
887
    );
950
    );
888
951
Lines 899-911 subtest checkin_withdrawn => sub { Link Here
899
            retries  => 5,
962
            retries  => 5,
900
        }
963
        }
901
    };
964
    };
902
    my $ils = C4::SIP::ILS->new( $instituation );
965
    my $ils = C4::SIP::ILS->new($instituation);
903
966
904
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', '1');
967
    t::lib::Mocks::mock_preference( 'BlockReturnOfWithdrawnItems', '1' );
905
    my $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
968
    my $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
906
    is( $circ->{screen_msg}, 'Item withdrawn, return not allowed', "Got correct screen message" );
969
    is( $circ->{screen_msg}, 'Item withdrawn, return not allowed', "Got correct screen message" );
907
970
908
    t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', '0');
971
    t::lib::Mocks::mock_preference( 'BlockReturnOfWithdrawnItems', '0' );
909
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
972
    $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp, undef, $library->branchcode );
910
    is( $circ->{screen_msg}, 'Item not checked out', "Got 'Item not checked out' screen message" );
973
    is( $circ->{screen_msg}, 'Item not checked out', "Got 'Item not checked out' screen message" );
911
};
974
};
Lines 929-940 $branch2:effective_itemtype:eq:CD:4\r Link Here
929
$branch2:itemcallnumber:>:600:5\r
992
$branch2:itemcallnumber:>:600:5\r
930
$branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6\r
993
$branch2:effective_itemtype:eq:BOOK:ccode:eq:TEEN:6\r
931
RULES
994
RULES
932
    t::lib::Mocks::mock_preference('SIP2SortBinMapping', $rules);
995
    t::lib::Mocks::mock_preference( 'SIP2SortBinMapping', $rules );
933
996
934
    my $item_cd = $builder->build_sample_item(
997
    my $item_cd = $builder->build_sample_item(
935
        {
998
        {
936
            library     => $library->branchcode,
999
            library => $library->branchcode,
937
            itype       => 'CD'
1000
            itype   => 'CD'
938
        }
1001
        }
939
    );
1002
    );
940
1003
Lines 957-978 RULES Link Here
957
    my $bin;
1020
    my $bin;
958
1021
959
    # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would)
1022
    # Set holdingbranch as though item returned to library other than homebranch (As AddReturn would)
960
    $item_cd->holdingbranch($library2->branchcode)->store();
1023
    $item_cd->holdingbranch( $library2->branchcode )->store();
961
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library2->branchcode );
1024
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library2->branchcode );
962
    is($bin, 'X', "Item parameter on RHS of comparison works (ne comparator)");
1025
    is( $bin, 'X', "Item parameter on RHS of comparison works (ne comparator)" );
963
1026
964
    # Reset holdingbranch as though item returned to home library
1027
    # Reset holdingbranch as though item returned to home library
965
    $item_cd->holdingbranch($library->branchcode)->store();
1028
    $item_cd->holdingbranch( $library->branchcode )->store();
966
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library->branchcode );
1029
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_cd, $library->branchcode );
967
    is($bin, '0', "Fixed value on RHS of comparison works (eq comparator)");
1030
    is( $bin, '0', "Fixed value on RHS of comparison works (eq comparator)" );
968
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1031
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
969
    is($bin, '1', "Rules applied in order (< comparator)");
1032
    is( $bin, '1', "Rules applied in order (< comparator)" );
970
    $item_book->itemcallnumber('350.20')->store();
1033
    $item_book->itemcallnumber('350.20')->store();
971
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
1034
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book, $library->branchcode );
972
    is($bin, '2', "Rules applied in order (< comparator)");
1035
    is( $bin, '2', "Rules applied in order (< comparator)" );
973
1036
974
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode );
1037
    $bin = C4::SIP::ILS::Transaction::Checkin::_get_sort_bin( $item_book2, $library2->branchcode );
975
    is($bin, '6', "Rules with multiple field matches");
1038
    is( $bin, '6', "Rules with multiple field matches" );
976
};
1039
};
977
1040
978
subtest item_circulation_status => sub {
1041
subtest item_circulation_status => sub {
Lines 990-997 subtest item_circulation_status => sub { Link Here
990
        }
1053
        }
991
    );
1054
    );
992
1055
993
    t::lib::Mocks::mock_userenv(
1056
    t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } );
994
        { branchcode => $library->branchcode, flags => 1 } );
995
1057
996
    my $item = $builder->build_sample_item(
1058
    my $item = $builder->build_sample_item(
997
        {
1059
        {
Lines 1000-1057 subtest item_circulation_status => sub { Link Here
1000
    );
1062
    );
1001
1063
1002
    my $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1064
    my $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1003
    my $status = $sip_item->sip_circulation_status;
1065
    my $status   = $sip_item->sip_circulation_status;
1004
    is( $status, '03', "Item circulation status is available");
1066
    is( $status, '03', "Item circulation status is available" );
1005
1067
1006
    my $transfer = Koha::Item::Transfer->new({
1068
    my $transfer = Koha::Item::Transfer->new(
1007
        itemnumber => $item->id,
1069
        {
1008
        datesent   => '2020-01-01',
1070
            itemnumber => $item->id,
1009
        frombranch => $library->branchcode,
1071
            datesent   => '2020-01-01',
1010
        tobranch   => $library2->branchcode,
1072
            frombranch => $library->branchcode,
1011
    })->store();
1073
            tobranch   => $library2->branchcode,
1074
        }
1075
    )->store();
1012
1076
1013
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1077
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1014
    $status = $sip_item->sip_circulation_status;
1078
    $status   = $sip_item->sip_circulation_status;
1015
    is( $status, '10', "Item circulation status is in transit" );
1079
    is( $status, '10', "Item circulation status is in transit" );
1016
1080
1017
    $transfer->delete;
1081
    $transfer->delete;
1018
1082
1019
    my $claim = Koha::Checkouts::ReturnClaim->new({
1083
    my $claim = Koha::Checkouts::ReturnClaim->new(
1020
        itemnumber     => $item->id,
1084
        {
1021
        borrowernumber => $patron->id,
1085
            itemnumber     => $item->id,
1022
        created_by     => $patron->id,
1086
            borrowernumber => $patron->id,
1023
    })->store();
1087
            created_by     => $patron->id,
1088
        }
1089
    )->store();
1024
1090
1025
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1091
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1026
    $status = $sip_item->sip_circulation_status;
1092
    $status   = $sip_item->sip_circulation_status;
1027
    is( $status, '11', "Item circulation status is claimed returned" );
1093
    is( $status, '11', "Item circulation status is claimed returned" );
1028
1094
1029
    $claim->delete;
1095
    $claim->delete;
1030
1096
1031
    $item->itemlost(1)->store();
1097
    $item->itemlost(1)->store();
1032
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1098
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1033
    $status = $sip_item->sip_circulation_status;
1099
    $status   = $sip_item->sip_circulation_status;
1034
    is( $status, '12', "Item circulation status is lost" );
1100
    is( $status, '12', "Item circulation status is lost" );
1035
    $item->itemlost(0)->store();
1101
    $item->itemlost(0)->store();
1036
1102
1037
    my $location = $item->location;
1103
    my $location = $item->location;
1038
    $item->location("CART")->store();
1104
    $item->location("CART")->store();
1039
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1105
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1040
    $status = $sip_item->sip_circulation_status;
1106
    $status   = $sip_item->sip_circulation_status;
1041
    is( $status, '09', "Item circulation status is waiting to be re-shelved" );
1107
    is( $status, '09', "Item circulation status is waiting to be re-shelved" );
1042
    $item->location($location)->store();
1108
    $item->location($location)->store();
1043
1109
1044
    my $nfl = $item->notforloan;
1110
    my $nfl = $item->notforloan;
1045
    $item->notforloan(-1)->store();
1111
    $item->notforloan(-1)->store();
1046
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1112
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1047
    $status = $sip_item->sip_circulation_status;
1113
    $status   = $sip_item->sip_circulation_status;
1048
    is( $status, '02', "Item circulation status is on order" );
1114
    is( $status, '02', "Item circulation status is on order" );
1049
    $item->notforloan($nfl)->store();
1115
    $item->notforloan($nfl)->store();
1050
1116
1051
    my $damaged = $item->damaged;
1117
    my $damaged = $item->damaged;
1052
    $item->damaged(1)->store();
1118
    $item->damaged(1)->store();
1053
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1119
    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
1054
    $status = $sip_item->sip_circulation_status;
1120
    $status   = $sip_item->sip_circulation_status;
1055
    is( $status, '01', "Item circulation status is damaged" );
1121
    is( $status, '01', "Item circulation status is damaged" );
1056
    $item->damaged(0)->store();
1122
    $item->damaged(0)->store();
1057
};
1123
};
1058
- 

Return to bug 34737