Skip to content

Commit

Permalink
CM-887: update json_ext on update (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan <j.dolkowski@soldevelo.com>
  • Loading branch information
jdolkowski and Jan authored Apr 30, 2024
1 parent 169a5c0 commit 0245bbf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions individual/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def create(self, obj_data):

@register_service_signal('individual_service.update')
def update(self, obj_data):
self._update_json_ext(obj_data)
return super().update(obj_data)

@register_service_signal('individual_service.delete')
Expand Down Expand Up @@ -103,6 +104,22 @@ def select_individuals_to_benefit_plan(self, custom_filters, benefit_plan_id, st
def create_accept_enrolment_task(self, individual_queryset, benefit_plan_id):
pass

def _update_json_ext(self, obj_data):
if not obj_data or 'json_ext' not in obj_data:
return

json_ext = obj_data['json_ext']
if not json_ext:
return

for field in ('first_name', 'last_name', 'dob'):
individual_field_value = obj_data.get(field)
json_ext_value = json_ext.get(field)
if json_ext_value and json_ext_value != individual_field_value:
json_ext[field] = individual_field_value

obj_data['json_ext'] = json_ext

OBJECT_TYPE = Individual

def __init__(self, user, validation_class=IndividualValidation):
Expand Down

0 comments on commit 0245bbf

Please sign in to comment.