Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monthly report date range fixed #512

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/project_reports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
)


def get_month_year(date):
return date.strftime("%Y-%m")


def check_range_exists(project, from_date, to_date):
for date in project.projectmonthlyreport_set.all():
if from_date == date.from_date and to_date == date.to_date:
return True
return False


class ProjectMonthlyReportForm(forms.ModelForm):
class Meta:
model = ProjectMonthlyReport
Expand Down Expand Up @@ -54,9 +65,19 @@ def clean(self):
project = obj

if from_date and to_date:
if from_date > today_date:
from_month_year = get_month_year(from_date)
to_month_year = get_month_year(to_date)
today_month_year = get_month_year(today_date)

if check_range_exists(project, from_date, to_date):
self.add_error("from_date", "Date range already exists.")
self.add_error("to_date", "Date range already exists.")

if from_month_year > today_month_year:
print(f"{from_month_year} ******* {today_month_year}")
self.add_error("from_date", "Unable to select future date.")
if to_date > today_date:
if to_month_year > today_month_year:
print(f"{to_month_year} ******* {today_month_year}")
self.add_error("to_date", "Unable to select future date.")
if from_date.month != to_date.month:
self.add_error("from_date", "From date and to date must be in the same month.")
Expand Down
Loading