fix: compound shopping names + auto-Bring on depletion + panna da cucina
1. shopping_name compound-phrase map (computeShoppingName) Add phraseMap checked against the full product name BEFORE the single-token keyword loop. Prevents 'pane grattugiato' → 'Pane', 'panna da cucina' → 'Panna', etc. Key new phrases: - pane/pan grattugiato → Pangrattato - panna da cucina / panna cucina / panna chef → Panna da cucina - fette biscottate → Fette biscottate - aceto balsamico / glassa balsamico → Aceto balsamico - latte condensato/evaporato/vegetale/di soia/mandorla/avena/riso/cocco → specific - prosciutto cotto → Prosciutto cotto - farina di riso/mais/integrale → specific - pasta fresca, zucchero di canna, acqua minerale/frizzante/gassata, brodo, … Also added single-token safety-net entries: 'grattugiato'/'grattato'/'pangrattato' → 'Pangrattato', 'biscottate' → 'Fette biscottate'. 2. DB migration (sqlite3 UPDATE) Re-classified 10 products that had wrong shopping_name: Pane grattugiato → Pangrattato Panna da cucina (×4) → Panna da cucina Fette biscottate (×2) → Fette biscottate Aceto balsamico (×3) → Aceto balsamico Cleared 2 stale Gemini cache entries. 3. showLowStockBringPrompt (app.js) When totalRemaining <= 0 (product fully depleted), skip the modal entirely. The backend already auto-adds to Bring! on depletion; the JS only asks as a fallback if that failed (fire-and-forget async, never blocks the UI). The afterCallback (e.g. move-remainder modal, navigate to dashboard) is called immediately without user interaction.
This commit is contained in:
@@ -5922,6 +5922,29 @@ function showLowStockBringPrompt(result, afterCallback) {
|
||||
const defaultQty = result.product_default_qty || parseFloat(currentProduct?.default_quantity) || 0;
|
||||
const totalRemaining = result.total_remaining;
|
||||
|
||||
// ── Fully depleted: no need to ask — backend already added to Bring! ──
|
||||
// Skip the modal entirely and proceed to the next step (e.g. move modal).
|
||||
if (totalRemaining <= 0) {
|
||||
// Backend auto-adds to Bring! when fully depleted. If it failed (Bring not
|
||||
// configured, or product already on list), silently attempt it from JS.
|
||||
if (!result.added_to_bring && name) {
|
||||
// Fire-and-forget — don't block the callback
|
||||
(async () => {
|
||||
try {
|
||||
const spec = name;
|
||||
const payload = { items: [{ name, specification: spec }] };
|
||||
if (shoppingListUUID) payload.listUUID = shoppingListUUID;
|
||||
const data = await api('bring_add', {}, 'POST', payload);
|
||||
if (data.success && data.added > 0) {
|
||||
showToast('🛒 Prodotto finito → aggiunto a Bring!', 'info');
|
||||
}
|
||||
} catch(_e) { /* silent */ }
|
||||
})();
|
||||
}
|
||||
if (afterCallback) afterCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isLowStock(totalRemaining, unit, defaultQty)) {
|
||||
if (afterCallback) afterCallback();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user