Bug 18930: Move lost item refund rules to circulation_rules table
[koha-equinox.git] / Koha / RefundLostItemFeeRules.pm
index 3e37f43..b08ac11 100644 (file)
@@ -22,7 +22,9 @@ use Modern::Perl;
 use Koha::Database;
 use Koha::Exceptions;
 
-use base qw(Koha::Objects);
+use Koha::CirculationRule;
+
+use base qw(Koha::CirculationRules);
 
 =head1 NAME
 
@@ -39,7 +41,7 @@ Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
 =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;
 }
 
@@ -130,14 +139,25 @@ sub _choose_branch {
 =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   => '*',
+            categorycode => undef,
+            itemtype     => undef,
+            rule_name    => 'refund',
+        }
+    )->next();
+
+    return (defined $default_rule)
+                ? $default_rule->rule_value
+                : 1;
 }
 
 1;