ACQ : apply default owning_lib value to batched copies user/berick/acq-batch-update-default-owning-lib
authorBill Erickson <berick@esilibrary.com>
Fri, 10 Jan 2014 20:51:52 +0000 (15:51 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 10 Jan 2014 20:51:52 +0000 (15:51 -0500)
Copies created/edited via batch update (PO interface) are now given a
default owning lib of the PO ordering agency.  If the lineitem has no PO
(which is not currently a possible series of events), the picklist org
unit is used instead.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem/BatchUpdate.pm

index a12052c..0633b64 100644 (file)
@@ -291,6 +291,7 @@ sub lineitem_batch_update_impl {
         my $starting_use_count =
             $dist_formula ? $dist_formula->use_count : undef;
 
+        my $li_owner; # cache to avoid repeat lookups on the same lineitem
         for (my $i = 0; $i < scalar @{$jub->lineitem_details}; $i++) {
             my $lid = $jub->lineitem_details->[$i];
 
@@ -331,6 +332,17 @@ sub lineitem_batch_update_impl {
             my $method = ($lid->isnew ? "create" : "update") .
                 "_acq_lineitem_detail";
 
+            # Apply a default owning_lib to affected LIDs as needed.
+            if (!$lid->owning_lib) {
+                if (!$li_owner) {
+                    $li_owner = ($jub->purchase_order) ?
+                        $e->retrieve_acq_purchase_order(
+                            $jub->purchase_order)->ordering_agency :
+                        $e->retrieve_acq_picklist($jub->picklist)->org_unit;
+                }
+                $lid->owning_lib($li_owner);
+            }
+
             if ($fund_changed) {
                 # handle_changed_lid updates any existing fund debits
                 # linked to the LID to use the new fund.  If the fund