Fix time entry 500 and inventory edit pencil visibility
- Remove parseInt() from time entry worker select — GUIDs were destroyed to NaN → sent as null → FindByIdAsync(null) threw 500 - Ledger pencil: also show for Adjustment rows (no PO) so scan-without-job entries get an edit button, not just JobUsage rows - InventoryController: always write JobUsage type for scan-based logs; accept Adjustment in edit endpoints; promote Adjustment→JobUsage when a job is assigned via edit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1424,8 +1424,8 @@ public class InventoryController : Controller
|
||||
}
|
||||
|
||||
var userId = _userManager.GetUserId(User) ?? string.Empty;
|
||||
var txnType = jobId.HasValue ? InventoryTransactionType.JobUsage
|
||||
: (Enum.TryParse<InventoryTransactionType>(transactionType, out var parsed) ? parsed : InventoryTransactionType.Adjustment);
|
||||
// Scan-based logging always records as JobUsage; Adjustment is for manual stock corrections only
|
||||
var txnType = InventoryTransactionType.JobUsage;
|
||||
|
||||
item.QuantityOnHand -= quantity;
|
||||
item.UpdatedAt = DateTime.UtcNow;
|
||||
@@ -1719,8 +1719,9 @@ public class InventoryController : Controller
|
||||
var txn = await _unitOfWork.InventoryTransactions.GetByIdAsync(id, false,
|
||||
t => t.Job, t => t.InventoryItem);
|
||||
if (txn == null) return NotFound();
|
||||
if (txn.TransactionType != InventoryTransactionType.JobUsage)
|
||||
return BadRequest("Only JobUsage transactions can be edited here.");
|
||||
if (txn.TransactionType != InventoryTransactionType.JobUsage
|
||||
&& txn.TransactionType != InventoryTransactionType.Adjustment)
|
||||
return BadRequest("Only usage transactions can be edited here.");
|
||||
|
||||
var allJobs = await _unitOfWork.Jobs.FindAsync(
|
||||
j => !j.JobStatus.IsTerminalStatus,
|
||||
@@ -1762,7 +1763,8 @@ public class InventoryController : Controller
|
||||
{
|
||||
var txn = await _unitOfWork.InventoryTransactions.GetByIdAsync(id);
|
||||
if (txn == null) return NotFound();
|
||||
if (txn.TransactionType != InventoryTransactionType.JobUsage)
|
||||
if (txn.TransactionType != InventoryTransactionType.JobUsage
|
||||
&& txn.TransactionType != InventoryTransactionType.Adjustment)
|
||||
return BadRequest();
|
||||
|
||||
if (jobId.HasValue)
|
||||
@@ -1777,6 +1779,10 @@ public class InventoryController : Controller
|
||||
txn.Reference = null;
|
||||
}
|
||||
|
||||
// Promote Adjustment→JobUsage when a job is assigned so it shows in Powder Usage By Job tab
|
||||
if (jobId.HasValue && txn.TransactionType == InventoryTransactionType.Adjustment)
|
||||
txn.TransactionType = InventoryTransactionType.JobUsage;
|
||||
|
||||
txn.Notes = notes?.Trim();
|
||||
txn.TransactionDate = transactionDate.Kind == DateTimeKind.Utc
|
||||
? transactionDate : DateTime.SpecifyKind(transactionDate, DateTimeKind.Utc);
|
||||
|
||||
Reference in New Issue
Block a user