Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2514 Added placeholder code for workbook version check #2651

Merged
merged 22 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bcebdbd
#2460 Just renaming
sambodeme Oct 27, 2023
f2e1ebc
#2460 Removed logic that transforms individual named range into string
sambodeme Oct 27, 2023
0851850
#2460 Added logic to turn all named ranges into stripped string + log…
sambodeme Oct 27, 2023
fe64ec0
#2460 Ensure dollar decimal dollar amounts fail
sambodeme Oct 27, 2023
c340a92
#2514 Added placeholder code for workbook version check
sambodeme Oct 30, 2023
26f6f26
Merge branch 'main' into 2514-check-workbook-version
sambodeme Oct 30, 2023
f288796
#2514 Switched WB version from formula to value to unblock failing un…
sambodeme Oct 31, 2023
0a8b6e7
#2514 Code cleaning
sambodeme Oct 31, 2023
87e3eff
#2567 Increased wb rows
sambodeme Oct 31, 2023
933bdb1
#2514 Regenerate workbooks
sambodeme Oct 31, 2023
bc37799
#2514 Updated workbook version
sambodeme Oct 31, 2023
ad66619
Removed unnecessary code since version and section name are now set b…
sambodeme Oct 31, 2023
030d193
More cleaning
sambodeme Oct 31, 2023
0bb0bf1
Regenerated test workbooks
sambodeme Oct 31, 2023
479cc3e
#2514 Enforcing version control
sambodeme Oct 31, 2023
63df6d3
Merge branch '2460-workbook-validation-improvement-spaces-in-t3' into…
sambodeme Oct 31, 2023
bdfd08e
#2514 Linting
sambodeme Oct 31, 2023
69769ad
#2460 Renamed function
sambodeme Nov 1, 2023
27a0425
Merge branch 'main' into 2460-workbook-validation-improvement-spaces-…
sambodeme Nov 1, 2023
95bcbbf
Code restructuring
sambodeme Nov 1, 2023
5f57056
Merge branch '2460-workbook-validation-improvement-spaces-in-t3' into…
sambodeme Nov 1, 2023
0ca26c7
Merge branch 'main' into 2514-check-workbook-version
sambodeme Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 6 additions & 2 deletions backend/audit/intakelib/checks/check_is_a_workbook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.core.exceptions import ValidationError
import logging
from audit.intakelib.intermediate_representation import get_sheet_by_name
from audit.intakelib.intermediate_representation import (
get_sheet_by_name,
get_range_by_name,
)

logger = logging.getLogger(__name__)

Expand All @@ -12,7 +15,8 @@
# sloppy and still have a coversheet page.
def is_a_workbook(ir):
coversheet = get_sheet_by_name(ir, "Coversheet")
if not coversheet:
version_range = get_range_by_name(ir, "version")
if not (coversheet and version_range):
raise ValidationError(
(
"(O_o)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# DESCRIPTION
# The sum of the amount_expended should equal the total_amount_expended
# B5=SUM(Form!F$2:F$5000)
# B5=SUM(Form!F$2:F$MAX_ROWS)
def total_amount_expended_is_correct(ir):
total_amount_expended_value = get_range_values_by_name(ir, "total_amount_expended")
amount_expended_values = get_range_values_by_name(ir, "amount_expended")
Expand Down
32 changes: 32 additions & 0 deletions backend/audit/intakelib/checks/check_version_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.core.exceptions import ValidationError
import logging
from audit.intakelib.intermediate_representation import (
get_range_by_name,
)
from audit.intakelib.common import get_message, build_cell_error_tuple

logger = logging.getLogger(__name__)

AUTHORIZED_VERSIONS = {"1.0.0", "1.0.1", "1.0.2", "1.0.3"}


# DESCRIPTION
# This checks if the uploaded workbook version is valid.
def validate_workbook_version(ir):
version_range = get_range_by_name(ir, "version")
errors = []
for index, version in enumerate(version_range["values"]):
# Check if version is not in the set of valid versions
if version not in AUTHORIZED_VERSIONS:
errors.append(
build_cell_error_tuple(
ir,
version_range,
index,
get_message("check_workbook_version").format(version),
)
)

if errors:
logger.info("Raising a validation error.")
raise ValidationError(errors)
2 changes: 2 additions & 0 deletions backend/audit/intakelib/checks/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .check_start_and_end_rows_of_all_columns_are_same import (
start_and_end_rows_of_all_columns_are_same,
)
from .check_version_number import validate_workbook_version

############
# Federal awards checks
Expand Down Expand Up @@ -50,6 +51,7 @@

general_checks = [
is_a_workbook,
validate_workbook_version,
uei_exists,
look_for_empty_rows,
start_and_end_rows_of_all_columns_are_same,
Expand Down
1 change: 1 addition & 0 deletions backend/audit/intakelib/common/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
"check_federal_award_amount_passed_through_not_allowed": "When Federal Award Passed Through is <b>N</b>, Amount Passed Through must be empty",
"check_loan_balance": "The loan balance is currently set to {}. It should either be a positive number, N/A, or left empty",
"check_cardinality_of_passthrough_names_and_ids": "You used a <b>|</b> (bar character) to indicate multiple passthrough names and IDs; you must provide equal numbers of names and IDs. You provided <b>{}</b> name{} and <b>{}</b> ID{}",
"check_workbook_version": "Single audit workbook template version {} is not supported. Please download the latest workbook and transfer your data to it",
"check_integer_values": "<b>{}</b> is not a valid integer",
}
2 changes: 1 addition & 1 deletion backend/audit/intakelib/intermediate_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def extract_workbook_as_ir(file):
sheet["ranges"] = ranges
sheets.append(sheet)

# Remove all the Nones at the bottom of the sheets, since we have 5000 rows of formulas.
# Remove all the Nones at the bottom of the sheets, since we have 10000 rows of formulas.
for sheet in sheets:
remove_null_rows(sheet)

Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/additional_eins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)


from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import

import openpyxl as pyxl
Expand All @@ -29,7 +28,6 @@ def generate_additional_eins(dbkey, year, outfile):
wb = pyxl.load_workbook(templates["AdditionalEINs"])

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "additional-eins-workbook")

addl_eins = Eins.select().where(Eins.dbkey == g.dbkey)
map_simple_columns(wb, mappings, addl_eins)
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/additional_ueis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)


from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import

import openpyxl as pyxl
Expand All @@ -28,7 +27,6 @@ def generate_additional_ueis(dbkey, year, outfile):
Gen = dynamic_import("Gen", year)
wb = pyxl.load_workbook(templates["AdditionalUEIs"])
g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "additional-ueis-workbook")
if int(year) >= 22:
Ueis = dynamic_import("Ueis", year)
addl_ueis = Ueis.select().where(Ueis.dbkey == g.dbkey)
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/corrective_action_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
test_pfix,
)

from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import


Expand All @@ -33,7 +32,6 @@ def generate_corrective_action_plan(dbkey, year, outfile):
]

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "corrective-action-plan-workbook")

captexts = Captext.select().where(Captext.dbkey == g.dbkey)

Expand Down
10 changes: 0 additions & 10 deletions backend/dissemination/workbooklib/excel_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
from datetime import date
from config import settings
import re
import json

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -211,12 +210,3 @@ def extract_metadata(sheet_json, range):
if ("range_name" in scell) and (scell["range_name"] == range):
result = scell["formula"]
return result


def insert_version_and_sheet_name(wb, sheet_json):
ver_cell = extract_metadata(sheet_json, "version")
ver_re = re.search('"(.*?)"', ver_cell)[1]
wb_name_cell = extract_metadata(sheet_json, "section_name")
wb_name_re = re.search('"(.*?)"', wb_name_cell)[1]
set_single_cell_range(wb, "version", ver_re)
set_single_cell_range(wb, "section_name", wb_name_re)
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/federal_awards.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
set_range,
)

from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import

from config import settings
Expand Down Expand Up @@ -202,7 +201,6 @@ def generate_federal_awards(dbkey, year, outfile):
# In sheet : in DB

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "federal-awards-workbook")

cfdas = Cfda.select().where(Cfda.dbkey == dbkey).order_by(Cfda.index)
map_simple_columns(wb, mappings, cfdas)
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
set_range,
)

from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import


Expand Down Expand Up @@ -96,7 +95,6 @@ def generate_findings(dbkey, year, outfile):
Cfda = dynamic_import("Cfda", year)
wb = pyxl.load_workbook(templates["AuditFindings"])
g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "federal-awards-audit-findings-workbook")

cfdas = Cfda.select().where(Cfda.dbkey == g.dbkey).order_by(Cfda.index)
# For each of them, I need to generate an elec -> award mapping.
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/findings_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
test_pfix,
)

from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import

import openpyxl as pyxl
Expand All @@ -33,7 +32,6 @@ def generate_findings_text(dbkey, year, outfile):
wb = pyxl.load_workbook(templates["AuditFindingsText"])

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "audit-findings-text-workbook")

ftexts = Findingstext.select().where(Findingstext.dbkey == g.dbkey)
map_simple_columns(wb, mappings, ftexts)
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/notes_to_sefa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
)

from dissemination.workbooklib.excel_creation import (
insert_version_and_sheet_name,
set_range,
)
from dissemination.workbooklib.census_models.census import dynamic_import
Expand Down Expand Up @@ -47,7 +46,6 @@ def generate_notes_to_sefa(dbkey, year, outfile):
wb = pyxl.load_workbook(templates["SEFA"])

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "notes-to-sefa-workbook")

# The mapping is weird.
# https://facdissem.census.gov/Documents/DataDownloadKey.xlsx
Expand Down
2 changes: 0 additions & 2 deletions backend/dissemination/workbooklib/secondary_auditors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
test_pfix,
)

from dissemination.workbooklib.excel_creation import insert_version_and_sheet_name
from dissemination.workbooklib.census_models.census import dynamic_import


Expand Down Expand Up @@ -58,7 +57,6 @@ def generate_secondary_auditors(dbkey, year, outfile):
wb = pyxl.load_workbook(templates["SecondaryAuditors"])

g = set_uei(Gen, wb, dbkey)
insert_version_and_sheet_name(wb, "secondary-auditors-workbook")

sec_cpas = Cpas.select().where(Cpas.dbkey == g.dbkey)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"single_cells": [
{
"format": "text",
"formula": "=\"1.0.2\"",
"help": {
"link": "https://fac.gov/documentation/validation/#plain_text",
"text": "Only plain text is allowed, no emoji, formatting, or other special additions"
Expand All @@ -45,11 +44,11 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "1.0.3",
"width": 48
},
{
"format": "text",
"formula": "=\"AdditionalEins\"",
"help": {
"link": "https://fac.gov/documentation/validation/#section_name",
"text": "The workbook you tried to upload is for a different section."
Expand All @@ -63,6 +62,7 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "AdditionalEins",
"width": 48
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"single_cells": [
{
"format": "text",
"formula": "=\"1.0.2\"",
"help": {
"link": "https://fac.gov/documentation/validation/#plain_text",
"text": "Only plain text is allowed, no emoji, formatting, or other special additions"
Expand All @@ -45,11 +44,11 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "1.0.3",
"width": 48
},
{
"format": "text",
"formula": "=\"AdditionalUeis\"",
"help": {
"link": "https://fac.gov/documentation/validation/#section_name",
"text": "The workbook you tried to upload is for a different section."
Expand All @@ -63,6 +62,7 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "AdditionalUeis",
"width": 48
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"single_cells": [
{
"format": "text",
"formula": "=\"1.0.2\"",
"help": {
"link": "https://fac.gov/documentation/validation/#plain_text",
"text": "Only plain text is allowed, no emoji, formatting, or other special additions"
Expand All @@ -45,11 +44,11 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "1.0.3",
"width": 48
},
{
"format": "text",
"formula": "=\"FindingsText\"",
"help": {
"link": "https://fac.gov/documentation/validation/#section_name",
"text": "The workbook you tried to upload is for a different section."
Expand All @@ -63,6 +62,7 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "FindingsText",
"width": 48
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"single_cells": [
{
"format": "text",
"formula": "=\"1.0.2\"",
"help": {
"link": "https://fac.gov/documentation/validation/#plain_text",
"text": "Only plain text is allowed, no emoji, formatting, or other special additions"
Expand All @@ -45,11 +44,11 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "1.0.3",
"width": 48
},
{
"format": "text",
"formula": "=\"CorrectiveActionPlan\"",
"help": {
"link": "https://fac.gov/documentation/validation/#section_name",
"text": "The workbook you tried to upload is for a different section."
Expand All @@ -63,6 +62,7 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "CorrectiveActionPlan",
"width": 48
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"single_cells": [
{
"format": "text",
"formula": "=\"1.0.2\"",
"help": {
"link": "https://fac.gov/documentation/validation/#plain_text",
"text": "Only plain text is allowed, no emoji, formatting, or other special additions"
Expand All @@ -45,11 +44,11 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "1.0.3",
"width": 48
},
{
"format": "text",
"formula": "=\"FindingsUniformGuidance\"",
"help": {
"link": "https://fac.gov/documentation/validation/#section_name",
"text": "The workbook you tried to upload is for a different section."
Expand All @@ -63,6 +62,7 @@
"validation": {
"type": "NOVALIDATION"
},
"value": "FindingsUniformGuidance",
"width": 48
},
{
Expand Down
Loading