This commit is contained in:
2021-06-04 15:08:21 +00:00
parent d6792262cb
commit c936ff5e3e
2 changed files with 54 additions and 44 deletions

View File

@@ -8,5 +8,5 @@ Inventory changes from v7 with new workorder system
No "Used in service", now Parts are consumed immediately from inventory when selected on workorder and saved No "Used in service", now Parts are consumed immediately from inventory when selected on workorder and saved
Work order item part records consume or return inventory immediately upon save or delete or changes Work order item part records consume or return inventory immediately upon save or delete or changes
Serial numbers are likewise immediately consumed / returned to the pool upon edits to workorder item part records Serial numbers are likewise immediately consumed / returned to the pool upon edits to workorder item part records
A zero quantity part will be considered a "placeholder" and will neither affect inventory nor serial numbers until a quantity is entered and saved

View File

@@ -3454,7 +3454,7 @@ namespace AyaNova.Biz
//CREATED, HANDLE INVENTORY / CONSUME SERIALS //CREATED, HANDLE INVENTORY / CONSUME SERIALS
if (ayaEvent == AyaEvent.Created) if (ayaEvent == AyaEvent.Created && newObj.Quantity != 0)//allow zero quantity parts on workorder as placeholder, serials will not be consumed
{ {
dtInternalPartInventory pi = dtInternalPartInventory pi =
new dtInternalPartInventory new dtInternalPartInventory
@@ -3492,68 +3492,78 @@ namespace AyaNova.Biz
//UPDATED, HANDLE INVENTORY / UPDATE SERIALS AS REQUIRED //UPDATED, HANDLE INVENTORY / UPDATE SERIALS AS REQUIRED
if (ayaEvent == AyaEvent.Modified) if (ayaEvent == AyaEvent.Modified)
{ {
//determine if any changes affecting inventory //INVENTORY
if (newObj.PartId != oldObj.PartId || newObj.Quantity != oldObj.Quantity) if (newObj.PartId != oldObj.PartId || newObj.Quantity != oldObj.Quantity)
{ {
//OUT with the old //OUT with the old
dtInternalPartInventory piOld = new dtInternalPartInventory if (oldObj.Quantity != 0)//zero quantity doesn't affect inventory or serials
{ {
PartId = oldObj.PartId, dtInternalPartInventory piOld = new dtInternalPartInventory
PartWarehouseId = oldObj.PartWarehouseId, {
Quantity = oldObj.Quantity, PartId = oldObj.PartId,
SourceType = null,//null because the po no longer exists so this is technically a manual adjustment PartWarehouseId = oldObj.PartWarehouseId,
SourceId = null,//'' Quantity = oldObj.Quantity,
Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted") SourceType = null,//null because the po no longer exists so this is technically a manual adjustment
}; SourceId = null,//''
if (await pib.CreateAsync(piOld) == null) Description = await Translate("WorkOrderItemPart") + $" {oldObj.Serials} " + await Translate("EventDeleted")
{ };
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piOld.Description}):{pib.GetErrorsAsString()}"); if (await pib.CreateAsync(piOld) == null)
return; {
} AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piOld.Description}):{pib.GetErrorsAsString()}");
else return;
{ //return serial numbers to part }
if (!string.IsNullOrWhiteSpace(oldObj.Serials)) else
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); { //return serial numbers to part
if (!string.IsNullOrWhiteSpace(oldObj.Serials))
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
}
} }
//IN with the new //IN with the new
dtInternalPartInventory piNew = new dtInternalPartInventory if (newObj.Quantity != 0)
{ {//NOTE: zero quantity is considered to be a placeholder and no serials will be consumed, nor inventory affected
PartId = newObj.PartId, dtInternalPartInventory piNew = new dtInternalPartInventory
PartWarehouseId = newObj.PartWarehouseId, {
Quantity = newObj.Quantity * -1, PartId = newObj.PartId,
SourceType = AyaType.WorkOrderItemPart, PartWarehouseId = newObj.PartWarehouseId,
SourceId = newObj.Id, Quantity = newObj.Quantity * -1,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated") SourceType = AyaType.WorkOrderItemPart,
}; SourceId = newObj.Id,
Description = await Translate("WorkOrderItemPart") + $" {newObj.Serials} " + await Translate("EventCreated")
};
if (await pib.CreateAsync(piNew) == null) if (await pib.CreateAsync(piNew) == null)
{ {
AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}"); AddError(ApiErrorCode.API_SERVER_ERROR, "generalerror", $"Error updating inventory ({piNew.Description}):{pib.GetErrorsAsString()}");
return; return;
} }
else else
{ //Consume serial numbers from part { //Consume serial numbers from part
if (!string.IsNullOrWhiteSpace(newObj.Serials)) if (!string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
}
} }
} }
else if (newObj.Serials != oldObj.Serials) //SERIALS
if (newObj.Serials != oldObj.Serials)
{ {
//Only a serial number adjustment so in and out all serials to be safe and not try to parse too closely //NOTE: zero quantity is considered to be a placeholder and no serials will be consumed (hence not returned either)
//return serial numbers to part //return serial numbers to part
if (!string.IsNullOrWhiteSpace(oldObj.Serials)) if (oldObj.Quantity != 0 && !string.IsNullOrWhiteSpace(oldObj.Serials))
await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId); await PartBiz.AppendSerialsAsync(oldObj.PartId, oldObj.Serials, ct, UserId);
//Consume serial numbers from part //Consume serial numbers from part
if (!string.IsNullOrWhiteSpace(newObj.Serials)) if (newObj.Quantity != 0 && !string.IsNullOrWhiteSpace(newObj.Serials))
await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId); await PartBiz.RemoveSerialsAsync(newObj.PartId, newObj.Serials, ct, UserId);
} }
} }
} }