This commit is contained in:
2021-08-23 18:16:23 +00:00
parent 155be2f03f
commit 80c59b44c9

View File

@@ -4005,15 +4005,14 @@ namespace AyaNova.Biz
// //
private async Task PartInventoryAdjustmentAsync(AyaEvent ayaEvent, WorkOrderItemPart newObj, WorkOrderItemPart oldObj, IDbContextTransaction transaction) private async Task PartInventoryAdjustmentAsync(AyaEvent ayaEvent, WorkOrderItemPart newObj, WorkOrderItemPart oldObj, IDbContextTransaction transaction)
{ {
if (AyaNova.Util.ServerGlobalBizSettings.Cache.UseInventory)
{
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles); PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
//DELETED, HANDLE INVENTORY / SERIALS //DELETED, HANDLE INVENTORY / SERIALS
if (ayaEvent == AyaEvent.Deleted && oldObj.Quantity != 0) if (ayaEvent == AyaEvent.Deleted && oldObj.Quantity != 0)
{ {
//NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//was originally a return of inventory so needs reversal //was originally a return of inventory so needs to consume the inventory back again
if (oldObj.Quantity < 0) if (oldObj.Quantity < 0)
{ {
dtInternalPartInventory pi = dtInternalPartInventory pi =
@@ -4021,7 +4020,7 @@ namespace AyaNova.Biz
{ {
PartId = oldObj.PartId, PartId = oldObj.PartId,
PartWarehouseId = oldObj.PartWarehouseId, PartWarehouseId = oldObj.PartWarehouseId,
Quantity = oldObj.Quantity * -1,//was originally returned so needs to be removed Quantity = oldObj.Quantity * -1,//was originally returned (negative) so needs to be consumed
SourceType = AyaType.WorkOrderItemPart, SourceType = AyaType.WorkOrderItemPart,
SourceId = oldObj.Id, SourceId = oldObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted") Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted")
@@ -4071,7 +4070,6 @@ namespace AyaNova.Biz
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
} }
} }
} }
@@ -4082,6 +4080,11 @@ namespace AyaNova.Biz
if (newObj.Quantity < 0) if (newObj.Quantity < 0)
{ {
//NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //NEGATIVE BLOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//NOTES: new record with negative quantity, this should only be a case where a customer is returning unused parts that were originally consumed by them on a work order
//this already requires the inventory full role during validation so if we're here it's allowed to happen
//in v7 this was openly allowed by anyone who could make a work order but it was a loophole to circumvent inventory adjustment system
//in v8 we allow it only for the narrowly defined pupose of reversing a prior work order consumption of parts but it's not really enforced in code other than requiring a
//inventory full role to do it so that the inventory person is at least involved in what's happening and can think it through
//RETURN INVENTORY //RETURN INVENTORY
dtInternalPartInventory pi = dtInternalPartInventory pi =
@@ -4089,11 +4092,30 @@ namespace AyaNova.Biz
{ {
PartId = newObj.PartId, PartId = newObj.PartId,
PartWarehouseId = newObj.PartWarehouseId, PartWarehouseId = newObj.PartWarehouseId,
Quantity = newObj.Quantity * -1, Quantity = newObj.Quantity,//is negative
SourceType = AyaType.WorkOrderItemPart, SourceType = AyaType.WorkOrderItemPart,
SourceId = newObj.Id, SourceId = newObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated") Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
}; };
if (await pib.CreateAsync(pi) == null)
{
if (pib.HasErrors)
{
foreach (var e in pib.Errors)
{
if (e.Code == ApiErrorCode.INSUFFICIENT_INVENTORY)
AddError(e.Code, "Quantity", e.Message);
else
AddError(e.Code, e.Target, e.Message);
}
}
return;
}
else
{ //Append serial numbers from part
if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.AppendSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
}
//<<<<<<<<<<<<<<<<<<<<<< NEGATIVE BLOCK //<<<<<<<<<<<<<<<<<<<<<< NEGATIVE BLOCK
} }
@@ -4202,7 +4224,7 @@ namespace AyaNova.Biz
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
} }
} }
}
} }
@@ -4253,6 +4275,7 @@ namespace AyaNova.Biz
return; return;
} }
if (AyaNova.Util.ServerGlobalBizSettings.Cache.UseInventory)
if (proposedObj.Quantity < 0 && !UserHasInventoryFullRole)//negative quantities are not allowed unless the user has inventory full role if (proposedObj.Quantity < 0 && !UserHasInventoryFullRole)//negative quantities are not allowed unless the user has inventory full role
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Quantity", await Translate("InventoryRoleRequired")); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Quantity", await Translate("InventoryRoleRequired"));