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 283-289 sub set_pickup_location { Link Here
283
      )
281
      )
284
    {
282
    {
285
        # all good, set the new pickup location
283
        # all good, set the new pickup location
286
        $self->branchcode( $params->{library_id} )->store;
284
        $self->pickup_library_id( $params->{library_id} )->store;
287
    }
285
    }
288
    else {
286
    else {
289
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
287
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
Lines 304-310 sub set_processing { Link Here
304
    my ( $self ) = @_;
302
    my ( $self ) = @_;
305
303
306
    $self->priority(0);
304
    $self->priority(0);
307
    $self->found('P');
305
    $self->status('processing');
308
    $self->store();
306
    $self->store();
309
307
310
    return $self;
308
    return $self;
Lines 319-328 Returns true if hold is waiting, in transit or in processing Link Here
319
sub is_found {
317
sub is_found {
320
    my ($self) = @_;
318
    my ($self) = @_;
321
319
322
    return 0 unless $self->found();
320
    if (
323
    return 1 if $self->found() eq 'W';
321
             $self->status eq 'waiting'
324
    return 1 if $self->found() eq 'T';
322
          or $self->status eq 'in_transit'
325
    return 1 if $self->found() eq 'P';
323
          or $self->status eq 'processing'
324
      )
325
    {
326
        return 1;
327
    }
328
329
    return 0;
326
}
330
}
327
331
328
=head3 is_waiting
332
=head3 is_waiting
Lines 334-341 Returns true if hold is a waiting hold Link Here
334
sub is_waiting {
338
sub is_waiting {
335
    my ($self) = @_;
339
    my ($self) = @_;
336
340
337
    my $found = $self->found;
341
    return $self->status eq 'waiting';
338
    return $found && $found eq 'W';
339
}
342
}
340
343
341
=head3 is_in_transit
344
=head3 is_in_transit
Lines 347-354 Returns true if hold is a in_transit hold Link Here
347
sub is_in_transit {
350
sub is_in_transit {
348
    my ($self) = @_;
351
    my ($self) = @_;
349
352
350
    return 0 unless $self->found();
353
    return $self->status eq 'in_transit';
351
    return $self->found() eq 'T';
352
}
354
}
353
355
354
=head3 is_in_processing
356
=head3 is_in_processing
Lines 360-367 Returns true if hold is a in_processing hold Link Here
360
sub is_in_processing {
362
sub is_in_processing {
361
    my ($self) = @_;
363
    my ($self) = @_;
362
364
363
    return 0 unless $self->found();
365
    return $self->status eq 'processing';
364
    return $self->found() eq 'P';
365
}
366
}
366
367
367
=head3 is_cancelable_from_opac
368
=head3 is_cancelable_from_opac
Lines 392-398 the hold item's holding branch Link Here
392
sub is_at_destination {
393
sub is_at_destination {
393
    my ($self) = @_;
394
    my ($self) = @_;
394
395
395
    return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
396
    return $self->is_waiting() && ( $self->pickup_library_id() eq $self->item()->holdingbranch() );
396
}
397
}
397
398
398
=head3 biblio
399
=head3 biblio
Lines 404-410 Returns the related Koha::Biblio object for this hold Link Here
404
sub biblio {
405
sub biblio {
405
    my ($self) = @_;
406
    my ($self) = @_;
406
407
407
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
408
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblio_id );
408
409
409
    return $self->{_biblio};
410
    return $self->{_biblio};
410
}
411
}
Lines 431-437 Returns the related Koha::Item object for this Hold Link Here
431
sub item {
432
sub item {
432
    my ($self) = @_;
433
    my ($self) = @_;
433
434
434
    $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
435
    $self->{_item} ||= Koha::Items->find( $self->item_id );
435
436
436
    return $self->{_item};
437
    return $self->{_item};
437
}
438
}
Lines 445-451 Returns the related Koha::Library object for this Hold Link Here
445
sub branch {
446
sub branch {
446
    my ($self) = @_;
447
    my ($self) = @_;
447
448
448
    $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
449
    $self->{_branch} ||= Koha::Libraries->find( $self->pickup_library_id );
449
450
450
    return $self->{_branch};
451
    return $self->{_branch};
451
}
452
}
Lines 473-479 Returns the related Koha::Patron object for this Hold Link Here
473
sub borrower {
474
sub borrower {
474
    my ($self) = @_;
475
    my ($self) = @_;
475
476
476
    $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
477
    $self->{_borrower} ||= Koha::Patrons->find( $self->patron_id );
477
478
478
    return $self->{_borrower};
479
    return $self->{_borrower};
479
}
480
}
Lines 487-496 my $bool = $hold->is_suspended(); Link Here
487
sub is_suspended {
488
sub is_suspended {
488
    my ( $self ) = @_;
489
    my ( $self ) = @_;
489
490
490
    return $self->suspend();
491
    return $self->suspended();
491
}
492
}
492
493
493
494
=head3 cancel
494
=head3 cancel
495
495
496
my $cancel_hold = $hold->cancel(
496
my $cancel_hold = $hold->cancel(
Lines 501-510 my $cancel_hold = $hold->cancel( Link Here
501
);
501
);
502
502
503
Cancel a hold:
503
Cancel a hold:
504
- The hold will be moved to the old_reserves table with a priority=0
504
- The hold will be marked as completed, status 'cancelled' and a priority=0
505
- The priority of other holds will be updated
505
- The priority of other holds will be updated
506
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
506
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
507
- The canceled hold will have the cancellation reason added to old_reserves.cancellation_reason if one is passed in
507
- The canceled hold will have the cancellation reason added to cancellation_reason if one is passed in
508
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
508
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
509
509
510
=cut
510
=cut
Lines 513-522 sub cancel { Link Here
513
    my ( $self, $params ) = @_;
513
    my ( $self, $params ) = @_;
514
    $self->_result->result_source->schema->txn_do(
514
    $self->_result->result_source->schema->txn_do(
515
        sub {
515
        sub {
516
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
516
            $self->set(
517
            $self->priority(0);
517
                {
518
            $self->cancellation_reason( $params->{cancellation_reason} );
518
                    completed_date => dt_from_string->strftime('%Y-%m-%d %H:%M:%S'),
519
            $self->store();
519
                    completed      => 1,
520
                    priority       => 0,
521
                    status         => 'cancelled',
522
                    cancellation_reason => $params->{cancellation_reason},
523
                }
524
            )->store();
520
525
521
            if ( $params->{cancellation_reason} ) {
526
            if ( $params->{cancellation_reason} ) {
522
                my $letter = C4::Letters::GetPreparedLetter(
527
                my $letter = C4::Letters::GetPreparedLetter(
Lines 527-536 sub cancel { Link Here
527
                    lang                   => $self->borrower->lang,
532
                    lang                   => $self->borrower->lang,
528
                    tables => {
533
                    tables => {
529
                        branches    => $self->borrower->branchcode,
534
                        branches    => $self->borrower->branchcode,
530
                        borrowers   => $self->borrowernumber,
535
                        borrowers   => $self->patron_id,
531
                        items       => $self->itemnumber,
536
                        items       => $self->item_id,
532
                        biblio      => $self->biblionumber,
537
                        biblio      => $self->biblio_id,
533
                        biblioitems => $self->biblionumber,
538
                        biblioitems => $self->biblio_id,
534
                        reserves    => $self->unblessed,
539
                        reserves    => $self->unblessed,
535
                    }
540
                    }
536
                );
541
                );
Lines 538-562 sub cancel { Link Here
538
                if ($letter) {
543
                if ($letter) {
539
                    C4::Letters::EnqueueLetter(
544
                    C4::Letters::EnqueueLetter(
540
                        {
545
                        {
541
                            letter                   => $letter,
546
                            letter                 => $letter,
542
                            borrowernumber         => $self->borrowernumber,
547
                            borrowernumber         => $self->patron_id,
543
                            message_transport_type => 'email',
548
                            message_transport_type => 'email',
544
                        }
549
                        }
545
                    );
550
                    );
546
                }
551
                }
547
            }
552
            }
548
553
549
            $self->_move_to_old;
550
            $self->SUPER::delete(); # Do not add a DELETE log
551
552
            # now fix the priority on the others....
554
            # now fix the priority on the others....
553
            C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });
555
            C4::Reserves::_FixPriority({ biblionumber => $self->biblio_id });
554
556
555
            # and, if desired, charge a cancel fee
557
            # and, if desired, charge a cancel fee
556
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
558
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
557
            if ( $charge && $params->{'charge_cancel_fee'} ) {
559
            if ( $charge && $params->{'charge_cancel_fee'} ) {
558
                my $account =
560
                my $account =
559
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
561
                  Koha::Account->new( { patron_id => $self->patron_id } );
560
                $account->add_debit(
562
                $account->add_debit(
561
                    {
563
                    {
562
                        amount     => $charge,
564
                        amount     => $charge,
Lines 564-575 sub cancel { Link Here
564
                        interface  => C4::Context->interface,
566
                        interface  => C4::Context->interface,
565
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
567
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
566
                        type       => 'RESERVE_EXPIRED',
568
                        type       => 'RESERVE_EXPIRED',
567
                        item_id    => $self->itemnumber
569
                        item_id    => $self->item_id
568
                    }
570
                    }
569
                );
571
                );
570
            }
572
            }
571
573
572
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) )
574
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->id, Dumper($self->unblessed) )
573
                if C4::Context->preference('HoldsLog');
575
                if C4::Context->preference('HoldsLog');
574
        }
576
        }
575
    );
577
    );
Lines 628-647 sub _set_default_expirationdate { Link Here
628
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
630
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
629
}
631
}
630
632
631
=head3 _move_to_old
632
633
my $is_moved = $hold->_move_to_old;
634
635
Move a hold to the old_reserve table following the same pattern as Koha::Patron->move_to_deleted
636
637
=cut
638
639
sub _move_to_old {
640
    my ($self) = @_;
641
    my $hold_infos = $self->unblessed;
642
    return Koha::Old::Hold->new( $hold_infos )->store;
643
}
644
645
=head3 to_api_mapping
633
=head3 to_api_mapping
646
634
647
This method returns the mapping for representing a Koha::Hold object
635
This method returns the mapping for representing a Koha::Hold object
Lines 651-674 on the API. Link Here
651
639
652
sub to_api_mapping {
640
sub to_api_mapping {
653
    return {
641
    return {
654
        reserve_id       => 'hold_id',
642
        id => 'hold_id'
655
        borrowernumber   => 'patron_id',
656
        reservedate      => 'hold_date',
657
        biblionumber     => 'biblio_id',
658
        branchcode       => 'pickup_library_id',
659
        notificationdate => undef,
660
        reminderdate     => undef,
661
        cancellationdate => 'cancellation_date',
662
        reservenotes     => 'notes',
663
        found            => 'status',
664
        itemnumber       => 'item_id',
665
        waitingdate      => 'waiting_date',
666
        expirationdate   => 'expiration_date',
667
        lowestPriority   => 'lowest_priority',
668
        suspend          => 'suspended',
669
        suspend_until    => 'suspended_until',
670
        itemtype         => 'item_type',
671
        item_level_hold  => 'item_level',
672
    };
643
    };
673
}
644
}
674
645
Lines 679-685 sub to_api_mapping { Link Here
679
=cut
650
=cut
680
651
681
sub _type {
652
sub _type {
682
    return 'Reserve';
653
    return 'Hold';
683
}
654
}
684
655
685
=head1 AUTHORS
656
=head1 AUTHORS
Lines 687-692 sub _type { Link Here
687
Kyle M Hall <kyle@bywatersolutions.com>
658
Kyle M Hall <kyle@bywatersolutions.com>
688
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
659
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
689
Martin Renvoize <martin.renvoize@ptfs-europe.com>
660
Martin Renvoize <martin.renvoize@ptfs-europe.com>
661
Tomás Cohen Arazu <tomascohen@theke.io>
690
662
691
=cut
663
=cut
692
664
(-)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-129 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
    $item_hold->set_pickup_location({ library_id => $library_1->branchcode, force => 1 });
128
    $item_hold->set_pickup_location({ library_id => $library_1->branchcode, force => 1 });
129
    $item_hold->discard_changes;
129
    $item_hold->discard_changes;
Lines 133-139 subtest 'set_pickup_location() tests' => sub { Link Here
133
    is( ref($ret), 'Koha::Hold', 'self is returned' );
133
    is( ref($ret), 'Koha::Hold', 'self is returned' );
134
134
135
    $item_hold->discard_changes;
135
    $item_hold->discard_changes;
136
    is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
136
    is( $item_hold->pickup_library_id, $library_2->id, 'Pickup location changed correctly' );
137
137
138
    throws_ok
138
    throws_ok
139
        { $item_hold->set_pickup_location({ library_id => undef }); }
139
        { $item_hold->set_pickup_location({ library_id => undef }); }
Lines 175-183 subtest 'is_pickup_location_valid() tests' => sub { Link Here
175
        {
175
        {
176
            class => "Koha::Holds",
176
            class => "Koha::Holds",
177
            value => {
177
            value => {
178
                biblionumber => $biblio->biblionumber,
178
                biblio_id          => $biblio->biblionumber,
179
                branchcode   => $library_3->branchcode,
179
                pickup_library_id  => $library_3->branchcode,
180
                itemnumber   => undef,
180
                item_it            => undef,
181
            }
181
            }
182
        }
182
        }
183
    );
183
    );
Lines 190-198 subtest 'is_pickup_location_valid() tests' => sub { Link Here
190
        {
190
        {
191
            class => "Koha::Holds",
191
            class => "Koha::Holds",
192
            value => {
192
            value => {
193
                biblionumber => $biblio->biblionumber,
193
                biblio_id           => $biblio->biblionumber,
194
                branchcode   => $library_3->branchcode,
194
                pickup_library_id   => $library_3->branchcode,
195
                itemnumber   => $item->itemnumber,
195
                item_id             => $item->itemnumber,
196
            }
196
            }
197
        }
197
        }
198
    );
198
    );
(-)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