From 35f92fd6cbb31025161fc412b22f2891c222e86f Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Mon, 22 Jul 2024 16:32:34 +0100
Subject: [PATCH] Bug 28762: Rename not_for_loan as
 effective_not_for_loan_status

This patch updates the method name to follow current conventions.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 Koha/Item.pm                                  | 13 ++++++------
 .../prog/en/includes/item-status.inc          |  4 ++--
 t/db_dependent/Koha/Item.t                    | 20 +++++++++----------
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/Koha/Item.pm b/Koha/Item.pm
index ed573d1b6a9..64c18e47f47 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -1737,9 +1737,7 @@ sub to_api {
 
     $overrides->{effective_item_type_id} = $self->effective_itemtype;
 
-    my $itype_notforloan = $self->itemtype->notforloan;
-    $overrides->{effective_not_for_loan_status} =
-        ( defined $itype_notforloan && !$self->notforloan ) ? $itype_notforloan : $self->notforloan;
+    $overrides->{effective_not_for_loan_status} = $self->effective_not_for_loan_status;
 
     return { %$response, %$overrides };
 }
@@ -1835,17 +1833,18 @@ sub item_type {
     return shift->itemtype;
 }
 
-=head3 not_for_loan
+=head3 effective_not_for_loan_status
 
-  my $nfl = $item->not_for_loan;
+  my $nfl = $item->effective_not_for_loan_status;
 
 Returns the effective not for loan status of the item
 
 =cut
 
-sub not_for_loan {
+sub effective_not_for_loan_status {
     my ($self) = @_;
-    return $self->notforloan ? $self->notforloan : $self->itemtype->notforloan;
+    my $itype_notforloan = $self->itemtype->notforloan;
+    return ( defined($itype_notforloan) && !$self->notforloan ) ? $itype_notforloan : $self->notforloan;
 }
 
 =head3 orders
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc
index 75ce267927d..a5dca17ec9e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc
@@ -43,9 +43,9 @@
     [% END %]
 [% END %]
 
-[% IF ( item.not_for_loan ) %]
+[% IF ( item.effective_not_for_loan_status ) %]
     [% SET itemavailable = 0 %]
-    [% notforloan_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => item.not_for_loan ) %]
+    [% notforloan_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => item.effective_not_for_loan_status ) %]
     [% IF notforloan_description %]
         <span class="item-status notforloan">[% notforloan_description | html %]</span>
     [% ELSE %]
diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t
index f92a4095d6e..d1d85dac725 100755
--- a/t/db_dependent/Koha/Item.t
+++ b/t/db_dependent/Koha/Item.t
@@ -20,7 +20,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 36;
+use Test::More tests => 35;
 use Test::Exception;
 use Test::MockModule;
 
@@ -2747,7 +2747,7 @@ subtest 'check_booking tests' => sub {
     $schema->storage->txn_rollback;
 };
 
-subtest 'not_for_loan() tests' => sub {
+subtest 'effective_not_for_loan_status() tests' => sub {
 
     plan tests => 5;
 
@@ -2769,14 +2769,14 @@ subtest 'not_for_loan() tests' => sub {
     note("item-level_itypes: 0");
 
     is(
-        $item->not_for_loan, $item->notforloan,
-        '->not_for_loan returns item specific notforloan value when defined and non-zero'
+        $item->effective_not_for_loan_status, $item->notforloan,
+        '->effective_not_for_loan_status returns item specific notforloan value when defined and non-zero'
     );
 
     $item->notforloan(0)->store();
     is(
-        $item->not_for_loan, $biblio_itype->notforloan,
-        '->not_for_loan returns biblio level itype notforloan value when item notforloan is 0'
+        $item->effective_not_for_loan_status, $biblio_itype->notforloan,
+        '->effective_not_for_loan_status returns biblio level itype notforloan value when item notforloan is 0'
     );
 
     t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
@@ -2784,14 +2784,14 @@ subtest 'not_for_loan() tests' => sub {
 
     $item->notforloan(1)->store();
     is(
-        $item->not_for_loan, $item->notforloan,
-        '->not_for_loan returns item specific notforloan value when defined and non-zero'
+        $item->effective_not_for_loan_status, $item->notforloan,
+        '->effective_not_for_loan_status returns item specific notforloan value when defined and non-zero'
     );
 
     $item->notforloan(0)->store();
     is(
-        $item->not_for_loan, $item_itype->notforloan,
-        '->not_for_loan returns biblio level itype notforloan value when item notforloan is 0'
+        $item->effective_not_for_loan_status, $item_itype->notforloan,
+        '->effective_not_for_loan_status returns biblio level itype notforloan value when item notforloan is 0'
     );
 
     $schema->storage->txn_rollback;
-- 
2.39.2