Add check for more copies in NCIP::ILS::Evergreen->delete_copy.
authorJason Stephenson <jason@sigio.com>
Sun, 14 Sep 2014 03:54:50 +0000 (23:54 -0400)
committerJason Stephenson <jason@sigio.com>
Sun, 14 Sep 2014 03:54:50 +0000 (23:54 -0400)
We now check if there are other copies on the call number before
we delete it.

We also fix a thinko when we were checking for additional call
numbers on the bib. We had map where we needed grep.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP/ILS/Evergreen.pm

index a2f8005..08cd2c1 100644 (file)
@@ -1333,30 +1333,34 @@ sub delete_copy {
                     'open-ils.pcrud.retrieve.acn',
                     $self->{session}->{authtoken},
                     $copy->call_number(),
-                    {flesh => 2, flesh_fields => {acn => ['record'], bre => ['call_numbers']}}
+                    {flesh => 2, flesh_fields => {acn => ['record','copies'], bre => ['call_numbers']}}
                 )->gather(1);
                 if ($acn) {
-                    # Get the bib and deflesh the acn.
-                    my $bib = $acn->record();
-                    $acn->record($bib->id());
                     # Check if we own the call_number.
                     if ($acn->owning_lib() == $ou_id) {
-                        $r = $session->request(
-                            'open-ils.pcrud.delete.acn',
-                            $self->{session}->{authtoken},
-                            $acn
-                        )->gather(1);
-                        if ($r) {
-                            # Check if we created the bib.
-                            if ($bib->creator() == $self->{session}->{user}->id()) {
+                        # check for additional copies on the acn.
+                        my @copies = grep {$_->id() != $copy->id() && !$U->is_true($_->deleted())} @{$acn->copies()};
+                        unless (@copies) {
+                            # Get the bib
+                            my $bib = $acn->record();
+                            $r = $session->request(
+                                'open-ils.pcrud.delete.acn',
+                                $self->{session}->{authtoken},
+                                $acn
+                            )->gather(1);
+                            if ($r) {
+                                # Check if we created the bib.
+                                if ($bib->creator() == $self->{session}->{user}->id()) {
                                 # Check for other call numbers on the bib:
-                                my @vols = map {$_->id() != $acn->id() && !$U->is_true($_->deleted())} @{$bib->call_numbers()};
-                                unless (@vols) {
-                                    $r = $session->request(
-                                        'open-ils.pcrud.delete.bre',
-                                        $self->{session}->{authtoken},
-                                        $bib
-                                    )->gather(1);
+                                    my @vols = grep {$_->id() != $acn->id() && !$U->is_true($_->deleted())}
+                                        @{$bib->call_numbers()};
+                                    unless (@vols) {
+                                        $r = $session->request(
+                                            'open-ils.pcrud.delete.bre',
+                                            $self->{session}->{authtoken},
+                                            $bib
+                                        )->gather(1);
+                                    }
                                 }
                             }
                         }