Skip to content

Commit 5e0d015

Browse files
JoleVLFJoleVLF
authored andcommitted
buf: Update usage of data streams
1 parent aae3009 commit 5e0d015

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

app/utils/irrigation_report.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def parse_irrigation_operations(data: dict) -> Optional[List[IrrigationOperation
3030

3131

3232
def create_pdf_from_operations(
33-
operations: List[IrrigationOperation], token: dict[str, str] = None
33+
operations: List[IrrigationOperation], token: dict[str, str] = None,
34+
data_used: bool = False,
3435
):
3536
"""
3637
Create PDF report from irrigation operations
@@ -118,7 +119,8 @@ def create_pdf_from_operations(
118119
)
119120

120121
if len(operations) > 1:
121-
operations.sort(key=lambda x: x.hasStartDatetime)
122+
if not data_used:
123+
operations.sort(key=lambda x: x.hasStartDatetime)
122124
pdf.set_fill_color(0, 255, 255)
123125
with pdf.table(text_align="CENTER", padding=0.5) as table:
124126
row = table.row()
@@ -186,7 +188,7 @@ def process_irrigation_data(
186188
"""
187189
Process irrigation data and generate PDF report
188190
"""
189-
191+
data_used = False
190192
if irrigation_id:
191193
json_data = make_get_request(
192194
url=f'{settings.REPORTING_FARMCALENDAR_BASE_URL}{settings.REPORTING_FARMCALENDAR_URLS["irrigations"]}{irrigation_id}/',
@@ -210,6 +212,7 @@ def process_irrigation_data(
210212
)
211213

212214
else:
215+
data_used = True
213216
json_data = json.loads(data)
214217
if json_data:
215218
json_data = json_data['@graph']
@@ -220,7 +223,7 @@ def process_irrigation_data(
220223
operations = []
221224

222225
try:
223-
pdf = create_pdf_from_operations(operations, token)
226+
pdf = create_pdf_from_operations(operations, token, data_used)
224227
except Exception:
225228
raise HTTPException(
226229
status_code=400, detail="PDF generation of irrigation report failed."

0 commit comments

Comments
 (0)