nice features
This commit is contained in:
parent
6acc614785
commit
175c4d9631
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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': [
|
||||
|
@ -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
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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" )
|
||||
|
||||
|
||||
|
||||
|
23
markt/migrations/0012_auto_20200525_0113.py
Normal file
23
markt/migrations/0012_auto_20200525_0113.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
Binary file not shown.
@ -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"
|
||||
|
13
markt/static/css/styles.css
Normal file
13
markt/static/css/styles.css
Normal file
@ -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;
|
||||
}
|
21
markt/templates/base_generic.html
Normal file
21
markt/templates/base_generic.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% block title %}<title>Houtmarkt</title>{% endblock %}
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<!-- Add additional CSS in static file -->
|
||||
{% load static %}
|
||||
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
</div>
|
||||
<div class="col-sm-10 ">{% block content %}{% endblock %}</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
53
markt/templates/markt/factuur_detail.html
Normal file
53
markt/templates/markt/factuur_detail.html
Normal file
@ -0,0 +1,53 @@
|
||||
{% extends "base_generic.html" %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
{% load static %}
|
||||
<h1>FACTUUR HOUTMARKTNAAM</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Klant</th>
|
||||
<th>{{factuur.Klant_ID}}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Datum</td>
|
||||
<td>TBD</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<h2>Order</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Product</th>
|
||||
<th>Aantal</th>
|
||||
<th>Prijs</th>
|
||||
</tr>
|
||||
{% for order in factuur.Orders.all %}
|
||||
<tr>
|
||||
<td>{{order.Voorraad_ID}}</td>
|
||||
<td>{{order.Amount}}</td>
|
||||
<td>SRD {{order.Prijs}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td>Subotaal</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>SRD {{factuur.Subtotal}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Korting</td>
|
||||
<td>{{factuur.Korting_percent}} %</td>
|
||||
<td>SRD {{korting}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Totaal</td>
|
||||
<td></td>
|
||||
<td>SRD {{factuur.Total}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
{% endblock %}
|
@ -2,5 +2,6 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('factuur/<int:pk>', views.FactuurDetailView.as_view(), name='factuur-detail'),
|
||||
|
||||
]
|
@ -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
|
Loading…
Reference in New Issue
Block a user