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

(-)a/Koha/Item.pm (-1 / +7 lines)
Lines 194-199 sub can_article_request { Link Here
194
194
195
=head3 can_be_transferred
195
=head3 can_be_transferred
196
196
197
$item->can_be_transferred({ to => $to_library, from => $from_library })
197
Checks if an item can be transferred to given library.
198
Checks if an item can be transferred to given library.
198
199
199
This feature is controlled by two system preferences:
200
This feature is controlled by two system preferences:
Lines 201-217 UseBranchTransferLimits to enable / disable the feature Link Here
201
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
202
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
202
                         for setting the limitations
203
                         for setting the limitations
203
204
205
Takes HASHref that can have the following parameters:
204
    MANDATORY PARAMETERS:
206
    MANDATORY PARAMETERS:
205
    $to   : Koha::Library or branchcode string
207
    $to   : Koha::Library or branchcode string
206
    OPTIONAL PARAMETERS:
208
    OPTIONAL PARAMETERS:
207
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
209
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
208
                                                # will be used instead
210
                                                # will be used instead
209
211
212
Returns 1 if item can be transferred to $to_library, otherwise 0.
213
210
=cut
214
=cut
211
215
212
sub can_be_transferred {
216
sub can_be_transferred {
213
    my ($self, $to, $from) = @_;
217
    my ($self, $params) = @_;
214
218
219
    my $to = $params->{'to'};
220
    my $from = $params->{'from'};
215
    if (ref($to) ne 'Koha::Library') {
221
    if (ref($to) ne 'Koha::Library') {
216
        my $tobranchcode = defined $to ? $to : '';
222
        my $tobranchcode = defined $to ? $to : '';
217
        $to = Koha::Libraries->find($tobranchcode);
223
        $to = Koha::Libraries->find($tobranchcode);
(-)a/t/db_dependent/Koha/Items.t (-7 / +6 lines)
Lines 142-148 subtest 'can_be_transferred' => sub { Link Here
142
        fromBranch => $library1,
142
        fromBranch => $library1,
143
        toBranch => $library2,
143
        toBranch => $library2,
144
    })->count, 0, 'There are no transfer limits between libraries.');
144
    })->count, 0, 'There are no transfer limits between libraries.');
145
    ok($item->can_be_transferred($library2),
145
    ok($item->can_be_transferred({ to => $library2 }),
146
       'Item can be transferred between libraries.');
146
       'Item can be transferred between libraries.');
147
147
148
    my $limit = Koha::Item::Transfer::Limit->new({
148
    my $limit = Koha::Item::Transfer::Limit->new({
Lines 154-168 subtest 'can_be_transferred' => sub { Link Here
154
        fromBranch => $library1,
154
        fromBranch => $library1,
155
        toBranch => $library2,
155
        toBranch => $library2,
156
    })->count, 1, 'Given we have added a transfer limit,');
156
    })->count, 1, 'Given we have added a transfer limit,');
157
    is($item->can_be_transferred($library2), 0,
157
    is($item->can_be_transferred({ to => $library2 }), 0,
158
       'Item can no longer be transferred between libraries.');
158
       'Item can no longer be transferred between libraries.');
159
    is($item->can_be_transferred($library2, $library1), 0,
159
    is($item->can_be_transferred({ to => $library2, $library1 }), 0,
160
       'We get the same result also if we pass the from-library parameter.');
160
       'We get the same result also if we pass the from-library parameter.');
161
    eval { $item->can_be_transferred(); };
161
    eval { $item->can_be_transferred({ to => undef }); };
162
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
162
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
163
    eval { $item->can_be_transferred('heaven'); };
163
    eval { $item->can_be_transferred({ to => 'heaven' }); };
164
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
164
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
165
    eval { $item->can_be_transferred($library2, 'hell'); };
165
    eval { $item->can_be_transferred({ to => $library2, from => 'hell' }); };
166
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
166
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
167
};
167
};
168
168
169
- 

Return to bug 18072