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

(-)a/C4/SIP/ILS.pm (-2 / +2 lines)
Lines 126-132 sub offline_ok { Link Here
126
# the response.
126
# the response.
127
#
127
#
128
sub checkout {
128
sub checkout {
129
    my ( $self, $patron_id, $item_id, $sc_renew, $fee_ack ) = @_;
129
    my ( $self, $patron_id, $item_id, $sc_renew, $fee_ack, $account ) = @_;
130
    my ( $patron, $item, $circ );
130
    my ( $patron, $item, $circ );
131
131
132
    $circ = C4::SIP::ILS::Transaction::Checkout->new();
132
    $circ = C4::SIP::ILS::Transaction::Checkout->new();
Lines 153-159 sub checkout { Link Here
153
        $circ->screen_msg("Item checked out to another patron");
153
        $circ->screen_msg("Item checked out to another patron");
154
    }
154
    }
155
    else {
155
    else {
156
        $circ->do_checkout();
156
        $circ->do_checkout($account);
157
        if ( $circ->ok ) {
157
        if ( $circ->ok ) {
158
            $debug and warn "circ is ok";
158
            $debug and warn "circ is ok";
159
159
(-)a/C4/SIP/ILS/Transaction/Checkout.pm (+3 lines)
Lines 47-57 sub new { Link Here
47
47
48
sub do_checkout {
48
sub do_checkout {
49
	my $self = shift;
49
	my $self = shift;
50
    my $account = shift;
50
	siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
51
	siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
51
    my $shelf          = $self->{item}->hold_attached;
52
    my $shelf          = $self->{item}->hold_attached;
52
	my $barcode        = $self->{item}->id;
53
	my $barcode        = $self->{item}->id;
53
    my $patron         = Koha::Patrons->find($self->{patron}->{borrowernumber});
54
    my $patron         = Koha::Patrons->find($self->{patron}->{borrowernumber});
54
    my $overridden_duedate; # usually passed as undef to AddIssue
55
    my $overridden_duedate; # usually passed as undef to AddIssue
56
    my $prevcheckout_block_checkout  = $account->{prevcheckout_block_checkout};
55
    $debug and warn "do_checkout borrower: . " . $patron->borrowernumber;
57
    $debug and warn "do_checkout borrower: . " . $patron->borrowernumber;
56
    my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode,
58
    my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode,
57
        C4::Context->preference("AllowItemsOnHoldCheckoutSIP")
59
        C4::Context->preference("AllowItemsOnHoldCheckoutSIP")
Lines 95-100 sub do_checkout { Link Here
95
                }
97
                }
96
            } elsif ($confirmation eq 'PREVISSUE') {
98
            } elsif ($confirmation eq 'PREVISSUE') {
97
                $self->screen_msg("This item was previously checked out by you");
99
                $self->screen_msg("This item was previously checked out by you");
100
                $noerror = 0 if ($prevcheckout_block_checkout);
98
                last;
101
                last;
99
            } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
102
            } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
100
                $self->screen_msg('Item must be checked out at a circulation desk');
103
                $self->screen_msg('Item must be checked out at a circulation desk');
(-)a/C4/SIP/Sip/MsgType.pm (-1 / +1 lines)
Lines 533-539 sub handle_checkout { Link Here
533
533
534
        # Does the transaction date really matter for items that are
534
        # Does the transaction date really matter for items that are
535
        # checkout out while the terminal is online?  I'm guessing 'no'
535
        # checkout out while the terminal is online?  I'm guessing 'no'
536
        $status = $ils->checkout( $patron_id, $item_id, $sc_renewal_policy, $fee_ack );
536
        $status = $ils->checkout( $patron_id, $item_id, $sc_renewal_policy, $fee_ack, $account );
537
    }
537
    }
538
538
539
    $item   = $status->item;
539
    $item   = $status->item;
(-)a/etc/SIPconfig.xml (+1 lines)
Lines 62-67 Link Here
62
             hide_fields="BD,BE,BF,PB"
62
             hide_fields="BD,BE,BF,PB"
63
             register_id=''
63
             register_id=''
64
             holds_block_checkin="0"
64
             holds_block_checkin="0"
65
             prevcheckout_block_checkout="0"
65
             overdues_block_checkout="1">
66
             overdues_block_checkout="1">
66
          <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />
67
          <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />
67
          <screen_msg_regex find="Invalid patron barcode." replace="Barcode not found, are you sure this is your library card?" />
68
          <screen_msg_regex find="Invalid patron barcode." replace="Barcode not found, are you sure this is your library card?" />
(-)a/t/db_dependent/SIP/Message.t (-2 / +75 lines)
Lines 21-27 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
use Test::More tests => 9;
24
use Test::More tests => 10;
25
use Test::MockObject;
25
use Test::MockObject;
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::Warn;
27
use Test::Warn;
Lines 30-35 use t::lib::Mocks; Link Here
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use C4::Reserves qw(AddReserve);
32
use C4::Reserves qw(AddReserve);
33
use C4::Circulation qw( AddReturn );
33
use Koha::Database;
34
use Koha::Database;
34
use Koha::AuthUtils qw(hash_password);
35
use Koha::AuthUtils qw(hash_password);
35
use Koha::DateUtils;
36
use Koha::DateUtils;
Lines 66-71 subtest 'Testing Patron Info Request V2' => sub { Link Here
66
    $schema->storage->txn_rollback;
67
    $schema->storage->txn_rollback;
67
};
68
};
68
69
70
subtest 'Checkout V2' => sub {
71
    my $schema = Koha::Database->new->schema;
72
    $schema->storage->txn_begin;
73
    plan tests => 3;
74
    $C4::SIP::Sip::protocol_version = 2;
75
    test_checkout_v2();
76
    $schema->storage->txn_rollback;
77
};
78
69
subtest 'Checkin V2' => sub {
79
subtest 'Checkin V2' => sub {
70
    my $schema = Koha::Database->new->schema;
80
    my $schema = Koha::Database->new->schema;
71
    $schema->storage->txn_begin;
81
    $schema->storage->txn_begin;
Lines 504-509 sub test_request_patron_info_v2 { Link Here
504
    check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' );
514
    check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' );
505
}
515
}
506
516
517
sub test_checkout_v2 {
518
    my $builder = t::lib::TestBuilder->new();
519
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
520
    my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
521
    my ( $response, $findpatron );
522
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
523
524
    # create some data
525
    my $patron1 = $builder->build({
526
        source => 'Borrower',
527
        value  => {
528
            password => hash_password( PATRON_PW ),
529
        },
530
    });
531
    my $card1 = $patron1->{cardnumber};
532
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
533
    $findpatron = $sip_patron1;
534
    my $item_object = $builder->build_sample_item({
535
        damaged => 0,
536
        withdrawn => 0,
537
        itemlost => 0,
538
        restricted => 0,
539
        homebranch => $branchcode,
540
        holdingbranch => $branchcode,
541
    });
542
543
    my $mockILS = $mocks->{ils};
544
    my $server = { ils => $mockILS, account => {} };
545
    $mockILS->mock( 'institution', sub { $branchcode; } );
546
    $mockILS->mock( 'supports', sub { return; } );
547
    $mockILS->mock( 'checkout', sub {
548
        shift;
549
        return C4::SIP::ILS->checkout(@_);
550
    });
551
    my $today = dt_from_string;
552
    t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 });
553
    t::lib::Mocks::mock_preference( 'CheckPrevCheckout',  'hardyes' );
554
555
    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store;
556
    my $return = AddReturn($item_object->barcode, $branchcode);
557
558
    my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) .
559
    siprequestdate( $today->clone->add( days => 1) ) .
560
    FID_INST_ID . $branchcode . '|'.
561
    FID_PATRON_ID . $sip_patron1->id . '|' .
562
    FID_ITEM_ID . $item_object->barcode . '|' .
563
    FID_TERMINAL_PWD . 'ignored' . '|';
564
    undef $response;
565
566
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
567
    $server->{account}->{prevcheckout_block_checkout} = 1;
568
    $msg->handle_checkout( $server );
569
    my $respcode = substr( $response, 0, 2 );
570
    check_field( $respcode, $response, FID_SCREEN_MSG, 'This item was previously checked out by you', 'Check screen msg', 'equals' );
571
572
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (prevcheckout_block_checkout enabled)");
573
574
    $server->{account}->{prevcheckout_block_checkout} = 0;
575
    $msg->handle_checkout( $server );
576
    $respcode = substr( $response, 0, 2 );
577
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (prevcheckout_block_checkout disabled)");
578
}
579
507
sub test_checkin_v2 {
580
sub test_checkin_v2 {
508
    my $builder = t::lib::TestBuilder->new();
581
    my $builder = t::lib::TestBuilder->new();
509
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
582
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
Lines 774-778 sub fixed_length { #length of fixed fields including response code Link Here
774
      ( PATRON_STATUS_RESP )  => 37,
847
      ( PATRON_STATUS_RESP )  => 37,
775
      ( PATRON_INFO_RESP )    => 61,
848
      ( PATRON_INFO_RESP )    => 61,
776
      ( CHECKIN_RESP )        => 24,
849
      ( CHECKIN_RESP )        => 24,
850
      ( CHECKOUT_RESP )       => 24,
777
    }->{$_[0]};
851
    }->{$_[0]};
778
}
852
}
779
- 

Return to bug 26591