Validate tax rates to be between 0 and 100

This commit is contained in:
Raphael Michel
2023-01-10 11:48:24 +01:00
parent eadc1b4812
commit d07948613a
2 changed files with 13 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ import json
from decimal import Decimal
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.formats import localize
from django.utils.translation import gettext_lazy as _, pgettext
@@ -149,7 +150,15 @@ class TaxRule(LoggedModel):
rate = models.DecimalField(
max_digits=10,
decimal_places=2,
verbose_name=_("Tax rate")
validators=[
MaxValueValidator(
limit_value=Decimal("100.00"),
),
MinValueValidator(
limit_value=Decimal("0.00"),
),
],
verbose_name=_("Tax rate"),
)
price_includes_tax = models.BooleanField(
verbose_name=_("The configured product prices include the tax amount"),