fix karung view data and sync only sync with the current date

This commit is contained in:
Alberto-Audrix committed 2026-09-04 09:33:17 +07:00
1 parent b3556c6ef4
commit 5ae477a99d
8 files changed
+396 -32

No files matched your search

@@ -2,11 +2,11 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from apps.farms.models import Cycle
from apps.operations.services.karung_web import KarungWebError, request_karung
from apps.operations.services.karung_web import KarungWebError, sync_karung_for_cycle
class Command(BaseCommand):
help = "Sync FeedSacks rows from karung-web-admin active sections"
help = "Sync FeedSacks rows from karung-web-admin (today sections + combined history)"
def handle(self, *args, **options):
if not settings.KARUNG_WEB_ADMIN_SYNC_ENABLED:
@@ -15,11 +15,12 @@ class Command(BaseCommand):
synced = 0
for cycle in Cycle.objects.filter(status=Cycle.STATUS_ACTIVE):
try:
feed_sack, summary = request_karung(cycle, section="today")
feed_sack, summary = sync_karung_for_cycle(cycle, section="today")
synced += 1
self.stdout.write(
f"cycle={cycle.pk} in_today={feed_sack.in_today} "
f"out_today={feed_sack.out_today} date={summary.get('snapshot_date')}"
f"out_today={feed_sack.out_today} date={summary.get('snapshot_date')} "
f"history={','.join(summary.get('history_dates') or [])}"
)
except KarungWebError as exc:
self.stderr.write(f"cycle={cycle.pk} error={exc}")