Bug 10345: Increment copy number when adding multiple copies.
authorBjörn Nylén <bjorn.nylen@ub.lu.se>
Thu, 28 Mar 2019 09:28:29 +0000 (10:28 +0100)
committerLucas Gass <lucas@bywatersolutions.com>
Mon, 15 Apr 2019 17:26:11 +0000 (17:26 +0000)
To test:
1. Add multiple copies of an item with data in the 'Copy number' field. Note that tha data will be identical for all items.
2. Apply patch.
3. Add multiple copies of an item with a positive integer (ie. only digits) in the 'Copy number' field. Note that the copy number is incremented for each item.
4. Add multiple copies of an item with some other type of data in the 'Copy number' field. Note that the copy number field remains unchanged for the added items.

Signed-off-by: Pierre-Marc Thibault <pierre-marc.thibault@inLibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 0e0a3173859d4374087e99e1a7cd929c8da61c76)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 625265be742d27fb27e6b501df1e38e65ad1a878)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

cataloguing/additem.pl

index 7f4880f..49a9bee 100755 (executable)
@@ -533,8 +533,10 @@ if ($op eq "additem") {
 
         use C4::Barcodes;
         my $barcodeobj = C4::Barcodes->new;
+        my $copynumber = $addedolditem->{'copynumber'};
         my $oldbarcode = $addedolditem->{'barcode'};
         my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
+        my ($copytagfield,$copytagsubfield) = &GetMarcFromKohaField("items.copynumber",$frameworkcode);
 
     # If there is a barcode and we can't find their new values, we can't add multiple copies
        my $testbarcode;
@@ -568,6 +570,10 @@ if ($op eq "additem") {
                    # Checking if the barcode already exists
                    $exist_itemnumber = get_item_from_barcode($barcodevalue);
                }
+        # Updating record with the new copynumber
+        if ( $copynumber  ){
+            $record->field($copytagfield)->update($copytagsubfield => $copynumber);
+        }
 
                # Adding the item
         if (!$exist_itemnumber) {
@@ -578,6 +584,8 @@ if ($op eq "additem") {
             # 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++;
+            # Only increment copynumber if item was really added
+            $copynumber++  if ( $copynumber && $copynumber =~ m/^\d+$/ );
         }
 
                # Preparing the next iteration