diff --git a/db.sqlite3 b/db.sqlite3
index 4d3f068..5b1ca5a 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ
diff --git a/houtmarkt/__pycache__/settings.cpython-38.pyc b/houtmarkt/__pycache__/settings.cpython-38.pyc
index a9ba383..69cec55 100644
Binary files a/houtmarkt/__pycache__/settings.cpython-38.pyc and b/houtmarkt/__pycache__/settings.cpython-38.pyc differ
diff --git a/houtmarkt/__pycache__/urls.cpython-38.pyc b/houtmarkt/__pycache__/urls.cpython-38.pyc
index ac84431..087a23a 100644
Binary files a/houtmarkt/__pycache__/urls.cpython-38.pyc and b/houtmarkt/__pycache__/urls.cpython-38.pyc differ
diff --git a/houtmarkt/settings.py b/houtmarkt/settings.py
index 3787836..0316fd8 100644
--- a/houtmarkt/settings.py
+++ b/houtmarkt/settings.py
@@ -55,7 +55,7 @@ ROOT_URLCONF = 'houtmarkt.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'DIRS': [],
+ 'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
diff --git a/houtmarkt/urls.py b/houtmarkt/urls.py
index bc3a78a..87e9e7c 100644
--- a/houtmarkt/urls.py
+++ b/houtmarkt/urls.py
@@ -13,15 +13,16 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
+from django.conf import settings
from django.contrib import admin
from django.urls import path
-
+from django.conf.urls.static import static
from django.urls import include
urlpatterns = [
path('markt/', include('markt.urls')),
path('admin/', admin.site.urls),
-]
+] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.views.generic import RedirectView
diff --git a/markt/__pycache__/admin.cpython-38.pyc b/markt/__pycache__/admin.cpython-38.pyc
index 81fa099..e2cd229 100644
Binary files a/markt/__pycache__/admin.cpython-38.pyc and b/markt/__pycache__/admin.cpython-38.pyc differ
diff --git a/markt/__pycache__/models.cpython-38.pyc b/markt/__pycache__/models.cpython-38.pyc
index a8f3c5d..9aacba3 100644
Binary files a/markt/__pycache__/models.cpython-38.pyc and b/markt/__pycache__/models.cpython-38.pyc differ
diff --git a/markt/__pycache__/urls.cpython-38.pyc b/markt/__pycache__/urls.cpython-38.pyc
index f47f0fd..65cd8c7 100644
Binary files a/markt/__pycache__/urls.cpython-38.pyc and b/markt/__pycache__/urls.cpython-38.pyc differ
diff --git a/markt/__pycache__/views.cpython-38.pyc b/markt/__pycache__/views.cpython-38.pyc
index 9391dd2..112c3e3 100644
Binary files a/markt/__pycache__/views.cpython-38.pyc and b/markt/__pycache__/views.cpython-38.pyc differ
diff --git a/markt/admin.py b/markt/admin.py
index 8a3cf08..ba45202 100644
--- a/markt/admin.py
+++ b/markt/admin.py
@@ -9,7 +9,7 @@ class OrderAdmin(admin.ModelAdmin):
@admin.register(Factuur)
class FactuurAdmin(admin.ModelAdmin):
- list_display = ("Factuur_ID", "Klant_ID", "Total" )
+ list_display = ("Factuur_ID", "Klant_ID", "total" )
diff --git a/markt/migrations/0012_auto_20200525_0113.py b/markt/migrations/0012_auto_20200525_0113.py
new file mode 100644
index 0000000..62927da
--- /dev/null
+++ b/markt/migrations/0012_auto_20200525_0113.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.6 on 2020-05-25 04:13
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('markt', '0011_auto_20200524_1559'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='factuur',
+ name='Subtotal',
+ field=models.FloatField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name='factuur',
+ name='Total',
+ field=models.FloatField(blank=True, null=True),
+ ),
+ ]
diff --git a/markt/migrations/__pycache__/0012_auto_20200525_0113.cpython-38.pyc b/markt/migrations/__pycache__/0012_auto_20200525_0113.cpython-38.pyc
new file mode 100644
index 0000000..fcabad8
Binary files /dev/null and b/markt/migrations/__pycache__/0012_auto_20200525_0113.cpython-38.pyc differ
diff --git a/markt/models.py b/markt/models.py
index 1b8fe75..653db66 100644
--- a/markt/models.py
+++ b/markt/models.py
@@ -135,7 +135,8 @@ class Order(models.Model):
self.Prijs = self.Voorraad_ID.Prijs * self.Amount
new_amount = self.Voorraad_ID.Voorraad_Amount - self.Amount
if new_amount < 0:
- raise ValueError("Er zijn maar {} in voorraad".format(self.Voorraad_ID.Voorraad_Amount))
+ raise ValueError("Er zijn maar {} in voorraad".format(
+ self.Voorraad_ID.Voorraad_Amount))
self.Voorraad_ID.Voorraad_Amount -= self.Amount
self.Voorraad_ID.save()
return super(Order, self).save(*args, **kwargs)
@@ -146,38 +147,35 @@ class Factuur(models.Model):
Klant_ID = models.ForeignKey("Klant", on_delete=models.PROTECT)
Orders = models.ManyToManyField("Order", null=True, blank=True)
Korting_percent = models.FloatField()
- # Subtotal = models.FloatField(null=True, blank=True)
- # total = models.FloatField(null=True, blank=True)
+ Subtotal = models.FloatField(null=True, blank=True)
+ Total = models.FloatField(null=True, blank=True)
def get_absolute_url(self):
"""Returns the url to access a particular instance of the model."""
- return reverse('model-detail-view', args=[str(self.Factuur_ID)])
+ return reverse('factuur-detail', args=[str(self.Factuur_ID)])
def __str__(self):
"""String for representing the Model object."""
return str(self.Factuur_ID)
@property
- def Subtotal(self):
- if self.pk:
- return self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum']
- else:
- return 0
-
+ 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.save()
+ return self.Subtotal
+
@property
- def Total(self):
+ def total(self):
if self.pk:
- return (100 - self.Korting_percent) * self.Subtotal / 100
+ if not self.Total:
+ # TODO: Taxes moet eigenlijk hier verwerkt worden, niet korting
+ self.Total = (100 - self.Korting_percent) * self.subtotal / 100
+ self.save()
+ return self.Total
else:
return 0
-
- # def save(self, *args, **kwargs):
- # super(Factuur, self).save(*args, **kwargs)
- # self.Subtotal = sum([i.Prijs for i in self.Orders.all()])
- # self.total = self.Subtotal * (1 - self.Korting_percent/100)
-
- # return super(Factuur, self).save(*args, **kwargs)
-
class Meta:
db_table = "Factuur"
verbose_name_plural = "Facturen"
diff --git a/markt/static/css/styles.css b/markt/static/css/styles.css
new file mode 100644
index 0000000..6db71f6
--- /dev/null
+++ b/markt/static/css/styles.css
@@ -0,0 +1,13 @@
+table,
+th,
+td {
+ border: 1px solid black;
+ border-collapse: collapse;
+ padding: 0.5em;
+
+}
+
+td:nth-child(3),
+td:nth-child(2) {
+ text-align: right;
+}
\ No newline at end of file
diff --git a/markt/templates/base_generic.html b/markt/templates/base_generic.html
new file mode 100644
index 0000000..ca9b2af
--- /dev/null
+++ b/markt/templates/base_generic.html
@@ -0,0 +1,21 @@
+
+
+
+ {% block title %}Houtmarkt{% endblock %}
+
+
+
+
+ {% load static %}
+
+
+
+
+
+
+
+
{% block content %}{% endblock %}
+
+
+
+
\ No newline at end of file
diff --git a/markt/templates/markt/factuur_detail.html b/markt/templates/markt/factuur_detail.html
new file mode 100644
index 0000000..b8fc37f
--- /dev/null
+++ b/markt/templates/markt/factuur_detail.html
@@ -0,0 +1,53 @@
+{% extends "base_generic.html" %}
+
+
+{% block content %}
+{% load static %}
+FACTUUR HOUTMARKTNAAM
+
+
+ Klant |
+ {{factuur.Klant_ID}} |
+
+
+ Datum |
+ TBD |
+
+
+
+
+
+Order
+
+
+ Product |
+ Aantal |
+ Prijs |
+
+ {% for order in factuur.Orders.all %}
+
+ {{order.Voorraad_ID}} |
+ {{order.Amount}} |
+ SRD {{order.Prijs}} |
+
+ {% endfor %}
+
+ Subotaal |
+
+ |
+ SRD {{factuur.Subtotal}} |
+
+
+ Korting |
+ {{factuur.Korting_percent}} % |
+ SRD {{korting}} |
+
+
+ Totaal |
+ |
+ SRD {{factuur.Total}} |
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/markt/urls.py b/markt/urls.py
index 2d5ee3c..5e24bfd 100644
--- a/markt/urls.py
+++ b/markt/urls.py
@@ -2,5 +2,6 @@ from django.urls import path
from . import views
urlpatterns = [
+ path('factuur/', views.FactuurDetailView.as_view(), name='factuur-detail'),
]
\ No newline at end of file
diff --git a/markt/views.py b/markt/views.py
index 91ea44a..ee64dec 100644
--- a/markt/views.py
+++ b/markt/views.py
@@ -1,3 +1,17 @@
from django.shortcuts import render
-
+from django.views import generic
+from django.shortcuts import get_object_or_404
# Create your views here.
+
+from markt.models import Factuur, Order, Klant
+
+
+
+
+class FactuurDetailView(generic.DetailView):
+ model = Factuur
+ 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
+ return context
\ No newline at end of file