diff --git a/proto/common/data/models/reports.py b/proto/common/data/models/reports.py index 8ca241e13..1f9b0f5d7 100644 --- a/proto/common/data/models/reports.py +++ b/proto/common/data/models/reports.py @@ -71,7 +71,7 @@ def status(self): @property def can_be_submitted(self): return len(self.data_collection_instance.section_data) == len( - self.round.data_collection_definition.sections + self.reporting_round.data_collection_definition.sections ) and all(sd.completed for sd in self.data_collection_instance.section_data) @property diff --git a/proto/common/data/services/reports.py b/proto/common/data/services/reports.py index 3932499ef..36fab0032 100644 --- a/proto/common/data/services/reports.py +++ b/proto/common/data/services/reports.py @@ -2,7 +2,7 @@ import string import uuid -from sqlalchemy import select +from sqlalchemy import delete, select from db import db from proto.common.data.models import ( @@ -18,7 +18,14 @@ def _generate_report_code(): return "".join(random.choices(string.ascii_uppercase, k=6)) -def get_or_create_monitoring_reports_for_grant_recipient(grant_recipient: ProtoGrantRecipient) -> list[ProtoReport]: +def get_or_create_monitoring_reports_for_grant_recipient( + grant_recipient: ProtoGrantRecipient, preview: bool = False +) -> list[ProtoReport]: + if preview: + db.session.execute( + delete(ProtoReport).filter(ProtoReport.fake.is_(True), ProtoReport.recipient == grant_recipient) + ) + def _get_reports() -> list[ProtoReport]: return ( db.session.scalars( diff --git a/proto/manage/platform/reporting_rounds.py b/proto/manage/platform/reporting_rounds.py index 136d9d041..389cfbc58 100644 --- a/proto/manage/platform/reporting_rounds.py +++ b/proto/manage/platform/reporting_rounds.py @@ -581,7 +581,7 @@ def preview_report(grant_code, round_ext_id): form = PreviewReportForm(submit_label=None) if form.validate_on_submit(): get_or_create_monitoring_reports_for_grant_recipient( - get_grant_recipient_for_organisation(g.account.organisation_id, grant.short_name) + get_grant_recipient_for_organisation(g.account.organisation_id, grant.short_name), preview=True ) return redirect( url_for("proto_report.tasklist", short_name=grant.short_name, reporting_round_id=reporting_round.id)