bcgov / lcfs

An online application for fuel suppliers to manage their compliance obligations under the Low Carbon Fuels Act
Apache License 2.0
5 stars 3 forks source link

LCFS - Create supplemental report #1008

Open airinggov opened 1 month ago

airinggov commented 1 month ago

Description: Implement functionality for creating a supplemental report. When the "Create supplemental report" button is clicked, it will generate a new version of the assessed report, renamed from "Compliance report" to "Supplemental report" with a status of "Draft." The original compliance report needs to remain a permanent record.

A supplemental report in Draft status will include the bulleted list of schedule links, and the edit icon will be available on the schedules.

The new supplemental report will build on the original schedule data and only create data for new and amended information. Deleted data will also be tagged for tracking the changes. A new summary will be created resulting in a new summary snapshot when submitted and assessed. This will allow for comparison of historical summary data.

Changes to schedule data and while new schedules added will be reflected in a changelog; tracking all edits, deletions, and additions. The system will allow switching between 'track changes' and 'accepted changes' modes.

Wireframe: This wireframe contains some additional updates to the card layout that will likely be covered in a different ticket. https://preview.uxpin.com/da68049c0af15edd7ce4e47e4bee431fed40c30d#/pages/188097236

Purpose and benefit to user: This feature allows users to create an amended report based on the original compliance report, providing a clear view of all changes while retaining the original data. It simplifies tracking of report revisions and provides transparency through a "track changes" style functionality.

Acceptance Criteria:

Developer Requirements:

  1. Backend Implementation:

    • Supplemental Report Creation Logic:

      • Implement the "Create Supplemental Report" functionality.

      • On button click:

      • Create a new supplemental_report record.

      • Set status to 'DRAFT' and report_type to 'SUPPLEMENTAL'.

      • Set original_report_id and previous_report_id:

        • First Supplemental Report:
        • Both original_report_id and previous_report_id are set to the initial compliance report's ID.
        • Subsequent Supplemental Reports:
        • original_report_id remains the initial report's ID.
        • previous_report_id is set to the most recent supplemental report's ID.
      • Set the version number appropriately (initial report is version 1).

      • Ensure the original compliance report remains unaltered.

      • ComplianceReportSummary Model Adjustments:

        class ComplianceReportSummary(BaseModel, Auditable):
        __tablename__ = "compliance_report_summary"
        __table_args__ = (
           CheckConstraint(
               "(compliance_report_id IS NULL) != (supplemental_report_id IS NULL)",
               name="check_one_report_id_not_null",
           ),
           {"comment": "Summary of compliance calculations"},
        )
      • ComplianceReportHistory Model Adjustments:

        
        class ComplianceReportHistory(BaseModel, Auditable):
        __tablename__ = "compliance_report_history"
        __table_args__ = (
           CheckConstraint(
               "(compliance_report_id IS NULL) != (supplemental_report_id IS NULL)",
               name="check_one_report_id_not_null",
           ),
           {"comment": "Tracks status changes of compliance reports"},
        )
        compliance_report_history_id = Column(
           Integer,
           primary_key=True,
           autoincrement=True,
           comment="Unique identifier for the compliance report history",
        )
        compliance_report_id = Column(
           Integer,
           ForeignKey("compliance_report.compliance_report_id"),
           nullable=True,
           comment="Foreign key to the compliance report",
        )
        supplemental_report_id = Column(
           Integer,
           ForeignKey("supplemental_report.supplemental_report_id"),
           nullable=True,
           comment="Foreign key to the supplemental report",
        )
      
      - Update relationships and ensure that either `compliance_report_id` or `supplemental_report_id` is set, not both.
    • Creating ComplianceReportSummary Record:

      • On creation of the supplemental report:
      • Create a new compliance_report_summary record.
      • Set supplemental_report_id to the new supplemental report's ID.
      • Leave compliance_report_id as NULL.
      • Set the version number to match the supplemental report's version.
    • ComplianceReportHistory Record Creation:

      • Create a new compliance_report_history record referencing the new supplemental report.
      • Set status_id to 'DRAFT'.
      • Associate it with the user who created the supplemental report.
      • Ensure compliance_report_id is NULL and supplemental_report_id is set.
  2. Frontend Implementation:

    • UI Updates:

      • Add the "Create Supplemental Report" button on the compliance report view page.
      • Upon creating a supplemental report:
      • Redirect the user to the new supplemental report in Draft status.
      • Update the report title to "Supplemental Report".
      • Display the version number prominently.
    • Schedule Editing:

      • Enable the edit icon on schedules within the supplemental report.
      • Ensure users can add, edit, or delete data in the schedules.
      • Display schedule links in a bulleted list format.
  3. Data Integrity and Versioning:

    • Report Chain Management:

      • Ensure original_report_id and previous_report_id correctly represent the report chain.
      • Validate that version numbers are correctly incremented.
      • Implement checks to prevent skipping versions or incorrect associations.
    • Database Constraints:

      • Utilize database constraints (e.g., foreign keys, check constraints) to enforce data integrity.
      • Ensure that the Check Constraint in ComplianceReportSummary and ComplianceReportHistory enforces that only one of compliance_report_id or supplemental_report_id is non-null.
  4. Testing:

    • Unit Tests:

      • Write tests for creating supplemental reports and ensuring correct field values.
      • Test the creation of ComplianceReportSummary and ComplianceReportHistory records.
    • Data Integrity Tests:

      • Test scenarios where data integrity might be compromised (e.g., missing IDs, incorrect versioning).
      • Ensure that constraints and validations are effective.

Additional Context:

Notes:

Grulin commented 9 hours ago

Getting the following error: Image