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 61-66 Link Here
61
             av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"
61
             av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"
62
             hide_fields="BD,BE,BF,PB"
62
             hide_fields="BD,BE,BF,PB"
63
             register_id=''
63
             register_id=''
64
             prevcheckout_block_checkout="0"
64
             holds_block_checkin="0">
65
             holds_block_checkin="0">
65
          <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />
66
          <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />
66
          <screen_msg_regex find="Invalid patron barcode." replace="Barcode not found, are you sure this is your library card?" />
67
          <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 486-491 sub test_request_patron_info_v2 { Link Here
486
    check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' );
496
    check_field( $respcode, $response, FID_SCREEN_MSG, '.+', 'But we have a screen msg', 'regex' );
487
}
497
}
488
498
499
sub test_checkout_v2 {
500
    my $builder = t::lib::TestBuilder->new();
501
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
502
    my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
503
    my ( $response, $findpatron );
504
    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
505
506
    # create some data
507
    my $patron1 = $builder->build({
508
        source => 'Borrower',
509
        value  => {
510
            password => hash_password( PATRON_PW ),
511
        },
512
    });
513
    my $card1 = $patron1->{cardnumber};
514
    my $sip_patron1 = C4::SIP::ILS::Patron->new( $card1 );
515
    $findpatron = $sip_patron1;
516
    my $item_object = $builder->build_sample_item({
517
        damaged => 0,
518
        withdrawn => 0,
519
        itemlost => 0,
520
        restricted => 0,
521
        homebranch => $branchcode,
522
        holdingbranch => $branchcode,
523
    });
524
525
    my $mockILS = $mocks->{ils};
526
    my $server = { ils => $mockILS, account => {} };
527
    $mockILS->mock( 'institution', sub { $branchcode; } );
528
    $mockILS->mock( 'supports', sub { return; } );
529
    $mockILS->mock( 'checkout', sub {
530
        shift;
531
        return C4::SIP::ILS->checkout(@_);
532
    });
533
    my $today = dt_from_string;
534
    t::lib::Mocks::mock_userenv({ branchcode => $branchcode, flags => 1 });
535
    t::lib::Mocks::mock_preference( 'CheckPrevCheckout',  'hardyes' );
536
537
    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber })->store;
538
    my $return = AddReturn($item_object->barcode, $branchcode);
539
540
    my $siprequest = CHECKOUT . 'YN' . siprequestdate($today) .
541
    siprequestdate( $today->clone->add( days => 1) ) .
542
    FID_INST_ID . $branchcode . '|'.
543
    FID_PATRON_ID . $sip_patron1->id . '|' .
544
    FID_ITEM_ID . $item_object->barcode . '|' .
545
    FID_TERMINAL_PWD . 'ignored' . '|';
546
    undef $response;
547
548
    my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
549
    $server->{account}->{prevcheckout_block_checkout} = 1;
550
    $msg->handle_checkout( $server );
551
    my $respcode = substr( $response, 0, 2 );
552
    check_field( $respcode, $response, FID_SCREEN_MSG, 'This item was previously checked out by you', 'Check screen msg', 'equals' );
553
554
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was not checked out (prevcheckout_block_checkout enabled)");
555
556
    $server->{account}->{prevcheckout_block_checkout} = 0;
557
    $msg->handle_checkout( $server );
558
    $respcode = substr( $response, 0, 2 );
559
    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was checked out (prevcheckout_block_checkout disabled)");
560
}
561
489
sub test_checkin_v2 {
562
sub test_checkin_v2 {
490
    my $builder = t::lib::TestBuilder->new();
563
    my $builder = t::lib::TestBuilder->new();
491
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
564
    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
Lines 756-760 sub fixed_length { #length of fixed fields including response code Link Here
756
      ( PATRON_STATUS_RESP )  => 37,
829
      ( PATRON_STATUS_RESP )  => 37,
757
      ( PATRON_INFO_RESP )    => 61,
830
      ( PATRON_INFO_RESP )    => 61,
758
      ( CHECKIN_RESP )        => 24,
831
      ( CHECKIN_RESP )        => 24,
832
      ( CHECKOUT_RESP )       => 24,
759
    }->{$_[0]};
833
    }->{$_[0]};
760
}
834
}
761
- 

Return to bug 26591