This commit is contained in:
2021-01-02 19:55:38 +00:00
parent fbaf59ba2f
commit 676fc0b756

View File

@@ -199,6 +199,15 @@ namespace AyaNova.PlugIn.V8
return V7ToV8IdMap[id];
}
private long? Getv7v8IdMapNullOk(Guid id)
{
if (id == Guid.Empty) return null;
if (!V7ToV8IdMap.ContainsKey(id)) return null;
return V7ToV8IdMap[id];
}
private long SafeGetUserMap(Guid id)
{
@@ -1587,7 +1596,7 @@ namespace AyaNova.PlugIn.V8
//Step 2: export the objects
UnitPickList pl = UnitPickList.GetListOfAll();
progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s");
progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s (step 1/2)");
foreach (UnitPickList.UnitPickListInfo i in pl)
{
@@ -1599,12 +1608,44 @@ namespace AyaNova.PlugIn.V8
var ObjectTID = new TypeAndID(RootObjectTypes.Unit, c.ID);
dynamic d = new JObject();
d.name = GetUniqueName(c.Serial);
d.Serial = c.Serial;
if (IsDuplicatev7v8IdMapItem(c.ID, c.Serial, progress)) continue;
progress.Op(ObjectTypeName + " " + d.name);
d.active = c.Active;
d.notes = c.Notes;
// Tagit(c.RegionID, tags);
d.customerId = Getv7v8IdMap(c.ClientID, "Client for Unit " + d.name);
// d.parentUnitId = Getv7v8IdMapNullOk(c.ParentID);
d.unitModelId = Getv7v8IdMapNullOk(c.UnitModelID);
d.unitHasOwnAddress = c.UnitHasOwnAddress;
d.boughtHere = c.BoughtHere;
d.purchasedFromVendorId = Getv7v8IdMapNullOk(c.PurchasedFromID);
d.receipt = c.Receipt;
d.purchasedDate = util.DateToV8(c.PurchasedDate);
d.description = c.Description;
d.replacedByUnitId = null;
d.parentUnitId = null;
d.overrideModelWarranty = c.OverrideModelWarranty;
if (c.WarrantyLength != 0)
d.warrantyLength = c.WarrantyLength;
d.warrantyTerms = c.WarrantyTerms;
d.usesBanking = c.UsesBanking;
d.metered = c.Metered;
d.lifeTimeWarranty = c.LifeTimeWarranty;
d.text1 = c.Text1;
d.text2 = c.Text2;
d.text3 = c.Text3;
d.text4 = c.Text4;
if (c.UnitHasOwnAddress)
{
d.address = c.GoToAddress.DeliveryAddress;
d.city = c.GoToAddress.City;
d.region = c.GoToAddress.StateProv;
d.country = c.GoToAddress.Country;
d.latitude = c.GoToAddress.Latitude;
d.longitude = c.GoToAddress.Longitude;
}
SetTags(d, tags);
if (c.UsesBanking)
@@ -1643,11 +1684,32 @@ namespace AyaNova.PlugIn.V8
await util.PutAsync("unit", d.ToString());
//-----
//DONT DO THIS for second steppers UNTIL THE SECOND STEP BELOW OR IT WILL BE WRONG for them
//Event log fixup
await util.EventLog(util.AyaType.Unit, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified);
if (c.ParentID == Guid.Empty && c.ReplacedByUnitID == Guid.Empty)
await util.EventLog(util.AyaType.Unit, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified);
}
//################# Now loop through the units again and set parent and replaced ID's
progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s (step 2/2)");
foreach (UnitPickList.UnitPickListInfo i in pl)
{
if (!progress.KeepGoing) return;
Unit c = Unit.GetItem(i.ID);
if (c.ParentID == Guid.Empty && c.ReplacedByUnitID == Guid.Empty) continue;
var ObjectTID = new TypeAndID(RootObjectTypes.Unit, c.ID);
dynamic d = util.GetAsync("unit/" + Getv7v8IdMap(c.ID, "Unit for parent / replaced by unit step 2 unit import").ToString());
progress.Op(ObjectTypeName + " " + d.name);
d.replacedByUnitId = Getv7v8IdMapNullOk(c.ReplacedByUnitID);
d.parentUnitId = Getv7v8IdMapNullOk(c.ParentID);
if (d.parentUnitId != null || d.replacedByUnitId != null)
await util.PutAsync("unit", d.ToString());
//-----
//Event log fixup
await util.EventLog(util.AyaType.Unit, d.id, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified);
}
}
#endregion Units