Last active
March 28, 2024 21:22
-
-
Save jasonleibowitz/cc7b74d576b3e0e50f598505dfd777eb to your computer and use it in GitHub Desktop.
Quickly update the Due Date for Existing GP Publish Tasks without one & with an invalid one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fund_admin.express.task_management.services import TaskService, WorkflowService | |
from fund_admin.express.task_management.constants import WorkflowStatus | |
from fund_admin.reporting.services import FinancialPackageService | |
from fund_admin.fund_properties.amendable_properties.services import FundPropertiesService | |
from fund_admin.reporting.services.financial_package.express import TaskTemplate | |
workflow_template = "publish-financial-package" | |
object_type = "reporting.FinancialPackageReport" | |
gp_publish_tasks_with_incorrect_due_date = list() | |
gp_publish_tasks = TaskService().list( | |
object_type=object_type, | |
workflow_template=workflow_template, | |
task_templates=[TaskTemplate.GP_PUBLISH_PACKAGE], | |
workflow_statuses=[WorkflowStatus.ACTIVE] | |
) | |
for task in gp_publish_tasks: | |
if task.due_date is not None: | |
gp_publish_tasks_with_incorrect_due_date.append(task) | |
print(f"Total GP Publish Tasks: {len(gp_publish_tasks)}") | |
print(f"Total GP Publish Tasks with Incorrect Due Date: {len(gp_publish_tasks_with_incorrect_due_date)}") | |
print(f"Total GP Publish Tasks Missing Due Date: {len(gp_publish_tasks) - len(gp_publish_tasks_with_incorrect_due_date)}") | |
print("-----------------") | |
print() | |
for task in gp_publish_tasks: | |
workflow = WorkflowService().get_by_workflow_id(task.workflow_id) | |
package_id = workflow.object_id | |
old_due_date = task.due_date | |
package = FinancialPackageService().get_package(id=package_id) | |
fund_reporting_deadlines = FundPropertiesService.factory().get_reporting_deadlines_by_fund_id( | |
fund_id=package.fund_id) | |
new_due_date = fund_reporting_deadlines.get_deadline_by_reporting_interval( | |
reporting_interval=package.report_interval, | |
reporting_period=package.reporting_period, | |
package_end_date=package.end_date, | |
) | |
print(f"Package ID: {package_id}") | |
print(f"Previous Due Date: {old_due_date}") | |
print(f"New Due Date: {new_due_date}") | |
if not old_due_date: | |
print(f"Adding due date for package {package_id}. Due date is {new_due_date}") | |
elif old_due_date != new_due_date: | |
print(f"Due Date for package {package_id} is wrong. Previously {old_due_date} will be updated to {new_due_date}") | |
task.due_date = new_due_date | |
task.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good point. That was a holdover from previous logic.