ceate excel for herd and livestock

This commit is contained in:
7nimor
2025-08-06 09:25:13 +03:30
parent 8d7af93498
commit 74ca5ba82a
2 changed files with 8 additions and 4 deletions

View File

@@ -61,8 +61,8 @@ class LiveStockExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
gender = 'نر' if data.get('gender') == 1 else 'ماده'
weight_type = 'سنگین' if data.get('weight_type') == 'H' else 'سبک'
date = data.get('birthdate') or None
if date:
sh_date = shamsi_date(convert_str_to_date(date))
if date is not None:
sh_date = shamsi_date(convert_str_to_date(date),in_value=True)
else:
sh_date = '-'

View File

@@ -308,6 +308,10 @@ def convert_str_to_date(string):
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%S.%fZ').date()
except ValueError:
try:
return datetime.strptime(string, '%Y-%m-%d').date()
return datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ').date() # Added format without milliseconds
except ValueError:
return None
try:
return datetime.strptime(string, '%Y-%m-%d').date()
except ValueError:
return None