fixed stuff
This commit is contained in:
parent
175c4d9631
commit
b3b988a02b
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
20
markt/migrations/0013_factuur_date.py
Normal file
20
markt/migrations/0013_factuur_date.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 3.0.6 on 2020-05-26 13:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('markt', '0012_auto_20200525_0113'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='factuur',
|
||||||
|
name='Date',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
18
markt/migrations/0014_auto_20200526_1037.py
Normal file
18
markt/migrations/0014_auto_20200526_1037.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.0.6 on 2020-05-26 13:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('markt', '0013_factuur_date'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='factuur',
|
||||||
|
name='Orders',
|
||||||
|
field=models.ManyToManyField(blank=True, to='markt.Order'),
|
||||||
|
),
|
||||||
|
]
|
BIN
markt/migrations/__pycache__/0013_factuur_date.cpython-38.pyc
Normal file
BIN
markt/migrations/__pycache__/0013_factuur_date.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
@ -132,7 +132,8 @@ class Order(models.Model):
|
|||||||
verbose_name_plural = "Orders"
|
verbose_name_plural = "Orders"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.Prijs = self.Voorraad_ID.Prijs * self.Amount
|
self.Prijs = round(self.Voorraad_ID.Prijs * self.Amount, 2)
|
||||||
|
|
||||||
new_amount = self.Voorraad_ID.Voorraad_Amount - self.Amount
|
new_amount = self.Voorraad_ID.Voorraad_Amount - self.Amount
|
||||||
if new_amount < 0:
|
if new_amount < 0:
|
||||||
raise ValueError("Er zijn maar {} in voorraad".format(
|
raise ValueError("Er zijn maar {} in voorraad".format(
|
||||||
@ -145,11 +146,11 @@ class Order(models.Model):
|
|||||||
class Factuur(models.Model):
|
class Factuur(models.Model):
|
||||||
Factuur_ID = models.AutoField(primary_key=True)
|
Factuur_ID = models.AutoField(primary_key=True)
|
||||||
Klant_ID = models.ForeignKey("Klant", on_delete=models.PROTECT)
|
Klant_ID = models.ForeignKey("Klant", on_delete=models.PROTECT)
|
||||||
Orders = models.ManyToManyField("Order", null=True, blank=True)
|
Orders = models.ManyToManyField("Order", blank=True)
|
||||||
Korting_percent = models.FloatField()
|
Korting_percent = models.FloatField()
|
||||||
Subtotal = models.FloatField(null=True, blank=True)
|
Subtotal = models.FloatField(null=True, blank=True)
|
||||||
Total = models.FloatField(null=True, blank=True)
|
Total = models.FloatField(null=True, blank=True)
|
||||||
|
Date = models.DateTimeField(auto_now_add=True)
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Returns the url to access a particular instance of the model."""
|
"""Returns the url to access a particular instance of the model."""
|
||||||
return reverse('factuur-detail', args=[str(self.Factuur_ID)])
|
return reverse('factuur-detail', args=[str(self.Factuur_ID)])
|
||||||
@ -161,8 +162,7 @@ class Factuur(models.Model):
|
|||||||
@property
|
@property
|
||||||
def subtotal(self):
|
def subtotal(self):
|
||||||
if not self.Subtotal:
|
if not self.Subtotal:
|
||||||
# TODO: Korting moet mischien hier verwerkt worden
|
self.Subtotal = round(self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum'], 2)
|
||||||
self.Subtotal = self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum']
|
|
||||||
self.save()
|
self.save()
|
||||||
return self.Subtotal
|
return self.Subtotal
|
||||||
|
|
||||||
@ -170,8 +170,8 @@ class Factuur(models.Model):
|
|||||||
def total(self):
|
def total(self):
|
||||||
if self.pk:
|
if self.pk:
|
||||||
if not self.Total:
|
if not self.Total:
|
||||||
# TODO: Taxes moet eigenlijk hier verwerkt worden, niet korting
|
|
||||||
self.Total = (100 - self.Korting_percent) * self.subtotal / 100
|
self.Total = (100 - self.Korting_percent) * self.subtotal / 100
|
||||||
|
self.Total = round(1.08 * self.Total , 2)
|
||||||
self.save()
|
self.save()
|
||||||
return self.Total
|
return self.Total
|
||||||
else:
|
else:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load l10n %}
|
||||||
<h1>FACTUUR HOUTMARKTNAAM</h1>
|
<h1>FACTUUR HOUTMARKTNAAM</h1>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@ -11,7 +12,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Datum</td>
|
<td>Datum</td>
|
||||||
<td>TBD</td>
|
<td>{{ factuur.Date|date:"D d/m/Y G:i" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -28,24 +29,29 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{order.Voorraad_ID}}</td>
|
<td>{{order.Voorraad_ID}}</td>
|
||||||
<td>{{order.Amount}}</td>
|
<td>{{order.Amount}}</td>
|
||||||
<td>SRD {{order.Prijs}}</td>
|
<td>SRD {{order.Prijs |floatformat:2}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Subotaal</td>
|
<td>Subotaal</td>
|
||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
<td>SRD {{factuur.Subtotal}}</td>
|
<td>SRD {{factuur.Subtotal |floatformat:2}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Korting</td>
|
<td>Korting</td>
|
||||||
<td>{{factuur.Korting_percent}} %</td>
|
<td>{{factuur.Korting_percent}} %</td>
|
||||||
<td>SRD {{korting}}</td>
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Belasting</td>
|
||||||
|
<td>8%</td>
|
||||||
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Totaal</td>
|
<td>Totaal</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>SRD {{factuur.Total}}</td>
|
<td>SRD {{factuur.Total |floatformat:2}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -13,5 +13,8 @@ class FactuurDetailView(generic.DetailView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
# Call the base implementation first to get the context
|
# Call the base implementation first to get the context
|
||||||
context = super(FactuurDetailView, self).get_context_data(**kwargs)
|
context = super(FactuurDetailView, self).get_context_data(**kwargs)
|
||||||
context['korting'] = context["factuur"].Korting_percent * context["factuur"].Subtotal / 100
|
# context['korting'] = context["factuur"].Korting_percent * context["factuur"].Subtotal / 100
|
||||||
|
# context["beforetax"] = context["factuur"].Subtotal - context["korting"]
|
||||||
|
# context["tax"] = context["beforetax"] * 0.08
|
||||||
|
|
||||||
return context
|
return context
|
Loading…
Reference in New Issue
Block a user