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

(-)a/Koha/Hold.pm (-99 / +71 lines)
Lines 67-77 sub age { Link Here
67
    my $age;
67
    my $age;
68
68
69
    if ( $use_calendar ) {
69
    if ( $use_calendar ) {
70
        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
70
        my $calendar = Koha::Calendar->new( branchcode => $self->pickup_library_id );
71
        $age = $calendar->days_between( dt_from_string( $self->reservedate ), $today );
71
        $age = $calendar->days_between( dt_from_string( $self->created_date ), $today );
72
    }
72
    }
73
    else {
73
    else {
74
        $age = $today->delta_days( dt_from_string( $self->reservedate ) );
74
        $age = $today->delta_days( dt_from_string( $self->created_date ) );
75
    }
75
    }
76
76
77
    $age = $age->in_units( 'days' );
77
    $age = $age->in_units( 'days' );
Lines 91-101 sub suspend_hold { Link Here
91
    my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef;
91
    my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef;
92
92
93
    if ( $self->is_found ) {    # We can't suspend found holds
93
    if ( $self->is_found ) {    # We can't suspend found holds
94
        if ( $self->is_waiting ) {
94
        if ( $self->is_waiting or
95
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'W' );
95
             $self->is_in_transit ) {
96
        }
96
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => $self->status );
97
        elsif ( $self->is_in_transit ) {
98
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'T' );
99
        }
97
        }
100
        elsif ( $self->is_in_processing ) {
98
        elsif ( $self->is_in_processing ) {
101
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'P' );
99
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'P' );
Lines 104-120 sub suspend_hold { Link Here
104
            Koha::Exceptions::Hold::CannotSuspendFound->throw(
102
            Koha::Exceptions::Hold::CannotSuspendFound->throw(
105
                      'Unhandled data exception on found hold (id='
103
                      'Unhandled data exception on found hold (id='
106
                    . $self->id
104
                    . $self->id
107
                    . ', found='
105
                    . ', status='
108
                    . $self->found
106
                    . $self->status
109
                    . ')' );
107
                    . ')' );
110
        }
108
        }
111
    }
109
    }
112
110
113
    $self->suspend(1);
111
    $self->suspended(1);
114
    $self->suspend_until($date);
112
    $self->suspended_until_date($date);
115
    $self->store();
113
    $self->store();
116
114
117
    logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper( $self->unblessed ) )
115
    logaction( 'HOLDS', 'SUSPEND', $self->id, Dumper( $self->unblessed ) )
118
        if C4::Context->preference('HoldsLog');
116
        if C4::Context->preference('HoldsLog');
119
117
120
    return $self;
118
    return $self;
Lines 129-140 my $hold = $hold->resume(); Link Here
129
sub resume {
127
sub resume {
130
    my ( $self ) = @_;
128
    my ( $self ) = @_;
131
129
132
    $self->suspend(0);
130
    $self->suspended(0);
133
    $self->suspend_until( undef );
131
    $self->suspended_until_date( undef );
134
132
135
    $self->store();
133
    $self->store();
136
134
137
    logaction( 'HOLDS', 'RESUME', $self->reserve_id, Dumper($self->unblessed) )
135
    logaction( 'HOLDS', 'RESUME', $self->id, Dumper($self->unblessed) )
138
        if C4::Context->preference('HoldsLog');
136
        if C4::Context->preference('HoldsLog');
139
137
140
    return $self;
138
    return $self;
Lines 151-157 sub delete { Link Here
151
149
152
    my $deleted = $self->SUPER::delete($self);
150
    my $deleted = $self->SUPER::delete($self);
153
151
154
    logaction( 'HOLDS', 'DELETE', $self->reserve_id, Dumper($self->unblessed) )
152
    logaction( 'HOLDS', 'DELETE', $self->id, Dumper($self->unblessed) )
155
        if C4::Context->preference('HoldsLog');
153
        if C4::Context->preference('HoldsLog');
156
154
157
    return $deleted;
155
    return $deleted;
Lines 165-171 sub set_transfer { Link Here
165
    my ( $self ) = @_;
163
    my ( $self ) = @_;
166
164
167
    $self->priority(0);
165
    $self->priority(0);
168
    $self->found('T');
166
    $self->status('in_transit');
169
    $self->store();
167
    $self->store();
170
168
171
    return $self;
169
    return $self;
Lines 182-195 sub set_waiting { Link Here
182
180
183
    my $today = dt_from_string();
181
    my $today = dt_from_string();
184
    my $values = {
182
    my $values = {
185
        found => 'W',
183
        status       => 'waiting',
186
        waitingdate => $today->ymd,
184
        waiting_date => $today->ymd,
187
        desk_id => $desk_id,
185
        desk_id      => $desk_id,
188
    };
186
    };
189
187
190
    my $requested_expiration;
188
    my $requested_expiration;
191
    if ($self->expirationdate) {
189
    if ($self->expiration_date) {
192
        $requested_expiration = dt_from_string($self->expirationdate);
190
        $requested_expiration = dt_from_string($self->expiration_date);
193
    }
191
    }
194
192
195
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
193
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
Lines 202-213 sub set_waiting { Link Here
202
        my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype;
200
        my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype;
203
        my $daysmode = Koha::CirculationRules->get_effective_daysmode(
201
        my $daysmode = Koha::CirculationRules->get_effective_daysmode(
204
            {
202
            {
205
                categorycode => $self->borrower->categorycode,
203
                categorycode => $self->patron->categorycode,
206
                itemtype     => $itemtype,
204
                itemtype     => $itemtype,
207
                branchcode   => $self->branchcode,
205
                branchcode   => $self->pickup_library_id,
208
            }
206
            }
209
        );
207
        );
210
        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode, days_mode => $daysmode );
208
        my $calendar = Koha::Calendar->new( branchcode => $self->pickup_library_id, days_mode => $daysmode );
211
209
212
        $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay );
210
        $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay );
213
    }
211
    }
Lines 215-221 sub set_waiting { Link Here
215
    # If patron's requested expiration date is prior to the
213
    # If patron's requested expiration date is prior to the
216
    # calculated one, we keep the patron's one.
214
    # calculated one, we keep the patron's one.
217
    my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
215
    my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
218
    $values->{expirationdate} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
216
    $values->{expiration_date} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
219
217
220
    $self->set($values)->store();
218
    $self->set($values)->store();
221
219
Lines 242-248 sub is_pickup_location_valid { Link Here
242
240
243
    my @pickup_locations;
241
    my @pickup_locations;
244
242
245
    if ( $self->itemnumber ) { # item-level
243
    if ( $self->item_id ) { # item-level
246
        @pickup_locations = $self->item->pickup_locations({ patron => $self->patron });
244
        @pickup_locations = $self->item->pickup_locations({ patron => $self->patron });
247
    }
245
    }
248
    else { # biblio-level
246
    else { # biblio-level
Lines 269-275 sub set_pickup_location { Link Here
269
267
270
    if ( $self->is_pickup_location_valid({ library_id => $params->{library_id} }) ) {
268
    if ( $self->is_pickup_location_valid({ library_id => $params->{library_id} }) ) {
271
        # all good, set the new pickup location
269
        # all good, set the new pickup location
272
        $self->branchcode( $params->{library_id} )->store;
270
        $self->pickup_library_id( $params->{library_id} )->store;
273
    }
271
    }
274
    else {
272
    else {
275
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
273
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
Lines 290-296 sub set_processing { Link Here
290
    my ( $self ) = @_;
288
    my ( $self ) = @_;
291
289
292
    $self->priority(0);
290
    $self->priority(0);
293
    $self->found('P');
291
    $self->status('processing');
294
    $self->store();
292
    $self->store();
295
293
296
    return $self;
294
    return $self;
Lines 305-314 Returns true if hold is waiting, in transit or in processing Link Here
305
sub is_found {
303
sub is_found {
306
    my ($self) = @_;
304
    my ($self) = @_;
307
305
308
    return 0 unless $self->found();
306
    if (
309
    return 1 if $self->found() eq 'W';
307
             $self->status eq 'waiting'
310
    return 1 if $self->found() eq 'T';
308
          or $self->status eq 'in_transit'
311
    return 1 if $self->found() eq 'P';
309
          or $self->status eq 'processing'
310
      )
311
    {
312
        return 1;
313
    }
314
315
    return 0;
312
}
316
}
313
317
314
=head3 is_waiting
318
=head3 is_waiting
Lines 320-327 Returns true if hold is a waiting hold Link Here
320
sub is_waiting {
324
sub is_waiting {
321
    my ($self) = @_;
325
    my ($self) = @_;
322
326
323
    my $found = $self->found;
327
    return $self->status eq 'waiting';
324
    return $found && $found eq 'W';
325
}
328
}
326
329
327
=head3 is_in_transit
330
=head3 is_in_transit
Lines 333-340 Returns true if hold is a in_transit hold Link Here
333
sub is_in_transit {
336
sub is_in_transit {
334
    my ($self) = @_;
337
    my ($self) = @_;
335
338
336
    return 0 unless $self->found();
339
    return $self->status eq 'in_transit';
337
    return $self->found() eq 'T';
338
}
340
}
339
341
340
=head3 is_in_processing
342
=head3 is_in_processing
Lines 346-353 Returns true if hold is a in_processing hold Link Here
346
sub is_in_processing {
348
sub is_in_processing {
347
    my ($self) = @_;
349
    my ($self) = @_;
348
350
349
    return 0 unless $self->found();
351
    return $self->status eq 'processing';
350
    return $self->found() eq 'P';
351
}
352
}
352
353
353
=head3 is_cancelable_from_opac
354
=head3 is_cancelable_from_opac
Lines 378-384 the hold item's holding branch Link Here
378
sub is_at_destination {
379
sub is_at_destination {
379
    my ($self) = @_;
380
    my ($self) = @_;
380
381
381
    return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
382
    return $self->is_waiting() && ( $self->pickup_library_id() eq $self->item()->holdingbranch() );
382
}
383
}
383
384
384
=head3 biblio
385
=head3 biblio
Lines 390-396 Returns the related Koha::Biblio object for this hold Link Here
390
sub biblio {
391
sub biblio {
391
    my ($self) = @_;
392
    my ($self) = @_;
392
393
393
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
394
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblio_id );
394
395
395
    return $self->{_biblio};
396
    return $self->{_biblio};
396
}
397
}
Lines 417-423 Returns the related Koha::Item object for this Hold Link Here
417
sub item {
418
sub item {
418
    my ($self) = @_;
419
    my ($self) = @_;
419
420
420
    $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
421
    $self->{_item} ||= Koha::Items->find( $self->item_id );
421
422
422
    return $self->{_item};
423
    return $self->{_item};
423
}
424
}
Lines 431-437 Returns the related Koha::Library object for this Hold Link Here
431
sub branch {
432
sub branch {
432
    my ($self) = @_;
433
    my ($self) = @_;
433
434
434
    $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
435
    $self->{_branch} ||= Koha::Libraries->find( $self->pickup_library_id );
435
436
436
    return $self->{_branch};
437
    return $self->{_branch};
437
}
438
}
Lines 459-465 Returns the related Koha::Patron object for this Hold Link Here
459
sub borrower {
460
sub borrower {
460
    my ($self) = @_;
461
    my ($self) = @_;
461
462
462
    $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
463
    $self->{_borrower} ||= Koha::Patrons->find( $self->patron_id );
463
464
464
    return $self->{_borrower};
465
    return $self->{_borrower};
465
}
466
}
Lines 473-482 my $bool = $hold->is_suspended(); Link Here
473
sub is_suspended {
474
sub is_suspended {
474
    my ( $self ) = @_;
475
    my ( $self ) = @_;
475
476
476
    return $self->suspend();
477
    return $self->suspended();
477
}
478
}
478
479
479
480
=head3 cancel
480
=head3 cancel
481
481
482
my $cancel_hold = $hold->cancel(
482
my $cancel_hold = $hold->cancel(
Lines 487-496 my $cancel_hold = $hold->cancel( Link Here
487
);
487
);
488
488
489
Cancel a hold:
489
Cancel a hold:
490
- The hold will be moved to the old_reserves table with a priority=0
490
- The hold will be marked as completed, status 'cancelled' and a priority=0
491
- The priority of other holds will be updated
491
- The priority of other holds will be updated
492
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
492
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
493
- The canceled hold will have the cancellation reason added to old_reserves.cancellation_reason if one is passed in
493
- The canceled hold will have the cancellation reason added to cancellation_reason if one is passed in
494
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
494
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
495
495
496
=cut
496
=cut
Lines 499-508 sub cancel { Link Here
499
    my ( $self, $params ) = @_;
499
    my ( $self, $params ) = @_;
500
    $self->_result->result_source->schema->txn_do(
500
    $self->_result->result_source->schema->txn_do(
501
        sub {
501
        sub {
502
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
502
            $self->set(
503
            $self->priority(0);
503
                {
504
            $self->cancellation_reason( $params->{cancellation_reason} );
504
                    completed_date => dt_from_string->strftime('%Y-%m-%d %H:%M:%S'),
505
            $self->store();
505
                    completed      => 1,
506
                    priority       => 0,
507
                    status         => 'cancelled',
508
                    cancellation_reason => $params->{cancellation_reason},
509
                }
510
            )->store();
506
511
507
            if ( $params->{cancellation_reason} ) {
512
            if ( $params->{cancellation_reason} ) {
508
                my $letter = C4::Letters::GetPreparedLetter(
513
                my $letter = C4::Letters::GetPreparedLetter(
Lines 513-522 sub cancel { Link Here
513
                    lang                   => $self->borrower->lang,
518
                    lang                   => $self->borrower->lang,
514
                    tables => {
519
                    tables => {
515
                        branches    => $self->borrower->branchcode,
520
                        branches    => $self->borrower->branchcode,
516
                        borrowers   => $self->borrowernumber,
521
                        borrowers   => $self->patron_id,
517
                        items       => $self->itemnumber,
522
                        items       => $self->item_id,
518
                        biblio      => $self->biblionumber,
523
                        biblio      => $self->biblio_id,
519
                        biblioitems => $self->biblionumber,
524
                        biblioitems => $self->biblio_id,
520
                        reserves    => $self->unblessed,
525
                        reserves    => $self->unblessed,
521
                    }
526
                    }
522
                );
527
                );
Lines 524-548 sub cancel { Link Here
524
                if ($letter) {
529
                if ($letter) {
525
                    C4::Letters::EnqueueLetter(
530
                    C4::Letters::EnqueueLetter(
526
                        {
531
                        {
527
                            letter                   => $letter,
532
                            letter                 => $letter,
528
                            borrowernumber         => $self->borrowernumber,
533
                            borrowernumber         => $self->patron_id,
529
                            message_transport_type => 'email',
534
                            message_transport_type => 'email',
530
                        }
535
                        }
531
                    );
536
                    );
532
                }
537
                }
533
            }
538
            }
534
539
535
            $self->_move_to_old;
536
            $self->SUPER::delete(); # Do not add a DELETE log
537
538
            # now fix the priority on the others....
540
            # now fix the priority on the others....
539
            C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });
541
            C4::Reserves::_FixPriority({ biblionumber => $self->biblio_id });
540
542
541
            # and, if desired, charge a cancel fee
543
            # and, if desired, charge a cancel fee
542
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
544
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
543
            if ( $charge && $params->{'charge_cancel_fee'} ) {
545
            if ( $charge && $params->{'charge_cancel_fee'} ) {
544
                my $account =
546
                my $account =
545
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
547
                  Koha::Account->new( { patron_id => $self->patron_id } );
546
                $account->add_debit(
548
                $account->add_debit(
547
                    {
549
                    {
548
                        amount     => $charge,
550
                        amount     => $charge,
Lines 550-581 sub cancel { Link Here
550
                        interface  => C4::Context->interface,
552
                        interface  => C4::Context->interface,
551
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
553
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
552
                        type       => 'RESERVE_EXPIRED',
554
                        type       => 'RESERVE_EXPIRED',
553
                        item_id    => $self->itemnumber
555
                        item_id    => $self->item_id
554
                    }
556
                    }
555
                );
557
                );
556
            }
558
            }
557
559
558
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) )
560
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->id, Dumper($self->unblessed) )
559
                if C4::Context->preference('HoldsLog');
561
                if C4::Context->preference('HoldsLog');
560
        }
562
        }
561
    );
563
    );
562
    return $self;
564
    return $self;
563
}
565
}
564
566
565
=head3 _move_to_old
566
567
my $is_moved = $hold->_move_to_old;
568
569
Move a hold to the old_reserve table following the same pattern as Koha::Patron->move_to_deleted
570
571
=cut
572
573
sub _move_to_old {
574
    my ($self) = @_;
575
    my $hold_infos = $self->unblessed;
576
    return Koha::Old::Hold->new( $hold_infos )->store;
577
}
578
579
=head3 to_api_mapping
567
=head3 to_api_mapping
580
568
581
This method returns the mapping for representing a Koha::Hold object
569
This method returns the mapping for representing a Koha::Hold object
Lines 585-608 on the API. Link Here
585
573
586
sub to_api_mapping {
574
sub to_api_mapping {
587
    return {
575
    return {
588
        reserve_id       => 'hold_id',
576
        id => 'hold_id'
589
        borrowernumber   => 'patron_id',
590
        reservedate      => 'hold_date',
591
        biblionumber     => 'biblio_id',
592
        branchcode       => 'pickup_library_id',
593
        notificationdate => undef,
594
        reminderdate     => undef,
595
        cancellationdate => 'cancellation_date',
596
        reservenotes     => 'notes',
597
        found            => 'status',
598
        itemnumber       => 'item_id',
599
        waitingdate      => 'waiting_date',
600
        expirationdate   => 'expiration_date',
601
        lowestPriority   => 'lowest_priority',
602
        suspend          => 'suspended',
603
        suspend_until    => 'suspended_until',
604
        itemtype         => 'item_type',
605
        item_level_hold  => 'item_level',
606
    };
577
    };
607
}
578
}
608
579
Lines 613-619 sub to_api_mapping { Link Here
613
=cut
584
=cut
614
585
615
sub _type {
586
sub _type {
616
    return 'Reserve';
587
    return 'Hold';
617
}
588
}
618
589
619
=head1 AUTHORS
590
=head1 AUTHORS
Lines 621-626 sub _type { Link Here
621
Kyle M Hall <kyle@bywatersolutions.com>
592
Kyle M Hall <kyle@bywatersolutions.com>
622
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
593
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
623
Martin Renvoize <martin.renvoize@ptfs-europe.com>
594
Martin Renvoize <martin.renvoize@ptfs-europe.com>
595
Tomás Cohen Arazu <tomascohen@theke.io>
624
596
625
=cut
597
=cut
626
598
(-)a/Koha/Holds.pm (-6 / +16 lines)
Lines 33-39 Koha::Holds - Koha Hold object set class Link Here
33
33
34
=head1 API
34
=head1 API
35
35
36
=head2 Class Methods
36
=head2 Class methods
37
37
38
=cut
38
=cut
39
39
Lines 46-52 returns a set of holds that are waiting from an existing set Link Here
46
sub waiting {
46
sub waiting {
47
    my ( $self ) = @_;
47
    my ( $self ) = @_;
48
48
49
    return $self->search( { found => 'W' } );
49
    return $self->search(
50
        {
51
            status    => 'waiting',
52
            completed => 0
53
        }
54
    );
50
}
55
}
51
56
52
=head3 unfilled
57
=head3 unfilled
Lines 58-64 returns a set of holds that are unfilled from an existing set Link Here
58
sub unfilled {
63
sub unfilled {
59
    my ( $self ) = @_;
64
    my ( $self ) = @_;
60
65
61
    return $self->search( { found => undef } );
66
    return $self->search(
67
        {
68
            status    => 'placed',
69
            completed => 0
70
        }
71
    );
62
}
72
}
63
73
64
=head3 forced_hold_level
74
=head3 forced_hold_level
Lines 83-92 that would prevent one or the other. Link Here
83
sub forced_hold_level {
93
sub forced_hold_level {
84
    my ($self) = @_;
94
    my ($self) = @_;
85
95
86
    my $item_level_count = $self->search( { itemnumber => { '!=' => undef } } )->count();
96
    my $item_level_count = $self->search( { item_id => { '!=' => undef } } )->count();
87
    return 'item' if $item_level_count > 0;
97
    return 'item' if $item_level_count > 0;
88
98
89
    my $record_level_count = $self->search( { itemnumber => undef } )->count();
99
    my $record_level_count = $self->search( { item_id => undef } )->count();
90
    return 'record' if $record_level_count > 0;
100
    return 'record' if $record_level_count > 0;
91
101
92
    return;
102
    return;
Lines 158-164 sub get_items_that_can_fill { Link Here
158
=cut
168
=cut
159
169
160
sub _type {
170
sub _type {
161
    return 'Reserve';
171
    return 'Hold';
162
}
172
}
163
173
164
=head3 object_class
174
=head3 object_class
(-)a/t/db_dependent/Koha/Hold.t (-17 / +17 lines)
Lines 42-48 subtest 'patron() tests' => sub { Link Here
42
        {
42
        {
43
            class => 'Koha::Holds',
43
            class => 'Koha::Holds',
44
            value => {
44
            value => {
45
                borrowernumber => $patron->borrowernumber
45
                patron_id => $patron->borrowernumber
46
            }
46
            }
47
        }
47
        }
48
    );
48
    );
Lines 84-92 subtest 'set_pickup_location() tests' => sub { Link Here
84
        {
84
        {
85
            class => "Koha::Holds",
85
            class => "Koha::Holds",
86
            value => {
86
            value => {
87
                biblionumber => $biblio->biblionumber,
87
                biblio_id         => $biblio->biblionumber,
88
                branchcode   => $library_3->branchcode,
88
                pickup_library_id => $library_3->branchcode,
89
                itemnumber   => undef,
89
                item_id           => undef,
90
            }
90
            }
91
        }
91
        }
92
    );
92
    );
Lines 97-118 subtest 'set_pickup_location() tests' => sub { Link Here
97
        'Exception thrown on invalid pickup location';
97
        'Exception thrown on invalid pickup location';
98
98
99
    $biblio_hold->discard_changes;
99
    $biblio_hold->discard_changes;
100
    is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
100
    is( $biblio_hold->pickup_library_id, $library_3->branchcode, 'branchcode remains untouched' );
101
101
102
    my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id });
102
    my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id });
103
    is( ref($ret), 'Koha::Hold', 'self is returned' );
103
    is( ref($ret), 'Koha::Hold', 'self is returned' );
104
104
105
    $biblio_hold->discard_changes;
105
    $biblio_hold->discard_changes;
106
    is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
106
    is( $biblio_hold->pickup_library_id, $library_2->id, 'Pickup location changed correctly' );
107
107
108
    # Test item-level holds
108
    # Test item-level holds
109
    my $item_hold = $builder->build_object(
109
    my $item_hold = $builder->build_object(
110
        {
110
        {
111
            class => "Koha::Holds",
111
            class => "Koha::Holds",
112
            value => {
112
            value => {
113
                biblionumber => $biblio->biblionumber,
113
                biblio_id           => $biblio->biblionumber,
114
                branchcode   => $library_3->branchcode,
114
                pickup_library_id   => $library_3->branchcode,
115
                itemnumber   => $item->itemnumber,
115
                item_id             => $item->itemnumber,
116
            }
116
            }
117
        }
117
        }
118
    );
118
    );
Lines 123-135 subtest 'set_pickup_location() tests' => sub { Link Here
123
        'Exception thrown on invalid pickup location';
123
        'Exception thrown on invalid pickup location';
124
124
125
    $item_hold->discard_changes;
125
    $item_hold->discard_changes;
126
    is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
126
    is( $item_hold->pickup_library_id, $library_3->branchcode, 'branchcode remains untouched' );
127
127
128
    $ret = $item_hold->set_pickup_location({ library_id => $library_2->id });
128
    $ret = $item_hold->set_pickup_location({ library_id => $library_2->id });
129
    is( ref($ret), 'Koha::Hold', 'self is returned' );
129
    is( ref($ret), 'Koha::Hold', 'self is returned' );
130
130
131
    $item_hold->discard_changes;
131
    $item_hold->discard_changes;
132
    is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
132
    is( $item_hold->pickup_library_id, $library_2->id, 'Pickup location changed correctly' );
133
133
134
    throws_ok
134
    throws_ok
135
        { $item_hold->set_pickup_location({ library_id => undef }); }
135
        { $item_hold->set_pickup_location({ library_id => undef }); }
Lines 171-179 subtest 'is_pickup_location_valid() tests' => sub { Link Here
171
        {
171
        {
172
            class => "Koha::Holds",
172
            class => "Koha::Holds",
173
            value => {
173
            value => {
174
                biblionumber => $biblio->biblionumber,
174
                biblio_id          => $biblio->biblionumber,
175
                branchcode   => $library_3->branchcode,
175
                pickup_library_id  => $library_3->branchcode,
176
                itemnumber   => undef,
176
                item_it            => undef,
177
            }
177
            }
178
        }
178
        }
179
    );
179
    );
Lines 186-194 subtest 'is_pickup_location_valid() tests' => sub { Link Here
186
        {
186
        {
187
            class => "Koha::Holds",
187
            class => "Koha::Holds",
188
            value => {
188
            value => {
189
                biblionumber => $biblio->biblionumber,
189
                biblio_id           => $biblio->biblionumber,
190
                branchcode   => $library_3->branchcode,
190
                pickup_library_id   => $library_3->branchcode,
191
                itemnumber   => $item->itemnumber,
191
                item_id             => $item->itemnumber,
192
            }
192
            }
193
        }
193
        }
194
    );
194
    );
(-)a/t/db_dependent/Koha/Holds.t (-10 / +8 lines)
Lines 298-306 subtest 'cancel with reason' => sub { Link Here
298
    $hold->cancel({cancellation_reason => 'TEST_REASON'});
298
    $hold->cancel({cancellation_reason => 'TEST_REASON'});
299
299
300
    $hold = Koha::Holds->find($reserve_id);
300
    $hold = Koha::Holds->find($reserve_id);
301
    is( $hold, undef, 'Hold is not in the reserves table');
301
    is( ref($hold), 'Koha::Hold', 'Hold still exists');
302
    $hold = Koha::Old::Holds->find($reserve_id);
302
    ok( $hold->completed, 'Hold marked as complete');
303
    ok( $hold, 'Hold was found in the old reserves table');
304
303
305
    my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'});
304
    my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'});
306
    ok( $message, 'Found hold cancellation message');
305
    ok( $message, 'Found hold cancellation message');
Lines 313-319 subtest 'cancel with reason' => sub { Link Here
313
};
312
};
314
313
315
subtest 'cancel all with reason' => sub {
314
subtest 'cancel all with reason' => sub {
316
    plan tests => 7;
315
316
    plan tests => 6;
317
317
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
318
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
318
    my $item = $builder->build_sample_item({ library => $library->branchcode });
319
    my $item = $builder->build_sample_item({ library => $library->branchcode });
319
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
320
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
Lines 355-364 subtest 'cancel all with reason' => sub { Link Here
355
356
356
    ModReserveCancelAll($item->id, $patron->id, 'TEST_REASON');
357
    ModReserveCancelAll($item->id, $patron->id, 'TEST_REASON');
357
358
358
    $hold = Koha::Holds->find($reserve_id);
359
    $hold->discard_changes;
359
    is( $hold, undef, 'Hold is not in the reserves table');
360
    ok( $hold->completed, 'Hold is marked completed');
360
    $hold = Koha::Old::Holds->find($reserve_id);
361
    ok( $hold, 'Hold was found in the old reserves table');
362
361
363
    my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'});
362
    my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'});
364
    ok( $message, 'Found hold cancellation message');
363
    ok( $message, 'Found hold cancellation message');
Lines 404-410 subtest 'Desks' => sub { Link Here
404
    ok($reserve_id, "Hold created");
403
    ok($reserve_id, "Hold created");
405
    ok($hold, "Hold found");
404
    ok($hold, "Hold found");
406
    $hold->set_waiting($desk->desk_id);
405
    $hold->set_waiting($desk->desk_id);
407
    is($hold->found, 'W', 'Hold is waiting with correct status set');
406
    is($hold->status, 'waiting', 'Hold is waiting with correct status set');
408
    is($hold->desk_id, $desk->desk_id, 'Hold is attach to its desk');
407
    is($hold->desk_id, $desk->desk_id, 'Hold is attach to its desk');
409
408
410
};
409
};
411
- 

Return to bug 25260