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 3830-3865 sub SendCirculationAlert { Link Here
3830
    return;
3829
    return;
3831
}
3830
}
3832
3831
3833
=head2 updateWrongTransfer
3834
3835
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3836
3837
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 
3838
3839
=cut
3840
3841
sub updateWrongTransfer {
3842
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3843
3844
    # first step: cancel the original transfer
3845
    my $item = Koha::Items->find($itemNumber);
3846
    my $transfer = $item->get_transfer;
3847
    $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' })->store();
3848
3849
    # second step: create a new transfer to the right location
3850
    my $new_transfer = $item->request_transfer(
3851
        {
3852
            to            => $transfer->to_library,
3853
            reason        => $transfer->reason,
3854
            comment       => $transfer->comments,
3855
            ignore_limits => 1,
3856
            enqueue       => 1
3857
        }
3858
    );
3859
3860
    return $new_transfer;
3861
}
3862
3863
=head2 CalcDateDue
3832
=head2 CalcDateDue
3864
3833
3865
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3834
$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 721-727 sub check_booking { Link Here
721
    {
721
    {
722
        to     => $to_library,
722
        to     => $to_library,
723
        reason => $reason,
723
        reason => $reason,
724
        [ ignore_limits => 0, enqueue => 1, replace => 1 ]
724
        [ ignore_limits => 0, enqueue => 1, replace => 'reason' ]
725
    }
725
    }
726
  );
726
  );
727
727
Lines 760-767 sub request_transfer { Link Here
760
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
760
    Koha::Exceptions::Item::Transfer::InQueue->throw( transfer => $request )
761
      if ( $request && !$params->{enqueue} && !$params->{replace} );
761
      if ( $request && !$params->{enqueue} && !$params->{replace} );
762
762
763
    $request->cancel( { reason => $params->{reason}, force => 1 } )
763
    $request->cancel( { reason => $params->{replace}, force => 1 } )
764
        if ( defined($request) && $params->{replace} );
764
      if ( defined($request) && $params->{replace} );
765
765
766
    my $transfer = Koha::Item::Transfer->new(
766
    my $transfer = Koha::Item::Transfer->new(
767
        {
767
        {
(-)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 762-768 subtest 'pickup_locations() tests' => sub { Link Here
762
};
762
};
763
763
764
subtest 'request_transfer' => sub {
764
subtest 'request_transfer' => sub {
765
    plan tests => 13;
765
    plan tests => 14;
766
    $schema->storage->txn_begin;
766
    $schema->storage->txn_begin;
767
767
768
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
768
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
Lines 777-791 subtest 'request_transfer' => sub { Link Here
777
    # Mandatory fields tests
777
    # Mandatory fields tests
778
    throws_ok { $item->request_transfer( { to => $library1 } ) }
778
    throws_ok { $item->request_transfer( { to => $library1 } ) }
779
    'Koha::Exceptions::MissingParameter',
779
    'Koha::Exceptions::MissingParameter',
780
      'Exception thrown if `reason` parameter is missing';
780
        'Exception thrown if `reason` parameter is missing';
781
781
782
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
782
    throws_ok { $item->request_transfer( { reason => 'Manual' } ) }
783
    'Koha::Exceptions::MissingParameter',
783
    'Koha::Exceptions::MissingParameter',
784
      'Exception thrown if `to` parameter is missing';
784
        'Exception thrown if `to` parameter is missing';
785
785
786
    # Successful request
786
    # Successful request
787
    my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' });
787
    my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } );
788
    is( ref($transfer), 'Koha::Item::Transfer',
788
    is(
789
        ref($transfer), 'Koha::Item::Transfer',
789
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
790
        'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
790
    );
791
    );
791
    my $original_transfer = $transfer->get_from_storage;
792
    my $original_transfer = $transfer->get_from_storage;
Lines 793-842 subtest 'request_transfer' => sub { Link Here
793
    # Transfer already in progress
794
    # Transfer already in progress
794
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
795
    throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
795
    'Koha::Exceptions::Item::Transfer::InQueue',
796
    'Koha::Exceptions::Item::Transfer::InQueue',
796
      'Exception thrown if transfer is already in progress';
797
        'Exception thrown if transfer is already in progress';
797
798
798
    my $exception = $@;
799
    my $exception = $@;
799
    is( ref( $exception->transfer ),
800
    is(
801
        ref( $exception->transfer ),
800
        'Koha::Item::Transfer',
802
        'Koha::Item::Transfer',
801
        'The exception contains the found Koha::Item::Transfer' );
803
        'The exception contains the found Koha::Item::Transfer'
804
    );
802
805
803
    # Queue transfer
806
    # Queue transfer
804
    my $queued_transfer = $item->request_transfer(
807
    my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } );
805
        { to => $library2, reason => 'Manual', enqueue => 1 } );
808
    is(
806
    is( ref($queued_transfer), 'Koha::Item::Transfer',
809
        ref($queued_transfer), 'Koha::Item::Transfer',
807
        'Koha::Item->request_transfer allowed when enqueue is set' );
810
        'Koha::Item->request_transfer allowed when enqueue is set'
811
    );
808
    my $transfers = $item->get_transfers;
812
    my $transfers = $item->get_transfers;
809
    is($transfers->count, 2, "There are now 2 live transfers in the queue");
813
    is( $transfers->count, 2, "There are now 2 live transfers in the queue" );
810
    $transfer = $transfer->get_from_storage;
814
    $transfer = $transfer->get_from_storage;
811
    is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged");
815
    is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" );
812
    $queued_transfer->datearrived(dt_from_string)->store();
816
    $queued_transfer->datearrived(dt_from_string)->store();
813
817
814
    # Replace transfer
818
    # Replace transfer
815
    my $replaced_transfer = $item->request_transfer(
819
    my $replaced_transfer =
816
        { to => $library2, reason => 'Manual', replace => 1 } );
820
        $item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } );
817
    is( ref($replaced_transfer), 'Koha::Item::Transfer',
821
    is(
818
        'Koha::Item->request_transfer allowed when replace is set' );
822
        ref($replaced_transfer), 'Koha::Item::Transfer',
823
        'Koha::Item->request_transfer allowed when replace is set'
824
    );
819
    $original_transfer->discard_changes;
825
    $original_transfer->discard_changes;
820
    ok($original_transfer->datecancelled, "Original transfer cancelled");
826
    ok( $original_transfer->datecancelled, "Original transfer cancelled" );
827
    is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" );
821
    $transfers = $item->get_transfers;
828
    $transfers = $item->get_transfers;
822
    is($transfers->count, 1, "There is only 1 live transfer in the queue");
829
    is( $transfers->count, 1, "There is only 1 live transfer in the queue" );
823
    $replaced_transfer->datearrived(dt_from_string)->store();
830
    $replaced_transfer->datearrived(dt_from_string)->store();
824
831
825
    # BranchTransferLimits
832
    # BranchTransferLimits
826
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
833
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  1 );
827
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
834
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
828
    my $limit = Koha::Item::Transfer::Limit->new({
835
    my $limit = Koha::Item::Transfer::Limit->new(
829
        fromBranch => $library2->branchcode,
836
        {
830
        toBranch => $library1->branchcode,
837
            fromBranch => $library2->branchcode,
831
        itemtype => $item->effective_itemtype,
838
            toBranch   => $library1->branchcode,
832
    })->store;
839
            itemtype   => $item->effective_itemtype,
840
        }
841
    )->store;
833
842
834
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
843
    throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) }
835
    'Koha::Exceptions::Item::Transfer::Limit',
844
    'Koha::Exceptions::Item::Transfer::Limit',
836
      'Exception thrown if transfer is prevented by limits';
845
        'Exception thrown if transfer is prevented by limits';
837
846
838
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
847
    my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } );
839
    is( ref($forced_transfer), 'Koha::Item::Transfer',
848
    is(
849
        ref($forced_transfer), 'Koha::Item::Transfer',
840
        'Koha::Item->request_transfer allowed when ignore_limits is set'
850
        'Koha::Item->request_transfer allowed when ignore_limits is set'
841
    );
851
    );
842
852
843
- 

Return to bug 28294