Skip to content

Commit

Permalink
Create constituency if it does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMwashuma committed Nov 6, 2024
1 parent 4271090 commit 83742bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tally_ho/apps/tally/management/commands/import_centers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def create_centers_from_centers_file_data(
constituency = get_constituency_by_name(
field_val,
constituencies_by_name,
kwargs.get('sub_constituency')
kwargs.get('sub_constituency'),
tally,
)
kwargs['constituency'] = constituency
continue
Expand Down
8 changes: 6 additions & 2 deletions tally_ho/apps/tally/management/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ def get_constituency_by_name(
constituency_name,
constituency_by_name,
sc_code,
tally,
):
constituency = None
if constituency_name != NO_CONSTITUENCY and\
sc_code != SPECIAL_VOTING and sc_code != OCV_VOTING:
constituency =\
constituency_by_name.get(constituency_name)
if constituency is None:
raise Constituency.DoesNotExist(
f'Constituency {constituency_name} does not exist')
constituency_obj, _ = Constituency.objects.get_or_create(
name=constituency_name,
tally=tally,
)
constituency = constituency_obj

return constituency

Expand Down

0 comments on commit 83742bd

Please sign in to comment.