Lines 38-44
use C4::Reserves;
Link Here
|
38 |
use C4::Overdues qw(UpdateFine CalcFine); |
38 |
use C4::Overdues qw(UpdateFine CalcFine); |
39 |
use Koha::DateUtils; |
39 |
use Koha::DateUtils; |
40 |
use Koha::Database; |
40 |
use Koha::Database; |
41 |
use Koha::IssuingRules; |
|
|
42 |
use Koha::Items; |
41 |
use Koha::Items; |
43 |
use Koha::Checkouts; |
42 |
use Koha::Checkouts; |
44 |
use Koha::Patrons; |
43 |
use Koha::Patrons; |
Lines 252-278
is(
Link Here
|
252 |
); |
251 |
); |
253 |
|
252 |
|
254 |
# Set a simple circ policy |
253 |
# Set a simple circ policy |
255 |
$dbh->do('DELETE FROM issuingrules'); |
254 |
$dbh->do('DELETE FROM circulation_rules'); |
256 |
Koha::CirculationRules->search()->delete(); |
255 |
Koha::CirculationRules->set_rules( |
257 |
$dbh->do( |
256 |
{ |
258 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, |
257 |
categorycode => '*', |
259 |
issuelength, lengthunit, |
258 |
branchcode => '*', |
260 |
renewalsallowed, renewalperiod, |
259 |
itemtype => '*', |
261 |
norenewalbefore, auto_renew, |
260 |
rules => { |
262 |
fine, chargeperiod) |
261 |
reservesallowed => 25, |
263 |
VALUES (?, ?, ?, ?, |
262 |
issuelength => 14, |
264 |
?, ?, |
263 |
lengthunit => 'days', |
265 |
?, ?, |
264 |
renewalsallowed => 1, |
266 |
?, ?, |
265 |
renewalperiod => 7, |
267 |
?, ? |
266 |
norenewalbefore => undef, |
268 |
) |
267 |
auto_renew => 0, |
269 |
}, |
268 |
fine => .10, |
270 |
{}, |
269 |
chargeperiod => 1, |
271 |
'*', '*', '*', 25, |
270 |
} |
272 |
14, 'days', |
271 |
} |
273 |
1, 7, |
|
|
274 |
undef, 0, |
275 |
.10, 1 |
276 |
); |
272 |
); |
277 |
|
273 |
|
278 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
274 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
Lines 394-400
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
394 |
); |
390 |
); |
395 |
|
391 |
|
396 |
# Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds |
392 |
# Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds |
397 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); |
393 |
Koha::CirculationRules->set_rule( |
|
|
394 |
{ |
395 |
categorycode => '*', |
396 |
branchcode => '*', |
397 |
itemtype => '*', |
398 |
rule_name => 'onshelfholds', |
399 |
rule_value => '1', |
400 |
} |
401 |
); |
398 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
402 |
t::lib::Mocks::mock_preference('AllowRenewalIfOtherItemsAvailable', 1 ); |
399 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
403 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
400 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
404 |
is( $renewokay, 1, 'Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds'); |
Lines 609-615
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
609 |
|
613 |
|
610 |
# Bug 7413 |
614 |
# Bug 7413 |
611 |
# Test premature manual renewal |
615 |
# Test premature manual renewal |
612 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7'); |
616 |
Koha::CirculationRules->set_rule( |
|
|
617 |
{ |
618 |
categorycode => '*', |
619 |
branchcode => '*', |
620 |
itemtype => '*', |
621 |
rule_name => 'norenewalbefore', |
622 |
rule_value => '7', |
623 |
} |
624 |
); |
613 |
|
625 |
|
614 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
626 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
615 |
is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature'); |
627 |
is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature'); |
Lines 644-650
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
644 |
|
656 |
|
645 |
# Change policy so that loans can only be renewed exactly on due date (0 days prior to due date) |
657 |
# Change policy so that loans can only be renewed exactly on due date (0 days prior to due date) |
646 |
# and test automatic renewal again |
658 |
# and test automatic renewal again |
647 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 0'); |
659 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'}); |
648 |
( $renewokay, $error ) = |
660 |
( $renewokay, $error ) = |
649 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
661 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
650 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
662 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' ); |
Lines 654-660
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
654 |
|
666 |
|
655 |
# Change policy so that loans can be renewed 99 days prior to the due date |
667 |
# Change policy so that loans can be renewed 99 days prior to the due date |
656 |
# and test automatic renewal again |
668 |
# and test automatic renewal again |
657 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 99'); |
669 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'}); |
658 |
( $renewokay, $error ) = |
670 |
( $renewokay, $error ) = |
659 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
671 |
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber ); |
660 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' ); |
672 |
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' ); |
Lines 678-720
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
678 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
690 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
679 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
691 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
680 |
|
692 |
|
681 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9'); |
693 |
Koha::CirculationRules->set_rules( |
|
|
694 |
{ |
695 |
categorycode => '*', |
696 |
branchcode => '*', |
697 |
itemtype => '*', |
698 |
rules => { |
699 |
norenewalbefore => '7', |
700 |
no_auto_renewal_after => '9', |
701 |
} |
702 |
} |
703 |
); |
682 |
( $renewokay, $error ) = |
704 |
( $renewokay, $error ) = |
683 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
705 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
684 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
706 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
685 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
707 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
686 |
|
708 |
|
687 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10'); |
709 |
Koha::CirculationRules->set_rules( |
|
|
710 |
{ |
711 |
categorycode => '*', |
712 |
branchcode => '*', |
713 |
itemtype => '*', |
714 |
rules => { |
715 |
norenewalbefore => '7', |
716 |
no_auto_renewal_after => '10', |
717 |
} |
718 |
} |
719 |
); |
688 |
( $renewokay, $error ) = |
720 |
( $renewokay, $error ) = |
689 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
721 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
690 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
722 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
691 |
is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' ); |
723 |
is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' ); |
692 |
|
724 |
|
693 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11'); |
725 |
Koha::CirculationRules->set_rules( |
|
|
726 |
{ |
727 |
categorycode => '*', |
728 |
branchcode => '*', |
729 |
itemtype => '*', |
730 |
rules => { |
731 |
norenewalbefore => '7', |
732 |
no_auto_renewal_after => '11', |
733 |
} |
734 |
} |
735 |
); |
694 |
( $renewokay, $error ) = |
736 |
( $renewokay, $error ) = |
695 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
737 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
696 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
738 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
697 |
is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' ); |
739 |
is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' ); |
698 |
|
740 |
|
699 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11'); |
741 |
Koha::CirculationRules->set_rules( |
|
|
742 |
{ |
743 |
categorycode => '*', |
744 |
branchcode => '*', |
745 |
itemtype => '*', |
746 |
rules => { |
747 |
norenewalbefore => '10', |
748 |
no_auto_renewal_after => '11', |
749 |
} |
750 |
} |
751 |
); |
700 |
( $renewokay, $error ) = |
752 |
( $renewokay, $error ) = |
701 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
753 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
702 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
754 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
703 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
755 |
is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); |
704 |
|
756 |
|
705 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) ); |
757 |
Koha::CirculationRules->set_rules( |
|
|
758 |
{ |
759 |
categorycode => '*', |
760 |
branchcode => '*', |
761 |
itemtype => '*', |
762 |
rules => { |
763 |
norenewalbefore => '10', |
764 |
no_auto_renewal_after => undef, |
765 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => -1 ), |
766 |
} |
767 |
} |
768 |
); |
706 |
( $renewokay, $error ) = |
769 |
( $renewokay, $error ) = |
707 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
770 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
708 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
771 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
709 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
772 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
710 |
|
773 |
|
711 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => -1 ) ); |
774 |
Koha::CirculationRules->set_rules( |
|
|
775 |
{ |
776 |
categorycode => '*', |
777 |
branchcode => '*', |
778 |
itemtype => '*', |
779 |
rules => { |
780 |
norenewalbefore => '7', |
781 |
no_auto_renewal_after => '15', |
782 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => -1 ), |
783 |
} |
784 |
} |
785 |
); |
712 |
( $renewokay, $error ) = |
786 |
( $renewokay, $error ) = |
713 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
787 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
714 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
788 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
715 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
789 |
is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' ); |
716 |
|
790 |
|
717 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 1 ) ); |
791 |
Koha::CirculationRules->set_rules( |
|
|
792 |
{ |
793 |
categorycode => '*', |
794 |
branchcode => '*', |
795 |
itemtype => '*', |
796 |
rules => { |
797 |
norenewalbefore => '10', |
798 |
no_auto_renewal_after => undef, |
799 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => 1 ), |
800 |
} |
801 |
} |
802 |
); |
718 |
( $renewokay, $error ) = |
803 |
( $renewokay, $error ) = |
719 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
804 |
CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
720 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
805 |
is( $renewokay, 0, 'Do not renew, renewal is automatic' ); |
Lines 736-742
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
736 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
821 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
737 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
822 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
738 |
|
823 |
|
739 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11'); |
824 |
Koha::CirculationRules->set_rules( |
|
|
825 |
{ |
826 |
categorycode => '*', |
827 |
branchcode => '*', |
828 |
itemtype => '*', |
829 |
rules => { |
830 |
norenewalbefore => '10', |
831 |
no_auto_renewal_after => '11', |
832 |
} |
833 |
} |
834 |
); |
740 |
C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1'); |
835 |
C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1'); |
741 |
C4::Context->set_preference('OPACFineNoRenewals','10'); |
836 |
C4::Context->set_preference('OPACFineNoRenewals','10'); |
742 |
C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1'); |
837 |
C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1'); |
Lines 874-904
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
874 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
969 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
875 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
970 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
876 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
971 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
877 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = NULL'); |
972 |
Koha::CirculationRules->set_rules( |
|
|
973 |
{ |
974 |
categorycode => '*', |
975 |
branchcode => '*', |
976 |
itemtype => '*', |
977 |
rules => { |
978 |
norenewalbefore => '7', |
979 |
no_auto_renewal_after => '', |
980 |
no_auto_renewal_after_hard_limit => undef, |
981 |
} |
982 |
} |
983 |
); |
878 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
984 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
879 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' ); |
985 |
is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after or no_auto_renewal_after_hard_limit are not defined' ); |
880 |
my $five_days_before = dt_from_string->add( days => -5 ); |
986 |
my $five_days_before = dt_from_string->add( days => -5 ); |
881 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); |
987 |
Koha::CirculationRules->set_rules( |
|
|
988 |
{ |
989 |
categorycode => '*', |
990 |
branchcode => '*', |
991 |
itemtype => '*', |
992 |
rules => { |
993 |
norenewalbefore => '10', |
994 |
no_auto_renewal_after => '5', |
995 |
no_auto_renewal_after_hard_limit => undef, |
996 |
} |
997 |
} |
998 |
); |
882 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
999 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
883 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
1000 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
884 |
$five_days_before->truncate( to => 'minute' ), |
1001 |
$five_days_before->truncate( to => 'minute' ), |
885 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
1002 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
886 |
); |
1003 |
); |
887 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
1004 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
888 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); |
1005 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'}); |
|
|
1006 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'}); |
1007 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'}); |
1008 |
Koha::CirculationRules->set_rules( |
1009 |
{ |
1010 |
categorycode => '*', |
1011 |
branchcode => '*', |
1012 |
itemtype => '*', |
1013 |
rules => { |
1014 |
norenewalbefore => '10', |
1015 |
no_auto_renewal_after => '15', |
1016 |
no_auto_renewal_after_hard_limit => undef, |
1017 |
} |
1018 |
} |
1019 |
); |
889 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
1020 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
890 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
1021 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
891 |
$five_days_ahead->truncate( to => 'minute' ), |
1022 |
$five_days_ahead->truncate( to => 'minute' ), |
892 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
1023 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
893 |
); |
1024 |
); |
894 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1025 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
895 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
1026 |
Koha::CirculationRules->set_rules( |
|
|
1027 |
{ |
1028 |
categorycode => '*', |
1029 |
branchcode => '*', |
1030 |
itemtype => '*', |
1031 |
rules => { |
1032 |
norenewalbefore => '10', |
1033 |
no_auto_renewal_after => '', |
1034 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => 2 ), |
1035 |
} |
1036 |
} |
1037 |
); |
896 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
1038 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
897 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1039 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
898 |
$two_days_ahead->truncate( to => 'day' ), |
1040 |
$two_days_ahead->truncate( to => 'day' ), |
899 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
1041 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
900 |
); |
1042 |
); |
901 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = ?', undef, dt_from_string->add( days => 2 ) ); |
1043 |
Koha::CirculationRules->set_rules( |
|
|
1044 |
{ |
1045 |
categorycode => '*', |
1046 |
branchcode => '*', |
1047 |
itemtype => '*', |
1048 |
rules => { |
1049 |
norenewalbefore => '10', |
1050 |
no_auto_renewal_after => '15', |
1051 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => 2 ), |
1052 |
} |
1053 |
} |
1054 |
); |
902 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
1055 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
903 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1056 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
904 |
$two_days_ahead->truncate( to => 'day' ), |
1057 |
$two_days_ahead->truncate( to => 'day' ), |
Lines 906-916
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
906 |
); |
1059 |
); |
907 |
|
1060 |
|
908 |
}; |
1061 |
}; |
909 |
|
|
|
910 |
# Too many renewals |
1062 |
# Too many renewals |
911 |
|
1063 |
|
912 |
# set policy to forbid renewals |
1064 |
# set policy to forbid renewals |
913 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = NULL, renewalsallowed = 0'); |
1065 |
Koha::CirculationRules->set_rules( |
|
|
1066 |
{ |
1067 |
categorycode => '*', |
1068 |
branchcode => '*', |
1069 |
itemtype => '*', |
1070 |
rules => { |
1071 |
norenewalbefore => undef, |
1072 |
renewalsallowed => 0, |
1073 |
} |
1074 |
} |
1075 |
); |
914 |
|
1076 |
|
915 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
1077 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
916 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
1078 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
Lines 1145-1171
subtest "Bug 13841 - Do not create new 0 amount fines" => sub {
Link Here
|
1145 |
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { |
1307 |
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { |
1146 |
$dbh->do('DELETE FROM issues'); |
1308 |
$dbh->do('DELETE FROM issues'); |
1147 |
$dbh->do('DELETE FROM items'); |
1309 |
$dbh->do('DELETE FROM items'); |
1148 |
$dbh->do('DELETE FROM issuingrules'); |
1310 |
$dbh->do('DELETE FROM circulation_rules'); |
1149 |
Koha::CirculationRules->search()->delete(); |
|
|
1150 |
$dbh->do( |
1151 |
q{ |
1152 |
INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod, |
1153 |
norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) |
1154 |
}, |
1155 |
{}, |
1156 |
'*', '*', '*', 25, |
1157 |
14, 'days', |
1158 |
1, 7, |
1159 |
undef, 0, |
1160 |
.10, 1 |
1161 |
); |
1162 |
Koha::CirculationRules->set_rules( |
1311 |
Koha::CirculationRules->set_rules( |
1163 |
{ |
1312 |
{ |
1164 |
categorycode => '*', |
1313 |
categorycode => '*', |
1165 |
itemtype => '*', |
1314 |
itemtype => '*', |
1166 |
branchcode => '*', |
1315 |
branchcode => '*', |
1167 |
rules => { |
1316 |
rules => { |
1168 |
maxissueqty => 20 |
1317 |
reservesallowed => 25, |
|
|
1318 |
issuelength => 14, |
1319 |
lengthunit => 'days', |
1320 |
renewalsallowed => 1, |
1321 |
renewalperiod => 7, |
1322 |
norenewalbefore => undef, |
1323 |
auto_renew => 0, |
1324 |
fine => .10, |
1325 |
chargeperiod => 1, |
1326 |
maxissueqty => 20 |
1169 |
} |
1327 |
} |
1170 |
} |
1328 |
} |
1171 |
); |
1329 |
); |
Lines 1214-1235
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
1214 |
undef, undef, undef |
1372 |
undef, undef, undef |
1215 |
); |
1373 |
); |
1216 |
|
1374 |
|
1217 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0"); |
1375 |
Koha::CirculationRules->set_rules( |
|
|
1376 |
{ |
1377 |
categorycode => '*', |
1378 |
itemtype => '*', |
1379 |
branchcode => '*', |
1380 |
rules => { |
1381 |
onshelfholds => 0, |
1382 |
} |
1383 |
} |
1384 |
); |
1218 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1385 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1219 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1386 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1220 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
1387 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
1221 |
|
1388 |
|
1222 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0"); |
1389 |
Koha::CirculationRules->set_rules( |
|
|
1390 |
{ |
1391 |
categorycode => '*', |
1392 |
itemtype => '*', |
1393 |
branchcode => '*', |
1394 |
rules => { |
1395 |
onshelfholds => 0, |
1396 |
} |
1397 |
} |
1398 |
); |
1223 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1399 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1224 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1400 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1225 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
1401 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
1226 |
|
1402 |
|
1227 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); |
1403 |
Koha::CirculationRules->set_rules( |
|
|
1404 |
{ |
1405 |
categorycode => '*', |
1406 |
itemtype => '*', |
1407 |
branchcode => '*', |
1408 |
rules => { |
1409 |
onshelfholds => 1, |
1410 |
} |
1411 |
} |
1412 |
); |
1228 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1413 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1229 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1414 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1230 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
1415 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
1231 |
|
1416 |
|
1232 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); |
1417 |
Koha::CirculationRules->set_rules( |
|
|
1418 |
{ |
1419 |
categorycode => '*', |
1420 |
itemtype => '*', |
1421 |
branchcode => '*', |
1422 |
rules => { |
1423 |
onshelfholds => 1, |
1424 |
} |
1425 |
} |
1426 |
); |
1233 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1427 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1234 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1428 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1235 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
1429 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
Lines 1706-1725
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
1706 |
} |
1900 |
} |
1707 |
)->unblessed; |
1901 |
)->unblessed; |
1708 |
|
1902 |
|
1709 |
# And the issuing rule |
1903 |
# And the circulation rule |
1710 |
Koha::IssuingRules->search->delete; |
1904 |
Koha::CirculationRules->search->delete; |
1711 |
my $rule = Koha::IssuingRule->new( |
1905 |
Koha::CirculationRules->set_rules( |
1712 |
{ |
1906 |
{ |
1713 |
categorycode => '*', |
1907 |
categorycode => '*', |
1714 |
itemtype => '*', |
1908 |
itemtype => '*', |
1715 |
branchcode => '*', |
1909 |
branchcode => '*', |
1716 |
issuelength => 1, |
1910 |
rules => { |
1717 |
firstremind => 1, # 1 day of grace |
1911 |
issuelength => 1, |
1718 |
finedays => 2, # 2 days of fine per day of overdue |
1912 |
firstremind => 1, # 1 day of grace |
1719 |
lengthunit => 'days', |
1913 |
finedays => 2, # 2 days of fine per day of overdue |
|
|
1914 |
lengthunit => 'days', |
1915 |
} |
1720 |
} |
1916 |
} |
1721 |
); |
1917 |
); |
1722 |
$rule->store(); |
|
|
1723 |
|
1918 |
|
1724 |
# Patron cannot issue item_1, they have overdues |
1919 |
# Patron cannot issue item_1, they have overdues |
1725 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1920 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
Lines 2017-2035
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2017 |
} |
2212 |
} |
2018 |
)->unblessed; |
2213 |
)->unblessed; |
2019 |
|
2214 |
|
2020 |
Koha::IssuingRules->search->delete; |
2215 |
Koha::CirculationRules->search->delete; |
2021 |
my $rule = Koha::IssuingRule->new( |
2216 |
my $rule = Koha::CirculationRules->set_rules( |
2022 |
{ |
2217 |
{ |
2023 |
categorycode => '*', |
2218 |
categorycode => '*', |
2024 |
itemtype => '*', |
2219 |
itemtype => '*', |
2025 |
branchcode => '*', |
2220 |
branchcode => '*', |
2026 |
issuelength => 6, |
2221 |
rules => { |
2027 |
lengthunit => 'days', |
2222 |
issuelength => 6, |
2028 |
fine => 1, # Charge 1 every day of overdue |
2223 |
lengthunit => 'days', |
2029 |
chargeperiod => 1, |
2224 |
fine => 1, # Charge 1 every day of overdue |
|
|
2225 |
chargeperiod => 1, |
2226 |
} |
2030 |
} |
2227 |
} |
2031 |
); |
2228 |
); |
2032 |
$rule->store(); |
|
|
2033 |
|
2229 |
|
2034 |
my $now = dt_from_string; |
2230 |
my $now = dt_from_string; |
2035 |
my $one_day_ago = dt_from_string->subtract( days => 1 ); |
2231 |
my $one_day_ago = dt_from_string->subtract( days => 1 ); |