Restore form when form submit fails due to error

This commit is contained in:
2024-12-20 19:41:38 +01:00
parent 8ebea00896
commit f9d7dc7d3a
3 changed files with 42 additions and 8 deletions

View File

@ -117,12 +117,16 @@ class BaseBasketForm(BaseFormSet):
super().clean()
if len(self) == 0:
return
if len(self.errors) > 0:
return
self._check_forms_have_errors()
self._check_recorded_products(self[0].customer)
self._check_enough_money(self[0].counter, self[0].customer)
def _check_forms_have_errors(self):
for form in self:
if len(form.errors):
raise ValidationError(_("Submmited basket is invalid"))
def _check_enough_money(self, counter: Counter, customer: Customer):
self.total_price = sum([data["total_price"] for data in self.cleaned_data])
if self.total_price > customer.amount: