|
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 |
my $fines_amount = 5; |
837 |
my $fines_amount = 5; |
|
Lines 853-883
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 853 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
948 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 854 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
949 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 855 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
950 |
AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } ); |
| 856 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = NULL, no_auto_renewal_after_hard_limit = NULL'); |
951 |
Koha::CirculationRules->set_rules( |
|
|
952 |
{ |
| 953 |
categorycode => '*', |
| 954 |
branchcode => '*', |
| 955 |
itemtype => '*', |
| 956 |
rules => { |
| 957 |
norenewalbefore => '7', |
| 958 |
no_auto_renewal_after => '', |
| 959 |
no_auto_renewal_after_hard_limit => undef, |
| 960 |
} |
| 961 |
} |
| 962 |
); |
| 857 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
963 |
my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 858 |
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' ); |
964 |
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' ); |
| 859 |
my $five_days_before = dt_from_string->add( days => -5 ); |
965 |
my $five_days_before = dt_from_string->add( days => -5 ); |
| 860 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5, no_auto_renewal_after_hard_limit = NULL'); |
966 |
Koha::CirculationRules->set_rules( |
|
|
967 |
{ |
| 968 |
categorycode => '*', |
| 969 |
branchcode => '*', |
| 970 |
itemtype => '*', |
| 971 |
rules => { |
| 972 |
norenewalbefore => '10', |
| 973 |
no_auto_renewal_after => '5', |
| 974 |
no_auto_renewal_after_hard_limit => undef, |
| 975 |
} |
| 976 |
} |
| 977 |
); |
| 861 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
978 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 862 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
979 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 863 |
$five_days_before->truncate( to => 'minute' ), |
980 |
$five_days_before->truncate( to => 'minute' ), |
| 864 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
981 |
'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before' |
| 865 |
); |
982 |
); |
| 866 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
983 |
my $five_days_ahead = dt_from_string->add( days => 5 ); |
| 867 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15, no_auto_renewal_after_hard_limit = NULL'); |
984 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'}); |
|
|
985 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'}); |
| 986 |
$dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'}); |
| 987 |
Koha::CirculationRules->set_rules( |
| 988 |
{ |
| 989 |
categorycode => '*', |
| 990 |
branchcode => '*', |
| 991 |
itemtype => '*', |
| 992 |
rules => { |
| 993 |
norenewalbefore => '10', |
| 994 |
no_auto_renewal_after => '15', |
| 995 |
no_auto_renewal_after_hard_limit => undef, |
| 996 |
} |
| 997 |
} |
| 998 |
); |
| 868 |
$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} ); |
| 869 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
1000 |
is( $latest_auto_renew_date->truncate( to => 'minute' ), |
| 870 |
$five_days_ahead->truncate( to => 'minute' ), |
1001 |
$five_days_ahead->truncate( to => 'minute' ), |
| 871 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
1002 |
'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before' |
| 872 |
); |
1003 |
); |
| 873 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
1004 |
my $two_days_ahead = dt_from_string->add( days => 2 ); |
| 874 |
$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 ) ); |
1005 |
Koha::CirculationRules->set_rules( |
|
|
1006 |
{ |
| 1007 |
categorycode => '*', |
| 1008 |
branchcode => '*', |
| 1009 |
itemtype => '*', |
| 1010 |
rules => { |
| 1011 |
norenewalbefore => '10', |
| 1012 |
no_auto_renewal_after => '', |
| 1013 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => 2 ), |
| 1014 |
} |
| 1015 |
} |
| 1016 |
); |
| 875 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
1017 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 876 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1018 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 877 |
$two_days_ahead->truncate( to => 'day' ), |
1019 |
$two_days_ahead->truncate( to => 'day' ), |
| 878 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
1020 |
'GetLatestAutoRenewDate should return +2 days if no_auto_renewal_after_hard_limit is defined and not no_auto_renewal_after' |
| 879 |
); |
1021 |
); |
| 880 |
$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 ) ); |
1022 |
Koha::CirculationRules->set_rules( |
|
|
1023 |
{ |
| 1024 |
categorycode => '*', |
| 1025 |
branchcode => '*', |
| 1026 |
itemtype => '*', |
| 1027 |
rules => { |
| 1028 |
norenewalbefore => '10', |
| 1029 |
no_auto_renewal_after => '15', |
| 1030 |
no_auto_renewal_after_hard_limit => dt_from_string->add( days => 2 ), |
| 1031 |
} |
| 1032 |
} |
| 1033 |
); |
| 881 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
1034 |
$latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); |
| 882 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
1035 |
is( $latest_auto_renew_date->truncate( to => 'day' ), |
| 883 |
$two_days_ahead->truncate( to => 'day' ), |
1036 |
$two_days_ahead->truncate( to => 'day' ), |
|
Lines 885-895
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 885 |
); |
1038 |
); |
| 886 |
|
1039 |
|
| 887 |
}; |
1040 |
}; |
| 888 |
|
|
|
| 889 |
# Too many renewals |
1041 |
# Too many renewals |
| 890 |
|
1042 |
|
| 891 |
# set policy to forbid renewals |
1043 |
# set policy to forbid renewals |
| 892 |
$dbh->do('UPDATE issuingrules SET norenewalbefore = NULL, renewalsallowed = 0'); |
1044 |
Koha::CirculationRules->set_rules( |
|
|
1045 |
{ |
| 1046 |
categorycode => '*', |
| 1047 |
branchcode => '*', |
| 1048 |
itemtype => '*', |
| 1049 |
rules => { |
| 1050 |
norenewalbefore => undef, |
| 1051 |
renewalsallowed => 0, |
| 1052 |
} |
| 1053 |
} |
| 1054 |
); |
| 893 |
|
1055 |
|
| 894 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
1056 |
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber); |
| 895 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
1057 |
is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); |
|
Lines 1124-1150
subtest "Bug 13841 - Do not create new 0 amount fines" => sub {
Link Here
|
| 1124 |
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { |
1286 |
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { |
| 1125 |
$dbh->do('DELETE FROM issues'); |
1287 |
$dbh->do('DELETE FROM issues'); |
| 1126 |
$dbh->do('DELETE FROM items'); |
1288 |
$dbh->do('DELETE FROM items'); |
| 1127 |
$dbh->do('DELETE FROM issuingrules'); |
1289 |
$dbh->do('DELETE FROM circulation_rules'); |
| 1128 |
Koha::CirculationRules->search()->delete(); |
|
|
| 1129 |
$dbh->do( |
| 1130 |
q{ |
| 1131 |
INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod, |
| 1132 |
norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) |
| 1133 |
}, |
| 1134 |
{}, |
| 1135 |
'*', '*', '*', 25, |
| 1136 |
14, 'days', |
| 1137 |
1, 7, |
| 1138 |
undef, 0, |
| 1139 |
.10, 1 |
| 1140 |
); |
| 1141 |
Koha::CirculationRules->set_rules( |
1290 |
Koha::CirculationRules->set_rules( |
| 1142 |
{ |
1291 |
{ |
| 1143 |
categorycode => '*', |
1292 |
categorycode => '*', |
| 1144 |
itemtype => '*', |
1293 |
itemtype => '*', |
| 1145 |
branchcode => '*', |
1294 |
branchcode => '*', |
| 1146 |
rules => { |
1295 |
rules => { |
| 1147 |
maxissueqty => 20 |
1296 |
reservesallowed => 25, |
|
|
1297 |
issuelength => 14, |
| 1298 |
lengthunit => 'days', |
| 1299 |
renewalsallowed => 1, |
| 1300 |
renewalperiod => 7, |
| 1301 |
norenewalbefore => undef, |
| 1302 |
auto_renew => 0, |
| 1303 |
fine => .10, |
| 1304 |
chargeperiod => 1, |
| 1305 |
maxissueqty => 20 |
| 1148 |
} |
1306 |
} |
| 1149 |
} |
1307 |
} |
| 1150 |
); |
1308 |
); |
|
Lines 1193-1214
subtest "AllowRenewalIfOtherItemsAvailable tests" => sub {
Link Here
|
| 1193 |
undef, undef, undef |
1351 |
undef, undef, undef |
| 1194 |
); |
1352 |
); |
| 1195 |
|
1353 |
|
| 1196 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0"); |
1354 |
Koha::CirculationRules->set_rules( |
|
|
1355 |
{ |
| 1356 |
categorycode => '*', |
| 1357 |
itemtype => '*', |
| 1358 |
branchcode => '*', |
| 1359 |
rules => { |
| 1360 |
onshelfholds => 0, |
| 1361 |
} |
| 1362 |
} |
| 1363 |
); |
| 1197 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1364 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
| 1198 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1365 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
| 1199 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
1366 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfholds are disabled' ); |
| 1200 |
|
1367 |
|
| 1201 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 0"); |
1368 |
Koha::CirculationRules->set_rules( |
|
|
1369 |
{ |
| 1370 |
categorycode => '*', |
| 1371 |
itemtype => '*', |
| 1372 |
branchcode => '*', |
| 1373 |
rules => { |
| 1374 |
onshelfholds => 0, |
| 1375 |
} |
| 1376 |
} |
| 1377 |
); |
| 1202 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1378 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
| 1203 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1379 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
| 1204 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
1380 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled and onshelfholds is disabled' ); |
| 1205 |
|
1381 |
|
| 1206 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); |
1382 |
Koha::CirculationRules->set_rules( |
|
|
1383 |
{ |
| 1384 |
categorycode => '*', |
| 1385 |
itemtype => '*', |
| 1386 |
branchcode => '*', |
| 1387 |
rules => { |
| 1388 |
onshelfholds => 1, |
| 1389 |
} |
| 1390 |
} |
| 1391 |
); |
| 1207 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
1392 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 0 ); |
| 1208 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1393 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
| 1209 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
1394 |
is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is disabled and onshelfhold is enabled' ); |
| 1210 |
|
1395 |
|
| 1211 |
C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); |
1396 |
Koha::CirculationRules->set_rules( |
|
|
1397 |
{ |
| 1398 |
categorycode => '*', |
| 1399 |
itemtype => '*', |
| 1400 |
branchcode => '*', |
| 1401 |
rules => { |
| 1402 |
onshelfholds => 1, |
| 1403 |
} |
| 1404 |
} |
| 1405 |
); |
| 1212 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
1406 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
| 1213 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
1407 |
( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); |
| 1214 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
1408 |
is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' ); |
|
Lines 1685-1704
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
| 1685 |
} |
1879 |
} |
| 1686 |
)->unblessed; |
1880 |
)->unblessed; |
| 1687 |
|
1881 |
|
| 1688 |
# And the issuing rule |
1882 |
# And the circulation rule |
| 1689 |
Koha::IssuingRules->search->delete; |
1883 |
Koha::CirculationRules->search->delete; |
| 1690 |
my $rule = Koha::IssuingRule->new( |
1884 |
Koha::CirculationRules->set_rules( |
| 1691 |
{ |
1885 |
{ |
| 1692 |
categorycode => '*', |
1886 |
categorycode => '*', |
| 1693 |
itemtype => '*', |
1887 |
itemtype => '*', |
| 1694 |
branchcode => '*', |
1888 |
branchcode => '*', |
| 1695 |
issuelength => 1, |
1889 |
rules => { |
| 1696 |
firstremind => 1, # 1 day of grace |
1890 |
issuelength => 1, |
| 1697 |
finedays => 2, # 2 days of fine per day of overdue |
1891 |
firstremind => 1, # 1 day of grace |
| 1698 |
lengthunit => 'days', |
1892 |
finedays => 2, # 2 days of fine per day of overdue |
|
|
1893 |
lengthunit => 'days', |
| 1894 |
} |
| 1699 |
} |
1895 |
} |
| 1700 |
); |
1896 |
); |
| 1701 |
$rule->store(); |
|
|
| 1702 |
|
1897 |
|
| 1703 |
# Patron cannot issue item_1, they have overdues |
1898 |
# Patron cannot issue item_1, they have overdues |
| 1704 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1899 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
|
Lines 1998-2016
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
| 1998 |
} |
2193 |
} |
| 1999 |
)->unblessed; |
2194 |
)->unblessed; |
| 2000 |
|
2195 |
|
| 2001 |
Koha::IssuingRules->search->delete; |
2196 |
Koha::CirculationRules->search->delete; |
| 2002 |
my $rule = Koha::IssuingRule->new( |
2197 |
my $rule = Koha::CirculationRules->set_rules( |
| 2003 |
{ |
2198 |
{ |
| 2004 |
categorycode => '*', |
2199 |
categorycode => '*', |
| 2005 |
itemtype => '*', |
2200 |
itemtype => '*', |
| 2006 |
branchcode => '*', |
2201 |
branchcode => '*', |
| 2007 |
issuelength => 6, |
2202 |
rules => { |
| 2008 |
lengthunit => 'days', |
2203 |
issuelength => 6, |
| 2009 |
fine => 1, # Charge 1 every day of overdue |
2204 |
lengthunit => 'days', |
| 2010 |
chargeperiod => 1, |
2205 |
fine => 1, # Charge 1 every day of overdue |
|
|
2206 |
chargeperiod => 1, |
| 2207 |
} |
| 2011 |
} |
2208 |
} |
| 2012 |
); |
2209 |
); |
| 2013 |
$rule->store(); |
|
|
| 2014 |
|
2210 |
|
| 2015 |
my $now = dt_from_string; |
2211 |
my $now = dt_from_string; |
| 2016 |
my $one_day_ago = dt_from_string->subtract( days => 1 ); |
2212 |
my $one_day_ago = dt_from_string->subtract( days => 1 ); |