From 350d98f98284e8dac8906635d5593ca50edc564b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sun, 3 May 2020 00:03:59 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 71 +++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index c81bb3a..0059dc9 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -257,8 +257,8 @@ namespace AyaNova.PlugIn.V8 await ExportHeadOffices(progress); await ExportContracts(progress); await ExportLoanItems(progress); - //await ExportParts(progress); - //await ExportProjects(progress); + await ExportParts(progress); + await ExportProjects(progress); //await ExportPurchaseOrders(progress); //await ExportUnits(progress); //await ExportUnitModels(progress); @@ -748,6 +748,73 @@ namespace AyaNova.PlugIn.V8 } #endregion LoanItems + #region Parts + private async System.Threading.Tasks.Task ExportParts(ProgressForm progress) + { + if (!progress.KeepGoing) return; + var ObjectTypeName = "Part"; + var RavenObjectName = "Part"; + //Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too + var ocf = ObjectHasCustomFieldDataToExport(ObjectTypeName); + bool ShouldExportCustom = ocf != null; + var DateCustomFields = await ExportCustomFieldSchema(ocf, ObjectTypeName, RavenObjectName); + + //Step 2: export the objects + PartPickList pl=PartPickList.GetAllParts(); + // PickListAutoComplete pl = PickListAutoComplete.GetList("**", "loanitem"); + progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s"); + + foreach (PartPickList.PartPickListInfo i in pl) + { + if (!progress.KeepGoing) return; + List tags = new List(); + tags.Add(ImportTag); + + Part c = Part.GetItem(i.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.Part, c.ID); + + dynamic d = new JObject(); + d.name = i.DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat); + progress.Op(ObjectTypeName + " " + d.name); + d.active = c.Active; + d.notes = c.Notes; + + SetTags(d, tags); + + var hasWiki = WikiPage.HasWiki(c.ID); + if (hasWiki) + { + d.wiki = GetWikiContent(ObjectTID); + } + + //Custom fields? + if (ShouldExportCustom) + d.customFields = CustomFieldData(c, DateCustomFields); + + var rMainObject = await util.PostAsync(RavenObjectName, d.ToString()); + long RavenId = util.IdFromResponse(rMainObject); + Map.Add(c.ID, RavenId); + + //Attachments / FILES + await ExportAttachments(ObjectTID, progress); + + //docs + string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress); + if (!string.IsNullOrEmpty(NonFileUrls)) + { + //need to repost the object with the notes modified + d = rMainObject.ObjectResponse["data"]; + d.notes = NonFileUrls + "\n-----------------\n" + d.notes; + await util.PutAsync(RavenObjectName + "/" + RavenId.ToString(), d.ToString()); + } + + //Event log fixup + await util.EventLog(util.AyaType.Part, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified); + + } + } + #endregion Parts + #region locales private async System.Threading.Tasks.Task ExportLocales(ProgressForm progress)