Browse Source

fixed date parsing bug due to changed format in superx export

pull/1/head
www-data 1 year ago
parent
commit
e47a2ad4f7
  1. BIN
      budgets/Budget-Vorlage-2021.xlsx
  2. BIN
      budgets/Budget-Vorlage-2022.xlsx
  3. BIN
      budgets/Budget-Vorlage-2023.xlsx
  4. 2
      superx_budget/helpers.py
  5. 2
      superx_budget/pyramid/overview.py
  6. 3
      superx_budget/superx.py
  7. 6
      tests/test_budget_parser.py
  8. 14
      tests/test_overview.py
  9. 6
      tests/test_superx_parser.py

BIN
budgets/Budget-Vorlage-2021.xlsx

Binary file not shown.

BIN
budgets/Budget-Vorlage-2022.xlsx

Binary file not shown.

BIN
budgets/Budget-Vorlage-2023.xlsx

Binary file not shown.

2
superx_budget/helpers.py

@ -19,7 +19,7 @@ def excel_value_as_number(value):
def get_sheet_of_file(excel_file, sheet=None): def get_sheet_of_file(excel_file, sheet=None):
""" returns a sheet from an excel FileCache """returns a sheet from an excel FileCache
if name is set to None, the function returns the first sheet if name is set to None, the function returns the first sheet
""" """

2
superx_budget/pyramid/overview.py

@ -142,7 +142,7 @@ def send_overview(context, request):
or not budget_file.is_file() or not budget_file.is_file()
): ):
request.session.flash( request.session.flash(
f"There was an error with your submisssion, please try again.", "There was an error with your submisssion, please try again.",
"error", "error",
) )
return HTTPFound("/") return HTTPFound("/")

3
superx_budget/superx.py

@ -51,9 +51,10 @@ def _get_export_metadata(row):
raise SuperXParserError( raise SuperXParserError(
f"unexpected grouping: {metadata['Gruppierung']}" f"unexpected grouping: {metadata['Gruppierung']}"
) )
date_part, *rest = metadata["Stand"].split(",")
return SuperXResult( return SuperXResult(
metadata["Haushaltsjahr"], metadata["Haushaltsjahr"],
datetime.strptime(metadata["Stand"], "%d.%m.%Y"), datetime.strptime(date_part.strip(), "%d.%m.%Y"),
None, None,
) )

6
tests/test_budget_parser.py

@ -2,7 +2,7 @@ import pytest
def test_check_table_header_raises_error(): def test_check_table_header_raises_error():
from superx_budget.budget import _check_table_header, ExcelRow from superx_budget.budget import ExcelRow, _check_table_header
from superx_budget.exceptions import BudgetParserError from superx_budget.exceptions import BudgetParserError
row = ExcelRow(None, ["not", "the", "expected", "row", None, 0]) row = ExcelRow(None, ["not", "the", "expected", "row", None, 0])
@ -12,7 +12,7 @@ def test_check_table_header_raises_error():
def test_skip_empty_lines(): def test_skip_empty_lines():
from superx_budget.budget import _skip_empty_lines, ExcelRow from superx_budget.budget import ExcelRow, _skip_empty_lines
rows = [ rows = [
ExcelRow(0, [""]), ExcelRow(0, [""]),
@ -29,7 +29,7 @@ def test_skip_empty_lines():
def test_parse_data_table(): def test_parse_data_table():
from superx_budget.budget import _parse_data_table, ExcelRow from superx_budget.budget import ExcelRow, _parse_data_table
rows = [ rows = [
ExcelRow(2, list("ABCDEFG")), ExcelRow(2, list("ABCDEFG")),

14
tests/test_overview.py

@ -79,8 +79,8 @@ def test_project_overview_available_property(example_budget_data):
def test_create_overview_map(budget_example_file): def test_create_overview_map(budget_example_file):
from superx_budget.overview import _create_overview_map
from superx_budget.budget import parse_budget_file from superx_budget.budget import parse_budget_file
from superx_budget.overview import _create_overview_map
budget_data = parse_budget_file(budget_example_file) budget_data = parse_budget_file(budget_example_file)
result = _create_overview_map(budget_data) result = _create_overview_map(budget_data)
@ -92,12 +92,12 @@ def test_create_overview_map(budget_example_file):
def test_create_entries_from_export(budget_example_file, superx_example_file): def test_create_entries_from_export(budget_example_file, superx_example_file):
from superx_budget.budget import parse_budget_file
from superx_budget.superx import parse_exported_file
from superx_budget.overview import ( from superx_budget.overview import (
_create_entries_from_superx,
_create_overview_map, _create_overview_map,
_create_entries_from_superx,
) )
from superx_budget.budget import parse_budget_file
from superx_budget.superx import parse_exported_file
superx_data = parse_exported_file(superx_example_file) superx_data = parse_exported_file(superx_example_file)
budget_data = parse_budget_file(budget_example_file) budget_data = parse_budget_file(budget_example_file)
@ -109,11 +109,11 @@ def test_create_entries_from_export(budget_example_file, superx_example_file):
def test_filter_superx_material_expenses(superx_example_file): def test_filter_superx_material_expenses(superx_example_file):
from superx_budget.superx import parse_exported_file
from superx_budget.overview import ( from superx_budget.overview import (
_filter_superx_material_expenses,
VALID_MATERIAL_IDS, VALID_MATERIAL_IDS,
_filter_superx_material_expenses,
) )
from superx_budget.superx import parse_exported_file
superx_data = parse_exported_file(superx_example_file) superx_data = parse_exported_file(superx_example_file)
result = list(_filter_superx_material_expenses(superx_data)) result = list(_filter_superx_material_expenses(superx_data))
@ -124,9 +124,9 @@ def test_filter_superx_material_expenses(superx_example_file):
def test_create_overview(budget_example_file, superx_example_file): def test_create_overview(budget_example_file, superx_example_file):
from superx_budget.overview import create_overview
from superx_budget.budget import parse_budget_file from superx_budget.budget import parse_budget_file
from superx_budget.superx import parse_exported_file from superx_budget.superx import parse_exported_file
from superx_budget.overview import create_overview
superx_data = parse_exported_file(superx_example_file) superx_data = parse_exported_file(superx_example_file)
budget_data = parse_budget_file(budget_example_file) budget_data = parse_budget_file(budget_example_file)

6
tests/test_superx_parser.py

@ -15,9 +15,10 @@ def test_check_export_headline():
def test_get_export_metadata_ok(): def test_get_export_metadata_ok():
from superx_budget.superx import _get_export_metadata
from datetime import datetime from datetime import datetime
from superx_budget.superx import _get_export_metadata
value = "Haushaltsjahr: XXX;Stand:31.12.2020;Gruppierung:automatisch" value = "Haushaltsjahr: XXX;Stand:31.12.2020;Gruppierung:automatisch"
row = [value] row = [value]
metadata = _get_export_metadata(row) metadata = _get_export_metadata(row)
@ -88,9 +89,10 @@ def test_parse_data_table():
def test_parse_export_data(superx_example_workbook): def test_parse_export_data(superx_example_workbook):
from superx_budget.superx import parse_export_data
from datetime import datetime from datetime import datetime
from superx_budget.superx import parse_export_data
result = parse_export_data(superx_example_workbook.active) result = parse_export_data(superx_example_workbook.active)
assert result.account_year == "2020" assert result.account_year == "2020"

Loading…
Cancel
Save