feat(products): improve replenishment-aware shopping suggestions

Replace product weight and repurchase intent fields with per-package remaining levels and inventory-first restock signals. Enrich shopping suggestions with usage-aware replenishment scoring so the frontend and LLM can prioritize real gaps and near-empty staples more reliably.
This commit is contained in:
Piotr Oleszczyk 2026-03-09 13:37:40 +01:00
parent bb5d402c15
commit d91d06455b
18 changed files with 587 additions and 210 deletions

View file

@ -187,11 +187,15 @@ def test_list_inventory_product_not_found(client):
def test_create_inventory(client, created_product):
pid = created_product["id"]
r = client.post(f"/products/{pid}/inventory", json={"is_opened": False})
r = client.post(
f"/products/{pid}/inventory",
json={"is_opened": True, "remaining_level": "medium"},
)
assert r.status_code == 201
data = r.json()
assert data["product_id"] == pid
assert data["is_opened"] is False
assert data["is_opened"] is True
assert data["remaining_level"] == "medium"
def test_create_inventory_product_not_found(client):
@ -204,11 +208,16 @@ def test_parse_text_accepts_numeric_strength_levels(client, monkeypatch):
class _FakeResponse:
text = (
'{"name":"Test Serum","actives":[{"name":"Niacinamide","percent":10,'
'{"name":"Test Serum","category":"serum","recommended_time":"both",'
'"leave_on":true,"actives":[{"name":"Niacinamide","percent":10,'
'"functions":["niacinamide"],"strength_level":2,"irritation_potential":1}]}'
)
monkeypatch.setattr(products_api, "call_gemini", lambda **kwargs: _FakeResponse())
monkeypatch.setattr(
products_api,
"call_gemini",
lambda **kwargs: (_FakeResponse(), None),
)
r = client.post("/products/parse-text", json={"text": "dummy input"})
assert r.status_code == 200