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

(-)a/C4/Circulation.pm (-26 / +26 lines)
Lines 565-571 sub TooMany { Link Here
565
565
566
=head2 CanBookBeIssued
566
=head2 CanBookBeIssued
567
567
568
  ( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $borrower, 
568
  ( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $patron, 
569
                      $barcode, $duedate, $inprocess, $ignore_reserves, $params );
569
                      $barcode, $duedate, $inprocess, $ignore_reserves, $params );
570
570
571
Check if a book can be issued.
571
Check if a book can be issued.
Lines 574-580 C<$issuingimpossible> and C<$needsconfirmation> are some hashref. Link Here
574
574
575
=over 4
575
=over 4
576
576
577
=item C<$borrower> hash with borrower informations (from Koha::Patron->unblessed)
577
=item C<$patron> is a Koha::Patron
578
578
579
=item C<$barcode> is the bar code of the book being issued.
579
=item C<$barcode> is the bar code of the book being issued.
580
580
Lines 665-671 if the borrower borrows to much things Link Here
665
=cut
665
=cut
666
666
667
sub CanBookBeIssued {
667
sub CanBookBeIssued {
668
    my ( $borrower, $barcode, $duedate, $inprocess, $ignore_reserves, $params ) = @_;
668
    my ( $patron, $barcode, $duedate, $inprocess, $ignore_reserves, $params ) = @_;
669
    my %needsconfirmation;    # filled with problems that needs confirmations
669
    my %needsconfirmation;    # filled with problems that needs confirmations
670
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
670
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
671
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
671
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
Lines 679-684 sub CanBookBeIssued { Link Here
679
	my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
679
	my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
680
	$item->{'itemtype'}=$item->{'itype'}; 
680
	$item->{'itemtype'}=$item->{'itype'}; 
681
    my $dbh             = C4::Context->dbh;
681
    my $dbh             = C4::Context->dbh;
682
    my $patron_unblessed = $patron->unblessed;
682
683
683
    # MANDATORY CHECKS - unless item exists, nothing else matters
684
    # MANDATORY CHECKS - unless item exists, nothing else matters
684
    unless ( $item->{barcode} ) {
685
    unless ( $item->{barcode} ) {
Lines 696-704 sub CanBookBeIssued { Link Here
696
    unless ( $duedate ) {
697
    unless ( $duedate ) {
697
        my $issuedate = $now->clone();
698
        my $issuedate = $now->clone();
698
699
699
        my $branch = _GetCircControlBranch($item,$borrower);
700
        my $branch = _GetCircControlBranch($item, $patron_unblessed);
700
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'};
701
        my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'};
701
        $duedate = CalcDateDue( $issuedate, $itype, $branch, $borrower );
702
        $duedate = CalcDateDue( $issuedate, $itype, $branch, $patron_unblessed );
702
703
703
        # Offline circ calls AddIssue directly, doesn't run through here
704
        # Offline circ calls AddIssue directly, doesn't run through here
704
        #  So issuingimpossible should be ok.
705
        #  So issuingimpossible should be ok.
Lines 716-722 sub CanBookBeIssued { Link Here
716
    #
717
    #
717
    # BORROWER STATUS
718
    # BORROWER STATUS
718
    #
719
    #
719
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
720
    if ( $patron->category->category_type eq 'X' && (  $item->{barcode}  )) { 
720
    if ( $patron->category->category_type eq 'X' && (  $item->{barcode}  )) { 
721
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
721
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
722
        &UpdateStats({
722
        &UpdateStats({
Lines 724-737 sub CanBookBeIssued { Link Here
724
                     type => 'localuse',
724
                     type => 'localuse',
725
                     itemnumber => $item->{'itemnumber'},
725
                     itemnumber => $item->{'itemnumber'},
726
                     itemtype => $item->{'itype'},
726
                     itemtype => $item->{'itype'},
727
                     borrowernumber => $borrower->{'borrowernumber'},
727
                     borrowernumber => $patron->borrowernumber,
728
                     ccode => $item->{'ccode'}}
728
                     ccode => $item->{'ccode'}}
729
                    );
729
                    );
730
        ModDateLastSeen( $item->{'itemnumber'} );
730
        ModDateLastSeen( $item->{'itemnumber'} );
731
        return( { STATS => 1 }, {});
731
        return( { STATS => 1 }, {});
732
    }
732
    }
733
733
734
    my $flags = C4::Members::patronflags( $borrower );
734
    my $flags = C4::Members::patronflags( $patron_unblessed );
735
    if ( ref $flags ) {
735
    if ( ref $flags ) {
736
        if ( $flags->{GNA} ) {
736
        if ( $flags->{GNA} ) {
737
            $issuingimpossible{GNA} = 1;
737
            $issuingimpossible{GNA} = 1;
Lines 743-752 sub CanBookBeIssued { Link Here
743
            $issuingimpossible{DEBARRED} = 1;
743
            $issuingimpossible{DEBARRED} = 1;
744
        }
744
        }
745
    }
745
    }
746
    if ( !defined $borrower->{dateexpiry} || $borrower->{'dateexpiry'} eq '0000-00-00') {
746
    if ( !defined $patron->dateexpiry || $patron->dateexpiry eq '0000-00-00') {
747
        $issuingimpossible{EXPIRED} = 1;
747
        $issuingimpossible{EXPIRED} = 1;
748
    } else {
748
    } else {
749
        my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'sql', 'floating' );
749
        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'sql', 'floating' );
750
        $expiry_dt->truncate( to => 'day');
750
        $expiry_dt->truncate( to => 'day');
751
        my $today = $now->clone()->truncate(to => 'day');
751
        my $today = $now->clone()->truncate(to => 'day');
752
        $today->set_time_zone( 'floating' );
752
        $today->set_time_zone( 'floating' );
Lines 761-767 sub CanBookBeIssued { Link Here
761
761
762
    # DEBTS
762
    # DEBTS
763
    my ($balance, $non_issue_charges, $other_charges) =
763
    my ($balance, $non_issue_charges, $other_charges) =
764
      C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
764
      C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
765
765
766
    my $amountlimit = C4::Context->preference("noissuescharge");
766
    my $amountlimit = C4::Context->preference("noissuescharge");
767
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
767
    my $allowfineoverride = C4::Context->preference("AllowFineOverride");
Lines 771-778 sub CanBookBeIssued { Link Here
771
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
771
    my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
772
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
772
    $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
773
    if ( defined $no_issues_charge_guarantees ) {
773
    if ( defined $no_issues_charge_guarantees ) {
774
        my $p = Koha::Patrons->find( $borrower->{borrowernumber} );
774
        my @guarantees = $patron->guarantees();
775
        my @guarantees = $p->guarantees();
776
        my $guarantees_non_issues_charges;
775
        my $guarantees_non_issues_charges;
777
        foreach my $g ( @guarantees ) {
776
        foreach my $g ( @guarantees ) {
778
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
777
            my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
Lines 811-817 sub CanBookBeIssued { Link Here
811
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
810
        $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
812
    }
811
    }
813
812
814
    $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
813
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
815
    if ( my $debarred_date = $patron->is_debarred ) {
814
    if ( my $debarred_date = $patron->is_debarred ) {
816
         # patron has accrued fine days or has a restriction. $count is a date
815
         # patron has accrued fine days or has a restriction. $count is a date
817
        if ($debarred_date eq '9999-12-31') {
816
        if ($debarred_date eq '9999-12-31') {
Lines 836-843 sub CanBookBeIssued { Link Here
836
          C4::Context->preference('SwitchOnSiteCheckouts')
835
          C4::Context->preference('SwitchOnSiteCheckouts')
837
      and $issue
836
      and $issue
838
      and $issue->onsite_checkout
837
      and $issue->onsite_checkout
839
      and $issue->borrowernumber == $borrower->{'borrowernumber'} ? 1 : 0 );
838
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
840
    my $toomany = TooMany( $borrower, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
839
    my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
841
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
840
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
842
    if ( $toomany ) {
841
    if ( $toomany ) {
843
        if ( $toomany->{max_allowed} == 0 ) {
842
        if ( $toomany->{max_allowed} == 0 ) {
Lines 857-863 sub CanBookBeIssued { Link Here
857
    #
856
    #
858
    # CHECKPREVCHECKOUT: CHECK IF ITEM HAS EVER BEEN LENT TO PATRON
857
    # CHECKPREVCHECKOUT: CHECK IF ITEM HAS EVER BEEN LENT TO PATRON
859
    #
858
    #
860
    $patron = Koha::Patrons->find($borrower->{borrowernumber});
859
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
861
    my $wants_check = $patron->wants_check_for_previous_checkout;
860
    my $wants_check = $patron->wants_check_for_previous_checkout;
862
    $needsconfirmation{PREVISSUE} = 1
861
    $needsconfirmation{PREVISSUE} = 1
863
        if ($wants_check and $patron->do_check_for_previous_checkout($item));
862
        if ($wants_check and $patron->do_check_for_previous_checkout($item));
Lines 924-931 sub CanBookBeIssued { Link Here
924
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
923
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
925
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
924
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
926
            }
925
            }
927
            $needsconfirmation{BORRNOTSAMEBRANCH} = $borrower->{'branchcode'}
926
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
928
              if ( $borrower->{'branchcode'} ne $userenv->{branch} );
927
              if ( $patron->branchcode ne $userenv->{branch} );
929
        }
928
        }
930
    }
929
    }
931
    #
930
    #
Lines 934-940 sub CanBookBeIssued { Link Here
934
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
933
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
935
934
936
    if ( $rentalConfirmation ){
935
    if ( $rentalConfirmation ){
937
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
936
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
938
        if ( $rentalCharge > 0 ){
937
        if ( $rentalCharge > 0 ){
939
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
938
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
940
        }
939
        }
Lines 943-949 sub CanBookBeIssued { Link Here
943
    #
942
    #
944
    # CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
943
    # CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
945
    #
944
    #
946
    if ( $issue && $issue->borrowernumber eq $borrower->{'borrowernumber'} ){
945
    if ( $issue && $issue->borrowernumber eq $patron->borrowernumber ){
947
946
948
        # Already issued to current borrower.
947
        # Already issued to current borrower.
949
        # If it is an on-site checkout if it can be switched to a normal checkout
948
        # If it is an on-site checkout if it can be switched to a normal checkout
Lines 954-960 sub CanBookBeIssued { Link Here
954
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
953
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
955
        } else {
954
        } else {
956
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
955
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
957
                $borrower->{'borrowernumber'},
956
                $patron->borrowernumber,
958
                $item->{'itemnumber'},
957
                $item->{'itemnumber'},
959
            );
958
            );
960
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
959
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
Lines 995-1001 sub CanBookBeIssued { Link Here
995
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
994
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
996
        if ($restype) {
995
        if ($restype) {
997
            my $resbor = $res->{'borrowernumber'};
996
            my $resbor = $res->{'borrowernumber'};
998
            if ( $resbor ne $borrower->{'borrowernumber'} ) {
997
            if ( $resbor ne $patron->borrowernumber ) {
999
                my $patron = Koha::Patrons->find( $resbor );
998
                my $patron = Koha::Patrons->find( $resbor );
1000
                if ( $restype eq "Waiting" )
999
                if ( $restype eq "Waiting" )
1001
                {
1000
                {
Lines 1025-1031 sub CanBookBeIssued { Link Here
1025
1024
1026
    ## CHECK AGE RESTRICTION
1025
    ## CHECK AGE RESTRICTION
1027
    my $agerestriction  = $biblioitem->{'agerestriction'};
1026
    my $agerestriction  = $biblioitem->{'agerestriction'};
1028
    my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $borrower );
1027
    my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $patron->unblessed );
1029
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1028
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1030
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1029
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1031
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
1030
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
Lines 1037-1043 sub CanBookBeIssued { Link Here
1037
1036
1038
    ## check for high holds decreasing loan period
1037
    ## check for high holds decreasing loan period
1039
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1038
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1040
        my $check = checkHighHolds( $item, $borrower );
1039
        my $check = checkHighHolds( $item, $patron_unblessed );
1041
1040
1042
        if ( $check->{exceeded} ) {
1041
        if ( $check->{exceeded} ) {
1043
            if ($override_high_holds) {
1042
            if ($override_high_holds) {
Lines 1070-1078 sub CanBookBeIssued { Link Here
1070
        require C4::Serials;
1069
        require C4::Serials;
1071
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1070
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1072
        unless ($is_a_subscription) {
1071
        unless ($is_a_subscription) {
1072
            # FIXME Should be $patron->checkouts($args);
1073
            my $checkouts = Koha::Checkouts->search(
1073
            my $checkouts = Koha::Checkouts->search(
1074
                {
1074
                {
1075
                    borrowernumber => $borrower->{borrowernumber},
1075
                    borrowernumber => $patron->borrowernumber,
1076
                    biblionumber   => $biblionumber,
1076
                    biblionumber   => $biblionumber,
1077
                },
1077
                },
1078
                {
1078
                {
(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 550-556 sub GetServices { Link Here
550
    my $barcode = $item->{'barcode'} || '';
550
    my $barcode = $item->{'barcode'} || '';
551
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
551
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
552
    if ($barcode) {
552
    if ($barcode) {
553
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode );
553
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
554
554
555
        # TODO push @availablefor, 'loan';
555
        # TODO push @availablefor, 'loan';
556
    }
556
    }
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 315-321 if (@$barcodes) { Link Here
315
    my $template_params = { barcode => $barcode };
315
    my $template_params = { barcode => $barcode };
316
    # always check for blockers on issuing
316
    # always check for blockers on issuing
317
    my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
317
    my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
318
        $patron->unblessed,
318
        $patron,
319
        $barcode, $datedue,
319
        $barcode, $datedue,
320
        $inprocess,
320
        $inprocess,
321
        undef,
321
        undef,
(-)a/opac/sco/sco-main.pl (-5 / +5 lines)
Lines 108-117 if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { Link Here
108
    ($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw);
108
    ($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw);
109
}
109
}
110
110
111
my $borrower;
111
my ( $borrower, $patron );
112
if ( $patronid ) {
112
if ( $patronid ) {
113
    $borrower = Koha::Patrons->find( { cardnumber => $patronid } );
113
    $patron = Koha::Patrons->find( { cardnumber => $patronid } );
114
    $borrower = $borrower->unblessed if $borrower;
114
    $borrower = $patron->unblessed if $patron;
115
}
115
}
116
116
117
my $currencySymbol = "";
117
my $currencySymbol = "";
Lines 130-140 if ($op eq "logout") { Link Here
130
elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
130
elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
131
    my ($doreturn) = AddReturn( $barcode, $branch );
131
    my ($doreturn) = AddReturn( $barcode, $branch );
132
}
132
}
133
elsif ( $borrower and $op eq "checkout" ) {
133
elsif ( $patron and $op eq "checkout" ) {
134
    my $impossible  = {};
134
    my $impossible  = {};
135
    my $needconfirm = {};
135
    my $needconfirm = {};
136
    ( $impossible, $needconfirm ) = CanBookBeIssued(
136
    ( $impossible, $needconfirm ) = CanBookBeIssued(
137
        $borrower,
137
        $patron,
138
        $barcode,
138
        $barcode,
139
        undef,
139
        undef,
140
        0,
140
        0,
(-)a/t/db_dependent/Circulation.t (-10 / +10 lines)
Lines 1135-1142 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1135
    my $homebranch    = $builder->build( { source => 'Branch' } );
1135
    my $homebranch    = $builder->build( { source => 'Branch' } );
1136
    my $holdingbranch = $builder->build( { source => 'Branch' } );
1136
    my $holdingbranch = $builder->build( { source => 'Branch' } );
1137
    my $otherbranch   = $builder->build( { source => 'Branch' } );
1137
    my $otherbranch   = $builder->build( { source => 'Branch' } );
1138
    my $patron_1      = $builder->build( { source => 'Borrower' } );
1138
    my $patron_1      = $builder->build_object( { class => 'Koha::Patrons' } );
1139
    my $patron_2      = $builder->build( { source => 'Borrower' } );
1139
    my $patron_2      = $builder->build_object( { class => 'Koha::Patrons' } );
1140
1140
1141
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1141
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1142
    my $item = $builder->build(
1142
    my $item = $builder->build(
Lines 1155-1161 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1155
1155
1156
    set_userenv($holdingbranch);
1156
    set_userenv($holdingbranch);
1157
1157
1158
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1158
    my $issue = AddIssue( $patron_1->unblessed, $item->{barcode} );
1159
    is( ref($issue), 'Koha::Schema::Result::Issue' );    # FIXME Should be Koha::Checkout
1159
    is( ref($issue), 'Koha::Schema::Result::Issue' );    # FIXME Should be Koha::Checkout
1160
1160
1161
    my ( $error, $question, $alerts );
1161
    my ( $error, $question, $alerts );
Lines 1300-1306 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
1300
    plan tests => 8;
1300
    plan tests => 8;
1301
1301
1302
    my $library = $builder->build( { source => 'Branch' } );
1302
    my $library = $builder->build( { source => 'Branch' } );
1303
    my $patron  = $builder->build( { source => 'Borrower', value => { gonenoaddress => undef, lost => undef, debarred => undef, borrowernotes => "" } } );
1303
    my $patron  = $builder->build_object( { class => 'Koha::Patrons', value => { gonenoaddress => undef, lost => undef, debarred => undef, borrowernotes => "" } } );
1304
1304
1305
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1305
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
1306
    my $item_1 = $builder->build(
1306
    my $item_1 = $builder->build(
Lines 1335-1341 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
1335
1335
1336
    # Patron cannot issue item_1, they have overdues
1336
    # Patron cannot issue item_1, they have overdues
1337
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1337
    my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 );
1338
    my $issue = AddIssue( $patron, $item_1->{barcode}, $yesterday );    # Add an overdue
1338
    my $issue = AddIssue( $patron->unblessed, $item_1->{barcode}, $yesterday );    # Add an overdue
1339
1339
1340
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
1340
    t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'confirmation' );
1341
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1341
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
Lines 1349-1360 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
1349
1349
1350
    # Patron cannot issue item_1, they are debarred
1350
    # Patron cannot issue item_1, they are debarred
1351
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
1351
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
1352
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->{borrowernumber}, expiration => $tomorrow } );
1352
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber, expiration => $tomorrow } );
1353
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1353
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1354
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1354
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1355
    is( $error->{USERBLOCKEDWITHENDDATE}, output_pref( { dt => $tomorrow, dateformat => 'sql', dateonly => 1 } ), 'USERBLOCKEDWITHENDDATE should be tomorrow' );
1355
    is( $error->{USERBLOCKEDWITHENDDATE}, output_pref( { dt => $tomorrow, dateformat => 'sql', dateonly => 1 } ), 'USERBLOCKEDWITHENDDATE should be tomorrow' );
1356
1356
1357
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->{borrowernumber} } );
1357
    Koha::Patron::Debarments::AddDebarment( { borrowernumber => $patron->borrowernumber } );
1358
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1358
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1359
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1359
    is( keys(%$question) + keys(%$alerts),  0, 'No key for question and alert ' . keys(%$question) . ' ' . keys(%$alerts) );
1360
    is( $error->{USERBLOCKEDNOENDDATE},    '9999-12-31', 'USERBLOCKEDNOENDDATE should be 9999-12-31 for unlimited debarments' );
1360
    is( $error->{USERBLOCKEDNOENDDATE},    '9999-12-31', 'USERBLOCKEDNOENDDATE should be 9999-12-31 for unlimited debarments' );
Lines 1398-1404 subtest 'CanBookBeIssued + Statistic patrons "X"' => sub { Link Here
1398
        }
1398
        }
1399
    );
1399
    );
1400
1400
1401
    my ( $error, $question, $alerts ) = CanBookBeIssued( $patron->unblessed, $item_1->{barcode} );
1401
    my ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_1->{barcode} );
1402
    is( $error->{STATS}, 1, '"Error" flag "STATS" must be set if CanBookBeIssued is called with a statistic patron (category_type=X)' );
1402
    is( $error->{STATS}, 1, '"Error" flag "STATS" must be set if CanBookBeIssued is called with a statistic patron (category_type=X)' );
1403
1403
1404
    # TODO There are other tests to provide here
1404
    # TODO There are other tests to provide here
Lines 1516-1522 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1516
    plan tests => 5;
1516
    plan tests => 5;
1517
1517
1518
    my $library = $builder->build( { source => 'Branch' } );
1518
    my $library = $builder->build( { source => 'Branch' } );
1519
    my $patron  = $builder->build( { source => 'Borrower' } );
1519
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
1520
1520
1521
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1521
    my $biblioitem = $builder->build( { source => 'Biblioitem' } );
1522
    my $biblionumber = $biblioitem->{biblionumber};
1522
    my $biblionumber = $biblioitem->{biblionumber};
Lines 1546-1552 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1546
    );
1546
    );
1547
1547
1548
    my ( $error, $question, $alerts );
1548
    my ( $error, $question, $alerts );
1549
    my $issue = AddIssue( $patron, $item_1->{barcode}, dt_from_string->add( days => 1 ) );
1549
    my $issue = AddIssue( $patron->unblessed, $item_1->{barcode}, dt_from_string->add( days => 1 ) );
1550
1550
1551
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1551
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1552
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1552
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-3 / +3 lines)
Lines 40-55 my $item = $builder->build( Link Here
40
    }
40
    }
41
);
41
);
42
42
43
my $patron = $builder->build(
43
my $patron = $builder->build_object(
44
    {
44
    {
45
        source => 'Borrower',
45
        class => 'Koha::Patrons',
46
    }
46
    }
47
);
47
);
48
my $guarantee = $builder->build(
48
my $guarantee = $builder->build(
49
    {
49
    {
50
        source => 'Borrower',
50
        source => 'Borrower',
51
        value  => {
51
        value  => {
52
            guarantorid => $patron->{borrowernumber},
52
            guarantorid => $patron->borrowernumber,
53
        }
53
        }
54
    }
54
    }
55
);
55
);
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-6 / +7 lines)
Lines 50-62 my $branch = $builder->build({ Link Here
50
    source => 'Branch',
50
    source => 'Branch',
51
});
51
});
52
52
53
my $patron = $builder->build({
53
my $patron = $builder->build_object({
54
    source => 'Borrower',
54
    class => 'Koha::Patrons',
55
    value => {
55
    value => {
56
        branchcode => $branch->{branchcode},
56
        branchcode => $branch->{branchcode},
57
        debarred => undef,
57
        debarred => undef,
58
    },
58
    },
59
});
59
});
60
my $patron_unblessed = $patron->unblessed;
60
61
61
my $biblio = $builder->build({
62
my $biblio = $builder->build({
62
    source => 'Biblio',
63
    source => 'Biblio',
Lines 90-101 my $issuingrule = $builder->build({ Link Here
90
});
91
});
91
92
92
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
93
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
93
C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
94
C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
94
95
95
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
96
t::lib::Mocks::mock_preference('AllowTooManyOverride', 0);
96
97
97
# Add onsite checkout
98
# Add onsite checkout
98
C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
99
C4::Circulation::AddIssue( $patron_unblessed, $item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
99
100
100
my ( $impossible, $messages );
101
my ( $impossible, $messages );
101
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
102
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
Lines 106-112 t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1); Link Here
106
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
107
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
107
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
108
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
108
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
109
is( exists $impossible->{TOO_MANY}, '', 'If SwitchOnSiteCheckouts, switch the on-site checkout' );
109
C4::Circulation::AddIssue( $patron, $item->{barcode}, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
110
C4::Circulation::AddIssue( $patron_unblessed, $item->{barcode}, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
110
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
111
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
111
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
112
is( $issue->onsite_checkout, 0, 'The issue should have been switched to a regular checkout' );
112
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
113
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
Lines 126-132 my $another_item = $builder->build({ Link Here
126
    },
127
    },
127
});
128
});
128
129
129
C4::Circulation::AddIssue( $patron, $another_item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
130
C4::Circulation::AddIssue( $patron_unblessed, $another_item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
130
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
131
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} );
131
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
132
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 1 - Switch is allowed' );
132
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
133
is( exists $impossible->{TOO_MANY}, '', 'Specific case 1 - Switch is allowed' );
(-)a/t/db_dependent/Circulation/dateexpiry.t (-9 / +6 lines)
Lines 45-56 subtest 'Tests for CalcDateDue related to dateexpiry' => sub { Link Here
45
45
46
sub can_book_be_issued {
46
sub can_book_be_issued {
47
    my $item    = $builder->build( { source => 'Item' } );
47
    my $item    = $builder->build( { source => 'Item' } );
48
    my $patron  = $builder->build(
48
    my $patron  = $builder->build_object(
49
        {   source => 'Borrower',
49
        {   class  => 'Koha::Patrons',
50
            value  => { dateexpiry => '9999-12-31' }
50
            value  => { dateexpiry => '9999-12-31' }
51
        }
51
        }
52
    );
52
    );
53
    $patron->{flags} = C4::Members::patronflags( $patron );
54
    my $duration = gettimeofday();
53
    my $duration = gettimeofday();
55
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
54
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
56
    $duration = gettimeofday() - $duration;
55
    $duration = gettimeofday() - $duration;
Lines 58-80 sub can_book_be_issued { Link Here
58
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
57
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
59
58
60
    $item = $builder->build( { source => 'Item' } );
59
    $item = $builder->build( { source => 'Item' } );
61
    $patron = $builder->build(
60
    $patron = $builder->build_object(
62
        {   source => 'Borrower',
61
        {   class  => 'Koha::Patrons',
63
            value  => { dateexpiry => '0000-00-00' }
62
            value  => { dateexpiry => '0000-00-00' }
64
        }
63
        }
65
    );
64
    );
66
    $patron->{flags} = C4::Members::patronflags( $patron );
67
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
65
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
68
    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
66
    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
69
67
70
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
68
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
71
    $item = $builder->build( { source => 'Item' } );
69
    $item = $builder->build( { source => 'Item' } );
72
    $patron = $builder->build(
70
    $patron = $builder->build_object(
73
        {   source => 'Borrower',
71
        {   class  => 'Koha::Patrons',
74
            value  => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) },
72
            value  => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) },
75
        }
73
        }
76
    );
74
    );
77
    $patron->{flags} = C4::Members::patronflags( $patron );
78
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
75
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
79
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
76
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
80
77
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-3 / +4 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use C4::Circulation;
20
use C4::Circulation;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Patron;
22
use Koha::Patrons;
23
use Koha::Biblio;
23
use Koha::Biblio;
24
use Koha::Item;
24
use Koha::Item;
25
use Koha::Holds;
25
use Koha::Holds;
Lines 183-192 is( $data->{exceeded}, 1, "Should exceed threshold with one withdrawn item" ); Link Here
183
183
184
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
184
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
185
185
186
my ( undef, $needsconfirmation ) = CanBookBeIssued( $patron_hr, $item->barcode );
186
my $patron_object = Koha::Patrons->find( $patron_hr->{borrowernumber} );
187
my ( undef, $needsconfirmation ) = CanBookBeIssued( $patron_object, $item->barcode );
187
ok( $needsconfirmation->{HIGHHOLDS}, "High holds checkout needs confirmation" );
188
ok( $needsconfirmation->{HIGHHOLDS}, "High holds checkout needs confirmation" );
188
189
189
( undef, $needsconfirmation ) = CanBookBeIssued( $patron_hr, $item->barcode, undef, undef, undef, { override_high_holds => 1 } );
190
( undef, $needsconfirmation ) = CanBookBeIssued( $patron_object, $item->barcode, undef, undef, undef, { override_high_holds => 1 } );
190
ok( !$needsconfirmation->{HIGHHOLDS}, "High holds checkout does not need confirmation" );
191
ok( !$needsconfirmation->{HIGHHOLDS}, "High holds checkout does not need confirmation" );
191
192
192
$schema->storage->txn_rollback();
193
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Patron/Borrower_PrevCheckout.t (-2 / +2 lines)
Lines 379-385 test_it($cpvPmappings, "PostReturn"); Link Here
379
379
380
# Our Patron
380
# Our Patron
381
my $CBBI_patron = $builder->build({source => 'Borrower'});
381
my $CBBI_patron = $builder->build({source => 'Borrower'});
382
$patron = Koha::Patrons->find( $CBBI_patron->{borrowernumber} )->unblessed;
382
$patron = Koha::Patrons->find( $CBBI_patron->{borrowernumber} );
383
# Our Items
383
# Our Items
384
my $new_item = $builder->build({
384
my $new_item = $builder->build({
385
    source => 'Item',
385
    source => 'Item',
Lines 399-405 my $prev_item = $builder->build({ Link Here
399
});
399
});
400
# Second is Checked Out
400
# Second is Checked Out
401
BAIL_OUT("CanBookBeIssued Issue failed")
401
BAIL_OUT("CanBookBeIssued Issue failed")
402
    unless AddIssue($patron, $prev_item->{barcode});
402
    unless AddIssue($patron->unblessed, $prev_item->{barcode});
403
403
404
# Mappings
404
# Mappings
405
my $CBBI_mappings = [
405
my $CBBI_mappings = [
(-)a/t/db_dependent/rollingloans.t (-4 / +3 lines)
Lines 46-54 SKIP: { Link Here
46
sub try_issue {
46
sub try_issue {
47
    my ($cardnumber, $item ) = @_;
47
    my ($cardnumber, $item ) = @_;
48
    my $issuedate = '2011-05-16';
48
    my $issuedate = '2011-05-16';
49
    my $borrower = Koha::Patrons->find( { cardnumber => $cardnumber } )->unblessed;
49
    my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
50
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $borrower, $item );
50
    my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item );
51
    my $issue = AddIssue($borrower, $item, undef, 0, $issuedate);
51
    my $issue = AddIssue($patron->unblessed, $item, undef, 0, $issuedate);
52
    return dt_from_string( $issue->due_date() );
52
    return dt_from_string( $issue->due_date() );
53
}
53
}
54
54
55
- 

Return to bug 19280