Skip to content

Commit

Permalink
Merge pull request #751 from OpenUpSA/item-schema-update
Browse files Browse the repository at this point in the history
Item schema update
  • Loading branch information
michaelglenister authored Aug 15, 2024
2 parents 465570b + c3bd45b commit 3ef4b74
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 94 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ services:
USER_ID: ${USER_ID:-1001}
GROUP_ID: ${GROUP_ID:-1001}
dockerfile: Dockerfile-test
command: bin/wait-for-postgres.sh python manage.py test scorecard infrastructure household #municipal_finance
command: bin/wait-for-postgres.sh python manage.py test municipal_finance scorecard infrastructure household
volumes:
- ".:/app"
environment:
Expand Down
8 changes: 8 additions & 0 deletions municipal_finance/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ class CapitalTypeV2Admin(ImportExportModelAdmin):
"label",
)

@admin.register(CapitalItemsV2)
class CapitalItemsV2Admin(ImportExportModelAdmin):
resource_class = CapitalItemsV2Resource
list_display = (
"code",
"label",
)


@admin.register(DemarcationChanges)
class DemarcationChangesAdmin(admin.ModelAdmin):
Expand Down
53 changes: 53 additions & 0 deletions municipal_finance/migrations/0005_auto_20240814_1407.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 2.2.28 on 2024-08-14 12:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('municipal_finance', '0004_add_data_summary_and_item_schema'),
]

operations = [
migrations.AlterField(
model_name='bsheetitemsv1',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='capitalitemsv1',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='capitalitemsv2',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='cflowitemsv1',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='cflowitemsv2',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='financialpositionitemsv2',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='incexpitemsv1',
name='composition',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='incexpitemsv2',
name='composition',
field=models.TextField(blank=True, null=True),
),
]
7 changes: 4 additions & 3 deletions municipal_finance/models/capital.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CapitalItems(models.Model):
label = models.TextField()
position_in_return_form = models.IntegerField(null=True)
return_form_structure = models.TextField(null=True)
composition = models.TextField(null=True)
composition = models.TextField(blank=True, null=True)

class Meta:
abstract = True
Expand Down Expand Up @@ -82,7 +82,7 @@ class CapitalTypeV2(models.Model):

class Meta:
db_table = "capital_type_v2"
verbose_name_plural = "Capital Items (v2)"
verbose_name_plural = "Capital Type (v2)"

def __str__(self):
return self.code
Expand All @@ -96,8 +96,9 @@ class CapitalItemsV2(CapitalItems):
)

class Meta:
unique_together = ("code", "version")
db_table = "capital_items_v2"
unique_together = ("code", "version")
verbose_name_plural = "Capital Items (v2)"

def __str__(self):
return self.code
Expand Down
2 changes: 1 addition & 1 deletion municipal_finance/models/cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CflowItems(models.Model):
label = models.TextField()
position_in_return_form = models.IntegerField(null=True)
return_form_structure = models.TextField(null=True)
composition = models.TextField(null=True)
composition = models.TextField(blank=True, null=True)

class Meta:
abstract = True
Expand Down
4 changes: 2 additions & 2 deletions municipal_finance/models/financial_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BsheetItems(models.Model):
label = models.TextField()
position_in_return_form = models.IntegerField(null=True)
return_form_structure = models.TextField(null=True)
composition = models.TextField(null=True)
composition = models.TextField(blank=True, null=True)

class Meta:
abstract = True
Expand Down Expand Up @@ -72,7 +72,7 @@ class FinancialPositionItemsV2(BsheetItems):
class Meta:
unique_together = ("code", "version")
db_table = "financial_position_items_v2"
verbose_name_plural = "Balance Sheet Items (v2)"
verbose_name_plural = "Financial Position(Balance Sheet) Items (v2)"

def __str__(self):
return self.code
Expand Down
2 changes: 1 addition & 1 deletion municipal_finance/models/income_expenditure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IncexpItems(models.Model):
label = models.TextField()
position_in_return_form = models.IntegerField(null=True)
return_form_structure = models.TextField(null=True)
composition = models.TextField(null=True)
composition = models.TextField(blank=True, null=True)

class Meta:
abstract = True
Expand Down
24 changes: 0 additions & 24 deletions municipal_finance/templates/maintenance.html

This file was deleted.

54 changes: 0 additions & 54 deletions municipal_finance/templates/table-maintenance.html

This file was deleted.

5 changes: 2 additions & 3 deletions municipal_finance/tests/test_item_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ def test_schema_codes(self):
batch_size=4,
)
uploaded_items = CflowItemsV2.objects.all()
# Expecting 2 more items
self.assertEqual(uploaded_items.count(), 34)
# Expecting 1 more items
self.assertEqual(uploaded_items.count(), 33)

item_code = CflowItemsV2.objects.get(code="1234")
self.assertEqual(item_code.code, "1234")
self.assertEqual(item_code.version.version, "1")
7 changes: 4 additions & 3 deletions municipal_finance/update/item_code_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ def update_item_code_schema(update_obj, batch_size, **kwargs):
schema_code = sheet.row_values(i)[0].strip()
if schema_code != "" and schema_code in schema_codes:
desc = sheet.row_values(i)[2].strip()
desc = desc.split("/")[-1].strip()
desc = desc.split(" / ")[-1].strip()
code = sheet.row_values(i)[1].strip()
item_codes[code] = desc

for key in item_codes:
schema_codes[schema_code].objects.create(
code=key, label=item_codes[key], version=update_obj
schema_codes[schema_code].objects.update_or_create(
code=key,
defaults={'label': item_codes[key]}
)
4 changes: 2 additions & 2 deletions municipal_finance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def index(request):
"Unauthorised, Irregular, Fruitless and Wasteful Expenditure" : {"cube_info":[{"slug":"uifwexp"}]},
}

return render(request, 'maintenance.html', {
return render(request, 'index.html', {
'cubes': cubes,
'cube_count': len(cube_names),
'summary': summary_dict,
Expand Down Expand Up @@ -307,7 +307,7 @@ def table(request, cube_name):
'name': name,
}
cube = manager.get_cube(cube_name).model.to_dict()
return render(request, 'table-maintenance.html', {
return render(request, 'table.html', {
'cube_name': cube_name,
'cube_model': cube,
'cubes': cubes,
Expand Down

0 comments on commit 3ef4b74

Please sign in to comment.