LP#1745427: account for change in prediction patterns
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 20 Sep 2018 22:26:47 +0000 (18:26 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 21 Sep 2018 15:18:52 +0000 (11:18 -0400)
This patch fixes a bug in the web staff client where changing
the active prediction pattern for a subscription would not
reset the base issue when predicting the next run of issues.

To test
-------
1. Set up a subscription in the web staff client with a prediction
   pattern (e.g., monthly).  Predict some issues.
2. Create/select a new prediction pattern for a new publishing schedule,
   e.g., quarterly.
3. Activate the new pattern and deactivate the old pattern.
4. Click Predict New Issues.
5. Enter in the new publication date/enumerations/chronology as needed.
6. Enter a prediction count and select Save. Note that new issues
   appear to be based on the previous pattern.
7. Apply the patch, delete the issues created in step 6, then repeat
   steps 4-6.  This time, new issues should be created using the new
   prediction pattern.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/web/js/ui/default/staff/serials/services/core.js

index ccbcbb5..42e76dc 100644 (file)
@@ -316,6 +316,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         if (!sub) return args;
 
         var scap;
+        var pattern_changed = false;
         if (prev_iss && prev_iss.holding_code()) { // we're predicting
             var old_link_parts = JSON.parse(prev_iss.holding_code())[3].split('.');
             var olink = old_link_parts[0];
@@ -327,9 +328,14 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
 
             if (prev_iss.caption_and_pattern()) {
                 var tmp = sub.scaps().filter(function (s) {
-                    return (s.id() == prev_iss.caption_and_pattern());
+                    return (s.id() == prev_iss.caption_and_pattern() && s.active() == 't');
                 });
-                if (angular.isArray(tmp) && tmp[0]) scap = tmp[0];
+                if (angular.isArray(tmp) && tmp[0]) {
+                    scap = tmp[0];
+                } else {
+                    // pattern associated with last issue must no longer be active
+                    pattern_changed = true;
+                }
             }
 
             date = new Date(prev_iss.date_published());
@@ -379,7 +385,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         var freq_index = pat.indexOf('w');
         if (freq_index > -1) {
             freq = pat[freq_index + 1];
-            if (prev_iss) {
+            if (prev_iss && !args.pattern_changed) {
                 date = new Date(
                     date.getTime() + service.freq_offset[freq]
                 );
@@ -448,7 +454,8 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
             chrons       : chrons,
             others       : others,
             freq         : freq,
-            adhoc        : adhoc
+            adhoc        : adhoc,
+            pattern_changed : pattern_changed
         };
     }
 
@@ -1173,7 +1180,9 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
             }).then(function(hc) {
     
                 var base_iss;
-                if (!lastItem) {
+                var include_base_iss = 0;
+                if (!lastItem || hc.pattern_changed) {
+                    include_base_iss = 1;
                     base_iss = new egCore.idl.siss();
                     base_iss.creator( egCore.auth.user().id() );
                     base_iss.editor( egCore.auth.user().id() );
@@ -1183,7 +1192,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
                     base_iss.holding_code( JSON.stringify(hc.holding_code) );
                     base_iss.holding_type( hc.type );
                 }
-    
+
                 // if we're predicting without a preexisting holding, reduce the count
                 if (!lastItem) hc.count--;
     
@@ -1192,7 +1201,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
                     'open-ils.serial.make_predictions',
                     egCore.auth.token(),
                     { ssub_id : mySsubId,
-                      include_base_issuance : lastItem ? 0 : 1,
+                      include_base_issuance : include_base_iss,
                       num_to_predict : hc.count,
                       base_issuance : base_iss || lastItem
                     }