fix: unable to update TransactionRuleAction

This commit is contained in:
Herculino Trotta
2024-10-27 15:38:47 -03:00
parent 550da1d63e
commit 79e97e7a76
2 changed files with 21 additions and 7 deletions

View File

@@ -102,13 +102,21 @@ class TransactionRuleActionForm(forms.ModelForm):
field = cleaned_data.get("field")
if field and self.rule:
if TransactionRuleAction.objects.filter(
# Create a queryset that excludes the current instance
existing_action = TransactionRuleAction.objects.filter(
rule=self.rule, field=field
).exists():
)
if self.instance.pk:
existing_action = existing_action.exclude(pk=self.instance.pk)
if existing_action.exists():
raise ValidationError(
_("A value for this field already exists in the rule.")
)
return cleaned_data
def save(self, commit=True):
instance = super().save(commit=False)
instance.rule = self.rule