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

(-)a/Koha/Item.pm (-1 / +1 lines)
Lines 447-453 sub request_transfer { Link Here
447
    Koha::Exceptions::Item::Transfer::Found->throw( transfer => $request )
447
    Koha::Exceptions::Item::Transfer::Found->throw( transfer => $request )
448
      if ( $request && !$params->{enqueue} && !$params->{replace} );
448
      if ( $request && !$params->{enqueue} && !$params->{replace} );
449
449
450
    $request->cancel( $params->{reason} )
450
    $request->cancel( { reason => $params->{reason}, force => 1 } )
451
      if ( defined($request) && $params->{replace} );
451
      if ( defined($request) && $params->{replace} );
452
452
453
    my $transfer = Koha::Item::Transfer->new(
453
    my $transfer = Koha::Item::Transfer->new(
(-)a/Koha/Item/Transfer.pm (-5 / +5 lines)
Lines 118-142 sub receive { Link Here
118
118
119
=head3 cancel
119
=head3 cancel
120
120
121
  $transfer->cancel($reason);
121
  $transfer->cancel({ reason => $reason, [force => 1]});
122
122
123
Cancel the transfer by setting the datecancelled time and recording the reason.
123
Cancel the transfer by setting the datecancelled time and recording the reason.
124
124
125
=cut
125
=cut
126
126
127
sub cancel {
127
sub cancel {
128
    my ( $self, $reason ) = @_;
128
    my ( $self, $params ) = @_;
129
129
130
    Koha::Exceptions::MissingParameter->throw(
130
    Koha::Exceptions::MissingParameter->throw(
131
        error => "The 'reason' parameter is mandatory" )
131
        error => "The 'reason' parameter is mandatory" )
132
      unless defined($reason);
132
      unless defined($params->{reason});
133
133
134
    # Throw exception if item is in transit already
134
    # Throw exception if item is in transit already
135
    Koha::Exceptions::Item::Transfer::Transit->throw() if ( $self->in_transit );
135
    Koha::Exceptions::Item::Transfer::Transit->throw() if ( !$params->{force} && $self->in_transit );
136
136
137
    # Update the cancelled date
137
    # Update the cancelled date
138
    $self->set(
138
    $self->set(
139
        { datecancelled => dt_from_string, cancellation_reason => $reason } )
139
        { datecancelled => dt_from_string, cancellation_reason => $params->{reason} } )
140
      ->store;
140
      ->store;
141
141
142
    return $self;
142
    return $self;
(-)a/t/db_dependent/Circulation/transfers.t (-3 / +3 lines)
Lines 173-179 is(CreateBranchTransferLimit(undef,$branchcode_2),undef, Link Here
173
my @transfers = GetTransfers($item_id1);
173
my @transfers = GetTransfers($item_id1);
174
cmp_deeply(
174
cmp_deeply(
175
    \@transfers,
175
    \@transfers,
176
    [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2, re('[0-9]*'), re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), undef ],
176
    [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2, re('[0-9]*'), re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), 'Manual' ],
177
    "Transfers of the item1"
177
    "Transfers of the item1"
178
);    #NOTE: Only the first transfer is returned
178
);    #NOTE: Only the first transfer is returned
179
@transfers = GetTransfers;
179
@transfers = GetTransfers;
Lines 255-262 ModItemTransfer( Link Here
255
    $trigger
255
    $trigger
256
);
256
);
257
$transfer->{_result}->discard_changes;
257
$transfer->{_result}->discard_changes;
258
ok( $transfer->datearrived, 'Date arrived is set when new transfer is initiated' );
258
ok( $transfer->datecancelled, 'Date cancelled is set when new transfer is initiated' );
259
is( $transfer->comments, "Canceled, new transfer from $branchcode_1 to $branchcode_2 created", 'Transfer comment is set as expected when new transfer is initiated' );
259
is( $transfer->cancellation_reason, "Manual", 'Cancellation reason is set correctly when new transfer is initiated' );
260
260
261
$schema->storage->txn_rollback;
261
$schema->storage->txn_rollback;
262
262
(-)a/t/db_dependent/Koha/Item/Transfer.t (-6 / +11 lines)
Lines 208-214 subtest 'in_transit tests' => sub { Link Here
208
};
208
};
209
209
210
subtest 'cancel tests' => sub {
210
subtest 'cancel tests' => sub {
211
    plan tests => 5;
211
    plan tests => 7;
212
212
213
    $schema->storage->txn_begin;
213
    $schema->storage->txn_begin;
214
214
Lines 245-259 subtest 'cancel tests' => sub { Link Here
245
      'Exception thrown if a reason is not passed to cancel';
245
      'Exception thrown if a reason is not passed to cancel';
246
246
247
    # Item in transit should result in failure
247
    # Item in transit should result in failure
248
    throws_ok { $transfer->cancel($cancellation_reason) }
248
    throws_ok { $transfer->cancel({ reason => $cancellation_reason }) }
249
    'Koha::Exceptions::Item::Transfer::Transit',
249
    'Koha::Exceptions::Item::Transfer::Transit',
250
      'Exception thrown if item is in transit';
250
      'Exception thrown if item is in transit';
251
251
252
    $transfer->datesent(undef)->store();
252
    $transfer->cancel({ reason => $cancellation_reason, force => 1});
253
    ok( $transfer->datecancelled, 'Forced cancellation, cancellation date set' );
254
    is( $transfer->cancellation_reason, 'Manual', 'Forced cancellation, cancellation reason is set');
255
256
    $transfer->datecancelled(undef);
257
    $transfer->cancellation_reason(undef);
258
    $transfer->datesent(undef);
253
259
254
    # Transit state unset
260
    # Transit state unset
255
    $transfer->discard_changes;
261
    $transfer->store()->discard_changes;
256
    $transfer->cancel($cancellation_reason);
262
    $transfer->cancel({ reason => $cancellation_reason });
257
    ok( $transfer->datecancelled, 'Cancellation date set upon call to cancel' );
263
    ok( $transfer->datecancelled, 'Cancellation date set upon call to cancel' );
258
    is( $transfer->cancellation_reason, 'Manual', 'Cancellation reason is set');
264
    is( $transfer->cancellation_reason, 'Manual', 'Cancellation reason is set');
259
265
260
- 

Return to bug 24446