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

(-)a/Koha/Item.pm (-1 / +7 lines)
Lines 163-168 sub can_article_request { Link Here
163
163
164
=head3 can_be_transferred
164
=head3 can_be_transferred
165
165
166
$item->can_be_transferred({ to => $to_library, from => $from_library })
166
Checks if an item can be transferred to given library.
167
Checks if an item can be transferred to given library.
167
168
168
This feature is controlled by two system preferences:
169
This feature is controlled by two system preferences:
Lines 170-186 UseBranchTransferLimits to enable / disable the feature Link Here
170
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
171
BranchTransferLimitsType to use either an itemnumber or ccode as an identifier
171
                         for setting the limitations
172
                         for setting the limitations
172
173
174
Takes HASHref that can have the following parameters:
173
    MANDATORY PARAMETERS:
175
    MANDATORY PARAMETERS:
174
    $to   : Koha::Library or branchcode string
176
    $to   : Koha::Library or branchcode string
175
    OPTIONAL PARAMETERS:
177
    OPTIONAL PARAMETERS:
176
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
178
    $from : Koha::Library or branchcode string  # if not given, item holdingbranch
177
                                                # will be used instead
179
                                                # will be used instead
178
180
181
Returns 1 if item can be transferred to $to_library, otherwise 0.
182
179
=cut
183
=cut
180
184
181
sub can_be_transferred {
185
sub can_be_transferred {
182
    my ($self, $to, $from) = @_;
186
    my ($self, $params) = @_;
183
187
188
    my $to = $params->{'to'};
189
    my $from = $params->{'from'};
184
    if (ref($to) ne 'Koha::Library') {
190
    if (ref($to) ne 'Koha::Library') {
185
        my $tobranchcode = defined $to ? $to : '';
191
        my $tobranchcode = defined $to ? $to : '';
186
        $to = Koha::Libraries->find($tobranchcode);
192
        $to = Koha::Libraries->find($tobranchcode);
(-)a/t/db_dependent/Koha/Items.t (-7 / +6 lines)
Lines 106-112 subtest 'can_be_transferred' => sub { Link Here
106
        fromBranch => $library1,
106
        fromBranch => $library1,
107
        toBranch => $library2,
107
        toBranch => $library2,
108
    })->count, 0, 'There are no transfer limits between libraries.');
108
    })->count, 0, 'There are no transfer limits between libraries.');
109
    ok($item->can_be_transferred($library2),
109
    ok($item->can_be_transferred({ to => $library2 }),
110
       'Item can be transferred between libraries.');
110
       'Item can be transferred between libraries.');
111
111
112
    my $limit = Koha::Item::Transfer::Limit->new({
112
    my $limit = Koha::Item::Transfer::Limit->new({
Lines 118-132 subtest 'can_be_transferred' => sub { Link Here
118
        fromBranch => $library1,
118
        fromBranch => $library1,
119
        toBranch => $library2,
119
        toBranch => $library2,
120
    })->count, 1, 'Given we have added a transfer limit,');
120
    })->count, 1, 'Given we have added a transfer limit,');
121
    is($item->can_be_transferred($library2), 0,
121
    is($item->can_be_transferred({ to => $library2 }), 0,
122
       'Item can no longer be transferred between libraries.');
122
       'Item can no longer be transferred between libraries.');
123
    is($item->can_be_transferred($library2, $library1), 0,
123
    is($item->can_be_transferred({ to => $library2, $library1 }), 0,
124
       'We get the same result also if we pass the from-library parameter.');
124
       'We get the same result also if we pass the from-library parameter.');
125
    eval { $item->can_be_transferred(); };
125
    eval { $item->can_be_transferred({ to => undef }); };
126
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
126
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when no library given.');
127
    eval { $item->can_be_transferred('heaven'); };
127
    eval { $item->can_be_transferred({ to => 'heaven' }); };
128
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
128
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
129
    eval { $item->can_be_transferred($library2, 'hell'); };
129
    eval { $item->can_be_transferred({ to => $library2, from => 'hell' }); };
130
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
130
    is(ref($@), 'Koha::Exceptions::Library::NotFound', 'Exception thrown when invalid library is given.');
131
};
131
};
132
132
133
- 

Return to bug 18072