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:
2026-06-20 10:10:04 -04:00
parent ee86d7aaf6
commit 58a0010ae8
6 changed files with 22 additions and 8 deletions
@@ -693,6 +693,13 @@ namespace PowderCoating.Web.Controllers
ViewBag.RevenueAccounts = revenueAccounts; ViewBag.RevenueAccounts = revenueAccounts;
ViewBag.CogsAccounts = cogsAccounts; 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> /// <summary>
@@ -1667,6 +1667,13 @@ public class InventoryController : Controller
.OrderBy(a => a.AccountNumber) .OrderBy(a => a.AccountNumber)
.Select(a => new SelectListItem($"{a.AccountNumber} {a.Name}", a.Id.ToString())) .Select(a => new SelectListItem($"{a.AccountNumber} {a.Name}", a.Id.ToString()))
.ToList(); .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> /// <summary>
@@ -131,7 +131,7 @@
<div class="col-md-6 mb-3"> <div class="col-md-6 mb-3">
<label asp-for="RevenueAccountId" class="form-label"></label> <label asp-for="RevenueAccountId" class="form-label"></label>
<select asp-for="RevenueAccountId" class="form-select" asp-items="ViewBag.RevenueAccounts"> <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> </select>
<small class="form-text text-muted">Account credited when this item is invoiced.</small> <small class="form-text text-muted">Account credited when this item is invoiced.</small>
</div> </div>
@@ -139,7 +139,7 @@
<label asp-for="CogsAccountId" class="form-label"></label> <label asp-for="CogsAccountId" class="form-label"></label>
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Account debited when materials are consumed.</small> <small class="form-text text-muted">Account debited when materials are consumed.</small>
@@ -134,7 +134,7 @@
<div class="col-md-6 mb-3"> <div class="col-md-6 mb-3">
<label asp-for="RevenueAccountId" class="form-label"></label> <label asp-for="RevenueAccountId" class="form-label"></label>
<select asp-for="RevenueAccountId" class="form-select" asp-items="ViewBag.RevenueAccounts"> <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> </select>
<small class="form-text text-muted">Account credited when this item is invoiced.</small> <small class="form-text text-muted">Account credited when this item is invoiced.</small>
</div> </div>
@@ -142,7 +142,7 @@
<label asp-for="CogsAccountId" class="form-label"></label> <label asp-for="CogsAccountId" class="form-label"></label>
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Account debited when materials are consumed.</small> <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> <label asp-for="InventoryAccountId" class="form-label"></label>
<select asp-for="InventoryAccountId" class="form-select" asp-items="ViewBag.InventoryAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Asset account where inventory value is tracked (e.g., 1200 Inventory - Powder).</small> <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> <label asp-for="CogsAccountId" class="form-label"></label>
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Expense account debited when this material is consumed on a job.</small> <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> <label asp-for="InventoryAccountId" class="form-label"></label>
<select asp-for="InventoryAccountId" class="form-select" asp-items="ViewBag.InventoryAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Asset account where inventory value is tracked (e.g., 1200 Inventory - Powder).</small> <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> <label asp-for="CogsAccountId" class="form-label"></label>
<select asp-for="CogsAccountId" class="form-select" asp-items="ViewBag.CogsAccounts" <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"> 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&hellip;</option> <option value="__new__">+ Add New Account&hellip;</option>
</select> </select>
<small class="form-text text-muted">Expense account debited when this material is consumed on a job.</small> <small class="form-text text-muted">Expense account debited when this material is consumed on a job.</small>