From: Galen Charlton Date: Thu, 20 Sep 2018 22:26:47 +0000 (-0400) Subject: LP#1745427: account for change in prediction patterns X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1c3b4a9fac28e1e49234837debb275a8665abb40;p=working%2FEvergreen.git LP#1745427: account for change in prediction patterns 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 Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/web/js/ui/default/staff/serials/services/core.js b/Open-ILS/web/js/ui/default/staff/serials/services/core.js index ccbcbb5a28..42e76dcc3f 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/services/core.js +++ b/Open-ILS/web/js/ui/default/staff/serials/services/core.js @@ -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 }