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 3810-3845 sub SendCirculationAlert { Link Here
3810
    return;
3809
    return;
3811
}
3810
}
3812
3811
3813
=head2 updateWrongTransfer
3814
3815
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3816
3817
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 
3818
3819
=cut
3820
3821
sub updateWrongTransfer {
3822
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3823
3824
    # first step: cancel the original transfer
3825
    my $item = Koha::Items->find($itemNumber);
3826
    my $transfer = $item->get_transfer;
3827
    $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' })->store();
3828
3829
    # second step: create a new transfer to the right location
3830
    my $new_transfer = $item->request_transfer(
3831
        {
3832
            to            => $transfer->to_library,
3833
            reason        => $transfer->reason,
3834
            comment       => $transfer->comments,
3835
            ignore_limits => 1,
3836
            enqueue       => 1
3837
        }
3838
    );
3839
3840
    return $new_transfer;
3841
}
3842
3843
=head2 CalcDateDue
3812
=head2 CalcDateDue
3844
3813
3845
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3814
$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 702-708 sub place_booking { Link Here
702
    {
702
    {
703
        to     => $to_library,
703
        to     => $to_library,
704
        reason => $reason,
704
        reason => $reason,
705
        [ ignore_limits => 0, enqueue => 1, replace => 1 ]
705
        [ ignore_limits => 0, enqueue => 1, replace => 'reason' ]
706
    }
706
    }
707
  );
707
  );
708
708
Lines 741-748 sub request_transfer { Link Here
741
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
741
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
742
      if ( $request && !$params->{enqueue} && !$params->{replace} );
742
      if ( $request && !$params->{enqueue} && !$params->{replace} );
743
743
744
    $request->cancel( { reason => $params->{reason}, force => 1 } )
744
    $request->cancel( { reason => $params->{replace}, force => 1 } )
745
        if ( defined($request) && $params->{replace} );
745
      if ( defined($request) && $params->{replace} );
746
746
747
    my $transfer = Koha::Item::Transfer->new(
747
    my $transfer = Koha::Item::Transfer->new(
748
        {
748
        {
(-)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 557-563 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { Link Here
557
    );
557
    );
558
558
559
    # Update the transfer to reflect the new item holdingbranch
559
    # Update the transfer to reflect the new item holdingbranch
560
    my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch);
560
    my $item = Koha::Items->find($messages->{'WrongTransferItem'});
561
    my $old_transfer = $item->get_transfer;
562
    my $new_transfer = $item->request_transfer(
563
        { to => $old_transfer->tobranch, reason => $old_transfer->reason, replace => 'WrongTransfer' } );
561
    $template->param(
564
    $template->param(
562
        NewTransfer => $new_transfer->id
565
        NewTransfer => $new_transfer->id
563
    );
566
    );
(-)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 => 67;
21
use Test::More tests => 66;
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 5843-5888 subtest "Item's onloan value should be set if checked out item is checked out to Link Here
5843
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5843
    ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" );
5844
};
5844
};
5845
5845
5846
subtest "updateWrongTransfer tests" => sub {
5847
    plan tests => 5;
5848
5849
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
5850
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
5851
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
5852
    my $item     = $builder->build_sample_item(
5853
        {
5854
            homebranch    => $library1->branchcode,
5855
            holdingbranch => $library2->branchcode,
5856
            datelastseen  => undef
5857
        }
5858
    );
5859
5860
    my $transfer = $builder->build_object(
5861
        {
5862
            class => 'Koha::Item::Transfers',
5863
            value => {
5864
                itemnumber    => $item->itemnumber,
5865
                frombranch    => $library2->branchcode,
5866
                tobranch      => $library1->branchcode,
5867
                daterequested => dt_from_string,
5868
                datesent      => dt_from_string,
5869
                datecancelled => undef,
5870
                datearrived   => undef,
5871
                reason        => 'Manual'
5872
            }
5873
        }
5874
    );
5875
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
5876
5877
    my $new_transfer = C4::Circulation::updateWrongTransfer($item->itemnumber, $library1->branchcode);
5878
    is(ref($new_transfer), 'Koha::Item::Transfer', "updateWrongTransfer returns a 'Koha::Item::Transfer' object");
5879
    ok( !$new_transfer->in_transit, "New transfer is NOT created as in transit (or cancelled)");
5880
5881
    my $original_transfer = $transfer->get_from_storage;
5882
    ok( defined($original_transfer->datecancelled), "Original transfer was cancelled");
5883
    is( $original_transfer->cancellation_reason, 'WrongTransfer', "Original transfer cancellation reason is 'WrongTransfer'");
5884
};
5885
5886
subtest "SendCirculationAlert" => sub {
5846
subtest "SendCirculationAlert" => sub {
5887
    plan tests => 3;
5847
    plan tests => 3;
5888
5848
(-)a/t/db_dependent/Koha/Item.t (-30 / +39 lines)
Lines 757-763 subtest 'pickup_locations() tests' => sub { Link Here
757
};
757
};
758
758
759
subtest 'request_transfer' => sub {
759
subtest 'request_transfer' => sub {
760
    plan tests => 13;
760
    plan tests => 14;
761
    $schema->storage->txn_begin;
761
    $schema->storage->txn_begin;
762
762
763
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
763
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
Lines 772-786 subtest 'request_transfer' => sub { Link Here
772
    # Mandatory fields tests
772
    # Mandatory fields tests
773
    throws_ok { $item->request_transfer( { to => $library1 } ) }
773
    throws_ok { $item->request_transfer( { to => $library1 } ) }
774
    'Koha::Exceptions::MissingParameter',
774
    'Koha::Exceptions::MissingParameter',
775
      'Exception thrown if `reason` parameter is missing';
775
        'Exception thrown if `reason` parameter is missing';
776
776
777
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
777
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
778
    'Koha::Exceptions::MissingParameter',
778
    'Koha::Exceptions::MissingParameter',
779
      'Exception thrown if `to` parameter is missing';
779
        'Exception thrown if `to` parameter is missing';
780
780
781
    # Successful request
781
    # Successful request
782
    my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' });
782
    my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } );
783
    is( ref($transfer), 'Koha::Item::Transfer',
783
    is(
784
        ref($transfer), 'Koha::Item::Transfer',
784
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
785
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
785
    );
786
    );
786
    my $original_transfer = $transfer->get_from_storage;
787
    my $original_transfer = $transfer->get_from_storage;
Lines 788-837 subtest 'request_transfer' => sub { Link Here
788
    # Transfer already in progress
789
    # Transfer already in progress
789
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
790
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
790
    'Koha::Exceptions::Item::Transfer::InQueue',
791
    'Koha::Exceptions::Item::Transfer::InQueue',
791
      'Exception thrown if transfer is already in progress';
792
        'Exception thrown if transfer is already in progress';
792
793
793
    my $exception = $@;
794
    my $exception = $@;
794
    is( ref( $exception->transfer ),
795
    is(
796
        ref( $exception->transfer ),
795
        'Koha::Item::Transfer',
797
        'Koha::Item::Transfer',
796
        'The exception contains the found Koha::Item::Transfer' );
798
        'The exception contains the found Koha::Item::Transfer'
799
    );
797
800
798
    # Queue transfer
801
    # Queue transfer
799
    my $queued_transfer = $item->request_transfer(
802
    my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } );
800
        { to => $library2, reason => 'Manual', enqueue => 1 } );
803
    is(
801
    is( ref($queued_transfer), 'Koha::Item::Transfer',
804
        ref($queued_transfer), 'Koha::Item::Transfer',
802
        'Koha::Item->request_transfer allowed when enqueue is set' );
805
        'Koha::Item->request_transfer allowed when enqueue is set'
806
    );
803
    my $transfers = $item->get_transfers;
807
    my $transfers = $item->get_transfers;
804
    is($transfers->count, 2, "There are now 2 live transfers in the queue");
808
    is( $transfers->count, 2, "There are now 2 live transfers in the queue" );
805
    $transfer = $transfer->get_from_storage;
809
    $transfer = $transfer->get_from_storage;
806
    is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged");
810
    is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" );
807
    $queued_transfer->datearrived(dt_from_string)->store();
811
    $queued_transfer->datearrived(dt_from_string)->store();
808
812
809
    # Replace transfer
813
    # Replace transfer
810
    my $replaced_transfer = $item->request_transfer(
814
    my $replaced_transfer =
811
        { to => $library2, reason => 'Manual', replace => 1 } );
815
        $item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } );
812
    is( ref($replaced_transfer), 'Koha::Item::Transfer',
816
    is(
813
        'Koha::Item->request_transfer allowed when replace is set' );
817
        ref($replaced_transfer), 'Koha::Item::Transfer',
818
        'Koha::Item->request_transfer allowed when replace is set'
819
    );
814
    $original_transfer->discard_changes;
820
    $original_transfer->discard_changes;
815
    ok($original_transfer->datecancelled, "Original transfer cancelled");
821
    ok( $original_transfer->datecancelled, "Original transfer cancelled" );
822
    is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" );
816
    $transfers = $item->get_transfers;
823
    $transfers = $item->get_transfers;
817
    is($transfers->count, 1, "There is only 1 live transfer in the queue");
824
    is( $transfers->count, 1, "There is only 1 live transfer in the queue" );
818
    $replaced_transfer->datearrived(dt_from_string)->store();
825
    $replaced_transfer->datearrived(dt_from_string)->store();
819
826
820
    # BranchTransferLimits
827
    # BranchTransferLimits
821
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
828
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  1 );
822
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
829
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
823
    my $limit = Koha::Item::Transfer::Limit->new({
830
    my $limit = Koha::Item::Transfer::Limit->new(
824
        fromBranch => $library2->branchcode,
831
        {
825
        toBranch => $library1->branchcode,
832
            fromBranch => $library2->branchcode,
826
        itemtype => $item->effective_itemtype,
833
            toBranch   => $library1->branchcode,
827
    })->store;
834
            itemtype   => $item->effective_itemtype,
835
        }
836
    )->store;
828
837
829
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
838
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
830
    'Koha::Exceptions::Item::Transfer::Limit',
839
    'Koha::Exceptions::Item::Transfer::Limit',
831
      'Exception thrown if transfer is prevented by limits';
840
        'Exception thrown if transfer is prevented by limits';
832
841
833
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
842
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
834
    is( ref($forced_transfer), 'Koha::Item::Transfer',
843
    is(
844
        ref($forced_transfer), 'Koha::Item::Transfer',
835
        'Koha::Item->request_transfer allowed when ignore_limits is set'
845
        'Koha::Item->request_transfer allowed when ignore_limits is set'
836
    );
846
    );
837
847
838
- 

Return to bug 28294