Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Full-app QA fixes: currency preference on cards, tag creation in edit modal, settings cleanups

Omega (QA)29f88a7b4674
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fb4bf6..16b2d5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@
- _Files: `frontend/status.js`_
- **Global-view timeline fix:** The expiration timeline chart always fetched `/api/warranties` (current user only), so in global view it silently omitted other users' warranties. It now builds from the already-loaded view data, matching the rest of the dashboard.
- _Files: `frontend/status.js`_
+- **Currency preference now applies to warranty cards:** The settings page promises "the symbol to display for prices", but card prices preferred the per-warranty currency code (backend-stamped `USD`), so changing the preference never updated the cards. Card prices now use the user's display preference; the per-warranty currency remains as the creation default and in exports. New warranties created without an explicit currency now default to the user's preferred currency (matching CSV import) instead of hardcoded `USD`; edits preserve the existing currency when the form sends none.
+ - _Files: `frontend/js/components/warrantyRenderer.js`, `frontend/script.js`, `backend/warranties_routes.py`_
+- **Settings fixes:** Removed a leftover "temporary debug script" tag (`js/i18n-debug.js`, 404); fixed the currency dropdown defaulting to a blank value for fresh users (option values are codes like `USD`, but the default set `'$'`); removed a duplicated description paragraph under Expiring Soon Days.
+ - _Files: `frontend/settings-new.html`, `frontend/settings-new.js`_
+- **Tag creation in edit modal:** Creating a brand-new tag from the edit modal's tag dropdown attached it to the hidden add-wizard instead of the warranty being edited. The create-tag action now routes through the context-aware selection handler.
+ - _Files: `frontend/js/components/tagManager.js`_
### Fixed
- **Input validations are now enforced and translated:** three new HTTP 400 validations — product name over 255 chars (was an unhandled DB error → HTTP 500), expiration date before purchase date (was silently accepted), and invalid claim status (was silently coerced) — now return a stable machine-readable `code` (`product_name_too_long`, `expiration_before_purchase`, `invalid_claim_status`; claim-status errors also include `valid_statuses`) alongside the English fallback message. The frontend maps those codes to i18n keys via a new `apiErrorMessage()` helper in `ui.js` (used by the add-warranty form, edit modal, and claims toasts), so error toasts render in the user's language instead of always-English. Two new English keys were added (`messages.product_name_too_long`, `messages.invalid_claim_status`) and machine-translated into all 19 non-English locales with `{{statuses}}` placeholder integrity verified. Also removed the now-unused `safeErrorMessage()` helper from `apiService.js`.
diff --git a/backend/warranties_routes.py b/backend/warranties_routes.py
index 935fa76..c6c4c3f 100644
--- a/backend/warranties_routes.py
+++ b/backend/warranties_routes.py
@@ -33,6 +33,31 @@ logger = logging.getLogger(__name__)
warranties_bp = Blueprint('warranties_bp', __name__)
+# Map of currency symbols to ISO codes (mirrors frontend js/lib/currency.js).
+# Used to resolve a user's preferred currency symbol to a code for new warranties.
+SYMBOL_TO_CURRENCY_CODE = {
+ '$': 'USD', '€': 'EUR', '£': 'GBP', '¥': 'JPY', '₹': 'INR', '₩': 'KRW',
+ 'CHF': 'CHF', 'C$': 'CAD', 'A$': 'AUD', 'kr': 'SEK', 'zł': 'PLN',
+ 'Kč': 'CZK', 'Ft': 'HUF', '₽': 'RUB', 'R$': 'BRL', '₪': 'ILS',
+ '₺': 'TRY', 'NZ$': 'NZD',
+}
+
+def get_user_currency_code(user_id):
+ """Return the user's preferred currency code, falling back to 'USD'."""
+ try:
+ conn = get_db_connection()
+ try:
+ with conn.cursor() as cur:
+ cur.execute("SELECT currency_symbol FROM user_preferences WHERE user_id = %s", (user_id,))
+ row = cur.fetchone()
+ if row and row[0]:
+ return SYMBOL_TO_CURRENCY_CODE.get(row[0], 'USD')
+ finally:
+ release_db_connection(conn)
+ except Exception as e:
+ logger.warning(f"Could not load preferred currency for user {user_id}: {e}")
+ return 'USD'
+
def convert_decimals(obj):
@@ -280,8 +305,8 @@ def add_warranty():
except ValueError:
return jsonify({"error": "Purchase price must be a valid number"}), 400
- # Handle currency (optional, defaults to USD)
- currency = request.form.get('currency', 'USD')
+ # Handle currency (optional, defaults to the user's preferred currency)
+ currency = request.form.get('currency') or get_user_currency_code(user_id)
# Validate currency code
valid_currencies = [
'USD', 'EUR', 'GBP', 'JPY', 'CNY', 'INR', 'KRW', 'CHF', 'CAD', 'AUD',
@@ -626,12 +651,13 @@ def update_warranty(warranty_id):
with conn.cursor() as cur:
# Check if warranty exists and belongs to the user
if is_admin:
- cur.execute('SELECT id FROM warranties WHERE id = %s', (warranty_id,))
+ cur.execute('SELECT id, currency FROM warranties WHERE id = %s', (warranty_id,))
else:
- cur.execute('SELECT id FROM warranties WHERE id = %s AND user_id = %s', (warranty_id, user_id))
+ cur.execute('SELECT id, currency FROM warranties WHERE id = %s AND user_id = %s', (warranty_id, user_id))
warranty = cur.fetchone()
if not warranty:
return jsonify({"error": "Warranty not found or you don't have permission to update it"}), 404
+ existing_currency = warranty[1] if len(warranty) > 1 else None
# --- PATCH: Support JSON-only notes update ---
if request.is_json and 'notes' in request.json and len(request.json) == 1:
@@ -752,8 +778,8 @@ def update_warranty(warranty_id):
except ValueError:
return jsonify({"error": "Purchase price must be a valid number"}), 400
- # Handle currency (optional, defaults to USD)
- currency = request.form.get('currency', 'USD')
+ # Handle currency (optional, keep existing, else user's preferred currency)
+ currency = request.form.get('currency') or existing_currency or get_user_currency_code(user_id)
# Validate currency code
valid_currencies = [
'USD', 'EUR', 'GBP', 'JPY', 'CNY', 'INR', 'KRW', 'CHF', 'CAD', 'AUD',
diff --git a/frontend/js/components/warrantyRenderer.js b/frontend/js/components/warrantyRenderer.js
index 8b887e2..25255c5 100644
--- a/frontend/js/components/warrantyRenderer.js
+++ b/frontend/js/components/warrantyRenderer.js
@@ -272,7 +272,9 @@ function generateDocumentLink(warranty, docType) {
function getPriceHtml(warranty) {
if (!warranty.purchase_price) return '';
- const symbol = warranty.currency ? getCurrencySymbolByCode(warranty.currency) : getCurrencySymbol();
+ // The user's currency preference is the display currency for prices
+ // (Settings: "Choose the symbol to display for prices").
+ const symbol = getCurrencySymbol();
const position = getCurrencyPosition();
const formatted = formatCurrencyHTML(warranty.purchase_price, symbol, position);
const label = t('warranties.price', 'Price');
diff --git a/frontend/script.js b/frontend/script.js
index 5dabdd0..76e328a 100644
--- a/frontend/script.js
+++ b/frontend/script.js
@@ -1749,7 +1749,7 @@ async function renderWarranties(warrantiesToRender) {
<div><i class="fas fa-calendar"></i> ${window.i18next ? window.i18next.t('warranties.age') : 'Age'}: <span>${productAge}</span></div>
<div><i class="fas fa-file-alt"></i> ${window.i18next ? window.i18next.t('warranties.warranty') : 'Warranty'}: <span>${warrantyDurationText}</span></div>
<div><i class="fas fa-wrench"></i> ${window.i18next ? window.i18next.t('warranties.warranty_ends') : 'Warranty Ends'}: <span>${expirationDateText}</span></div>
- ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, warranty.currency ? getCurrencySymbolByCode(warranty.currency) : getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
+ ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
${validSerialNumbers.length > 0 ? `
<div><i class="fas fa-barcode"></i> ${window.i18next ? window.i18next.t('warranties.serial_number') : 'Serial Number'}: <span>${validSerialNumbers[0]}</span></div>
${validSerialNumbers.length > 1 ? `
@@ -1812,7 +1812,7 @@ async function renderWarranties(warrantiesToRender) {
<div><i class="fas fa-calendar"></i> ${window.i18next ? window.i18next.t('warranties.age') : 'Age'}: <span>${productAge}</span></div>
<div><i class="fas fa-file-alt"></i> ${window.i18next ? window.i18next.t('warranties.warranty') : 'Warranty'}: <span>${warrantyDurationText}</span></div>
<div><i class="fas fa-wrench"></i> ${window.i18next ? window.i18next.t('warranties.warranty_ends') : 'Warranty Ends'}: <span>${expirationDateText}</span></div>
- ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, warranty.currency ? getCurrencySymbolByCode(warranty.currency) : getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
+ ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
${validSerialNumbers.length > 0 ? `
<div><i class="fas fa-barcode"></i> ${window.i18next ? window.i18next.t('warranties.serial_number') : 'Serial Number'}: <span>${validSerialNumbers[0]}</span></div>
${validSerialNumbers.length > 1 ? `
@@ -1875,7 +1875,7 @@ async function renderWarranties(warrantiesToRender) {
<div><i class="fas fa-calendar"></i> ${window.i18next ? window.i18next.t('warranties.age') : 'Age'}: <span>${productAge}</span></div>
<div><i class="fas fa-file-alt"></i> ${window.i18next ? window.i18next.t('warranties.warranty') : 'Warranty'}: <span>${warrantyDurationText}</span></div>
<div><i class="fas fa-wrench"></i> ${window.i18next ? window.i18next.t('warranties.warranty_ends') : 'Warranty Ends'}: <span>${expirationDateText}</span></div>
- ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, warranty.currency ? getCurrencySymbolByCode(warranty.currency) : getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
+ ${warranty.purchase_price ? `<div><i class="fas fa-coins"></i> ${window.i18next ? window.i18next.t('warranties.price') : 'Price'}: <span>${formatCurrencyHTML(warranty.purchase_price, getCurrencySymbol(), getCurrencyPosition())}</span></div>` : ''}
${validSerialNumbers.length > 0 ? `
<div><i class="fas fa-barcode"></i> ${window.i18next ? window.i18next.t('warranties.serial_number') : 'Serial Number'}: <span>${validSerialNumbers[0]}</span></div>
${validSerialNumbers.length > 1 ? `
diff --git a/frontend/settings-new.html b/frontend/settings-new.html
index 0feede3..0bf366b 100644
--- a/frontend/settings-new.html
+++ b/frontend/settings-new.html
@@ -285,7 +285,6 @@
<div class="preference-item">
<div>
<label data-i18n="settings.expiring_soon_days">Expiring Soon Days</label>
- <p class="text-muted" data-i18n="settings.expiring_soon_days_desc">Number of days before expiration to show warnings</p>
<p class="text-muted" data-i18n="settings.expiring_soon_days_desc">Number of days before warranty expiration to mark as "Expiring Soon"</p>
</div>
<input type="number" id="expiringSoonDays" class="form-control" min="1" max="365" value="30">
diff --git a/frontend/settings-new.js b/frontend/settings-new.js
index 001a555..093eb51 100644
--- a/frontend/settings-new.js
+++ b/frontend/settings-new.js
@@ -953,10 +953,10 @@ async function loadPreferences() {
console.log(`Loaded currency symbol from ${prefix}currencySymbol: ${storedCurrency}`);
}
} else {
- // Default to '$' if nothing stored
- if (currencySymbolSelect) currencySymbolSelect.value = '$';
+ // Default to 'USD' if nothing stored (option values are currency codes)
+ if (currencySymbolSelect) currencySymbolSelect.value = 'USD';
if (currencySymbolCustom) currencySymbolCustom.style.display = 'none';
- console.log(`${prefix}currencySymbol not found, defaulting to $`);
+ console.log(`${prefix}currencySymbol not found, defaulting to USD`);
}
// Currency Position