updating cycle close request feature to get approval from national dashboard instead auto from system

This commit is contained in:
Alberto-Audrix committed 2026-09-09 14:18:39 +07:00
1 parent 3a868cf1db
commit e4dbfd0252
31 files changed
+1322 -182

No files matched your search

@@ -5,11 +5,12 @@ from apps.farms.models import Cycle
from apps.operations.services.chicken_counting_edge import (
ChickenCountingEdgeError,
sync_chicken_counting_for_cycle,
sync_chicken_weight_for_cycle,
)
class Command(BaseCommand):
help = "Sync chicken counting + mortality IoT from the edge vision API"
help = "Sync chicken counting, mortality, and weight from the edge vision API"
def add_arguments(self, parser):
parser.add_argument("--cycle-id", type=int, default=None)
@@ -17,7 +18,8 @@ class Command(BaseCommand):
def handle(self, *args, **options):
counting_on = settings.CHICKEN_COUNTING_EDGE_COUNTING_SYNC_ENABLED
mortality_on = settings.CHICKEN_COUNTING_EDGE_MORTALITY_SYNC_ENABLED
if not counting_on and not mortality_on:
weight_on = settings.CHICKEN_COUNTING_EDGE_WEIGHT_SYNC_ENABLED
if not counting_on and not mortality_on and not weight_on:
self.stdout.write(
"CHICKEN_COUNTING_EDGE_*_SYNC_ENABLED=false; skipping"
)
@@ -32,14 +34,27 @@ class Command(BaseCommand):
)
for cycle in cycles:
try:
summary = sync_chicken_counting_for_cycle(cycle)
except ChickenCountingEdgeError as exc:
self.stderr.write(f"cycle={cycle.pk}: {exc}")
continue
self.stdout.write(
self.style.SUCCESS(
f"cycle={cycle.pk} upserted={summary['upserted']} "
f"dates={','.join(d.isoformat() for d in summary['dates']) or '-'}"
)
)
if counting_on or mortality_on:
try:
summary = sync_chicken_counting_for_cycle(cycle)
except ChickenCountingEdgeError as exc:
self.stderr.write(f"cycle={cycle.pk} counting: {exc}")
else:
self.stdout.write(
self.style.SUCCESS(
f"cycle={cycle.pk} counting upserted={summary['upserted']} "
f"dates={','.join(d.isoformat() for d in summary['dates']) or '-'}"
)
)
if weight_on:
try:
w_summary = sync_chicken_weight_for_cycle(cycle)
except ChickenCountingEdgeError as exc:
self.stderr.write(f"cycle={cycle.pk} weight: {exc}")
else:
self.stdout.write(
self.style.SUCCESS(
f"cycle={cycle.pk} weight upserted={w_summary['upserted']} "
f"dates={','.join(d.isoformat() for d in w_summary['dates']) or '-'}"
)
)