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

(-)a/Koha/Hold.pm (-3 / +11 lines)
Lines 78-90 sub is_waiting { Link Here
78
78
79
Returns true if hold is a cancelable hold
79
Returns true if hold is a cancelable hold
80
80
81
Holds may be canceled if they not found, or
82
are found and waiting. A hold found but in
83
transit cannot be canceled.
84
81
=cut
85
=cut
82
86
83
sub is_cancelable {
87
sub is_cancelable {
84
    my ($self) = @_;
88
    my ($self) = @_;
85
89
86
    return ( $self->is_waiting() && !$self->is_found() )
90
    return 1 unless $self->is_found();
87
      || ( !$self->is_waiting() && !$self->is_in_transit() );
91
    return 0 if $self->is_in_transit();
92
    return 1 if $self->is_waiting();
93
    return 0;
88
}
94
}
89
95
90
=head3 is_in_transit
96
=head3 is_in_transit
Lines 102-108 sub is_in_transit { Link Here
102
108
103
=head3 is_at_destination
109
=head3 is_at_destination
104
110
105
Returns true if hold is a in_transit hold
111
Returns true if hold is waiting
112
and the hold's pickup branch matches
113
the hold item's holding branch
106
114
107
=cut
115
=cut
108
116
(-)a/t/db_dependent/Hold.t (-7 / +70 lines)
Lines 18-26 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Context;
20
use C4::Context;
21
use C4::Biblio qw( AddBiblio );
21
use Koha::Database;
22
use Koha::Database;
23
use Koha::Borrowers;
24
use Koha::Branches;
25
use Koha::Item;
22
26
23
use Test::More tests => 8;
27
use Test::More tests => 23;
24
28
25
use_ok('Koha::Hold');
29
use_ok('Koha::Hold');
26
30
Lines 30-57 $schema->storage->txn_begin(); Link Here
30
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
31
$dbh->{RaiseError} = 1;
35
$dbh->{RaiseError} = 1;
32
36
33
my $hold = Koha::Hold->new({ found => 'W', waitingdate => '2000-01-01'});
37
my @branches = Koha::Branches->search();
38
my $borrower = Koha::Borrowers->search()->next();
39
40
my $biblio = MARC::Record->new();
41
my $title  = 'Silence in the library';
42
$biblio->append_fields(
43
    MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
44
    MARC::Field->new( '245', ' ', ' ', a => $title ),
45
);
46
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
47
48
my $item = Koha::Item->new(
49
    {
50
        biblionumber     => $biblionumber,
51
        biblioitemnumber => $biblioitemnumber,
52
        holdingbranch    => $branches[0]->branchcode(),
53
        homebranch       => $branches[0]->branchcode(),
54
    }
55
);
56
$item->store();
57
58
my $hold = Koha::Hold->new(
59
    {
60
        biblionumber     => $biblionumber,
61
        itemnumber => $item->id(),
62
        found          => 'W',
63
        waitingdate    => '2000-01-01',
64
        borrowernumber => $borrower->borrowernumber(),
65
        branchcode     => $branches[1]->branchcode(),
66
    }
67
);
68
$hold->store();
69
70
$item = $hold->item();
71
72
my $hold_borrower = $hold->borrower();
73
ok( $hold_borrower, 'Got hold borrower' );
74
is( $hold_borrower->borrowernumber(), $borrower->borrowernumber(), 'Hold borrower matches correct borrower' );
34
75
35
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '' );
76
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '' );
36
my $dt = $hold->waiting_expires_on();
77
my $dt = $hold->waiting_expires_on();
37
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if ReservesMaxPickUpDelay is not set");
78
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if ReservesMaxPickUpDelay is not set" );
38
79
39
is( $hold->is_waiting, 1, 'The hold is waiting' );
80
is( $hold->is_waiting, 1, 'The hold is waiting' );
81
is( $hold->is_found,   1, 'The hold is found' );
82
ok( !$hold->is_in_transit, 'The hold is not in transit' );
40
83
41
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '5' );
84
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '5' );
42
$dt = $hold->waiting_expires_on();
85
$dt = $hold->waiting_expires_on();
43
is( $dt->ymd, "2000-01-06", "Koha::Hold->waiting_expires_on returns DateTime of waitingdate + ReservesMaxPickUpDelay if set");
86
is( $dt->ymd, "2000-01-06",
87
    "Koha::Hold->waiting_expires_on returns DateTime of waitingdate + ReservesMaxPickUpDelay if set" );
44
88
45
$hold->found('T');
89
$hold->found('T');
46
$dt = $hold->waiting_expires_on();
90
$dt = $hold->waiting_expires_on();
47
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to 'T' )");
91
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to 'T' )" );
48
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' );
92
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' );
93
is( $hold->is_found,      1, 'The hold is found' );
94
is( $hold->is_in_transit, 1, 'The hold is in transit' );
49
95
50
$hold->found(q{});
96
$hold->found(q{});
51
$dt = $hold->waiting_expires_on();
97
$dt = $hold->waiting_expires_on();
52
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to empty string )");
98
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to empty string )" );
53
isnt( $hold->is_waiting, 1, 'The hold is not waiting (W)' );
99
isnt( $hold->is_waiting, 1, 'The hold is not waiting (W)' );
54
100
101
# Test method is_cancelable
102
$hold->found(undef);
103
ok( $hold->is_cancelable(), "Unfound hold is cancelable" );
104
$hold->found('W');
105
ok( $hold->is_cancelable, "Waiting hold is cancelable" );
106
$hold->found('T');
107
ok( !$hold->is_cancelable, "In transit hold is not cancelable" );
108
109
# Test method is_at_destination
110
$hold->found(undef);
111
ok( !$hold->is_at_destination(), "Unfound hold cannot be at destination" );
112
$hold->found('T');
113
ok( !$hold->is_at_destination(), "In transit hold cannot be at destination" );
114
$hold->found('W');
115
ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the same as the item's holdingbranch is not at destination" );
116
$item->holdingbranch( $branches[1]->branchcode() );
117
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" );
118
55
$schema->storage->txn_rollback();
119
$schema->storage->txn_rollback();
56
120
57
1;
121
1;
58
- 

Return to bug 13918