update sync data from site dashboard and testing closing cycles
This commit is contained in:
1 parent
36639d8c38
commit
f49e72592c
42 files changed
+1966
-688
No files matched your search
+19
@@ -0,0 +1,19 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0010_delete_reportsnapshot"),
|
||||
("farms", "0020_kandang_flock_source_ids"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddConstraint(
|
||||
model_name="aiinsight",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("cycle", "date", "section", "session"),
|
||||
name="uniq_ai_insight_cycle_date_section_session",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -39,6 +39,12 @@ class AIInsight(models.Model):
|
||||
class Meta:
|
||||
db_table = "ai_insight"
|
||||
ordering = ["-date"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["cycle", "date", "section", "session"],
|
||||
name="uniq_ai_insight_cycle_date_section_session",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class FeedSacks(models.Model):
|
||||
|
||||
@@ -83,6 +83,26 @@ class OperationsAPITests(TestCase):
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(results[0]["date"], date.today().isoformat())
|
||||
|
||||
def test_panel_iot_active_cycle_null_end_date_does_not_500(self):
|
||||
"""Active cycles have end_date=None; filtering must not raise ValueError."""
|
||||
self.cycle.end_date = None
|
||||
self.cycle.status = Cycle.STATUS_ACTIVE
|
||||
self.cycle.save(update_fields=["end_date", "status", "updated_at"])
|
||||
IotPanel.objects.create(
|
||||
flock=self.flock,
|
||||
date=date.today(),
|
||||
average_temperature=27.0,
|
||||
)
|
||||
response = self.client.get(
|
||||
"/api/v1/panel-iot/dates/",
|
||||
{"cycle_id": self.cycle.pk, "flock_id": self.flock.pk},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200, response.data)
|
||||
iso_dates = [
|
||||
d.isoformat() if hasattr(d, "isoformat") else str(d) for d in response.data
|
||||
]
|
||||
self.assertIn(date.today().isoformat(), iso_dates)
|
||||
|
||||
def test_panel_iot_filters_by_flock(self):
|
||||
flock_b = Flock.objects.create(flock_name="Flock B", kandang=self.kandang)
|
||||
row = IotPanel.objects.create(
|
||||
|
||||
@@ -206,10 +206,12 @@ class IotPanelViewSet(viewsets.ModelViewSet):
|
||||
cycle = visible_cycles.get(pk=cycle_id)
|
||||
except Cycle.DoesNotExist:
|
||||
return qs.none()
|
||||
# Active cycles have end_date=None; date__lte=None raises ValueError (500).
|
||||
end = cycle.end_date or cycle.soft_end_date()
|
||||
qs = qs.filter(
|
||||
flock__kandang_id=cycle.kandang_id,
|
||||
date__gte=cycle.start_date,
|
||||
date__lte=cycle.end_date,
|
||||
date__lte=end,
|
||||
)
|
||||
if params.get("flock_id"):
|
||||
qs = qs.filter(flock_id=params["flock_id"])
|
||||
|
||||
Reference in new issue
Block a user