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

(-)a/Koha/Item.pm (-1 / +7 lines)
Lines 149-154 sub can_article_request { Link Here
149
149
150
=head3 can_be_transferred
150
=head3 can_be_transferred
151
151
152
$item->can_be_transferred({ to => $to_library, from => $from_library })
152
Checks if an item can be transferred to given library.
153
Checks if an item can be transferred to given library.
153
154
154
This feature is controlled by two system preferences:
155
This feature is controlled by two system preferences:
Lines 156-172 UseBranchTransferLimits to enable / disable the feature Link Here
156
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
157
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
157
                         for setting the limitations
158
                         for setting the limitations
158
159
160
Takes HASHref that can have the following parameters:
159
    MANDATORY PARAMETERS:
161
    MANDATORY PARAMETERS:
160
    $to   : Koha::Library or branchcode string
162
    $to   : Koha::Library or branchcode string
161
    OPTIONAL PARAMETERS:
163
    OPTIONAL PARAMETERS:
162
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
164
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
163
                                                # will be used instead
165
                                                # will be used instead
164
166
167
Returns 1 if item can be transferred to $to_library, otherwise 0.
168
165
=cut
169
=cut
166
170
167
sub can_be_transferred {
171
sub can_be_transferred {
168
    my ($self, $to, $from) = @_;
172
    my ($self, $params) = @_;
169
173
174
    my $to = $params->{'to'};
175
    my $from = $params->{'from'};
170
    if (ref($to) ne 'Koha::Library') {
176
    if (ref($to) ne 'Koha::Library') {
171
        my $tobranchcode = defined $to ? $to : '';
177
        my $tobranchcode = defined $to ? $to : '';
172
        $to = Koha::Libraries->find($tobranchcode);
178
        $to = Koha::Libraries->find($tobranchcode);
(-)a/t/db_dependent/Koha/Items.t (-7 / +6 lines)
Lines 98-104 subtest 'can_be_transferred' => sub { Link Here
98
        fromBranch => $library1,
98
        fromBranch => $library1,
99
        toBranch => $library2,
99
        toBranch => $library2,
100
    })->count, 0, 'There are no transfer limits between libraries.');
100
    })->count, 0, 'There are no transfer limits between libraries.');
101
    ok($item->can_be_transferred($library2),
101
    ok($item->can_be_transferred({ to => $library2 }),
102
       'Item can be transferred between libraries.');
102
       'Item can be transferred between libraries.');
103
103
104
    my $limit = Koha::Item::Transfer::Limit->new({
104
    my $limit = Koha::Item::Transfer::Limit->new({
Lines 110-124 subtest 'can_be_transferred' => sub { Link Here
110
        fromBranch => $library1,
110
        fromBranch => $library1,
111
        toBranch => $library2,
111
        toBranch => $library2,
112
    })->count, 1, 'Given we have added a transfer limit,');
112
    })->count, 1, 'Given we have added a transfer limit,');
113
    is($item->can_be_transferred($library2), 0,
113
    is($item->can_be_transferred({ to => $library2 }), 0,
114
       'Item can no longer be transferred between libraries.');
114
       'Item can no longer be transferred between libraries.');
115
    is($item->can_be_transferred($library2, $library1), 0,
115
    is($item->can_be_transferred({ to => $library2, $library1 }), 0,
116
       'We get the same result also if we pass the from-library parameter.');
116
       'We get the same result also if we pass the from-library parameter.');
117
    eval { $item->can_be_transferred(); };
117
    eval { $item->can_be_transferred({ to => undef }); };
118
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
118
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
119
    eval { $item->can_be_transferred('heaven'); };
119
    eval { $item->can_be_transferred({ to => 'heaven' }); };
120
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
120
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
121
    eval { $item->can_be_transferred($library2, 'hell'); };
121
    eval { $item->can_be_transferred({ to => $library2, from => 'hell' }); };
122
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
122
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
123
};
123
};
124
124
125
- 

Return to bug 18072