@@ -, +, @@ limiting rules --- C4/Circulation.pm | 6 +-- admin/smart-rules.pl | 18 ++++---- installer/data/mysql/atomicupdate/bug_18936.perl | 4 +- .../prog/en/modules/admin/smart-rules.tt | 4 +- t/db_dependent/Circulation.t | 50 ++++++++++++--------- t/db_dependent/Circulation/TooMany.t | 21 ++++----- .../Holds/DisallowHoldIfItemsAvailable.t | 52 +++++++++++++++++----- t/db_dependent/TestBuilder.t | 2 - 8 files changed, 99 insertions(+), 58 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -405,7 +405,7 @@ sub TooMany { # if a rule is found and has a loan limit set, count # how many loans the patron already has that meet that # rule - if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { + if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne '') { my @bind_params; my $count_query = q| SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts @@ -471,7 +471,7 @@ sub TooMany { my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0; my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0; - if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { + if ( $onsite_checkout and $max_onsite_checkouts_allowed ne '' ) { if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { return { reason => 'TOO_MANY_ONSITE_CHECKOUTS', @@ -2279,7 +2279,7 @@ sub _debar_user_on_return { # If the max suspension days is < than the suspension days # the suspension days is limited to this maximum period. my $max_sd = $issuing_rule->{maxsuspensiondays}; - if ( defined $max_sd ) { + if ( defined $max_sd && $max_sd ne '' ) { $max_sd = DateTime::Duration->new( days => $max_sd ); $suspension_days = $max_sd if DateTime::Duration->compare( $max_sd, $suspension_days ) < 0; --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -238,7 +238,7 @@ elsif ($op eq 'add') { my $fine = $input->param('fine'); my $finedays = $input->param('finedays'); my $maxsuspensiondays = $input->param('maxsuspensiondays'); - $maxsuspensiondays = undef if $maxsuspensiondays eq q||; + $maxsuspensiondays = '' if $maxsuspensiondays eq q||; my $firstremind = $input->param('firstremind'); my $chargeperiod = $input->param('chargeperiod'); my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at'); @@ -247,20 +247,20 @@ elsif ($op eq 'add') { my $renewalsallowed = $input->param('renewalsallowed'); my $renewalperiod = $input->param('renewalperiod'); my $norenewalbefore = $input->param('norenewalbefore'); - $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/; + $norenewalbefore = '' if $norenewalbefore =~ /^\s*$/; my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0; my $no_auto_renewal_after = $input->param('no_auto_renewal_after'); - $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/; - my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef; + $no_auto_renewal_after = '' if $no_auto_renewal_after =~ /^\s*$/; + my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || ''; $no_auto_renewal_after_hard_limit = eval { dt_from_string( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit ); $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit ); my $reservesallowed = $input->param('reservesallowed'); my $holds_per_record = $input->param('holds_per_record'); my $onshelfholds = $input->param('onshelfholds') || 0; $maxissueqty =~ s/\s//g; - $maxissueqty = undef if $maxissueqty !~ /^\d+/; + $maxissueqty = '' if $maxissueqty !~ /^\d+/; $maxonsiteissueqty =~ s/\s//g; - $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/; + $maxonsiteissueqty = '' if $maxonsiteissueqty !~ /^\d+/; my $issuelength = $input->param('issuelength'); $issuelength = $issuelength eq q{} ? undef : $issuelength; my $lengthunit = $input->param('lengthunit'); @@ -271,7 +271,7 @@ elsif ($op eq 'add') { my $rentaldiscount = $input->param('rentaldiscount'); my $opacitemholds = $input->param('opacitemholds') || 0; my $article_requests = $input->param('article_requests') || 'no'; - my $overduefinescap = $input->param('overduefinescap') || undef; + my $overduefinescap = $input->param('overduefinescap') || ''; my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on'; warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price"; @@ -300,6 +300,8 @@ elsif ($op eq 'add') { overduefinescap => $overduefinescap, cap_fine_to_replacement_price => $cap_fine_to_replacement_price, article_requests => $article_requests, + maxissueqty => $maxissueqty, + maxonsiteissueqty => $maxonsiteissueqty, }; Koha::CirculationRules->set_rules( @@ -308,8 +310,6 @@ elsif ($op eq 'add') { itemtype => $itemtype eq '*' ? undef : $itemtype, branchcode => $br eq '*' ? undef : $br, rules => { - maxissueqty => $maxissueqty, - maxonsiteissueqty => $maxonsiteissueqty, %$params, } } --- a/installer/data/mysql/atomicupdate/bug_18936.perl +++ a/installer/data/mysql/atomicupdate/bug_18936.perl @@ -27,13 +27,15 @@ if( CheckVersion( $DBversion ) ) { onshelfholds opacitemholds article_requests + maxissueqty + maxonsiteissueqty ); if ( column_exists( 'issuingrules', 'categorycode' ) ) { foreach my $column ( @columns ) { $dbh->do(" INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) - SELECT categorycode, branchcode, itemtype, \'$column\', $column + SELECT categorycode, branchcode, itemtype, \'$column\', COALESCE( $column, '' ) FROM issuingrules "); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -169,14 +169,14 @@ Delete