mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Restore form when form submit fails due to error
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user