Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: application history did not include change reasons with 0 diffs (hl-1484) #3413

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions backend/benefit/applications/services/change_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get_change_set_base(new_record: ModelChange):
}


merge_threshold_in_seconds = 0.25
look_up_for_application_save_in_seconds = 0.25


def _filter_and_format_changes(
Expand All @@ -215,7 +215,7 @@ def _filter_and_format_changes(
and (
delta_time
is None # We'll ignore this check for application changes as delta_time's not present
or 0 <= delta_time <= merge_threshold_in_seconds
or 0 <= delta_time <= look_up_for_application_save_in_seconds
),
changes,
),
Expand Down Expand Up @@ -255,14 +255,14 @@ def get_application_change_history_made_by_handler(application: Application) ->

app_diff_dates = [diff.new_record.history_date for diff in application_diffs]

# create Q objects for each datetime in the list
q_objects = Q()
# fetch employee history changes that occured during the saving of application
employee_q_objects = Q()
for dt in app_diff_dates:
start_date = dt - timedelta(seconds=merge_threshold_in_seconds)
end_date = dt + timedelta(seconds=merge_threshold_in_seconds)
q_objects |= Q(history_date__range=(start_date, end_date))
start_date = dt - timedelta(seconds=look_up_for_application_save_in_seconds)
end_date = dt + timedelta(seconds=look_up_for_application_save_in_seconds)
employee_q_objects |= Q(history_date__range=(start_date, end_date))

employee_history = application.employee.history.filter(q_objects)
employee_history = application.employee.history.filter(employee_q_objects)
employee_diffs = []
for i in range(0, len(employee_history) - 1):
diff = employee_history[i].diff_against(employee_history[i + 1])
Expand All @@ -282,7 +282,12 @@ def create_change_set(app_diff, employee_diffs):
employee_diff.changes, EXCLUDED_EMPLOYEE_FIELDS, True, delta_time
)

return change_set if len(change_set["changes"]) > 0 else None
return (
change_set
if len(change_set["changes"]) > 0
or (change_set["reason"] and len(change_set["reason"]) > 0)
else None
)

change_sets = list(
filter(
Expand Down
12 changes: 7 additions & 5 deletions frontend/benefit/handler/src/components/sidebar/ChangeSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ const ChangeSet: React.FC<ChangeSetProps> = ({ data }: ChangeSetProps) => {
))}
</dl>
<$ChangeSetFooter>
<p>
{t('common:changes.header.amountOfChanges', {
amount: changes.length,
})}
</p>
{changes.length > 0 && (
<p>
{t('common:changes.header.amountOfChanges', {
amount: changes.length,
})}
</p>
)}
<hr />
<$ViewFieldBold>
{t('common:applications.sections.fields.changeReason.placeholder')}
Expand Down
Loading