fix: Implement product lookup in RecordLoss method to accurately reduce inventory on loss
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m50s

This commit is contained in:
masoodafar-web
2026-01-05 00:58:52 +03:30
parent d03fbe0a98
commit f6704eaa99
@@ -222,10 +222,35 @@ public class InventoryService : InventoryContract.InventoryContractBase
throw new RpcException(new Status(StatusCode.Unimplemented, "ProcessReturn requires product lookup - not yet implemented"));
}
public override Task<Empty> RecordLoss(RecordLossRequest request, ServerCallContext context)
public override async Task<Empty> RecordLoss(RecordLossRequest request, ServerCallContext context)
{
// TODO: Implement with product lookup
throw new RpcException(new Status(StatusCode.Unimplemented, "RecordLoss requires product lookup - not yet implemented"));
// Lookup InventoryItem by ProductId + ProductType
var inventoryItem = await _mediator.Send(
new GetInventoryByProductQuery
{
ProductId = request.ProductId,
ProductType = (Domain.Enums.ProductType)request.ProductType
},
context.CancellationToken);
if (inventoryItem == null)
{
throw new RpcException(new Status(StatusCode.NotFound,
$"Inventory item not found for ProductId={request.ProductId}, ProductType={request.ProductType}"));
}
// Execute ReduceInventoryCommand to record the loss
await _mediator.Send(
new ReduceInventoryCommand
{
Id = inventoryItem.Id,
Quantity = request.Quantity,
FromReserved = false,
ReferenceNumber = request.ReferenceNumber ?? $"LOSS-{DateTime.UtcNow:yyyyMMddHHmmss}"
},
context.CancellationToken);
return new Empty();
}
// ========== Bulk Operations ==========