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

(-)a/C4/Circulation.pm (-31 lines)
Lines 107-113 BEGIN { Link Here
107
      transferbook
107
      transferbook
108
      TooMany
108
      TooMany
109
      GetTransfersFromTo
109
      GetTransfersFromTo
110
      updateWrongTransfer
111
      CalcDateDue
110
      CalcDateDue
112
      CheckValidBarcode
111
      CheckValidBarcode
113
      IsBranchTransferAllowed
112
      IsBranchTransferAllowed
Lines 3836-3871 sub SendCirculationAlert { Link Here
3836
    return;
3835
    return;
3837
}
3836
}
3838
3837
3839
=head2 updateWrongTransfer
3840
3841
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3842
3843
This function validate the line of brachtransfer but with the wrong destination (mistake from a librarian ...), and create a new line in branchtransfer from the actual library to the original library of reservation 
3844
3845
=cut
3846
3847
sub updateWrongTransfer {
3848
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3849
3850
    # first step: cancel the original transfer
3851
    my $item = Koha::Items->find($itemNumber);
3852
    my $transfer = $item->get_transfer;
3853
    $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' })->store();
3854
3855
    # second step: create a new transfer to the right location
3856
    my $new_transfer = $item->request_transfer(
3857
        {
3858
            to            => $transfer->to_library,
3859
            reason        => $transfer->reason,
3860
            comment       => $transfer->comments,
3861
            ignore_limits => 1,
3862
            enqueue       => 1
3863
        }
3864
    );
3865
3866
    return $new_transfer;
3867
}
3868
3869
=head2 CalcDateDue
3838
=head2 CalcDateDue
3870
3839
3871
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3840
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
(-)a/C4/Items.pm (-1 / +1 lines)
Lines 400-406 sub ModItemTransfer { Link Here
400
                        to            => $to_library,
400
                        to            => $to_library,
401
                        reason        => $trigger,
401
                        reason        => $trigger,
402
                        ignore_limits => 1,
402
                        ignore_limits => 1,
403
                        replace       => 1
403
                        replace       => $trigger
404
                    }
404
                    }
405
                );
405
                );
406
            }
406
            }
(-)a/C4/RotatingCollections.pm (-1 / +1 lines)
Lines 484-490 sub TransferCollection { Link Here
484
                            to            => $to_library,
484
                            to            => $to_library,
485
                            reason        => "RotatingCollection",
485
                            reason        => "RotatingCollection",
486
                            ignore_limits => 0,
486
                            ignore_limits => 0,
487
                            replace       => 1
487
                            replace       => "RotatingCollection"
488
                        }
488
                        }
489
                    );    # Replace transfer
489
                    );    # Replace transfer
490
                          # FIXME: If we just replaced a StockRotationAdvance,
490
                          # FIXME: If we just replaced a StockRotationAdvance,
(-)a/Koha/Item.pm (-3 / +3 lines)
Lines 736-742 sub check_booking { Link Here
736
    {
736
    {
737
        to     => $to_library,
737
        to     => $to_library,
738
        reason => $reason,
738
        reason => $reason,
739
        [ ignore_limits => 0, enqueue => 1, replace => 1 ]
739
        [ ignore_limits => 0, enqueue => 1, replace => 'reason' ]
740
    }
740
    }
741
  );
741
  );
742
742
Lines 775-782 sub request_transfer { Link Here
775
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
775
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
776
      if ( $request && !$params->{enqueue} && !$params->{replace} );
776
      if ( $request && !$params->{enqueue} && !$params->{replace} );
777
777
778
    $request->cancel( { reason => $params->{reason}, force => 1 } )
778
    $request->cancel( { reason => $params->{replace}, force => 1 } )
779
        if ( defined($request) && $params->{replace} );
779
      if ( defined($request) && $params->{replace} );
780
780
781
    my $transfer = Koha::Item::Transfer->new(
781
    my $transfer = Koha::Item::Transfer->new(
782
        {
782
        {
(-)a/Koha/StockRotationItem.pm (-1 / +1 lines)
Lines 265-271 sub advance { Link Here
265
                        to            => $new_stage->branchcode,
265
                        to            => $new_stage->branchcode,
266
                        reason        => "StockrotationAdvance",
266
                        reason        => "StockrotationAdvance",
267
                        ignore_limits => 1,
267
                        ignore_limits => 1,
268
                        replace       => 1
268
                        replace       => "StockrotationAdvance"
269
                    }
269
                    }
270
                );                                      # Replace transfer
270
                );                                      # Replace transfer
271
            }
271
            }
(-)a/circ/returns.pl (-2 / +5 lines)
Lines 35-41 use CGI qw ( -utf8 ); Link Here
35
use DateTime;
35
use DateTime;
36
36
37
use C4::Auth qw( get_template_and_user get_session haspermission );
37
use C4::Auth qw( get_template_and_user get_session haspermission );
38
use C4::Circulation qw( barcodedecode GetBranchItemRule AddReturn updateWrongTransfer LostItem );
38
use C4::Circulation qw( barcodedecode GetBranchItemRule AddReturn LostItem );
39
use C4::Context;
39
use C4::Context;
40
use C4::Members::Messaging;
40
use C4::Members::Messaging;
41
use C4::Members;
41
use C4::Members;
Lines 578-584 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { Link Here
578
    );
578
    );
579
579
580
    # Update the transfer to reflect the new item holdingbranch
580
    # Update the transfer to reflect the new item holdingbranch
581
    my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch);
581
    my $item = Koha::Items->find($messages->{'WrongTransferItem'});
582
    my $old_transfer = $item->get_transfer;
583
    my $new_transfer = $item->request_transfer(
584
        { to => $old_transfer->tobranch, reason => $old_transfer->reason, replace => 'WrongTransfer' } );
582
    $template->param(
585
    $template->param(
583
        NewTransfer => $new_transfer->id
586
        NewTransfer => $new_transfer->id
584
    );
587
    );
(-)a/t/db_dependent/Circulation.t (-42 / +2 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 75;
21
use Test::More tests => 74;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
Lines 33-39 use t::lib::TestBuilder; Link Here
33
33
34
use C4::Accounts;
34
use C4::Accounts;
35
use C4::Calendar qw( new insert_single_holiday insert_week_day_holiday delete_holiday );
35
use C4::Calendar qw( new insert_single_holiday insert_week_day_holiday delete_holiday );
36
use C4::Circulation qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges AddRenewal GetSoonestRenewDate GetLatestAutoRenewDate LostItem GetUpcomingDueIssues CanBookBeIssued AddIssuingCharge MarkIssueReturned ProcessOfflinePayment transferbook updateWrongTransfer );
36
use C4::Circulation qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges AddRenewal GetSoonestRenewDate GetLatestAutoRenewDate LostItem GetUpcomingDueIssues CanBookBeIssued AddIssuingCharge MarkIssueReturned ProcessOfflinePayment transferbook );
37
use C4::Biblio;
37
use C4::Biblio;
38
use C4::Items qw( ModItemTransfer );
38
use C4::Items qw( ModItemTransfer );
39
use C4::Log;
39
use C4::Log;
Lines 6404-6449 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
6404
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
6404
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
6405
};
6405
};
6406
6406
6407
subtest "updateWrongTransfer tests" => sub {
6408
    plan tests => 5;
6409
6410
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
6411
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
6412
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
6413
    my $item     = $builder->build_sample_item(
6414
        {
6415
            homebranch    => $library1->branchcode,
6416
            holdingbranch => $library2->branchcode,
6417
            datelastseen  => undef
6418
        }
6419
    );
6420
6421
    my $transfer = $builder->build_object(
6422
        {
6423
            class => 'Koha::Item::Transfers',
6424
            value => {
6425
                itemnumber    => $item->itemnumber,
6426
                frombranch    => $library2->branchcode,
6427
                tobranch      => $library1->branchcode,
6428
                daterequested => dt_from_string,
6429
                datesent      => dt_from_string,
6430
                datecancelled => undef,
6431
                datearrived   => undef,
6432
                reason        => 'Manual'
6433
            }
6434
        }
6435
    );
6436
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
6437
6438
    my $new_transfer = C4::Circulation::updateWrongTransfer($item->itemnumber, $library1->branchcode);
6439
    is(ref($new_transfer), 'Koha::Item::Transfer', "updateWrongTransfer returns a 'Koha::Item::Transfer' object");
6440
    ok( !$new_transfer->in_transit, "New transfer is NOT created as in transit (or cancelled)");
6441
6442
    my $original_transfer = $transfer->get_from_storage;
6443
    ok( defined($original_transfer->datecancelled), "Original transfer was cancelled");
6444
    is( $original_transfer->cancellation_reason, 'WrongTransfer', "Original transfer cancellation reason is 'WrongTransfer'");
6445
};
6446
6447
subtest "SendCirculationAlert" => sub {
6407
subtest "SendCirculationAlert" => sub {
6448
    plan tests => 3;
6408
    plan tests => 3;
6449
6409
(-)a/t/db_dependent/Koha/Item.t (-30 / +39 lines)
Lines 846-852 subtest 'pickup_locations() tests' => sub { Link Here
846
};
846
};
847
847
848
subtest 'request_transfer' => sub {
848
subtest 'request_transfer' => sub {
849
    plan tests => 13;
849
    plan tests => 14;
850
    $schema->storage->txn_begin;
850
    $schema->storage->txn_begin;
851
851
852
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
852
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
Lines 861-875 subtest 'request_transfer' => sub { Link Here
861
    # Mandatory fields tests
861
    # Mandatory fields tests
862
    throws_ok { $item->request_transfer( { to => $library1 } ) }
862
    throws_ok { $item->request_transfer( { to => $library1 } ) }
863
    'Koha::Exceptions::MissingParameter',
863
    'Koha::Exceptions::MissingParameter',
864
      'Exception thrown if `reason` parameter is missing';
864
        'Exception thrown if `reason` parameter is missing';
865
865
866
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
866
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
867
    'Koha::Exceptions::MissingParameter',
867
    'Koha::Exceptions::MissingParameter',
868
      'Exception thrown if `to` parameter is missing';
868
        'Exception thrown if `to` parameter is missing';
869
869
870
    # Successful request
870
    # Successful request
871
    my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' });
871
    my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } );
872
    is( ref($transfer), 'Koha::Item::Transfer',
872
    is(
873
        ref($transfer), 'Koha::Item::Transfer',
873
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
874
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
874
    );
875
    );
875
    my $original_transfer = $transfer->get_from_storage;
876
    my $original_transfer = $transfer->get_from_storage;
Lines 877-926 subtest 'request_transfer' => sub { Link Here
877
    # Transfer already in progress
878
    # Transfer already in progress
878
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
879
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
879
    'Koha::Exceptions::Item::Transfer::InQueue',
880
    'Koha::Exceptions::Item::Transfer::InQueue',
880
      'Exception thrown if transfer is already in progress';
881
        'Exception thrown if transfer is already in progress';
881
882
882
    my $exception = $@;
883
    my $exception = $@;
883
    is( ref( $exception->transfer ),
884
    is(
885
        ref( $exception->transfer ),
884
        'Koha::Item::Transfer',
886
        'Koha::Item::Transfer',
885
        'The exception contains the found Koha::Item::Transfer' );
887
        'The exception contains the found Koha::Item::Transfer'
888
    );
886
889
887
    # Queue transfer
890
    # Queue transfer
888
    my $queued_transfer = $item->request_transfer(
891
    my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } );
889
        { to => $library2, reason => 'Manual', enqueue => 1 } );
892
    is(
890
    is( ref($queued_transfer), 'Koha::Item::Transfer',
893
        ref($queued_transfer), 'Koha::Item::Transfer',
891
        'Koha::Item->request_transfer allowed when enqueue is set' );
894
        'Koha::Item->request_transfer allowed when enqueue is set'
895
    );
892
    my $transfers = $item->get_transfers;
896
    my $transfers = $item->get_transfers;
893
    is($transfers->count, 2, "There are now 2 live transfers in the queue");
897
    is( $transfers->count, 2, "There are now 2 live transfers in the queue" );
894
    $transfer = $transfer->get_from_storage;
898
    $transfer = $transfer->get_from_storage;
895
    is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged");
899
    is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" );
896
    $queued_transfer->datearrived(dt_from_string)->store();
900
    $queued_transfer->datearrived(dt_from_string)->store();
897
901
898
    # Replace transfer
902
    # Replace transfer
899
    my $replaced_transfer = $item->request_transfer(
903
    my $replaced_transfer =
900
        { to => $library2, reason => 'Manual', replace => 1 } );
904
        $item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } );
901
    is( ref($replaced_transfer), 'Koha::Item::Transfer',
905
    is(
902
        'Koha::Item->request_transfer allowed when replace is set' );
906
        ref($replaced_transfer), 'Koha::Item::Transfer',
907
        'Koha::Item->request_transfer allowed when replace is set'
908
    );
903
    $original_transfer->discard_changes;
909
    $original_transfer->discard_changes;
904
    ok($original_transfer->datecancelled, "Original transfer cancelled");
910
    ok( $original_transfer->datecancelled, "Original transfer cancelled" );
911
    is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" );
905
    $transfers = $item->get_transfers;
912
    $transfers = $item->get_transfers;
906
    is($transfers->count, 1, "There is only 1 live transfer in the queue");
913
    is( $transfers->count, 1, "There is only 1 live transfer in the queue" );
907
    $replaced_transfer->datearrived(dt_from_string)->store();
914
    $replaced_transfer->datearrived(dt_from_string)->store();
908
915
909
    # BranchTransferLimits
916
    # BranchTransferLimits
910
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
917
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  1 );
911
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
918
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
912
    my $limit = Koha::Item::Transfer::Limit->new({
919
    my $limit = Koha::Item::Transfer::Limit->new(
913
        fromBranch => $library2->branchcode,
920
        {
914
        toBranch => $library1->branchcode,
921
            fromBranch => $library2->branchcode,
915
        itemtype => $item->effective_itemtype,
922
            toBranch   => $library1->branchcode,
916
    })->store;
923
            itemtype   => $item->effective_itemtype,
924
        }
925
    )->store;
917
926
918
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
927
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
919
    'Koha::Exceptions::Item::Transfer::Limit',
928
    'Koha::Exceptions::Item::Transfer::Limit',
920
      'Exception thrown if transfer is prevented by limits';
929
        'Exception thrown if transfer is prevented by limits';
921
930
922
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
931
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
923
    is( ref($forced_transfer), 'Koha::Item::Transfer',
932
    is(
933
        ref($forced_transfer), 'Koha::Item::Transfer',
924
        'Koha::Item->request_transfer allowed when ignore_limits is set'
934
        'Koha::Item->request_transfer allowed when ignore_limits is set'
925
    );
935
    );
926
936
927
- 

Return to bug 28294