LP#1440114 PO stays open with active blanket charges
authorBill Erickson <berickxx@gmail.com>
Tue, 18 Aug 2015 18:34:16 +0000 (14:34 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 19 Aug 2015 16:33:28 +0000 (12:33 -0400)
When marking the final lineitem on a PO as received, a PO will remain
open (on-order) if blanket charges which are still encumbered link to
the PO.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index 69be3d7..d3a106e 100644 (file)
@@ -1180,8 +1180,8 @@ sub create_purchase_order {
 }
 
 # ----------------------------------------------------------------------------
-# if all of the lineitems for this PO are received,
-# mark the PO as received
+# if all of the lineitems for this PO are received and no 
+# blanket charges are still encumbered, mark the PO as received.
 # ----------------------------------------------------------------------------
 sub check_purchase_order_received {
     my($mgr, $po_id) = @_;
@@ -1194,6 +1194,21 @@ sub check_purchase_order_received {
     my $po = $mgr->editor->retrieve_acq_purchase_order($po_id);
     return $po if @$non_recv_li;
 
+    # avoid marking the PO as received if any blanket charges
+    # are still encumbered.
+    my $blankets = $mgr->editor->json_query({
+        select => {acqpoi => ['id']},
+        from => {
+            acqpoi => {
+                aiit => {filter => {blanket=>'t'}},
+                acqfdeb => {filter => {encumbrance => 't'}}
+            }
+        },
+        where => {'+acqpoi' => {purchase_order => $po_id}}
+    });
+
+    return $po if @$blankets;
+
     $po->state('received');
     return update_purchase_order($mgr, $po);
 }