Label blank account option "(None)" when no company default is set
The item account dropdowns showed "(Default … account)" on the blank option even when the company hadn't configured a default — implying a fallback that didn't exist. Now the blank option reads "(None)" unless a matching company default is configured, in which case it keeps the "(Default …)" label (the dropdown pre-selects the real account anyway). "Has default" flags are computed in the shared dropdown-population helpers so every render path (Create/Edit GET and invalid-POST) gets them. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -693,6 +693,13 @@ namespace PowderCoating.Web.Controllers
|
||||
|
||||
ViewBag.RevenueAccounts = revenueAccounts;
|
||||
ViewBag.CogsAccounts = cogsAccounts;
|
||||
|
||||
// Whether the company has configured default accounts — the views use this to label the
|
||||
// blank dropdown option "(Default …)" vs "(None)".
|
||||
var prefs = await _unitOfWork.CompanyPreferences
|
||||
.FirstOrDefaultAsync(p => p.CompanyId == companyId && !p.IsDeleted);
|
||||
ViewBag.HasDefaultRevenueAccount = prefs?.DefaultRevenueAccountId != null;
|
||||
ViewBag.HasDefaultCogsAccount = prefs?.DefaultCogsAccountId != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1667,6 +1667,13 @@ public class InventoryController : Controller
|
||||
.OrderBy(a => a.AccountNumber)
|
||||
.Select(a => new SelectListItem($"{a.AccountNumber} – {a.Name}", a.Id.ToString()))
|
||||
.ToList();
|
||||
|
||||
// Whether the company has configured default accounts — the views use this to label the
|
||||
// blank dropdown option "(Default …)" vs "(None)".
|
||||
var prefs = await _unitOfWork.CompanyPreferences
|
||||
.FirstOrDefaultAsync(p => p.CompanyId == companyId && !p.IsDeleted);
|
||||
ViewBag.HasDefaultInventoryAccount = prefs?.DefaultInventoryAccountId != null;
|
||||
ViewBag.HasDefaultCogsAccount = prefs?.DefaultCogsAccountId != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="RevenueAccountId" class="form-label"></label>
|
||||
<select asp-for="RevenueAccountId" class="form-select" asp-items="ViewBag.RevenueAccounts">
|
||||
<option value="">(Default revenue account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultRevenueAccount ?? false) ? "(Default revenue account)" : "(None)")</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Account credited when this item is invoiced.</small>
|
||||
</div>
|
||||
@@ -139,7 +139,7 @@
|
||||
<label asp-for="CogsAccountId" class="form-label"></label>
|
||||
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=40" data-quick-add-title="Add COGS Account">
|
||||
<option value="">(Default COGS account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultCogsAccount ?? false) ? "(Default COGS account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Account debited when materials are consumed.</small>
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="RevenueAccountId" class="form-label"></label>
|
||||
<select asp-for="RevenueAccountId" class="form-select" asp-items="ViewBag.RevenueAccounts">
|
||||
<option value="">(Default revenue account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultRevenueAccount ?? false) ? "(Default revenue account)" : "(None)")</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Account credited when this item is invoiced.</small>
|
||||
</div>
|
||||
@@ -142,7 +142,7 @@
|
||||
<label asp-for="CogsAccountId" class="form-label"></label>
|
||||
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=40" data-quick-add-title="Add COGS Account">
|
||||
<option value="">(Default COGS account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultCogsAccount ?? false) ? "(Default COGS account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Account debited when materials are consumed.</small>
|
||||
|
||||
@@ -375,7 +375,7 @@
|
||||
<label asp-for="InventoryAccountId" class="form-label"></label>
|
||||
<select asp-for="InventoryAccountId" class="form-select" asp-items="ViewBag.InventoryAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=4" data-quick-add-title="Add Inventory Account">
|
||||
<option value="">(Default inventory account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultInventoryAccount ?? false) ? "(Default inventory account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Asset account where inventory value is tracked (e.g., 1200 Inventory - Powder).</small>
|
||||
@@ -384,7 +384,7 @@
|
||||
<label asp-for="CogsAccountId" class="form-label"></label>
|
||||
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=40" data-quick-add-title="Add COGS Account">
|
||||
<option value="">(Default COGS account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultCogsAccount ?? false) ? "(Default COGS account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Expense account debited when this material is consumed on a job.</small>
|
||||
|
||||
@@ -374,7 +374,7 @@
|
||||
<label asp-for="InventoryAccountId" class="form-label"></label>
|
||||
<select asp-for="InventoryAccountId" class="form-select" asp-items="ViewBag.InventoryAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=4" data-quick-add-title="Add Inventory Account">
|
||||
<option value="">(Default inventory account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultInventoryAccount ?? false) ? "(Default inventory account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Asset account where inventory value is tracked (e.g., 1200 Inventory - Powder).</small>
|
||||
@@ -383,7 +383,7 @@
|
||||
<label asp-for="CogsAccountId" class="form-label"></label>
|
||||
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts"
|
||||
data-quick-add-url="/Accounts/Create?preSubType=40" data-quick-add-title="Add COGS Account">
|
||||
<option value="">(Default COGS account)</option>
|
||||
<option value="">@((ViewBag.HasDefaultCogsAccount ?? false) ? "(Default COGS account)" : "(None)")</option>
|
||||
<option value="__new__">+ Add New Account…</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Expense account debited when this material is consumed on a job.</small>
|
||||
|
||||
Reference in New Issue
Block a user