From ecc49306fc82b243d343fcddf8222588feddef7a Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 24 Sep 2021 10:25:53 +0100
Subject: [PATCH] Bug 28762: Move notforloan fallback into object

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 Koha/Item.pm                                        | 13 +++++++++++++
 .../intranet-tmpl/prog/en/includes/item-status.inc  |  5 ++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Koha/Item.pm b/Koha/Item.pm
index 91c15b22d55..a214a1dff0f 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -1832,6 +1832,19 @@ sub item_type {
     return shift->itemtype;
 }
 
+=head3 not_for_loan
+
+  my $nfl = $item->not_for_loan;
+
+Returns the effective not for loan status of the item
+
+=cut
+
+sub not_for_loan {
+    my ($self) = @_;
+    return $self->notforloan ? $self->notforloan : $self->itemtype->notforloan;
+}
+
 =head3 orders
 
   my $orders = $item->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 11adad376f3..75ce267927d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/item-status.inc
@@ -43,10 +43,9 @@
     [% END %]
 [% END %]
 
-[% IF ( item.notforloan || item.effective_itemtype.notforloan ) %]
+[% IF ( item.not_for_loan ) %]
     [% SET itemavailable = 0 %]
-    [% SET notforloan = item.notforloan || item.effective_itemtype.notforloan %]
-    [% notforloan_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => notforloan ) %]
+    [% notforloan_description = AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => item.not_for_loan ) %]
     [% IF notforloan_description %]
         <span class="item-status notforloan">[% notforloan_description | html %]</span>
     [% ELSE %]
-- 
2.44.0