Bug 25409: Add missing "Required" text and "required" classes
[koha-ffzg.git] / Koha / RefundLostItemFeeRules.pm
index 79a334e..9cb32d5 100644 (file)
@@ -4,25 +4,27 @@ package Koha::RefundLostItemFeeRules;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
 use Koha::Database;
 use Koha::Exceptions;
 
-use base qw(Koha::Objects);
+use Koha::CirculationRule;
+
+use base qw(Koha::CirculationRules);
 
 =head1 NAME
 
@@ -34,12 +36,12 @@ Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
 
 =cut
 
-=head3 type
+=head3 _type
 
 =cut
 
 sub _type {
-    return 'RefundLostItemFeeRule';
+    return 'CirculationRule';
 }
 
 =head3 object_class
@@ -47,7 +49,7 @@ sub _type {
 =cut
 
 sub object_class {
-    return 'Koha::RefundLostItemFeeRule';
+    return 'Koha::CirculationRule';
 }
 
 =head3 should_refund
@@ -82,10 +84,17 @@ sub _effective_branch_rule {
     my $self   = shift;
     my $branch = shift;
 
-    my $specific_rule = $self->find({ branchcode => $branch });
+    my $specific_rule = $self->search(
+        {
+            branchcode   => $branch,
+            categorycode => undef,
+            itemtype     => undef,
+            rule_name    => 'refund',
+        }
+    )->next();
 
     return ( defined $specific_rule )
-                ? $specific_rule->refund
+                ? $specific_rule->rule_value
                 : $self->_default_rule;
 }
 
@@ -106,9 +115,7 @@ sub _choose_branch {
     my $self = shift;
     my $param = shift;
 
-    my $behaviour = Koha::Config::SysPrefs
-                        ->find( 'RefundLostOnReturnControl' )
-                        ->value // 'CheckinLibrary';
+    my $behaviour = C4::Context->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
 
     my $param_mapping = {
            CheckinLibrary => 'current_branch',
@@ -129,17 +136,44 @@ sub _choose_branch {
     return $branch;
 }
 
+=head3 Koha::RefundLostItemFeeRules->find();
+
+Inherit from Koha::Objects->find(), but forces rule_name => 'refund'
+
+=cut
+
+sub find {
+    my ( $self, @pars ) = @_;
+
+    if ( ref($pars[0]) eq 'HASH' ) {
+        $pars[0]->{rule_name} = 'refund';
+    }
+
+    return $self->SUPER::find(@pars);
+}
+
 =head3 _default_rule (internal)
 
 This function returns the default rule defined for refunding lost
-item fees on return.
+item fees on return. It defaults to 1 if no rule is defined.
 
 =cut
 
 sub _default_rule {
-    my $self = shift;
 
-    return $self->find({ branchcode => '*' })->refund;
+    my $self = shift;
+    my $default_rule = $self->search(
+        {
+            branchcode   => undef,
+            categorycode => undef,
+            itemtype     => undef,
+            rule_name    => 'refund',
+        }
+    )->next();
+
+    return (defined $default_rule)
+                ? $default_rule->rule_value
+                : 1;
 }
 
 1;