LP#978095 - Mark lineitem received when lineitem details are received or canceled. user/csharp/lp978095_acq_lineitems_with_canceled_copies
authorChris Sharp <csharp@georgialibraries.org>
Fri, 4 Nov 2016 17:49:50 +0000 (13:49 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Sun, 8 Oct 2017 18:49:12 +0000 (14:49 -0400)
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index 3eae860..295ebda 100644 (file)
@@ -601,9 +601,32 @@ sub describe_affected_po {
 
 sub check_lineitem_received {
     my($mgr, $li_id) = @_;
-
-    my $non_recv = $mgr->editor->search_acq_lineitem_detail(
-        {recv_time => undef, lineitem => $li_id}, {idlist=>1});
+    # we account for cancel_reasons with keep_debits = false
+    # here to make sure the lineitem gets marked "received"
+    # when, say, all but one are received and the last is
+    # canceled
+    my $non_recv = $mgr->editor->json_query({
+        select => {acqlid => ['id']},
+        from => {
+            jub => {
+                acqlid => {
+                    join => {
+                        acqcr => {
+                            type => 'left'
+                        }
+                    }
+                }
+            }
+        },
+        where => {
+            '-or' => [
+                {'+acqlid' => {cancel_reason => undef}},
+                {'+acqcr' => {keep_debits => 't'}}
+            ],
+        '+jub' => {id => $li_id}
+        },
+        limit => 1
+    });
 
     return 1 if @$non_recv;