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

(-)a/C4/SIP/ILS/Transaction/Checkout.pm (-31 / +34 lines)
Lines 40-56 sub new { Link Here
40
}
40
}
41
41
42
sub do_checkout {
42
sub do_checkout {
43
	my $self = shift;
43
        my $self              = shift;
44
    my $account = shift;
44
        my $account           = shift;
45
    my $no_block_due_date = shift;
45
        my $no_block_due_date = shift;
46
	siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
46
        siplog( 'LOG_DEBUG', "ILS::Transaction::Checkout performing checkout..." );
47
    my $shelf          = $self->{item}->hold_attached;
47
        my $shelf   = $self->{item}->hold_attached;
48
	my $barcode        = $self->{item}->id;
48
        my $barcode = $self->{item}->id;
49
    my $patron         = Koha::Patrons->find($self->{patron}->{borrowernumber});
49
        my $patron  = Koha::Patrons->find( $self->{patron}->{borrowernumber} );
50
    my $overridden_duedate; # usually passed as undef to AddIssue
50
        my $overridden_duedate;    # usually passed as undef to AddIssue
51
    my $prevcheckout_block_checkout  = $account->{prevcheckout_block_checkout};
51
        my $prevcheckout_block_checkout         = $account->{prevcheckout_block_checkout};
52
    my $allow_additional_materials_checkout = $account->{allow_additional_materials_checkout};
52
        my $allow_additional_materials_checkout = $account->{allow_additional_materials_checkout};
53
    my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode, 0);
53
        my ( $issuingimpossible, $needsconfirmation ) = _can_we_issue( $patron, $barcode, 0 );
54
54
55
    if ( $no_block_due_date ) {
55
    if ( $no_block_due_date ) {
56
        my $year = substr($no_block_due_date,0,4);
56
        my $year = substr($no_block_due_date,0,4);
Lines 65-114 sub do_checkout { Link Here
65
    }
65
    }
66
66
67
    my $noerror=1;  # If set to zero we block the issue
67
    my $noerror=1;  # If set to zero we block the issue
68
    if (keys %{$issuingimpossible}) {
68
    if ( keys %{$issuingimpossible} ) {
69
        foreach (keys %{$issuingimpossible}) {
69
        foreach ( keys %{$issuingimpossible} ) {
70
70
            # do something here so we pass these errors
71
            # do something here so we pass these errors
71
            $self->screen_msg("Issue failed : $_");
72
            $self->screen_msg("Issue failed : $_");
72
            $noerror = 0;
73
            $noerror = 0;
73
            last;
74
            last;
74
        }
75
        }
75
    } else {
76
    } else {
76
        foreach my $confirmation (keys %{$needsconfirmation}) {
77
        foreach my $confirmation ( keys %{$needsconfirmation} ) {
77
            if ($confirmation eq 'RENEW_ISSUE'){
78
            if ( $confirmation eq 'RENEW_ISSUE' ) {
78
                $self->screen_msg("Item already checked out to you: renewing item.");
79
                $self->screen_msg("Item already checked out to you: renewing item.");
79
            } elsif ($confirmation eq 'RESERVED' and !C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
80
            } elsif ( $confirmation eq 'RESERVED' and !C4::Context->preference("AllowItemsOnHoldCheckoutSIP") ) {
80
                $self->screen_msg("Item is reserved for another patron upon return.");
81
                $self->screen_msg("Item is reserved for another patron upon return.");
81
                $noerror = 0;
82
                $noerror = 0;
82
            } elsif ($confirmation eq 'RESERVED' and C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
83
            } elsif ( $confirmation eq 'RESERVED' and C4::Context->preference("AllowItemsOnHoldCheckoutSIP") ) {
83
                next;
84
                next;
84
            } elsif ($confirmation eq 'RESERVE_WAITING'
85
            } elsif ( $confirmation eq 'RESERVE_WAITING'
85
                      or $confirmation eq 'TRANSFERRED'
86
                or $confirmation eq 'TRANSFERRED'
86
                      or $confirmation eq 'PROCESSING') {
87
                or $confirmation eq 'PROCESSING' )
87
               $self->screen_msg("Item is on hold for another patron.");
88
            {
88
               $noerror = 0;
89
                $self->screen_msg("Item is on hold for another patron.");
89
            } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
90
                $noerror = 0;
91
            } elsif ( $confirmation eq 'ISSUED_TO_ANOTHER' ) {
90
                $self->screen_msg("Item already checked out to another patron.  Please return item for check-in.");
92
                $self->screen_msg("Item already checked out to another patron.  Please return item for check-in.");
91
                $noerror = 0;
93
                $noerror = 0;
92
                last;
94
                last;
93
            } elsif ($confirmation eq 'DEBT') {
95
            } elsif ( $confirmation eq 'DEBT' ) {
94
                $self->screen_msg('Outstanding Fines block issue');
96
                $self->screen_msg('Outstanding Fines block issue');
95
                $noerror = 0;
97
                $noerror = 0;
96
                last;
98
                last;
97
            } elsif ($confirmation eq 'HIGHHOLDS') {
99
            } elsif ( $confirmation eq 'HIGHHOLDS' ) {
98
                $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
100
                $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
99
                $self->screen_msg('Loan period reduced for high-demand item');
101
                $self->screen_msg('Loan period reduced for high-demand item');
100
            } elsif ($confirmation eq 'RENTALCHARGE') {
102
            } elsif ( $confirmation eq 'RENTALCHARGE' ) {
101
                if ($self->{fee_ack} ne 'Y') {
103
                if ( $self->{fee_ack} ne 'Y' ) {
102
                    $noerror = 0;
104
                    $noerror = 0;
103
                    last;
105
                    last;
104
                }
106
                }
105
            } elsif ($confirmation eq 'PREVISSUE') {
107
            } elsif ( $confirmation eq 'PREVISSUE' ) {
106
                $self->screen_msg("This item was previously checked out by you");
108
                $self->screen_msg("This item was previously checked out by you");
107
                $noerror = 0 if ($prevcheckout_block_checkout);
109
                $noerror = 0 if ($prevcheckout_block_checkout);
108
                last;
110
                last;
109
            } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
111
            } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
110
                if ( $allow_additional_materials_checkout ) {
112
                if ($allow_additional_materials_checkout) {
111
                    my $item = Koha::Items->find({ barcode => $barcode });
113
                    my $item = Koha::Items->find( { barcode => $barcode } );
112
                    $self->screen_msg( 'Item has additional materials: ' . $item->materials );
114
                    $self->screen_msg( 'Item has additional materials: ' . $item->materials );
113
                } else {
115
                } else {
114
                    $self->screen_msg('Item must be checked out at a circulation desk');
116
                    $self->screen_msg('Item must be checked out at a circulation desk');
Lines 116-125 sub do_checkout { Link Here
116
                    last;
118
                    last;
117
                }
119
                }
118
            } else {
120
            } else {
121
119
                # We've been returned a case other than those above
122
                # We've been returned a case other than those above
120
                $self->screen_msg("Item cannot be issued: $confirmation");
123
                $self->screen_msg("Item cannot be issued: $confirmation");
121
                $noerror = 0;
124
                $noerror = 0;
122
                siplog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
125
                siplog( 'LOG_DEBUG', "Blocking checkout Reason:$confirmation" );
123
                last;
126
                last;
124
            }
127
            }
125
        }
128
        }
(-)a/t/db_dependent/SIP/Message.t (-42 / +66 lines)
Lines 583-646 subtest 'test_allow_additional_materials_checkout' => sub { Link Here
583
583
584
    plan tests => 4;
584
    plan tests => 4;
585
585
586
    my $builder = t::lib::TestBuilder->new();
586
    my $builder     = t::lib::TestBuilder->new();
587
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
587
    my $branchcode  = $builder->build( { source => 'Branch' } )->{branchcode};
588
    my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
588
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
589
    my ( $response, $findpatron );
589
    my ( $response, $findpatron );
590
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
590
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
591
591
592
    # create some data
592
    # create some data
593
    my $patron1 = $builder->build({
593
    my $patron1 = $builder->build(
594
        source => 'Borrower',
594
        {
595
        value  => {
595
            source => 'Borrower',
596
            password => hash_password( PATRON_PW ),
596
            value  => {
597
        },
597
                password => hash_password(PATRON_PW),
598
    });
598
            },
599
    my $card1 = $patron1->{cardnumber};
599
        }
600
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
600
    );
601
    my $card1       = $patron1->{cardnumber};
602
    my $sip_patron1 = C4::SIP::ILS::Patron->new($card1);
601
    $findpatron = $sip_patron1;
603
    $findpatron = $sip_patron1;
602
    my $item_object = $builder->build_sample_item({
604
    my $item_object = $builder->build_sample_item(
603
        damaged => 0,
605
        {
604
        withdrawn => 0,
606
            damaged       => 0,
605
        itemlost => 0,
607
            withdrawn     => 0,
606
        restricted => 0,
608
            itemlost      => 0,
607
        homebranch => $branchcode,
609
            restricted    => 0,
608
        holdingbranch => $branchcode,
610
            homebranch    => $branchcode,
609
        materials => "This is a materials note",
611
            holdingbranch => $branchcode,
610
    });
612
            materials     => "This is a materials note",
613
        }
614
    );
611
615
612
    my $mockILS = $mocks->{ils};
616
    my $mockILS = $mocks->{ils};
613
    my $server = { ils => $mockILS, account => {} };
617
    my $server  = { ils => $mockILS, account => {} };
614
    $mockILS->mock( 'institution', sub { $branchcode; } );
618
    $mockILS->mock( 'institution', sub { $branchcode; } );
615
    $mockILS->mock( 'supports', sub { return; } );
619
    $mockILS->mock( 'supports',    sub { return; } );
616
    $mockILS->mock( 'checkout', sub {
620
    $mockILS->mock(
617
        shift;
621
        'checkout',
618
        return C4::SIP::ILS->checkout(@_);
622
        sub {
619
    });
623
            shift;
624
            return C4::SIP::ILS->checkout(@_);
625
        }
626
    );
620
    my $today = dt_from_string;
627
    my $today = dt_from_string;
621
    t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 });
628
    t::lib::Mocks::mock_userenv( { branchcode => $branchcode, flags => 1 } );
622
    t::lib::Mocks::mock_preference( 'CircConfirmItemParts',  '1' );
629
    t::lib::Mocks::mock_preference( 'CircConfirmItemParts', '1' );
623
630
624
    my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) .
631
    my $siprequest =
625
    siprequestdate( $today->clone->add( days => 1) ) .
632
          CHECKOUT . 'YN'
626
    FID_INST_ID . $branchcode . '|'.
633
        . siprequestdate($today)
627
    FID_PATRON_ID . $sip_patron1->id . '|' .
634
        . siprequestdate( $today->clone->add( days => 1 ) )
628
    FID_ITEM_ID . $item_object->barcode . '|' .
635
        . FID_INST_ID
629
    FID_TERMINAL_PWD . 'ignored' . '|';
636
        . $branchcode . '|'
637
        . FID_PATRON_ID
638
        . $sip_patron1->id . '|'
639
        . FID_ITEM_ID
640
        . $item_object->barcode . '|'
641
        . FID_TERMINAL_PWD
642
        . 'ignored' . '|';
630
    undef $response;
643
    undef $response;
631
644
632
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
645
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
633
    $server->{account}->{allow_additional_materials_checkout} = 0;
646
    $server->{account}->{allow_additional_materials_checkout} = 0;
634
    $msg->handle_checkout( $server );
647
    $msg->handle_checkout($server);
635
    my $respcode = substr( $response, 0, 2 );
648
    my $respcode = substr( $response, 0, 2 );
636
    check_field( $respcode, $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk', 'Check screen msg', 'equals' );
649
    check_field(
637
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (allow_additional_materials_checkout disabled)");
650
        $respcode,          $response, FID_SCREEN_MSG, 'Item must be checked out at a circulation desk',
651
        'Check screen msg', 'equals'
652
    );
653
    is(
654
        Koha::Checkouts->search( { itemnumber => $item_object->id } )->count, 0,
655
        "Item was not checked out (allow_additional_materials_checkout disabled)"
656
    );
638
657
639
    $server->{account}->{allow_additional_materials_checkout} = 1;
658
    $server->{account}->{allow_additional_materials_checkout} = 1;
640
    $msg->handle_checkout( $server );
659
    $msg->handle_checkout($server);
641
    $respcode = substr( $response, 0, 2 );
660
    $respcode = substr( $response, 0, 2 );
642
    check_field( $respcode, $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note', 'Check screen msg', 'equals' );
661
    check_field(
643
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (allow_additional_materials_checkout enabled");
662
        $respcode,          $response, FID_SCREEN_MSG, 'Item has additional materials: This is a materials note',
663
        'Check screen msg', 'equals'
664
    );
665
    is(
666
        Koha::Checkouts->search( { itemnumber => $item_object->id } )->count, 1,
667
        "Item was checked out (allow_additional_materials_checkout enabled"
668
    );
644
};
669
};
645
670
646
# Here is room for some more subtests
671
# Here is room for some more subtests
647
- 

Return to bug 34153