Ensure an account only has one strategy with active management
This commit is contained in:
parent
ea0a6f21ce
commit
db58fb34eb
|
@ -217,6 +217,21 @@ class StrategyForm(RestrictedFormMixin, ModelForm):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if cleaned_data.get("active_management_enabled"):
|
if cleaned_data.get("active_management_enabled"):
|
||||||
|
# Ensure that no other strategy with this account has active management enabled
|
||||||
|
if (
|
||||||
|
Strategy.objects.filter(
|
||||||
|
account=cleaned_data.get("account"),
|
||||||
|
active_management_enabled=True,
|
||||||
|
enabled=True,
|
||||||
|
)
|
||||||
|
.exclude(id=self.instance.id)
|
||||||
|
.exists()
|
||||||
|
):
|
||||||
|
self.add_error(
|
||||||
|
"active_management_enabled",
|
||||||
|
"You cannot have more than one strategy with active management enabled for the same account.",
|
||||||
|
)
|
||||||
|
return
|
||||||
if not cleaned_data.get("active_management_policy"):
|
if not cleaned_data.get("active_management_policy"):
|
||||||
self.add_error(
|
self.add_error(
|
||||||
"active_management_policy",
|
"active_management_policy",
|
||||||
|
|
Loading…
Reference in New Issue