[Koha-patches] [PATCH 4/7] bug 3481 followup - set temporary processing location

Galen Charlton gmcharlt at gmail.com
Sun Aug 23 19:07:03 CEST 2009


Ensure that the temporary processing location is always
set regardless of whether one item is added or multiple
copies are added at once.

Signed-off-by: Galen Charlton <gmcharlt at gmail.com>
---
 cataloguing/additem.pl |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index d5bf07e..e25bb44 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -58,6 +58,16 @@ sub get_item_from_barcode {
     return($result);
 }
 
+sub set_item_default_location {
+    my $itemnumber = shift;
+    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
+        my $item = GetItem( $itemnumber );
+        $item->{'permanent_location'} = $item->{'location'};
+        $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
+        ModItem( $item, undef, $itemnumber);
+    }
+}
+
 my $input = new CGI;
 my $dbh = C4::Context->dbh;
 my $error        = $input->param('error');
@@ -130,7 +140,10 @@ if ($op eq "additem") {
 	my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
 	push @errors,"barcode_not_unique" if($exist_itemnumber);
 	# if barcode exists, don't create, but report The problem.
-	my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber);
+    unless ($exist_itemnumber) {
+	    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
+        set_item_default_location($oldbibitemnum);
+    }
 	$nextop = "additem";
 	if ($exist_itemnumber) {
 	    $itemrecord = $record;
@@ -200,17 +213,12 @@ if ($op eq "additem") {
 		# Adding the item
         if (!$exist_itemnumber) {
             my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber);
+            set_item_default_location($oldbibitemnum);
 
             # We count the item only if it was really added
             # That way, all items are added, even if there was some already existing barcodes
             # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
             $i++;
-            if ( C4::Context->preference('NewItemsDefaultLocation') ) {
-                my $item = GetItem( $oldbibitemnum );
-                $item->{'permanent_location'} = $item->{'location'};
-                $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
-                ModItem( $item, $oldbiblionumber, $oldbibitemnum );
-            }
         }
 
 		# Preparing the next iteration
-- 
1.6.3.3




More information about the Koha-patches mailing list