fixed stuff

This commit is contained in:
MassiveAtoms 2020-05-26 10:37:22 -03:00
parent 175c4d9631
commit b3b988a02b
10 changed files with 59 additions and 12 deletions

Binary file not shown.

View 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,
),
]

View 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'),
),
]

View File

@ -132,7 +132,8 @@ class Order(models.Model):
verbose_name_plural = "Orders"
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
if new_amount < 0:
raise ValueError("Er zijn maar {} in voorraad".format(
@ -145,11 +146,11 @@ class Order(models.Model):
class Factuur(models.Model):
Factuur_ID = models.AutoField(primary_key=True)
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()
Subtotal = 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):
"""Returns the url to access a particular instance of the model."""
return reverse('factuur-detail', args=[str(self.Factuur_ID)])
@ -161,8 +162,7 @@ class Factuur(models.Model):
@property
def subtotal(self):
if not self.Subtotal:
# TODO: Korting moet mischien hier verwerkt worden
self.Subtotal = self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum']
self.Subtotal = round(self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum'], 2)
self.save()
return self.Subtotal
@ -170,8 +170,8 @@ class Factuur(models.Model):
def total(self):
if self.pk:
if not self.Total:
# TODO: Taxes moet eigenlijk hier verwerkt worden, niet korting
self.Total = (100 - self.Korting_percent) * self.subtotal / 100
self.Total = round(1.08 * self.Total , 2)
self.save()
return self.Total
else:

View File

@ -3,6 +3,7 @@
{% block content %}
{% load static %}
{% load l10n %}
<h1>FACTUUR HOUTMARKTNAAM</h1>
<table>
<tr>
@ -11,7 +12,7 @@
</tr>
<tr>
<td>Datum</td>
<td>TBD</td>
<td>{{ factuur.Date|date:"D d/m/Y G:i" }}</td>
</tr>
</table>
@ -28,24 +29,29 @@
<tr>
<td>{{order.Voorraad_ID}}</td>
<td>{{order.Amount}}</td>
<td>SRD {{order.Prijs}}</td>
<td>SRD {{order.Prijs |floatformat:2}}</td>
</tr>
{% endfor %}
<tr>
<td>Subotaal</td>
<td>
</td>
<td>SRD {{factuur.Subtotal}}</td>
<td>SRD {{factuur.Subtotal |floatformat:2}}</td>
</tr>
<tr>
<td>Korting</td>
<td>{{factuur.Korting_percent}} %</td>
<td>SRD {{korting}}</td>
<td></td>
</tr>
<tr>
<td>Belasting</td>
<td>8%</td>
<td></td>
</tr>
<tr>
<td>Totaal</td>
<td></td>
<td>SRD {{factuur.Total}}</td>
<td>SRD {{factuur.Total |floatformat:2}}</td>
</tr>
</table>

View File

@ -13,5 +13,8 @@ class FactuurDetailView(generic.DetailView):
def get_context_data(self, **kwargs):
# Call the base implementation first to get the context
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