feat: Implement currency management with models, routes, and UI updates; add backfill script for existing records

This commit is contained in:
2025-10-21 10:33:08 +02:00
parent fcea39deb0
commit 672cafa5b9
14 changed files with 478 additions and 10 deletions

View File

@@ -41,6 +41,42 @@ document.addEventListener("DOMContentLoaded", () => {
const capexCurrencySelect = document.getElementById("capex-form-currency");
const opexCurrencySelect = document.getElementById("opex-form-currency");
// If no currency options were injected server-side, fetch from API
const fetchCurrencyOptions = async () => {
try {
const resp = await fetch("/api/currencies/");
if (!resp.ok) return;
const list = await resp.json();
if (Array.isArray(list) && list.length) {
currencyOptions = list;
populateCurrencySelects();
}
} catch (err) {
console.warn("Unable to fetch currency options", err);
}
};
const populateCurrencySelects = () => {
const selectElements = [capexCurrencySelect, opexCurrencySelect].filter(Boolean);
selectElements.forEach((sel) => {
if (!sel) return;
// Clear non-empty options except the empty placeholder
const placeholder = sel.querySelector("option[value='']");
sel.innerHTML = "";
if (placeholder) sel.appendChild(placeholder);
currencyOptions.forEach((opt) => {
const option = document.createElement("option");
option.value = opt.id;
option.textContent = opt.name || opt.id;
sel.appendChild(option);
});
});
};
// populate from injected options first, then fetch to refresh
if (currencyOptions && currencyOptions.length) populateCurrencySelects();
else fetchCurrencyOptions();
const showFeedback = (element, message, type = "success") => {
if (!element) {
return;