fix: low stock detection for rarely-used items

- PHP smart_shopping: add absolute stock fallback that flags conf/pz items
  with <=2 units (medium) or <=1 unit (high) and g/ml at <=20% of default,
  regardless of usage frequency. Fixes products like Panna da cucina that
  are rarely used but running low and were invisible to the frequency-based
  urgency logic (pctLeft was 66% since last purchase was 3 at once).
- JS isLowStock(): return true (not false) when totalRemaining <= 0.
  A fully depleted item is definitely low-stock; the Bring! add prompt
  should fire when you use the very last unit.
This commit is contained in:
dadaloop82
2026-04-06 10:53:15 +00:00
parent 6424f381af
commit 5be62cfbfd
2 changed files with 31 additions and 1 deletions
+1 -1
View File
@@ -3781,7 +3781,7 @@ function selectUseLocation(btn, loc) {
// ===== LOW STOCK → BRING! PROMPT =====
function isLowStock(totalRemaining, unit, defaultQty) {
if (totalRemaining <= 0) return false; // already fully depleted → auto-added
if (totalRemaining <= 0) return true; // fully depleted → definitely needs restocking
if (unit === 'pz') return totalRemaining <= 2;
if (unit === 'conf') return totalRemaining <= 1;
// Weight/volume: use percentage of default_qty or fixed threshold