diff --git a/app/commands.py b/app/commands.py index ad7e8ad2f..d2a56e1c6 100644 --- a/app/commands.py +++ b/app/commands.py @@ -46,6 +46,7 @@ from app.dao.jobs_dao import dao_get_job_by_id from app.dao.organisation_dao import ( dao_add_service_to_organisation, dao_get_organisation_by_email_address, + dao_get_organisation_by_id, ) from app.dao.permissions_dao import permission_dao from app.dao.provider_rates_dao import ( @@ -698,6 +699,39 @@ def populate_organisations_from_file(file_name): db.session.rollback() +@notify_command(name='populate-organisation-agreement-details-from-file') +@click.option('-f', '--file_name', required=True, + help="CSV file containing id, agreement_signed_version, " + "agreement_signed_on_behalf_of_name, agreement_signed_at") +def populate_organisation_agreement_details_from_file(file_name): + """ + The input file should be a comma separated CSV file with a header row and 4 columns + id: the organisation ID + agreement_signed_version + agreement_signed_on_behalf_of_name + agreement_signed_at: The date the agreement was signed in the format of 'dd/mm/yyyy' + """ + with open(file_name) as f: + csv_reader = csv.reader(f) + + # ignore the header row + next(csv_reader) + + for row in csv_reader: + org = dao_get_organisation_by_id(row[0]) + + current_app.logger.info(f"Updating {org.name}") + + assert org.agreement_signed + + org.agreement_signed_version = float(row[1]) + org.agreement_signed_on_behalf_of_name = row[2].strip() + org.agreement_signed_at = datetime.strptime(row[3], "%d/%m/%Y") + + db.session.add(org) + db.session.commit() + + @notify_command(name='get-letter-details-from-zips-sent-file') @click.argument('file_paths', required=True, nargs=-1) @statsd(namespace="tasks")