bot_fam / python_backend /app /services /expiry_rules.py
JairoDanielMT's picture
Add receipt image registration with category expiry rules
9218640
raw
history blame contribute delete
925 Bytes
from __future__ import annotations
from datetime import date, timedelta
from .datetime_utils import NO_EXPIRY_DATE, today_in_config_timezone
CATEGORY_RULES = {
"fresco_preparado": 4,
"verdura_entera": 30,
"snack_seco": 180,
"dulce_sellado": 180,
"gaseosa_botella": 90,
"congelado": 120,
"abarrote_seco": 365,
"mayonesa_cerrada": 120,
"sin_caducidad": None,
"bebida_alcoholica": 270,
}
def list_supported_categories() -> list[str]:
return sorted(CATEGORY_RULES.keys())
def estimate_expiry_for_category(category: str, base_date: date | None = None) -> str:
category = (category or "").strip().lower()
if category not in CATEGORY_RULES:
return ""
days = CATEGORY_RULES[category]
if days is None:
return NO_EXPIRY_DATE
base = base_date or date.fromisoformat(today_in_config_timezone())
return (base + timedelta(days=days)).isoformat()