nice features

This commit is contained in:
MassiveAtoms 2020-05-25 02:15:12 -03:00
parent 6acc614785
commit 175c4d9631
18 changed files with 149 additions and 25 deletions

Binary file not shown.

View File

@ -55,7 +55,7 @@ ROOT_URLCONF = 'houtmarkt.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [

View File

@ -13,15 +13,16 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from django.conf.urls.static import static
from django.urls import include from django.urls import include
urlpatterns = [ urlpatterns = [
path('markt/', include('markt.urls')), path('markt/', include('markt.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.views.generic import RedirectView from django.views.generic import RedirectView

View File

@ -9,7 +9,7 @@ class OrderAdmin(admin.ModelAdmin):
@admin.register(Factuur) @admin.register(Factuur)
class FactuurAdmin(admin.ModelAdmin): class FactuurAdmin(admin.ModelAdmin):
list_display = ("Factuur_ID", "Klant_ID", "Total" ) list_display = ("Factuur_ID", "Klant_ID", "total" )

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

View File

@ -135,7 +135,8 @@ class Order(models.Model):
self.Prijs = self.Voorraad_ID.Prijs * self.Amount self.Prijs = self.Voorraad_ID.Prijs * self.Amount
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(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.Voorraad_Amount -= self.Amount
self.Voorraad_ID.save() self.Voorraad_ID.save()
return super(Order, self).save(*args, **kwargs) return super(Order, self).save(*args, **kwargs)
@ -146,38 +147,35 @@ class Factuur(models.Model):
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", null=True, 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)
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('model-detail-view', args=[str(self.Factuur_ID)]) return reverse('factuur-detail', args=[str(self.Factuur_ID)])
def __str__(self): def __str__(self):
"""String for representing the Model object.""" """String for representing the Model object."""
return str(self.Factuur_ID) return str(self.Factuur_ID)
@property @property
def Subtotal(self): def subtotal(self):
if self.pk: if not self.Subtotal:
return self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum'] # TODO: Korting moet mischien hier verwerkt worden
else: self.Subtotal = self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum']
return 0 self.save()
return self.Subtotal
@property @property
def Total(self): def total(self):
if self.pk: 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: else:
return 0 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: class Meta:
db_table = "Factuur" db_table = "Factuur"
verbose_name_plural = "Facturen" verbose_name_plural = "Facturen"

View 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;
}

View 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>

View 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 %}

View File

@ -2,5 +2,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('factuur/<int:pk>', views.FactuurDetailView.as_view(), name='factuur-detail'),
] ]

View File

@ -1,3 +1,17 @@
from django.shortcuts import render from django.shortcuts import render
from django.views import generic
from django.shortcuts import get_object_or_404
# Create your views here. # 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