Skip to content

Commit

Permalink
Allow fractional tax rates
Browse files Browse the repository at this point in the history
  • Loading branch information
ssinger committed Nov 15, 2024
1 parent afe2037 commit 528cf4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
20 changes: 20 additions & 0 deletions postgresqleu/invoices/migrations/0021_alter_vatrate_vatpercent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.22 on 2024-09-29 02:12

import django.core.validators
from django.db import migrations
import postgresqleu.invoices.models


class Migration(migrations.Migration):

dependencies = [
('invoices', '0020_regtransfer_processor'),
]

operations = [
migrations.AlterField(
model_name='vatrate',
name='vatpercent',
field=postgresqleu.invoices.models.VatPercentage(decimal_places=6, default=0, max_digits=9, validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)], verbose_name='VAT percentage'),
),
]
15 changes: 12 additions & 3 deletions postgresqleu/invoices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,22 @@ class Meta:
ordering = ('-id', )


class VatPercentage(models.DecimalField):
def __str__(self):
return str(self.normalize())

def from_db_value(self, value, expression, connection):
return value.normalize()

def to_python(self, value):
return super().to_python(value).normalize()


class VatRate(models.Model):
name = models.CharField(max_length=100, blank=False, null=False)
shortname = models.CharField(max_length=16, blank=False, null=False, verbose_name="Short name")
vatpercent = models.IntegerField(null=False, default=0, verbose_name="VAT percentage",
validators=[MaxValueValidator(100), MinValueValidator(0)])
vatpercent = VatPercentage(null=False, default=0, verbose_name="VAT percentage", max_digits=9, decimal_places=6, validators=[MaxValueValidator(100), MinValueValidator(0)])
vataccount = models.ForeignKey(Account, null=False, blank=False, on_delete=models.CASCADE, verbose_name="VAT account")

_safe_attributes = ('vatpercent', 'shortstr', 'shortname', 'name')

def __str__(self):
Expand Down

0 comments on commit 528cf4a

Please sign in to comment.