Fixed #23 -- Tax handling for payment fees

This commit is contained in:
Raphael Michel
2016-03-11 21:55:52 +01:00
parent b7c009343b
commit f095cded08
7 changed files with 70 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-11 20:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0010_orderposition_secret'),
]
operations = [
migrations.AddField(
model_name='order',
name='payment_fee_tax_rate',
field=models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='Payment method fee tax rate'),
preserve_default=False,
),
migrations.AddField(
model_name='order',
name='payment_fee_tax_value',
field=models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='Payment method fee tax'),
),
]

View File

@@ -123,6 +123,14 @@ class Order(LoggedModel):
decimal_places=2, max_digits=10,
default=0, verbose_name=_("Payment method fee")
)
payment_fee_tax_rate = models.DecimalField(
decimal_places=2, max_digits=10,
verbose_name=_("Payment method fee tax rate")
)
payment_fee_tax_value = models.DecimalField(
decimal_places=2, max_digits=10,
default=0, verbose_name=_("Payment method fee tax")
)
payment_info = models.TextField(
verbose_name=_("Payment information"),
null=True, blank=True
@@ -157,8 +165,18 @@ class Order(LoggedModel):
self.assign_code()
if not self.datetime:
self.datetime = now()
if self.payment_fee_tax_rate is None:
self._calculate_tax()
super().save(*args, **kwargs)
def _calculate_tax(self):
self.payment_fee_tax_rate = self.event.settings.get('tax_rate_default')
if self.payment_fee_tax_rate:
self.payment_fee_tax_value = round_decimal(
self.payment_fee * (1 - 100 / (100 + self.payment_fee_tax_rate)))
else:
self.payment_fee_tax_value = Decimal('0.00')
def assign_code(self):
charset = list('ABCDEFGHKLMNPQRSTUVWXYZ23456789')
while True:

View File

@@ -57,6 +57,10 @@ DEFAULTS = {
'default': 'True',
'type': bool
},
'tax_rate_default': {
'default': '0.00',
'type': decimal.Decimal
},
'show_items_outside_presale_period': {
'default': 'True',
'type': bool