From 6ded11c2fbc5152008c583f6f1ee5d6fbce1b74e Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 3 Sep 2021 19:52:50 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index dbffa04..c2d5510 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -239,7 +239,7 @@ namespace AyaNova.PlugIn.V8 //UNKNOWN / MISSING RECORD OBJECT STAND INs - private long UnknownV7PartId = 0;//used when there is no part id on a workorderitempart record + private string MissingDataNamePrefix = "zV8migrate_substitute";//append guid to ensure uniqueness @@ -423,7 +423,7 @@ namespace AyaNova.PlugIn.V8 //as of this time it's the only slow thing affecting migrate mode settling in progress.SubOp("Pausing 7 seconds to give server time to complete current jobs and settle into migrate mode"); await System.Threading.Tasks.Task.Delay(7000); - + mSubstitutePartId = 0; ResetUniqueUserNames(); ResetUniqueNames(); Allv8WarehouseIds.Clear(); @@ -1891,24 +1891,29 @@ namespace AyaNova.PlugIn.V8 } } } + } + private long mSubstitutePartId = 0; + private async System.Threading.Tasks.Task GetSubstitutePartId() + { + if (mSubstitutePartId != 0) return mSubstitutePartId; + //needs to be made //UntrackedV7PartId //create a part just to hold untracked parts from v7 which are partid guid.empty on workorderitempart records which was allowed in v7 but not in v8 dynamic dx = new JObject(); dx.name = MissingDataNamePrefix; dx.partNumber = GetUniqueName(MissingDataNamePrefix); - progress.Op(ObjectTypeName + " " + dx.partNumber + " " + dx.name); dx.cost = 0; dx.retail = 0; dx.uPC = string.Empty; dx.unitOfMeasure = "each"; dx.active = false; - dx.notes = "This part created by v8 migrate plugin so work order item part records with no (or no valid) selected part can be migrated to v8\nv7 allowed work order item part entry without a corresponding Part record but v8 does not\nThis part stands in for those missing parts from v7\nThis record can be deleted after migration if no work order item parts rely on it"; + dx.notes = "This part created by v8 migrate plugin so work order item part records with no (or no valid) selected part can be migrated to v8\r\nv7 allowed work order item part entry without a corresponding Part record but v8 does not\r\nThis part stands in for those missing parts from v7\r\n"; List dxtags = new List(); AddImportTag(dxtags); SetTags(dx, dxtags); - UnknownV7PartId = util.IdFromResponse(await util.PostAsync("part", dx.ToString())); + mSubstitutePartId = util.IdFromResponse(await util.PostAsync("part", dx.ToString())); if (V7UseInventory) { @@ -1917,13 +1922,17 @@ namespace AyaNova.PlugIn.V8 //create opening initial inventory just so migrate can proceed without v8 balking dynamic di = new JObject(); di.description = "v8 migrate temporary initial inventory to allow migration"; - di.partId = UnknownV7PartId; + di.partId = mSubstitutePartId; di.partWarehouseId = l; di.quantity = 1000000000m;//one billion should cover it await util.PostAsync("part-inventory", di.ToString()); } } + return mSubstitutePartId; } + + + #endregion Parts @@ -3385,7 +3394,7 @@ namespace AyaNova.PlugIn.V8 var tryPartId = await Getv7v8IdMapNullOk(wip.PartID, RootObjectTypes.Part); if (tryPartId == null) { - dwip.partId = UnknownV7PartId; + dwip.partId = await GetSubstitutePartId(); if (wip.Quantity == 0 && string.IsNullOrWhiteSpace(wip.Description)) continue; //no part record, no quantity, no text at all, just skip it } @@ -3910,7 +3919,7 @@ namespace AyaNova.PlugIn.V8 var tryPartId = await Getv7v8IdMapNullOk(wip.PartID, RootObjectTypes.Part); if (tryPartId == null) { - dwip.partId = UnknownV7PartId; + dwip.partId = await GetSubstitutePartId(); if (wip.Quantity == 0 && string.IsNullOrWhiteSpace(wip.Description)) continue; //no part record, no quantity, no text at all, just skip it } @@ -4263,7 +4272,7 @@ namespace AyaNova.PlugIn.V8 var tryPartId = await Getv7v8IdMapNullOk(wip.PartID, RootObjectTypes.Part); if (tryPartId == null) { - dwip.partId = UnknownV7PartId; + dwip.partId = await GetSubstitutePartId(); if (wip.Quantity == 0 && string.IsNullOrWhiteSpace(wip.Description)) continue; //no part record, no quantity, no text at all, just skip it } @@ -4827,8 +4836,10 @@ namespace AyaNova.PlugIn.V8 } //Clear out inventory for special unknown missing part created in v8 for potentially missing parts + if(mSubstitutePartId!=0) { - JObject v8inv = (await util.GetAsync("part/latest-inventory/" + UnknownV7PartId)).ObjectResponse; + + JObject v8inv = (await util.GetAsync("part/latest-inventory/" + mSubstitutePartId)).ObjectResponse; //iterate v8 inventory foreach (JObject v8o in v8inv["data"]) { @@ -4838,7 +4849,7 @@ namespace AyaNova.PlugIn.V8 { dynamic di = new JObject(); di.description = "v8 migrate synchronize inventory"; - di.partId = UnknownV7PartId; + di.partId = mSubstitutePartId; di.partWarehouseId = (long)v8o["partWarehouseId"]; di.quantity = dAdjust; await util.PostAsync("part-inventory", di.ToString());