Properly handle changes in code attribute when a customer is deleted

Previously, `null` and empty value would be confused when a customer is
removed, resulting in incorrect pending changes being added, and thus a
"You have unsaved changes" message getting displayed and the save button
not getting disabled.
This commit is contained in:
David Rodríguez
2025-11-25 07:00:39 +01:00
parent 44c4a66970
commit dc631026d4
2 changed files with 5 additions and 7 deletions

View File

@@ -38,16 +38,13 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
# To ensure the customer is still updated, we check on the $destroy event to see if
# the attribute has changed, if so we queue up the change.
scope.$on '$destroy', (value) ->
# No update
return if scope.object()[scope.attr] is scope.savedValue
currentValue = scope.object()[scope.attr] || ""
# For some reason the code attribute is removed from the object when cleared, so we add
# an emptyvalue so it gets updated properly
if scope.attr is "code" and scope.object()[scope.attr] is undefined
scope.object()["code"] = ""
# No update
return if currentValue is scope.savedValue
# Queuing up change
addPendingChange(scope.attr, scope.object()[scope.attr])
addPendingChange(scope.attr, currentValue)
# private

View File

@@ -111,6 +111,7 @@ RSpec.describe 'Customers' do
end
end
expect(page).not_to have_selector "tr#c_#{customer2.id}"
expect(page).not_to have_content 'You have unsaved changes'
}.to change{ Customer.count }.by(-1)
end