This commit is contained in:
@@ -6,6 +6,8 @@ Import / export features
|
|||||||
TODO:
|
TODO:
|
||||||
OUTSTANDING FOR IMPORT:
|
OUTSTANDING FOR IMPORT:
|
||||||
Unit, Unitmodel, vendor, INVENTORY
|
Unit, Unitmodel, vendor, INVENTORY
|
||||||
|
HeadOffice contract code sb more like unit contract code with null vs empty handling of json
|
||||||
|
CustomerBiz contract code sb mroe like unit contract and updateable (update docs too to show it can be updated currently says no)
|
||||||
test each object
|
test each object
|
||||||
document each object
|
document each object
|
||||||
Once all importers are done, add to changes from v7 that import is now built in including UPDATE ability and included with v8 no longer a plugin
|
Once all importers are done, add to changes from v7 that import is now built in including UPDATE ability and included with v8 no longer a plugin
|
||||||
|
|||||||
@@ -432,11 +432,9 @@ namespace AyaNova.Biz
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Compile linked objects if specified
|
//Compile linked objects if specified
|
||||||
long? ImportCustomerId = -1;//default meaning not included / don't set
|
long ImportCustomerId = 0; //customer is required, can't be null so set to a definite bad setting
|
||||||
if (j["CustomerViz"] != null)
|
if (j["CustomerViz"] != null)
|
||||||
{
|
{
|
||||||
//something was specified, may be deliberate attempt to null it out so default to that
|
|
||||||
ImportCustomerId = null;
|
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["CustomerViz"]))
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["CustomerViz"]))
|
||||||
{
|
{
|
||||||
//a name was specified so attempt to find it
|
//a name was specified so attempt to find it
|
||||||
@@ -498,26 +496,25 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long? ImportContractId = -1;
|
long? ImportContractId = -1;
|
||||||
DateTime? ImportContractExpires = null;
|
DateTime? ImportContractExpires = null;
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
if (j["ContractViz"] != null)
|
||||||
{
|
{
|
||||||
ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
ImportContractId = null;
|
||||||
if (ImportContractId == 0)
|
if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"]))
|
||||||
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
{
|
||||||
|
ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
if (ImportContractId == 0)
|
||||||
ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'");
|
||||||
else
|
if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"]))
|
||||||
ImportContractExpires = (DateTime)j["ContractExpires"];
|
ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be
|
||||||
|
else
|
||||||
|
ImportContractExpires = (DateTime)j["ContractExpires"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long existingId = await ct.Unit.AsNoTracking().Where(z => z.Serial == (string)j["Serial"]).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
long existingId = await ct.Unit.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (existingId == 0)
|
if (existingId == 0)
|
||||||
{
|
{
|
||||||
if (importData.DoImport)
|
if (importData.DoImport)
|
||||||
@@ -526,24 +523,35 @@ namespace AyaNova.Biz
|
|||||||
var Target = j.ToObject<Unit>(jsset);
|
var Target = j.ToObject<Unit>(jsset);
|
||||||
Target.Tags.Add(ImportTag);
|
Target.Tags.Add(ImportTag);
|
||||||
|
|
||||||
if (ImportCustomerId != -1)
|
Target.CustomerId = ImportCustomerId;
|
||||||
Target.ManufacturerId = ImportCustomerId;
|
|
||||||
|
|
||||||
if (ImportParentUnitId != -1)
|
if (ImportParentUnitId != -1)
|
||||||
Target.WholeSalerId = ImportParentUnitId;
|
Target.ParentUnitId = ImportParentUnitId;
|
||||||
|
|
||||||
if (ImportUnitModelId != -1)
|
if (ImportUnitModelId != -1)
|
||||||
Target.AlternativeWholeSalerId = ImportUnitModelId;
|
Target.UnitModelId = ImportUnitModelId;
|
||||||
|
|
||||||
|
if (ImportPurchasedFromVendorId != -1)
|
||||||
|
Target.PurchasedFromVendorId = ImportPurchasedFromVendorId;
|
||||||
|
|
||||||
|
if (ImportReplacedByUnitId != -1)
|
||||||
|
Target.ReplacedByUnitId = ImportReplacedByUnitId;
|
||||||
|
|
||||||
|
if (ImportContractId != -1)
|
||||||
|
{
|
||||||
|
Target.ContractId = ImportContractId;
|
||||||
|
Target.ContractExpires = ImportContractExpires;
|
||||||
|
}
|
||||||
|
|
||||||
var res = await CreateAsync(Target);
|
var res = await CreateAsync(Target);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}");
|
ImportResult.Add($"❌ {Target.Serial}\r\n{this.GetErrorsAsString()}");
|
||||||
this.ClearErrors();
|
this.ClearErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
ImportResult.Add($"✔️ {Target.Serial}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -556,26 +564,39 @@ namespace AyaNova.Biz
|
|||||||
var Target = await GetAsync((long)existingId);
|
var Target = await GetAsync((long)existingId);
|
||||||
var Source = j.ToObject<Unit>(jsset);
|
var Source = j.ToObject<Unit>(jsset);
|
||||||
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList();
|
||||||
propertiesToUpdate.Remove("Name");
|
propertiesToUpdate.Remove("Serial");
|
||||||
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
ImportUtil.Update(Source, Target, propertiesToUpdate);
|
||||||
if (ImportCustomerId != -1)
|
|
||||||
Target.ManufacturerId = ImportCustomerId;
|
Target.CustomerId = ImportCustomerId;
|
||||||
|
|
||||||
if (ImportParentUnitId != -1)
|
if (ImportParentUnitId != -1)
|
||||||
Target.WholeSalerId = ImportParentUnitId;
|
Target.ParentUnitId = ImportParentUnitId;
|
||||||
|
|
||||||
if (ImportUnitModelId != -1)
|
if (ImportUnitModelId != -1)
|
||||||
Target.AlternativeWholeSalerId = ImportUnitModelId;
|
Target.UnitModelId = ImportUnitModelId;
|
||||||
|
|
||||||
|
if (ImportPurchasedFromVendorId != -1)
|
||||||
|
Target.PurchasedFromVendorId = ImportPurchasedFromVendorId;
|
||||||
|
|
||||||
|
if (ImportReplacedByUnitId != -1)
|
||||||
|
Target.ReplacedByUnitId = ImportReplacedByUnitId;
|
||||||
|
|
||||||
|
if (ImportContractId != -1)
|
||||||
|
{
|
||||||
|
Target.ContractId = ImportContractId;
|
||||||
|
Target.ContractExpires = ImportContractExpires;
|
||||||
|
}
|
||||||
|
|
||||||
var res = await PutAsync(Target);
|
var res = await PutAsync(Target);
|
||||||
|
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}");
|
ImportResult.Add($"❌ {Target.Serial} - {this.GetErrorsAsString()}");
|
||||||
this.ClearErrors();
|
this.ClearErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ImportResult.Add($"✔️ {Target.Serial}");
|
||||||
ImportResult.Add($"✔️ {Target.Name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user