From 4b3766aa484ce92b3cb4fcd13b8a9a5f1a4f23a0 Mon Sep 17 00:00:00 2001
From: Jane Wagner <jwagner@ptfs.com>
Date: Fri, 1 Apr 2011 10:28:04 -0400
Subject: [PATCH] [SIGNED OFF] Bug 6034 - Shelving cart feature can wipe permanent shelving location in certain circumstances
Content-Type: text/plain; charset="utf-8"

Bugfix for problems when shelving cart used without In Processing settings

To test, with InProcessingToShelvingCart off, NewItemsDefaultLocation blank,
and ReturnToShelvingCart on, create a new item.  Check the contents of the
location and permanent_location fields in its item record -- the same value
should be in both.  Then run the item through checkin, and look at those fields
again.  The location field should now be set to CART while permanent_location
should still have the original value.  After the cart_to_shelf cron job runs
with the proper timing, check the item record again.  Both location and
permanent_location should again be identical.
---
 C4/Items.pm            |    3 +++
 cataloguing/additem.pl |    6 +++++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 9342564..bc36dd1 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -415,6 +415,7 @@ my %default_values_for_mod_from_marc = (
     itemnotes            => undef, 
     itype                => undef, 
     location             => undef, 
+    permanent_location   => undef,
     materials            => undef, 
     notforloan           => 0,
     paidfor              => undef, 
@@ -1984,6 +1985,7 @@ sub _koha_new_item {
             holdingbranch       = ?,
             paidfor             = ?,
             location            = ?,
+            permanent_location            = ?,
             onloan              = ?,
             issues              = ?,
             renewals            = ?,
@@ -2021,6 +2023,7 @@ sub _koha_new_item {
             $item->{'holdingbranch'},
             $item->{'paidfor'},
             $item->{'location'},
+            $item->{'permanent_location'},
             $item->{'onloan'},
             $item->{'issues'},
             $item->{'renewals'},
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index faa9a0a..ff09e77 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -65,12 +65,16 @@ sub get_item_from_barcode {
 
 sub set_item_default_location {
     my $itemnumber = shift;
+    my $item = GetItem( $itemnumber );
     if ( C4::Context->preference('NewItemsDefaultLocation') ) {
-        my $item = GetItem( $itemnumber );
         $item->{'permanent_location'} = $item->{'location'};
         $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
         ModItem( $item, undef, $itemnumber);
     }
+    else {
+      $item->{'permanent_location'} = $item->{'location'} if !defined($item->{'permanent_location'});
+      ModItem( $item, undef, $itemnumber);
+    }
 }
 
 # NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
-- 
1.7.2.5