This commit is contained in:
2021-01-25 15:38:32 +00:00
parent 786a43aa40
commit d6f1430e69
4 changed files with 19 additions and 24 deletions

View File

@@ -54,8 +54,8 @@ namespace AyaNova.Biz
newObject.EntryDate = DateTime.UtcNow;
newObject.PartId = newDtObject.PartId;
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
newObject.SourceId = 0;
newObject.SourceType = AyaType.NoType;
newObject.SourceId = null;
newObject.SourceType = null;
newObject.Quantity = newDtObject.Quantity;
if (LastEntry != null)
@@ -162,6 +162,7 @@ namespace AyaNova.Biz
private async Task ValidateAsync(PartInventory proposedObj)
{
//NOTE: Many of these errors wouldn't happen in the official ayanova UI (api developer error only) so are not translated
if (!await BizObjectExistsInDatabase.ExistsAsync(AyaType.Part, proposedObj.PartId, ct))
{
AddError(ApiErrorCode.NOT_FOUND, "generalerror", $"PartInventory Part specified doesn't exist [id:{proposedObj.PartId}]");
@@ -174,21 +175,18 @@ namespace AyaNova.Biz
return;
}
if (proposedObj.SourceType != AyaType.NoType && proposedObj.SourceId != 0 && !await BizObjectExistsInDatabase.ExistsAsync(proposedObj.SourceType, proposedObj.SourceId, ct))
//Source id and type must either both be null or neither be null
if ((proposedObj.SourceId == null && proposedObj.SourceType != null) || (proposedObj.SourceId != null && proposedObj.SourceType == null))
{
AddError(ApiErrorCode.NOT_FOUND, "generalerror", $"PartInventory source object causing inventory change specified doesn't exist [type:{proposedObj.SourceType}, id:{proposedObj.SourceId}]");
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "Source type and id must be specified or both null for a manual adjustment");
return;
}
/*
"CONSTRAINT UNQ_PartInventory UNIQUE (sourceid, sourcetype, entrydate, balance), " +
"CONSTRAINT UNQ_PartInventory_Previous_values UNIQUE (sourceid, sourcetype, lastentrydate, lastbalance), " +
"CONSTRAINT fk_PartInventory_self FOREIGN KEY (sourceid, sourcetype, lastentrydate, lastbalance) references apartinventory(sourceid, sourcetype, entrydate, balance), " +
"CONSTRAINT CHK_PartInventory_Valid_Balance CHECK(balance >= 0 AND (balance = COALESCE(lastbalance, 0) + quantity)), " +
"CONSTRAINT CHK_PartInventory_Valid_Dates_Sequence CHECK(lastentrydate < entrydate), " +
"CONSTRAINT CHK_PartInventory_Valid_Previous_Columns CHECK((lastentrydate IS NULL AND lastbalance IS NULL) OR (lastentrydate IS NOT NULL AND lastbalance IS NOT NULL)) " +
*/
if (proposedObj.SourceType != null && proposedObj.SourceId != null && !await BizObjectExistsInDatabase.ExistsAsync((AyaType)proposedObj.SourceType, (long)proposedObj.SourceId, ct))
{
AddError(ApiErrorCode.NOT_FOUND, "generalerror", $"PartInventory source object causing inventory change specified doesn't exist [type:{proposedObj.SourceType}, id:{proposedObj.SourceId}]");
return;
}
//New entry must have *something* to bank
if (proposedObj.Quantity == 0)
@@ -214,8 +212,6 @@ namespace AyaNova.Biz
//valid previous columns?
//either they're all null or none of them are null
//fix and re-test
if (!((proposedObj.LastEntryDate == null
&& proposedObj.LastBalance == null) ||
(proposedObj.LastEntryDate != null