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 3838-3873 sub SendCirculationAlert { Link Here
3838
    return;
3837
    return;
3839
}
3838
}
3840
3839
3841
=head2 updateWrongTransfer
3842
3843
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3844
3845
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 
3846
3847
=cut
3848
3849
sub updateWrongTransfer {
3850
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3851
3852
    # first step: cancel the original transfer
3853
    my $item = Koha::Items->find($itemNumber);
3854
    my $transfer = $item->get_transfer;
3855
    $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' })->store();
3856
3857
    # second step: create a new transfer to the right location
3858
    my $new_transfer = $item->request_transfer(
3859
        {
3860
            to            => $transfer->to_library,
3861
            reason        => $transfer->reason,
3862
            comment       => $transfer->comments,
3863
            ignore_limits => 1,
3864
            enqueue       => 1
3865
        }
3866
    );
3867
3868
    return $new_transfer;
3869
}
3870
3871
=head2 CalcDateDue
3840
=head2 CalcDateDue
3872
3841
3873
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3842
$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 759-765 sub check_booking { Link Here
759
    {
759
    {
760
        to     => $to_library,
760
        to     => $to_library,
761
        reason => $reason,
761
        reason => $reason,
762
        [ ignore_limits => 0, enqueue => 1, replace => 1 ]
762
        [ ignore_limits => 0, enqueue => 1, replace => 'reason' ]
763
    }
763
    }
764
  );
764
  );
765
765
Lines 798-805 sub request_transfer { Link Here
798
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
798
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
799
      if ( $request && !$params->{enqueue} && !$params->{replace} );
799
      if ( $request && !$params->{enqueue} && !$params->{replace} );
800
800
801
    $request->cancel( { reason => $params->{reason}, force => 1 } )
801
    $request->cancel( { reason => $params->{replace}, force => 1 } )
802
        if ( defined($request) && $params->{replace} );
802
      if ( defined($request) && $params->{replace} );
803
803
804
    my $transfer = Koha::Item::Transfer->new(
804
    my $transfer = Koha::Item::Transfer->new(
805
        {
805
        {
(-)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 583-589 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { Link Here
583
    );
583
    );
584
584
585
    # Update the transfer to reflect the new item holdingbranch
585
    # Update the transfer to reflect the new item holdingbranch
586
    my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch);
586
    my $item = Koha::Items->find($messages->{'WrongTransferItem'});
587
    my $old_transfer = $item->get_transfer;
588
    my $new_transfer = $item->request_transfer(
589
        { to => $old_transfer->tobranch, reason => $old_transfer->reason, replace => 'WrongTransfer' } );
587
    $template->param(
590
    $template->param(
588
        NewTransfer => $new_transfer->id
591
        NewTransfer => $new_transfer->id
589
    );
592
    );
(-)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 => 76;
21
use Test::More tests => 75;
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 6418-6463 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
6418
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
6418
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
6419
};
6419
};
6420
6420
6421
subtest "updateWrongTransfer tests" => sub {
6422
    plan tests => 5;
6423
6424
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
6425
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
6426
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
6427
    my $item     = $builder->build_sample_item(
6428
        {
6429
            homebranch    => $library1->branchcode,
6430
            holdingbranch => $library2->branchcode,
6431
            datelastseen  => undef
6432
        }
6433
    );
6434
6435
    my $transfer = $builder->build_object(
6436
        {
6437
            class => 'Koha::Item::Transfers',
6438
            value => {
6439
                itemnumber    => $item->itemnumber,
6440
                frombranch    => $library2->branchcode,
6441
                tobranch      => $library1->branchcode,
6442
                daterequested => dt_from_string,
6443
                datesent      => dt_from_string,
6444
                datecancelled => undef,
6445
                datearrived   => undef,
6446
                reason        => 'Manual'
6447
            }
6448
        }
6449
    );
6450
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
6451
6452
    my $new_transfer = C4::Circulation::updateWrongTransfer($item->itemnumber, $library1->branchcode);
6453
    is(ref($new_transfer), 'Koha::Item::Transfer', "updateWrongTransfer returns a 'Koha::Item::Transfer' object");
6454
    ok( !$new_transfer->in_transit, "New transfer is NOT created as in transit (or cancelled)");
6455
6456
    my $original_transfer = $transfer->get_from_storage;
6457
    ok( defined($original_transfer->datecancelled), "Original transfer was cancelled");
6458
    is( $original_transfer->cancellation_reason, 'WrongTransfer', "Original transfer cancellation reason is 'WrongTransfer'");
6459
};
6460
6461
subtest "SendCirculationAlert" => sub {
6421
subtest "SendCirculationAlert" => sub {
6462
    plan tests => 3;
6422
    plan tests => 3;
6463
6423
(-)a/t/db_dependent/Koha/Item.t (-30 / +39 lines)
Lines 852-858 subtest 'pickup_locations() tests' => sub { Link Here
852
};
852
};
853
853
854
subtest 'request_transfer' => sub {
854
subtest 'request_transfer' => sub {
855
    plan tests => 13;
855
    plan tests => 14;
856
    $schema->storage->txn_begin;
856
    $schema->storage->txn_begin;
857
857
858
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
858
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
Lines 867-881 subtest 'request_transfer' => sub { Link Here
867
    # Mandatory fields tests
867
    # Mandatory fields tests
868
    throws_ok { $item->request_transfer( { to => $library1 } ) }
868
    throws_ok { $item->request_transfer( { to => $library1 } ) }
869
    'Koha::Exceptions::MissingParameter',
869
    'Koha::Exceptions::MissingParameter',
870
      'Exception thrown if `reason` parameter is missing';
870
        'Exception thrown if `reason` parameter is missing';
871
871
872
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
872
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
873
    'Koha::Exceptions::MissingParameter',
873
    'Koha::Exceptions::MissingParameter',
874
      'Exception thrown if `to` parameter is missing';
874
        'Exception thrown if `to` parameter is missing';
875
875
876
    # Successful request
876
    # Successful request
877
    my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' });
877
    my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } );
878
    is( ref($transfer), 'Koha::Item::Transfer',
878
    is(
879
        ref($transfer), 'Koha::Item::Transfer',
879
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
880
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
880
    );
881
    );
881
    my $original_transfer = $transfer->get_from_storage;
882
    my $original_transfer = $transfer->get_from_storage;
Lines 883-932 subtest 'request_transfer' => sub { Link Here
883
    # Transfer already in progress
884
    # Transfer already in progress
884
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
885
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
885
    'Koha::Exceptions::Item::Transfer::InQueue',
886
    'Koha::Exceptions::Item::Transfer::InQueue',
886
      'Exception thrown if transfer is already in progress';
887
        'Exception thrown if transfer is already in progress';
887
888
888
    my $exception = $@;
889
    my $exception = $@;
889
    is( ref( $exception->transfer ),
890
    is(
891
        ref( $exception->transfer ),
890
        'Koha::Item::Transfer',
892
        'Koha::Item::Transfer',
891
        'The exception contains the found Koha::Item::Transfer' );
893
        'The exception contains the found Koha::Item::Transfer'
894
    );
892
895
893
    # Queue transfer
896
    # Queue transfer
894
    my $queued_transfer = $item->request_transfer(
897
    my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } );
895
        { to => $library2, reason => 'Manual', enqueue => 1 } );
898
    is(
896
    is( ref($queued_transfer), 'Koha::Item::Transfer',
899
        ref($queued_transfer), 'Koha::Item::Transfer',
897
        'Koha::Item->request_transfer allowed when enqueue is set' );
900
        'Koha::Item->request_transfer allowed when enqueue is set'
901
    );
898
    my $transfers = $item->get_transfers;
902
    my $transfers = $item->get_transfers;
899
    is($transfers->count, 2, "There are now 2 live transfers in the queue");
903
    is( $transfers->count, 2, "There are now 2 live transfers in the queue" );
900
    $transfer = $transfer->get_from_storage;
904
    $transfer = $transfer->get_from_storage;
901
    is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged");
905
    is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" );
902
    $queued_transfer->datearrived(dt_from_string)->store();
906
    $queued_transfer->datearrived(dt_from_string)->store();
903
907
904
    # Replace transfer
908
    # Replace transfer
905
    my $replaced_transfer = $item->request_transfer(
909
    my $replaced_transfer =
906
        { to => $library2, reason => 'Manual', replace => 1 } );
910
        $item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } );
907
    is( ref($replaced_transfer), 'Koha::Item::Transfer',
911
    is(
908
        'Koha::Item->request_transfer allowed when replace is set' );
912
        ref($replaced_transfer), 'Koha::Item::Transfer',
913
        'Koha::Item->request_transfer allowed when replace is set'
914
    );
909
    $original_transfer->discard_changes;
915
    $original_transfer->discard_changes;
910
    ok($original_transfer->datecancelled, "Original transfer cancelled");
916
    ok( $original_transfer->datecancelled, "Original transfer cancelled" );
917
    is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" );
911
    $transfers = $item->get_transfers;
918
    $transfers = $item->get_transfers;
912
    is($transfers->count, 1, "There is only 1 live transfer in the queue");
919
    is( $transfers->count, 1, "There is only 1 live transfer in the queue" );
913
    $replaced_transfer->datearrived(dt_from_string)->store();
920
    $replaced_transfer->datearrived(dt_from_string)->store();
914
921
915
    # BranchTransferLimits
922
    # BranchTransferLimits
916
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
923
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  1 );
917
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
924
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
918
    my $limit = Koha::Item::Transfer::Limit->new({
925
    my $limit = Koha::Item::Transfer::Limit->new(
919
        fromBranch => $library2->branchcode,
926
        {
920
        toBranch => $library1->branchcode,
927
            fromBranch => $library2->branchcode,
921
        itemtype => $item->effective_itemtype,
928
            toBranch   => $library1->branchcode,
922
    })->store;
929
            itemtype   => $item->effective_itemtype,
930
        }
931
    )->store;
923
932
924
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
933
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
925
    'Koha::Exceptions::Item::Transfer::Limit',
934
    'Koha::Exceptions::Item::Transfer::Limit',
926
      'Exception thrown if transfer is prevented by limits';
935
        'Exception thrown if transfer is prevented by limits';
927
936
928
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
937
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
929
    is( ref($forced_transfer), 'Koha::Item::Transfer',
938
    is(
939
        ref($forced_transfer), 'Koha::Item::Transfer',
930
        'Koha::Item->request_transfer allowed when ignore_limits is set'
940
        'Koha::Item->request_transfer allowed when ignore_limits is set'
931
    );
941
    );
932
942
933
- 

Return to bug 28294