Skip to content

Commit 635b26c

Browse files
committed
added history and payment on models
1 parent 36dae2d commit 635b26c

File tree

8 files changed

+139
-6
lines changed

8 files changed

+139
-6
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gunicorn = "*"
1111
drf-yasg = "*"
1212
whitenoise = "*"
1313
coreapi = "*"
14-
# psycopg2-binary = "*"
14+
django-simple-history = "*"
1515

1616
[dev-packages]
1717
django_linter = "*"

TaxManagementSystem/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
'rest_framework',
2727
'drf_yasg',
28+
'simple_history',
2829

2930
# user app
3031
'user.apps.UserConfig',
@@ -41,6 +42,7 @@
4142
'django.contrib.auth.middleware.AuthenticationMiddleware',
4243
'django.contrib.messages.middleware.MessageMiddleware',
4344
'django.middleware.clickjacking.XFrameOptionsMiddleware',
45+
'simple_history.middleware.HistoryRequestMiddleware',
4446
]
4547

4648
ROOT_URLCONF = 'TaxManagementSystem.urls'

tax/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from django.contrib import admin
2+
from simple_history import register
3+
from simple_history.admin import SimpleHistoryAdmin
4+
25
from tax.models import Tax
36

47

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.2.6 on 2021-08-08 15:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tax', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='tax',
15+
name='payment_date',
16+
field=models.DateTimeField(blank=True, null=True),
17+
),
18+
migrations.AddField(
19+
model_name='tax',
20+
name='payment_status',
21+
field=models.BooleanField(default=False),
22+
),
23+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 3.2.6 on 2021-08-09 04:05
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tax', '0002_auto_20210808_2127'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='tax',
15+
name='deadline',
16+
field=models.DateTimeField(blank=True, null=True),
17+
),
18+
migrations.AddField(
19+
model_name='tax',
20+
name='fines',
21+
field=models.PositiveIntegerField(blank=True, default=0, null=True),
22+
),
23+
migrations.AddField(
24+
model_name='tax',
25+
name='total_amount',
26+
field=models.PositiveIntegerField(blank=True, default=0, null=True),
27+
),
28+
]

tax/migrations/0004_historicaltax.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by Django 3.2.6 on 2021-08-09 04:21
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
import simple_history.models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
13+
('tax', '0003_auto_20210809_0935'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='HistoricalTax',
19+
fields=[
20+
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
21+
('income', models.FloatField(default=0, verbose_name='Income Amount')),
22+
('status', models.CharField(choices=[('NEW', 'NEW'), ('PAID', 'PAID'), ('DELAYED', 'DELAYED')], default='NEW', max_length=7, verbose_name='Status Tax')),
23+
('tax_amount', models.FloatField(blank=True, null=True, verbose_name='Tax Amount')),
24+
('created_at', models.DateTimeField(blank=True, editable=False)),
25+
('updated_at', models.DateTimeField(blank=True, editable=False)),
26+
('deadline', models.DateTimeField(blank=True, null=True)),
27+
('fines', models.PositiveIntegerField(blank=True, default=0, null=True)),
28+
('total_amount', models.PositiveIntegerField(blank=True, default=0, null=True)),
29+
('payment_status', models.BooleanField(default=False)),
30+
('payment_date', models.DateTimeField(blank=True, null=True)),
31+
('history_id', models.AutoField(primary_key=True, serialize=False)),
32+
('history_date', models.DateTimeField()),
33+
('history_change_reason', models.CharField(max_length=100, null=True)),
34+
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
35+
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
36+
('tax_accountant', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
37+
('tax_payer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
38+
],
39+
options={
40+
'verbose_name': 'historical Tax',
41+
'ordering': ('-history_date', '-history_id'),
42+
'get_latest_by': 'history_date',
43+
},
44+
bases=(simple_history.models.HistoricalChanges, models.Model),
45+
),
46+
]

tax/models.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from datetime import timedelta
2+
13
from django.contrib.auth import get_user_model
24
from django.db import models
5+
from django.utils import timezone
6+
from simple_history.models import HistoricalRecords
37

48
UserModel = get_user_model()
59

@@ -44,6 +48,25 @@ class Tax(models.Model):
4448
created_at = models.DateTimeField(auto_now_add=True)
4549
updated_at = models.DateTimeField(auto_now=True)
4650

51+
deadline = models.DateTimeField(blank=True, null=True)
52+
53+
fines = models.PositiveIntegerField(
54+
default=0,
55+
blank=True,
56+
null=True
57+
)
58+
59+
total_amount = models.PositiveIntegerField(
60+
default=0,
61+
blank=True,
62+
null=True
63+
)
64+
65+
payment_status = models.BooleanField(default=False)
66+
payment_date = models.DateTimeField(blank=True, null=True)
67+
68+
history = HistoricalRecords()
69+
4770
class Meta:
4871
verbose_name = "Tax"
4972
verbose_name_plural = "Taxs"
@@ -57,9 +80,10 @@ def tax_calculate(self):
5780
tax_rate = 0
5881
income = float(self.income)
5982
if self.tax_payer.state == '':
83+
self.tax_amount = 0
6084
return None
6185
if self.tax_payer is not None:
62-
if self.tax_payer.union_territories:
86+
if not self.tax_payer.union_territories:
6387
sgst = 0.08
6488
else:
6589
sgst = 0
@@ -79,4 +103,11 @@ def tax_calculate(self):
79103

80104
def save(self, *args, **kwargs):
81105
self.tax_calculate()
106+
if self.deadline is not None and self.tax_amount >= 0:
107+
dt = self.deadline - timezone.now()
108+
if dt.days >= 0:
109+
self.fines = 0
110+
else:
111+
self.fines = self.tax_amount*0.01
112+
self.total_amount = self.tax_amount+self.fines
82113
super(Tax, self).save(*args, **kwargs)

user/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def registerTaxAccountant(request):
4646
data = request.data
4747
try:
4848
user = UserModel.objects.create_tax_accountant(
49-
username=data.get('username'),
50-
email=data.get('email')
49+
email=data.get('email'),
50+
username=data.get('username')
5151
)
5252
user.set_password(data.get('password'))
5353
user.save()
@@ -67,8 +67,8 @@ def registerTaxPayer(request):
6767
data = request.data
6868
try:
6969
user = UserModel.objects.create_tax_payer(
70-
username=data.get('username'),
71-
email=data.get('email')
70+
email=data.get('email'),
71+
username=data.get('username')
7272
)
7373
user.set_password(data.get('password'))
7474
user.save()

0 commit comments

Comments
 (0)