works better now
This commit is contained in:
commit
6acc614785
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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" )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
21
markt/migrations/0011_auto_20200524_1559.py
Normal file
21
markt/migrations/0011_auto_20200524_1559.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 3.0.6 on 2020-05-24 18:59
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('markt', '0010_auto_20200524_1530'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='factuur',
|
||||||
|
name='Subtotal',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='factuur',
|
||||||
|
name='total',
|
||||||
|
),
|
||||||
|
]
|
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
# Used to generate URLs by reversing the URL patterns
|
# Used to generate URLs by reversing the URL patterns
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.db.models import Sum
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
@ -135,7 +136,6 @@ class Order(models.Model):
|
|||||||
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,8 +146,8 @@ 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."""
|
||||||
@ -157,12 +157,26 @@ class Factuur(models.Model):
|
|||||||
"""String for representing the Model object."""
|
"""String for representing the Model object."""
|
||||||
return str(self.Factuur_ID)
|
return str(self.Factuur_ID)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
@property
|
||||||
super(Factuur, self).save(*args, **kwargs)
|
def Subtotal(self):
|
||||||
self.Subtotal = sum([i.Prijs for i in self.Orders.all()])
|
if self.pk:
|
||||||
self.total = self.Subtotal * (1 - self.Korting_percent/100)
|
return self.Orders.all().aggregate(Sum('Prijs'))['Prijs__sum']
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
return super(Factuur, self).save(*args, **kwargs)
|
@property
|
||||||
|
def Total(self):
|
||||||
|
if self.pk:
|
||||||
|
return (100 - self.Korting_percent) * self.Subtotal / 100
|
||||||
|
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:
|
class Meta:
|
||||||
db_table = "Factuur"
|
db_table = "Factuur"
|
||||||
|
Loading…
Reference in New Issue
Block a user