Example #1
0
    def reset_offices_by_events(cls, cursor, event_ids: list):
        """Reset offices to what they were before the given event ids."""
        # get address ids of offices that will be deleted
        addrs_to_delete = Address.get_addresses_by_event(cursor=cursor,
                                                         event_ids=event_ids,
                                                         table='office')

        # delete offices created on these events
        delete_from_table_by_event_ids(cursor=cursor,
                                       event_ids=event_ids,
                                       table='office')

        # delete addresses associated with directors that were deleted
        Address.delete(cursor=cursor, address_ids=addrs_to_delete)

        # reset offices ended on these events
        try:
            cursor.execute(f"""
                UPDATE office
                SET end_event_id = null
                WHERE end_event_id in ({stringify_list(event_ids)})
            """)
        except Exception as err:
            current_app.logger.error(
                f'Error in Office: Failed reset ended offices for events {event_ids}'
            )
            raise err
Example #2
0
    def reset_dirs_by_events(cls, cursor, event_ids: list):
        """Delete all parties created with given events and make all parties ended on given events active."""
        # get address ids of parties that will be deleted
        addrs_to_delete = Address.get_addresses_by_event(cursor=cursor,
                                                         event_ids=event_ids,
                                                         table='corp_party')

        # delete parties created on these events
        delete_from_table_by_event_ids(cursor=cursor,
                                       event_ids=event_ids,
                                       table='corp_party')

        # delete parties created on these events
        delete_from_table_by_event_ids(cursor=cursor,
                                       event_ids=event_ids,
                                       table='completing_party',
                                       column='event_id')

        # delete addresses associated with parties that were deleted
        Address.delete(cursor=cursor, address_ids=addrs_to_delete)

        # reset parties ended on these events
        try:
            cursor.execute(f"""
                UPDATE corp_party
                SET end_event_id = null, cessation_dt = null
                WHERE end_event_id in ({stringify_list(event_ids)})
            """)
        except Exception as err:
            current_app.logger.error(
                f'Error in corp_party: Failed to reset ended parties for events {event_ids}'
            )
            raise err