LP1411422 Copy details repeated in search results when item/volume moved with parts...
authorblake <blake@mobiusconsortium.org>
Mon, 13 Jun 2016 20:58:13 +0000 (15:58 -0500)
committerJason Stephenson <jason@sigio.com>
Tue, 13 Mar 2018 15:39:41 +0000 (11:39 -0400)
Added the code in perl to respect the existence of parts. Both "transferring volume"
and "transferring items". "Transferring items" was coded to use
open-ils.cat.asset.copy.fleshed.batch.update which means most of the work was done in js.
The web based staff client is coded to use open-ils.cat.transfer_copies_to_volume.
Decided to use that method for xul as well. Making it more consistent with the "transferring
volume" code. Considered coding it to move the part level holds to the destination part but
it's possible that the source part still has items.

Signed-off-by: blake <blake@mobiusconsortium.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>

Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm
Open-ILS/xul/staff_client/chrome/content/main/constants.js
Open-ILS/xul/staff_client/server/cat/util.js

index 19c0b6a..be3df96 100644 (file)
@@ -850,10 +850,24 @@ sub transfer_copies_to_volume {
 
     # flesh and munge the copies
     my $fleshed_copies = [];
-    my ($copy, $copy_evt);
+    my $copy;
     foreach my $copy_id ( @{ $copies } ) {
-        ($copy, $copy_evt) = $U->fetch_copy($copy_id);
-        return $copy_evt if $copy_evt;
+        $copy = $editor->search_asset_copy([
+            { id => $copy_id , deleted => 'f' },
+            {
+                join => {
+                    acpm => {
+                        type => 'left',
+                        join => {
+                            bmp => { type => 'left' }
+                        }
+                    }
+                },
+                flesh => 1,
+                flesh_fields => { acp => ['parts'] }
+            }
+        ])->[0];
+        return OpenILS::Event->new('ASSET_COPY_NOT_FOUND') if !$copy;
         $copy->call_number( $volume );
         $copy->circ_lib( $cn->owning_lib() );
         $copy->ischanged( 't' );
@@ -871,6 +885,35 @@ sub transfer_copies_to_volume {
         return $evt; 
     }
 
+    # take care of the parts
+    for my $copy (@$fleshed_copies) {
+        my $parts = $copy->parts;
+        next unless $parts;
+        my $part_objs = [];
+        foreach my $part (@$parts) {
+            my $part_label = $part->label;
+            my $part_obj = $editor->search_biblio_monograph_part(
+              {
+                   label=>$part_label,
+                   record=>$cn->record
+              }
+           )->[0];
+           if (!$part_obj) {
+               $part_obj = Fieldmapper::biblio::monograph_part->new();
+               $part_obj->label( $part_label );
+               $part_obj->record( $cn->record );
+               unless($editor->create_biblio_monograph_part($part_obj)) {
+                 return $editor->die_event if $editor->die_event;
+               }
+           }
+           push @$part_objs, $part_obj;
+        }
+        $copy->parts( $part_objs );
+        $copy->ischanged(1);
+        $evt = OpenILS::Application::Cat::AssetCommon->update_copy_parts($editor, $copy, 1); #delete_parts=1
+        return $evt if $evt;
+    }
+
     $editor->commit;
     $logger->info("copy to volume transfer successfully updated ".scalar(@$copies)." copies");
     reset_hold_list($auth, $retarget_holds);
@@ -1300,6 +1343,9 @@ sub batch_volume_transfer {
             }
         }
 
+        # record the difference between the destination bib and the present bib
+        my $same_bib = $vol->record == $rec;
+
         # see if there is a volume at the destination lib that 
         # already has the requested label
         my $existing_vol = $e->search_asset_call_number(
@@ -1351,7 +1397,21 @@ sub batch_volume_transfer {
 
         # regardless of what volume was used as the destination, 
         # update any copies that have moved over to the new lib
-        my $copies = $e->search_asset_copy({call_number=>$vol->id, deleted => 'f'});
+        my $copies = $e->search_asset_copy([
+            { call_number => $vol->id , deleted => 'f' },
+            {
+                join => {
+                    acpm => {
+                        type => 'left',
+                        join => {
+                            bmp => { type => 'left' }
+                        }
+                    }
+                },
+                flesh => 1,
+                flesh_fields => { acp => ['parts'] }
+            }
+        ]);
 
         # update circ lib on the copies - make this a method flag?
         for my $copy (@$copies) {
@@ -1363,6 +1423,39 @@ sub batch_volume_transfer {
             $e->update_asset_copy($copy) or return $e->event;
         }
 
+        # update parts if volume is moving bib records
+        if( !$same_bib ) {
+            for my $copy (@$copies) {
+                my $parts = $copy->parts;
+                next unless $parts;
+                my $part_objs = [];
+                foreach my $part (@$parts) {
+                    my $part_label = $part->label;
+                    my $part_obj = $e->search_biblio_monograph_part(
+                       {
+                            label=>$part_label,
+                            record=>$rec
+                       }
+                    )->[0];
+
+                    if (!$part_obj) {
+                        $part_obj = Fieldmapper::biblio::monograph_part->new();
+                        $part_obj->label( $part_label );
+                        $part_obj->record( $rec );
+                        unless($e->create_biblio_monograph_part($part_obj)) {
+                          return $e->die_event if $e->die_event;
+                        }
+                    }
+                    push @$part_objs, $part_obj;
+                }
+
+                $copy->parts( $part_objs );
+                $copy->ischanged(1);
+                $evt = OpenILS::Application::Cat::AssetCommon->update_copy_parts($e, $copy, 1); #delete_parts=1
+                return $evt if $evt;
+            }
+        }
+
         # Now see if any empty records need to be deleted after all of this
 
         for(@rec_ids) {
index 8f2e313..96e31fa 100644 (file)
@@ -107,6 +107,7 @@ var api = {
     'FM_ACP_UNFLESHED_BATCH_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.batch.retrieve', 'secure' : false },
     'FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed.batch.retrieve.authoritative', 'secure' : false },
     'FM_ACP_FLESHED_BATCH_UPDATE' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.copy.fleshed.batch.update' },
+    'FM_ACP_TRANSFER_COPIES_BATCH' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.transfer_copies_to_volume' },
     'FM_ACP_COUNT' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.biblio.record.copy_count.staff', 'secure' : false },
     'FM_ACP_COUNT.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.biblio.record.copy_count.staff.authoritative', 'secure' : false },
     'FM_ACPL_RETRIEVE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.copy_location.retrieve.all', 'secure' : false },
index f7da886..2f4e93a 100644 (file)
@@ -184,17 +184,9 @@ cat.util.transfer_copies = function(params) {
 
         JSAN.use('util.functional');
 
-        var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ params.copy_ids ]);
-
-        for (var i = 0; i < copies.length; i++) {
-            copies[i].call_number( data.marked_volume );
-            copies[i].circ_lib( params.owning_lib );
-            copies[i].ischanged( 1 );
-        }
-
         var robj = network.simple_request(
-            'FM_ACP_FLESHED_BATCH_UPDATE', 
-            [ ses(), copies, true ], 
+            'FM_ACP_TRANSFER_COPIES_BATCH',
+            [ ses(), data.marked_volume , params.copy_ids ],
             null,
             {
                 'title' : $("catStrings").getString('staff.cat.util.transfer_copies.override_transfer_failure'),