LP1411422 Copy details repeated in search results when item/volume moved with parts...
authorblake <blake@mobiusconsortium.org>
Fri, 1 Sep 2017 20:54:39 +0000 (20:54 +0000)
committerJason Stephenson <jason@sigio.com>
Tue, 13 Mar 2018 15:39:42 +0000 (11:39 -0400)
Added regression test and tweaked the part lookup query to remove deleted parts.

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/src/perlmods/live_t/25-lp1411422-transferring-items-volumes-with-parts.t [new file with mode: 0755]

index be3df96..4bc9a43 100644 (file)
@@ -895,7 +895,8 @@ sub transfer_copies_to_volume {
             my $part_obj = $editor->search_biblio_monograph_part(
               {
                    label=>$part_label,
-                   record=>$cn->record
+                   record=>$cn->record,
+                   deleted=>'f'
               }
            )->[0];
            if (!$part_obj) {
@@ -1434,7 +1435,8 @@ sub batch_volume_transfer {
                     my $part_obj = $e->search_biblio_monograph_part(
                        {
                             label=>$part_label,
-                            record=>$rec
+                            record=>$rec,
+                            deleted=>'f'
                        }
                     )->[0];
 
diff --git a/Open-ILS/src/perlmods/live_t/25-lp1411422-transferring-items-volumes-with-parts.t b/Open-ILS/src/perlmods/live_t/25-lp1411422-transferring-items-volumes-with-parts.t
new file mode 100755 (executable)
index 0000000..18fe58c
--- /dev/null
@@ -0,0 +1,183 @@
+#!perl
+
+use Test::More tests => 7;
+
+diag("Test transferring holds with parts.");
+
+use constant WORKSTATION_NAME => 'BR1-test-25-lp1411422-transferring-items-volumes-with-parts.t';
+use constant WORKSTATION_LIB => 4;
+
+use strict; use warnings;
+
+use OpenILS::Utils::TestUtils;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
+use OpenILS::Utils::Fieldmapper;
+
+our $script = OpenILS::Utils::TestUtils->new();
+$script->bootstrap;
+
+our $e = new_editor(xact => 1);
+$e->init;
+
+
+# setup workstation and login
+# -------------
+setupLogin();
+
+# Find a copy with at least one part
+# -------------
+
+my $copy = $e->search_asset_copy([
+{ deleted => 'f' },
+{
+    join => {
+        acpm => {
+            type => 'inner',
+            join => {
+                bmp => { type => 'left' },
+            }
+        }
+    },
+    flesh => 1,
+    flesh_fields => { acp => ['parts']},
+    limit => 1
+}
+])->[0];
+
+diag("Using copy ". $copy->id);
+my $parts = $copy->parts;
+my $oldcallnumber = $copy->call_number;
+my $part_objs = [];
+my $part;
+
+foreach my $spart (@$parts) {
+    $part = $spart;
+}
+diag("Copy part label -> ". $part->label);
+
+diag("Copy call number ". $oldcallnumber);
+
+$oldcallnumber = $e->search_asset_call_number({id => $oldcallnumber, deleted => 'f'})->[0];
+
+diag("Copy attached to bib ". $oldcallnumber->record);
+
+# Find a bib without parts
+# -------------
+my $sdestbib = $e->search_biblio_record_entry([
+{
+id =>
+    {
+        'not in' =>
+            { "from" => 'bmp',
+                'select' =>  { "bmp" => [ 'record' ] }
+            }
+    },
+deleted => 'f' },
+{ limit => 3 }
+
+]);
+
+my $destbib;
+foreach(@{$sdestbib}) {
+    if ($_->id > -1) {
+        $destbib = $_;
+        last;
+    }
+}
+
+
+diag("Using this non parted bib ". $destbib->id);
+
+# Create a new volume for the copy to transfer to
+# -------------
+my $newcall = Fieldmapper::asset::call_number->new;
+
+$newcall->owning_lib($oldcallnumber->owning_lib);
+$newcall->record($destbib->id);
+$newcall->creator($oldcallnumber->creator);
+$newcall->editor($oldcallnumber->editor);
+$newcall->label('Test copy transfer with parts');
+
+
+my $stat = $e->create_asset_call_number($newcall);
+ok($stat, 'Created temporary volume on bib '.$destbib->id);
+
+diag( "New call number id: " . $newcall->id );
+
+# freshen up the variable
+# get all the rest of the values from the DB
+$newcall = $e->search_asset_call_number({id => $newcall->id})->[0];
+
+# save changes so that the storage request has access
+$e->commit;
+
+# make the transfer
+# -------------
+my @copy_id_array = ($copy->id);
+my $storage = $script->session('open-ils.cat');
+my $req = $storage->request(
+    'open-ils.cat.transfer_copies_to_volume',  $script->authtoken, $newcall->id, \@copy_id_array )->gather(1);
+
+# Did the code create a new part on the destination bib?
+# -------------
+$e->xact_begin;
+
+my $destparts = $e->search_biblio_monograph_part({record => $newcall->record, label => $part->label, deleted => 'f'})->[0];
+ok($destparts, 'Copy transfer with parts success on bib '.$destbib->id);
+
+is($destparts->label, $part->label, 'Part labels match and everything!');
+
+# Now test transferring volumes,
+# might as well transfer it back to the old bib
+# -------------
+
+my @vols = ($newcall->id);
+my $docid = $oldcallnumber->record;
+my $args = {lib => $oldcallnumber->owning_lib, docid => $docid, volumes => \@vols };
+$storage = $script->session('open-ils.cat');
+$req = $storage->request(
+    'open-ils.cat.asset.volume.batch.transfer',
+    $script->authtoken,
+    $args
+    )->gather(1);
+# Make sure that the old bib received the part
+my $destparts2 = $e->search_biblio_monograph_part({record => $oldcallnumber->record, label => $part->label, deleted => 'f'})->[0];
+ok($destparts2, 'Volume transfer with parts success on bib '.$oldcallnumber->record);
+is($destparts->label, $part->label, 'Part labels match and everything!');
+
+
+# Reverse the data
+# -------------
+$storage = $script->session('open-ils.cat');
+$req = $storage->request(
+    'open-ils.cat.transfer_copies_to_volume',  $script->authtoken, $oldcallnumber->id, \@copy_id_array )->gather(1);
+
+$stat = $e->delete_asset_call_number($newcall);
+
+$e->xact_commit;
+
+
+sub setupLogin {
+
+    my $workstation = $e->search_actor_workstation([ {name => WORKSTATION_NAME, owning_lib => WORKSTATION_LIB } ])->[0];
+
+    if(!$workstation )
+    {
+        $script->authenticate({
+            username => 'admin',
+            password => 'demo123',
+            type => 'staff'});
+        ok( $script->authtoken, 'Have an authtoken');
+        my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
+        ok( ! ref $ws, 'Registered a new workstation');
+        $script->logout();
+    }
+
+    $script->authenticate({
+        username => 'admin',
+        password => 'demo123',
+        type => 'staff',
+        workstation => WORKSTATION_NAME});
+    ok( $script->authtoken, 'Have an authtoken associated with the workstation');
+}
+