Two binding fixes for manage items
authordbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Feb 2011 16:47:49 +0000 (16:47 +0000)
committerdbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 3 Feb 2011 16:47:49 +0000 (16:47 +0000)
The first fix is more or less cosmetic.  When selecting a target unit, both areas need to refresh in order to not show the selected unit's items in the main list.

The second fix involves handling cases where moving items from one unit to another does not empty the 'donor' unit.  In those cases, we need to update the contents of both the new and the old unit.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19373 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
Open-ILS/xul/staff_client/server/serial/manage_items.js

index c70aefe..efd3da1 100644 (file)
@@ -1063,6 +1063,11 @@ __PACKAGE__->register_method(
                  name => 'call_numbers',
                  desc => 'hash of item_ids => call_numbers',
                  type => 'hash'
+            },
+            {
+                 name => 'donor_unit_ids',
+                 desc => 'hash of unit_ids => 1, keyed with ids of any units giving up items',
+                 type => 'hash'
             }
         ],
         'return' => {
@@ -1093,6 +1098,11 @@ __PACKAGE__->register_method(
                  name => 'call_numbers',
                  desc => 'hash of item_ids => call_numbers',
                  type => 'hash'
+            },
+            {
+                 name => 'donor_unit_ids',
+                 desc => 'hash of unit_ids => 1, keyed with ids of any units giving up items',
+                 type => 'hash'
             }
         ],
         'return' => {
@@ -1125,7 +1135,7 @@ __PACKAGE__->register_method(
 );
 
 sub unitize_items {
-    my ($self, $conn, $auth, $items, $barcodes, $call_numbers) = @_;
+    my ($self, $conn, $auth, $items, $barcodes, $call_numbers, $donor_unit_ids) = @_;
 
     my $editor = new_editor("authtoken" => $auth, "xact" => 1);
     return $editor->die_event unless $editor->checkauth;
@@ -1134,6 +1144,9 @@ sub unitize_items {
     my $mode = $1;
     
     my %found_unit_ids;
+    if ($donor_unit_ids) { # units giving up items need updating as well
+        %found_unit_ids = %$donor_unit_ids;
+    }
     my %found_stream_ids;
     my %found_types;
 
@@ -1262,8 +1275,24 @@ sub unitize_items {
             $call_number_string = $call_number_by_unit_id{$unit_id};
             $record_id = $sdist->subscription->record_entry;
         } else {
+            # XXX: this code assumes you will not have units which mix streams/distributions, but current code does not enforce this
             $sunit = $editor->retrieve_serial_unit($unit_id);
-            $sdist = $editor->search_serial_distribution([{"+sstr" => {"id" => $stream_ids_by_unit_id{$unit_id}}}, { "join" => {"sstr" => {}} }]);
+            if ($stream_ids_by_unit_id{$unit_id}) {
+                $sdist = $editor->search_serial_distribution([{"+sstr" => {"id" => $stream_ids_by_unit_id{$unit_id}}}, { "join" => {"sstr" => {}}, 'limit' => 1 }]);
+            } else {
+                $sdist = $editor->search_serial_distribution([
+                    {'+sunit' => {'id' => $unit_id}},
+                    { 'join' =>
+                        {'sstr' =>
+                            { 'join' =>
+                                { 'sitem' =>
+                                    { 'join' => 'sunit' }
+                                } 
+                            } 
+                        },
+                      'limit' => 1
+                    }]);
+            }
             $sdist = $sdist->[0];
         }
 
index e781237..b7cfc3e 100644 (file)
@@ -304,7 +304,10 @@ serial.manage_items.prototype = {
                                 var sstr_id = target.getAttribute('sstr_id');
                                 obj.set_sunit(sunit_id, label, sdist_id, sstr_id);
                                 obj.save_sunit(sunit_id, label, sdist_id, sstr_id);
-                                if (obj.mode == 'bind') obj.refresh_list('workarea');
+                                if (obj.mode == 'bind') {
+                                    obj.refresh_list('main');
+                                    obj.refresh_list('workarea');
+                                }
                             } catch(E) {
                                 obj.error.standard_unexpected_error_alert('cmd_set_sunit failed!',E);
                             }
@@ -314,7 +317,10 @@ serial.manage_items.prototype = {
                         ['command'],
                         function() {
                             obj.set_other_sunit();
-                            if (obj.mode == 'bind') obj.refresh_list('workarea');
+                            if (obj.mode == 'bind') {
+                                obj.refresh_list('main');
+                                obj.refresh_list('workarea');
+                            }
                         }
                     ],
                     'cmd_predict_items' : [
@@ -328,10 +334,14 @@ serial.manage_items.prototype = {
                         function() {
                             try {
                                 JSAN.use('util.functional');
+                                var donor_unit_ids = {};
                                 var list = util.functional.map_list(
                                         obj.retrieve_ids,
                                         function (o) {
                                             var item = obj.list_sitem_map[o.sitem_id];
+                                            if (item.unit()) {
+                                                donor_unit_ids[item.unit().id()] = 1;
+                                            }
                                             item.unit(obj.current_sunit_id);
                                             return item;
                                         }
@@ -439,7 +449,7 @@ serial.manage_items.prototype = {
                                 var robj = obj.network.request(
                                             'open-ils.serial',
                                             method,
-                                            [ ses(), list, barcodes, call_numbers ]
+                                            [ ses(), list, barcodes, call_numbers, donor_unit_ids ]
                                         );
                                 if (typeof robj.ilsevent != 'undefined') throw(robj); //TODO: catch for override