Skip to content

Commit

Permalink
Merge pull request #747 from OpenUpSA/feature-769-item-code-updates
Browse files Browse the repository at this point in the history
Trim item descriptions and handle duplicate item codes
  • Loading branch information
michaelglenister authored May 20, 2024
2 parents 0f12e34 + 7c2bb9f commit 9b95ecb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Binary file modified municipal_finance/fixtures/tests/update/item_schema.xlsx
Binary file not shown.
8 changes: 4 additions & 4 deletions municipal_finance/tests/test_item_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_schema_codes(self):
batch_size=4,
)
uploaded_items = CflowItemsV2.objects.all()
# Expecting 5 more items
self.assertEqual(uploaded_items.count(), 37)
# Expecting 2 more items
self.assertEqual(uploaded_items.count(), 34)

item_code = CflowItemsV2.objects.get(code="0110")
self.assertEqual(item_code.code, "0110")
item_code = CflowItemsV2.objects.get(code="1234")
self.assertEqual(item_code.code, "1234")
self.assertEqual(item_code.version.version, "1")
12 changes: 8 additions & 4 deletions municipal_finance/update/item_code_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ def update_item_code_schema(update_obj, batch_size, **kwargs):
for item_key in schema_codes:
if item_key in workbook.sheet_names():
sheet = workbook.sheet_by_name(item_key)
item_codes = {}

for i in range(sheet.nrows):
schema_code = sheet.row_values(i)[0].strip()
if schema_code != "" and schema_code in schema_codes:
label = sheet.row_values(i)[8].strip()
desc = sheet.row_values(i)[2].strip()
desc = desc.split("/")[-1].strip()
code = sheet.row_values(i)[1].strip()
item_codes[code] = desc

schema_codes[schema_code].objects.create(
code=code, label=label, version=update_obj
)
for key in item_codes:
schema_codes[schema_code].objects.create(
code=key, label=item_codes[key], version=update_obj
)

0 comments on commit 9b95ecb

Please sign in to comment.