diff --git a/db.sqlite3 b/db.sqlite3 index 5b1ca5a..bcfb261 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/markt/__pycache__/models.cpython-38.pyc b/markt/__pycache__/models.cpython-38.pyc index 9aacba3..a2345e8 100644 Binary files a/markt/__pycache__/models.cpython-38.pyc and b/markt/__pycache__/models.cpython-38.pyc differ diff --git a/markt/__pycache__/views.cpython-38.pyc b/markt/__pycache__/views.cpython-38.pyc index 112c3e3..7652e85 100644 Binary files a/markt/__pycache__/views.cpython-38.pyc and b/markt/__pycache__/views.cpython-38.pyc differ diff --git a/markt/migrations/0013_factuur_date.py b/markt/migrations/0013_factuur_date.py new file mode 100644 index 0000000..7b12c36 --- /dev/null +++ b/markt/migrations/0013_factuur_date.py @@ -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, + ), + ] diff --git a/markt/migrations/0014_auto_20200526_1037.py b/markt/migrations/0014_auto_20200526_1037.py new file mode 100644 index 0000000..2426821 --- /dev/null +++ b/markt/migrations/0014_auto_20200526_1037.py @@ -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'), + ), + ] diff --git a/markt/migrations/__pycache__/0013_factuur_date.cpython-38.pyc b/markt/migrations/__pycache__/0013_factuur_date.cpython-38.pyc new file mode 100644 index 0000000..b9f68ad Binary files /dev/null and b/markt/migrations/__pycache__/0013_factuur_date.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0014_auto_20200526_1037.cpython-38.pyc b/markt/migrations/__pycache__/0014_auto_20200526_1037.cpython-38.pyc new file mode 100644 index 0000000..92c235a Binary files /dev/null and b/markt/migrations/__pycache__/0014_auto_20200526_1037.cpython-38.pyc differ diff --git a/markt/models.py b/markt/models.py index 653db66..2afd162 100644 --- a/markt/models.py +++ b/markt/models.py @@ -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: diff --git a/markt/templates/markt/factuur_detail.html b/markt/templates/markt/factuur_detail.html index b8fc37f..4ffb866 100644 --- a/markt/templates/markt/factuur_detail.html +++ b/markt/templates/markt/factuur_detail.html @@ -3,6 +3,7 @@ {% block content %} {% load static %} +{% load l10n %}

FACTUUR HOUTMARKTNAAM

@@ -11,7 +12,7 @@ - +
DatumTBD{{ factuur.Date|date:"D d/m/Y G:i" }}
@@ -28,24 +29,29 @@ {{order.Voorraad_ID}} {{order.Amount}} - SRD {{order.Prijs}} + SRD {{order.Prijs |floatformat:2}} {% endfor %} Subotaal - SRD {{factuur.Subtotal}} + SRD {{factuur.Subtotal |floatformat:2}} Korting {{factuur.Korting_percent}} % - SRD {{korting}} + + + + Belasting + 8% + Totaal - SRD {{factuur.Total}} + SRD {{factuur.Total |floatformat:2}} diff --git a/markt/views.py b/markt/views.py index ee64dec..32a2de8 100644 --- a/markt/views.py +++ b/markt/views.py @@ -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 \ No newline at end of file