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

(-)a/Koha/Hold.pm (-99 / +71 lines)
Lines 66-76 sub age { Link Here
66
    my $age;
66
    my $age;
67
67
68
    if ( $use_calendar ) {
68
    if ( $use_calendar ) {
69
        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
69
        my $calendar = Koha::Calendar->new( branchcode => $self->pickup_library_id );
70
        $age = $calendar->days_between( dt_from_string( $self->reservedate ), $today );
70
        $age = $calendar->days_between( dt_from_string( $self->created_date ), $today );
71
    }
71
    }
72
    else {
72
    else {
73
        $age = $today->delta_days( dt_from_string( $self->reservedate ) );
73
        $age = $today->delta_days( dt_from_string( $self->created_date ) );
74
    }
74
    }
75
75
76
    $age = $age->in_units( 'days' );
76
    $age = $age->in_units( 'days' );
Lines 90-100 sub suspend_hold { Link Here
90
    my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef;
90
    my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef;
91
91
92
    if ( $self->is_found ) {    # We can't suspend found holds
92
    if ( $self->is_found ) {    # We can't suspend found holds
93
        if ( $self->is_waiting ) {
93
        if ( $self->is_waiting or
94
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'W' );
94
             $self->is_in_transit ) {
95
        }
95
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => $self->status );
96
        elsif ( $self->is_in_transit ) {
97
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'T' );
98
        }
96
        }
99
        elsif ( $self->is_in_processing ) {
97
        elsif ( $self->is_in_processing ) {
100
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'P' );
98
            Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'P' );
Lines 103-119 sub suspend_hold { Link Here
103
            Koha::Exceptions::Hold::CannotSuspendFound->throw(
101
            Koha::Exceptions::Hold::CannotSuspendFound->throw(
104
                      'Unhandled data exception on found hold (id='
102
                      'Unhandled data exception on found hold (id='
105
                    . $self->id
103
                    . $self->id
106
                    . ', found='
104
                    . ', status='
107
                    . $self->found
105
                    . $self->status
108
                    . ')' );
106
                    . ')' );
109
        }
107
        }
110
    }
108
    }
111
109
112
    $self->suspend(1);
110
    $self->suspended(1);
113
    $self->suspend_until($date);
111
    $self->suspended_until_date($date);
114
    $self->store();
112
    $self->store();
115
113
116
    logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper( $self->unblessed ) )
114
    logaction( 'HOLDS', 'SUSPEND', $self->id, Dumper( $self->unblessed ) )
117
        if C4::Context->preference('HoldsLog');
115
        if C4::Context->preference('HoldsLog');
118
116
119
    return $self;
117
    return $self;
Lines 128-139 my $hold = $hold->resume(); Link Here
128
sub resume {
126
sub resume {
129
    my ( $self ) = @_;
127
    my ( $self ) = @_;
130
128
131
    $self->suspend(0);
129
    $self->suspended(0);
132
    $self->suspend_until( undef );
130
    $self->suspended_until_date( undef );
133
131
134
    $self->store();
132
    $self->store();
135
133
136
    logaction( 'HOLDS', 'RESUME', $self->reserve_id, Dumper($self->unblessed) )
134
    logaction( 'HOLDS', 'RESUME', $self->id, Dumper($self->unblessed) )
137
        if C4::Context->preference('HoldsLog');
135
        if C4::Context->preference('HoldsLog');
138
136
139
    return $self;
137
    return $self;
Lines 150-156 sub delete { Link Here
150
148
151
    my $deleted = $self->SUPER::delete($self);
149
    my $deleted = $self->SUPER::delete($self);
152
150
153
    logaction( 'HOLDS', 'DELETE', $self->reserve_id, Dumper($self->unblessed) )
151
    logaction( 'HOLDS', 'DELETE', $self->id, Dumper($self->unblessed) )
154
        if C4::Context->preference('HoldsLog');
152
        if C4::Context->preference('HoldsLog');
155
153
156
    return $deleted;
154
    return $deleted;
Lines 164-170 sub set_transfer { Link Here
164
    my ( $self ) = @_;
162
    my ( $self ) = @_;
165
163
166
    $self->priority(0);
164
    $self->priority(0);
167
    $self->found('T');
165
    $self->status('in_transit');
168
    $self->store();
166
    $self->store();
169
167
170
    return $self;
168
    return $self;
Lines 181-194 sub set_waiting { Link Here
181
179
182
    my $today = dt_from_string();
180
    my $today = dt_from_string();
183
    my $values = {
181
    my $values = {
184
        found => 'W',
182
        status       => 'waiting',
185
        waitingdate => $today->ymd,
183
        waiting_date => $today->ymd,
186
        desk_id => $desk_id,
184
        desk_id      => $desk_id,
187
    };
185
    };
188
186
189
    my $requested_expiration;
187
    my $requested_expiration;
190
    if ($self->expirationdate) {
188
    if ($self->expiration_date) {
191
        $requested_expiration = dt_from_string($self->expirationdate);
189
        $requested_expiration = dt_from_string($self->expiration_date);
192
    }
190
    }
193
191
194
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
192
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
Lines 201-212 sub set_waiting { Link Here
201
        my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype;
199
        my $itemtype = $self->item ? $self->item->effective_itemtype : $self->biblio->itemtype;
202
        my $daysmode = Koha::CirculationRules->get_effective_daysmode(
200
        my $daysmode = Koha::CirculationRules->get_effective_daysmode(
203
            {
201
            {
204
                categorycode => $self->borrower->categorycode,
202
                categorycode => $self->patron->categorycode,
205
                itemtype     => $itemtype,
203
                itemtype     => $itemtype,
206
                branchcode   => $self->branchcode,
204
                branchcode   => $self->pickup_library_id,
207
            }
205
            }
208
        );
206
        );
209
        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode, days_mode => $daysmode );
207
        my $calendar = Koha::Calendar->new( branchcode => $self->pickup_library_id, days_mode => $daysmode );
210
208
211
        $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay );
209
        $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay );
212
    }
210
    }
Lines 214-220 sub set_waiting { Link Here
214
    # If patron's requested expiration date is prior to the
212
    # If patron's requested expiration date is prior to the
215
    # calculated one, we keep the patron's one.
213
    # calculated one, we keep the patron's one.
216
    my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
214
    my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
217
    $values->{expirationdate} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
215
    $values->{expiration_date} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
218
216
219
    $self->set($values)->store();
217
    $self->set($values)->store();
220
218
Lines 241-247 sub is_pickup_location_valid { Link Here
241
239
242
    my @pickup_locations;
240
    my @pickup_locations;
243
241
244
    if ( $self->itemnumber ) { # item-level
242
    if ( $self->item_id ) { # item-level
245
        @pickup_locations = $self->item->pickup_locations({ patron => $self->patron });
243
        @pickup_locations = $self->item->pickup_locations({ patron => $self->patron });
246
    }
244
    }
247
    else { # biblio-level
245
    else { # biblio-level
Lines 282-288 sub set_pickup_location { Link Here
282
      )
280
      )
283
    {
281
    {
284
        # all good, set the new pickup location
282
        # all good, set the new pickup location
285
        $self->branchcode( $params->{library_id} )->store;
283
        $self->pickup_library_id( $params->{library_id} )->store;
286
    }
284
    }
287
    else {
285
    else {
288
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
286
        Koha::Exceptions::Hold::InvalidPickupLocation->throw;
Lines 303-309 sub set_processing { Link Here
303
    my ( $self ) = @_;
301
    my ( $self ) = @_;
304
302
305
    $self->priority(0);
303
    $self->priority(0);
306
    $self->found('P');
304
    $self->status('processing');
307
    $self->store();
305
    $self->store();
308
306
309
    return $self;
307
    return $self;
Lines 318-327 Returns true if hold is waiting, in transit or in processing Link Here
318
sub is_found {
316
sub is_found {
319
    my ($self) = @_;
317
    my ($self) = @_;
320
318
321
    return 0 unless $self->found();
319
    if (
322
    return 1 if $self->found() eq 'W';
320
             $self->status eq 'waiting'
323
    return 1 if $self->found() eq 'T';
321
          or $self->status eq 'in_transit'
324
    return 1 if $self->found() eq 'P';
322
          or $self->status eq 'processing'
323
      )
324
    {
325
        return 1;
326
    }
327
328
    return 0;
325
}
329
}
326
330
327
=head3 is_waiting
331
=head3 is_waiting
Lines 333-340 Returns true if hold is a waiting hold Link Here
333
sub is_waiting {
337
sub is_waiting {
334
    my ($self) = @_;
338
    my ($self) = @_;
335
339
336
    my $found = $self->found;
340
    return $self->status eq 'waiting';
337
    return $found && $found eq 'W';
338
}
341
}
339
342
340
=head3 is_in_transit
343
=head3 is_in_transit
Lines 346-353 Returns true if hold is a in_transit hold Link Here
346
sub is_in_transit {
349
sub is_in_transit {
347
    my ($self) = @_;
350
    my ($self) = @_;
348
351
349
    return 0 unless $self->found();
352
    return $self->status eq 'in_transit';
350
    return $self->found() eq 'T';
351
}
353
}
352
354
353
=head3 is_in_processing
355
=head3 is_in_processing
Lines 359-366 Returns true if hold is a in_processing hold Link Here
359
sub is_in_processing {
361
sub is_in_processing {
360
    my ($self) = @_;
362
    my ($self) = @_;
361
363
362
    return 0 unless $self->found();
364
    return $self->status eq 'processing';
363
    return $self->found() eq 'P';
364
}
365
}
365
366
366
=head3 is_cancelable_from_opac
367
=head3 is_cancelable_from_opac
Lines 391-397 the hold item's holding branch Link Here
391
sub is_at_destination {
392
sub is_at_destination {
392
    my ($self) = @_;
393
    my ($self) = @_;
393
394
394
    return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
395
    return $self->is_waiting() && ( $self->pickup_library_id() eq $self->item()->holdingbranch() );
395
}
396
}
396
397
397
=head3 biblio
398
=head3 biblio
Lines 403-409 Returns the related Koha::Biblio object for this hold Link Here
403
sub biblio {
404
sub biblio {
404
    my ($self) = @_;
405
    my ($self) = @_;
405
406
406
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
407
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblio_id );
407
408
408
    return $self->{_biblio};
409
    return $self->{_biblio};
409
}
410
}
Lines 430-436 Returns the related Koha::Item object for this Hold Link Here
430
sub item {
431
sub item {
431
    my ($self) = @_;
432
    my ($self) = @_;
432
433
433
    $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
434
    $self->{_item} ||= Koha::Items->find( $self->item_id );
434
435
435
    return $self->{_item};
436
    return $self->{_item};
436
}
437
}
Lines 444-450 Returns the related Koha::Library object for this Hold Link Here
444
sub branch {
445
sub branch {
445
    my ($self) = @_;
446
    my ($self) = @_;
446
447
447
    $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
448
    $self->{_branch} ||= Koha::Libraries->find( $self->pickup_library_id );
448
449
449
    return $self->{_branch};
450
    return $self->{_branch};
450
}
451
}
Lines 472-478 Returns the related Koha::Patron object for this Hold Link Here
472
sub borrower {
473
sub borrower {
473
    my ($self) = @_;
474
    my ($self) = @_;
474
475
475
    $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
476
    $self->{_borrower} ||= Koha::Patrons->find( $self->patron_id );
476
477
477
    return $self->{_borrower};
478
    return $self->{_borrower};
478
}
479
}
Lines 486-495 my $bool = $hold->is_suspended(); Link Here
486
sub is_suspended {
487
sub is_suspended {
487
    my ( $self ) = @_;
488
    my ( $self ) = @_;
488
489
489
    return $self->suspend();
490
    return $self->suspended();
490
}
491
}
491
492
492
493
=head3 cancel
493
=head3 cancel
494
494
495
my $cancel_hold = $hold->cancel(
495
my $cancel_hold = $hold->cancel(
Lines 500-509 my $cancel_hold = $hold->cancel( Link Here
500
);
500
);
501
501
502
Cancel a hold:
502
Cancel a hold:
503
- The hold will be moved to the old_reserves table with a priority=0
503
- The hold will be marked as completed, status 'cancelled' and a priority=0
504
- The priority of other holds will be updated
504
- The priority of other holds will be updated
505
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
505
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
506
- The canceled hold will have the cancellation reason added to old_reserves.cancellation_reason if one is passed in
506
- The canceled hold will have the cancellation reason added to cancellation_reason if one is passed in
507
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
507
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
508
508
509
=cut
509
=cut
Lines 512-521 sub cancel { Link Here
512
    my ( $self, $params ) = @_;
512
    my ( $self, $params ) = @_;
513
    $self->_result->result_source->schema->txn_do(
513
    $self->_result->result_source->schema->txn_do(
514
        sub {
514
        sub {
515
            $self->cancellationdate( dt_from_string->strftime( '%Y-%m-%d %H:%M:%S' ) );
515
            $self->set(
516
            $self->priority(0);
516
                {
517
            $self->cancellation_reason( $params->{cancellation_reason} );
517
                    completed_date => dt_from_string->strftime('%Y-%m-%d %H:%M:%S'),
518
            $self->store();
518
                    completed      => 1,
519
                    priority       => 0,
520
                    status         => 'cancelled',
521
                    cancellation_reason => $params->{cancellation_reason},
522
                }
523
            )->store();
519
524
520
            if ( $params->{cancellation_reason} ) {
525
            if ( $params->{cancellation_reason} ) {
521
                my $letter = C4::Letters::GetPreparedLetter(
526
                my $letter = C4::Letters::GetPreparedLetter(
Lines 526-535 sub cancel { Link Here
526
                    lang                   => $self->borrower->lang,
531
                    lang                   => $self->borrower->lang,
527
                    tables => {
532
                    tables => {
528
                        branches    => $self->borrower->branchcode,
533
                        branches    => $self->borrower->branchcode,
529
                        borrowers   => $self->borrowernumber,
534
                        borrowers   => $self->patron_id,
530
                        items       => $self->itemnumber,
535
                        items       => $self->item_id,
531
                        biblio      => $self->biblionumber,
536
                        biblio      => $self->biblio_id,
532
                        biblioitems => $self->biblionumber,
537
                        biblioitems => $self->biblio_id,
533
                        reserves    => $self->unblessed,
538
                        reserves    => $self->unblessed,
534
                    }
539
                    }
535
                );
540
                );
Lines 537-561 sub cancel { Link Here
537
                if ($letter) {
542
                if ($letter) {
538
                    C4::Letters::EnqueueLetter(
543
                    C4::Letters::EnqueueLetter(
539
                        {
544
                        {
540
                            letter                   => $letter,
545
                            letter                 => $letter,
541
                            borrowernumber         => $self->borrowernumber,
546
                            borrowernumber         => $self->patron_id,
542
                            message_transport_type => 'email',
547
                            message_transport_type => 'email',
543
                        }
548
                        }
544
                    );
549
                    );
545
                }
550
                }
546
            }
551
            }
547
552
548
            $self->_move_to_old;
549
            $self->SUPER::delete(); # Do not add a DELETE log
550
551
            # now fix the priority on the others....
553
            # now fix the priority on the others....
552
            C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });
554
            C4::Reserves::_FixPriority({ biblionumber => $self->biblio_id });
553
555
554
            # and, if desired, charge a cancel fee
556
            # and, if desired, charge a cancel fee
555
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
557
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
556
            if ( $charge && $params->{'charge_cancel_fee'} ) {
558
            if ( $charge && $params->{'charge_cancel_fee'} ) {
557
                my $account =
559
                my $account =
558
                  Koha::Account->new( { patron_id => $self->borrowernumber } );
560
                  Koha::Account->new( { patron_id => $self->patron_id } );
559
                $account->add_debit(
561
                $account->add_debit(
560
                    {
562
                    {
561
                        amount     => $charge,
563
                        amount     => $charge,
Lines 563-574 sub cancel { Link Here
563
                        interface  => C4::Context->interface,
565
                        interface  => C4::Context->interface,
564
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
566
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
565
                        type       => 'RESERVE_EXPIRED',
567
                        type       => 'RESERVE_EXPIRED',
566
                        item_id    => $self->itemnumber
568
                        item_id    => $self->item_id
567
                    }
569
                    }
568
                );
570
                );
569
            }
571
            }
570
572
571
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) )
573
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->id, Dumper($self->unblessed) )
572
                if C4::Context->preference('HoldsLog');
574
                if C4::Context->preference('HoldsLog');
573
        }
575
        }
574
    );
576
    );
Lines 627-646 sub _set_default_expirationdate { Link Here
627
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
629
        dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
628
}
630
}
629
631
630
=head3 _move_to_old
631
632
my $is_moved = $hold->_move_to_old;
633
634
Move a hold to the old_reserve table following the same pattern as Koha::Patron->move_to_deleted
635
636
=cut
637
638
sub _move_to_old {
639
    my ($self) = @_;
640
    my $hold_infos = $self->unblessed;
641
    return Koha::Old::Hold->new( $hold_infos )->store;
642
}
643
644
=head3 to_api_mapping
632
=head3 to_api_mapping
645
633
646
This method returns the mapping for representing a Koha::Hold object
634
This method returns the mapping for representing a Koha::Hold object
Lines 650-673 on the API. Link Here
650
638
651
sub to_api_mapping {
639
sub to_api_mapping {
652
    return {
640
    return {
653
        reserve_id       => 'hold_id',
641
        id => 'hold_id'
654
        borrowernumber   => 'patron_id',
655
        reservedate      => 'hold_date',
656
        biblionumber     => 'biblio_id',
657
        branchcode       => 'pickup_library_id',
658
        notificationdate => undef,
659
        reminderdate     => undef,
660
        cancellationdate => 'cancellation_date',
661
        reservenotes     => 'notes',
662
        found            => 'status',
663
        itemnumber       => 'item_id',
664
        waitingdate      => 'waiting_date',
665
        expirationdate   => 'expiration_date',
666
        lowestPriority   => 'lowest_priority',
667
        suspend          => 'suspended',
668
        suspend_until    => 'suspended_until',
669
        itemtype         => 'item_type',
670
        item_level_hold  => 'item_level',
671
    };
642
    };
672
}
643
}
673
644
Lines 678-684 sub to_api_mapping { Link Here
678
=cut
649
=cut
679
650
680
sub _type {
651
sub _type {
681
    return 'Reserve';
652
    return 'Hold';
682
}
653
}
683
654
684
=head1 AUTHORS
655
=head1 AUTHORS
Lines 686-691 sub _type { Link Here
686
Kyle M Hall <kyle@bywatersolutions.com>
657
Kyle M Hall <kyle@bywatersolutions.com>
687
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
658
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
688
Martin Renvoize <martin.renvoize@ptfs-europe.com>
659
Martin Renvoize <martin.renvoize@ptfs-europe.com>
660
Tomás Cohen Arazu <tomascohen@theke.io>
689
661
690
=cut
662
=cut
691
663
(-)a/Koha/Holds.pm (-6 / +16 lines)
Lines 32-38 Koha::Holds - Koha Hold object set class Link Here
32
32
33
=head1 API
33
=head1 API
34
34
35
=head2 Class Methods
35
=head2 Class methods
36
36
37
=cut
37
=cut
38
38
Lines 45-51 returns a set of holds that are waiting from an existing set Link Here
45
sub waiting {
45
sub waiting {
46
    my ( $self ) = @_;
46
    my ( $self ) = @_;
47
47
48
    return $self->search( { found => 'W' } );
48
    return $self->search(
49
        {
50
            status    => 'waiting',
51
            completed => 0
52
        }
53
    );
49
}
54
}
50
55
51
=head3 unfilled
56
=head3 unfilled
Lines 57-63 returns a set of holds that are unfilled from an existing set Link Here
57
sub unfilled {
62
sub unfilled {
58
    my ( $self ) = @_;
63
    my ( $self ) = @_;
59
64
60
    return $self->search( { found => undef } );
65
    return $self->search(
66
        {
67
            status    => 'placed',
68
            completed => 0
69
        }
70
    );
61
}
71
}
62
72
63
=head3 forced_hold_level
73
=head3 forced_hold_level
Lines 82-91 that would prevent one or the other. Link Here
82
sub forced_hold_level {
92
sub forced_hold_level {
83
    my ($self) = @_;
93
    my ($self) = @_;
84
94
85
    my $item_level_count = $self->search( { itemnumber => { '!=' => undef } } )->count();
95
    my $item_level_count = $self->search( { item_id => { '!=' => undef } } )->count();
86
    return 'item' if $item_level_count > 0;
96
    return 'item' if $item_level_count > 0;
87
97
88
    my $record_level_count = $self->search( { itemnumber => undef } )->count();
98
    my $record_level_count = $self->search( { item_id => undef } )->count();
89
    return 'record' if $record_level_count > 0;
99
    return 'record' if $record_level_count > 0;
90
100
91
    return;
101
    return;
Lines 157-163 sub get_items_that_can_fill { Link Here
157
=cut
167
=cut
158
168
159
sub _type {
169
sub _type {
160
    return 'Reserve';
170
    return 'Hold';
161
}
171
}
162
172
163
=head3 object_class
173
=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