Acq - fix cloning of picklists so that all lineitems are cloned with a 'new' state
authorJames Fournie <jfournie@sitka.bclibraries.ca>
Thu, 1 Mar 2012 00:42:10 +0000 (16:42 -0800)
committerMike Rylander <mrylander@gmail.com>
Mon, 2 Apr 2012 16:20:57 +0000 (12:20 -0400)
This prevents duplicated items on purchase orders when the picklists are cloned and
other wacky problems.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm

index 0533d50..7272f63 100644 (file)
@@ -2186,19 +2186,22 @@ sub clone_picklist_api {
 
     my $li_ids = $e->search_acq_lineitem({picklist => $pl_id}, {idlist => 1});
 
+    # get the current user
+    my $cloner = $mgr->editor->requestor->id;
+
     for my $li_id (@$li_ids) {
 
-        # copy the lineitems
-        my $li = $e->retrieve_acq_lineitem($li_id);
-        my $new_li = create_lineitem($mgr, %{$li->to_bare_hash}, picklist => $new_pl->id) or return $e->die_event;
+        # copy the lineitems' MARC
+        my $marc = ($e->retrieve_acq_lineitem($li_id))->marc;
 
-        my $lid_ids = $e->search_acq_lineitem_detail({lineitem => $li_id}, {idlist => 1});
-        for my $lid_id (@$lid_ids) {
+        # create a skeletal clone of the item
+        my $li = Fieldmapper::acq::lineitem->new;
+        $li->creator($cloner);
+        $li->selector($cloner);
+        $li->editor($cloner);
+        $li->marc($marc);
 
-            # copy the lineitem details
-            my $lid = $e->retrieve_acq_lineitem_detail($lid_id);
-            create_lineitem_detail($mgr, %{$lid->to_bare_hash}, lineitem => $new_li->id) or return $e->die_event;
-        }
+        my $new_li = create_lineitem($mgr, %{$li->to_bare_hash}, picklist => $new_pl->id) or return $e->die_event;
 
         $mgr->respond;
     }