Răsfoiți Sursa

diff: use CalPrice public API in _diff_prices

Replaces the raw get_backend().fetch_range + 'Price: $' title-filter
copy with CalPrice().list(), the store's own event fetch. Deliberately
not CalPrice().get(), which fills in-memory defaults for missing dates
and would erase the local=None signal the diff relies on.

_diff_orphans is now the only raw-backend access left in diff; it
leaves with the orphans extraction.
ZiB 4 luni în urmă
părinte
comite
6c9dda4ce0
1 a modificat fișierele cu 3 adăugiri și 10 ștergeri
  1. 3 10
      room_cal/actions/diff.py

+ 3 - 10
room_cal/actions/diff.py

@@ -20,9 +20,6 @@ if TYPE_CHECKING:
 
 ACTION_SPEC = ('diff', [])
 
-_PRICE_PREFIX = 'Price: $'
-
-
 def _clamp_future(start_date: date) -> date:
   """Past dates are not compared — only reservation data has historical value."""
   return max(start_date, local_today())
@@ -97,12 +94,8 @@ async def _diff_prices(
   if start_date > end_date:
     return []
 
-  from datetime import datetime
-  backend = get_backend()
-  start_dt = datetime(start_date.year, start_date.month, start_date.day)
-  end_dt = datetime(end_date.year, end_date.month, end_date.day) + timedelta(days=1)
-  events, api_prices, res_events = await asyncio.gather(
-    backend.fetch_range(start_dt, end_dt),
+  price_events, api_prices, res_events = await asyncio.gather(
+    CalPrice().list(start_date, end_date),
     api.get_prices_range(start_date, end_date),
     Reservation().list(start_date, end_date),
   )
@@ -111,7 +104,7 @@ async def _diff_prices(
 
   svc_keys = _services()
   cal_prices: dict[str, PriceData] = {}
-  for e in filter_events(events, _PRICE_PREFIX, all_day=True):
+  for e in price_events:
     d = safe_json_loads(e.x_data)
     if d is not None:
       cal_prices[e.start.date().isoformat()] = PriceData.from_dict(d, svc_keys)