This commit is contained in:
MassiveAtoms 2020-05-24 15:48:06 -03:00
parent 265f7611df
commit 6755c617e8
19 changed files with 162 additions and 5 deletions

Binary file not shown.

View File

@ -6,6 +6,7 @@ class OrderAdmin(admin.ModelAdmin):
list_display = ("Order_ID", "Voorraad_ID", "Amount", "Prijs" )
@admin.register(Factuur)
class FactuurAdmin(admin.ModelAdmin):
list_display = ("Factuur_ID", "Klant_ID", "total" )

View File

@ -0,0 +1,23 @@
# Generated by Django 3.0.6 on 2020-05-24 18:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('markt', '0003_factuur_orders'),
]
operations = [
migrations.AlterField(
model_name='factuur',
name='Subtotal',
field=models.FloatField(blank=True, null=True),
),
migrations.AlterField(
model_name='factuur',
name='total',
field=models.FloatField(blank=True, null=True),
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.0.6 on 2020-05-24 18:10
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('markt', '0004_auto_20200524_1506'),
]
operations = [
migrations.RemoveField(
model_name='order',
name='Factuur_ID',
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.6 on 2020-05-24 18:13
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('markt', '0005_remove_order_factuur_id'),
]
operations = [
migrations.AddField(
model_name='order',
name='Factuur_ID',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='markt.Factuur'),
preserve_default=False,
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.0.6 on 2020-05-24 18:14
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('markt', '0006_order_factuur_id'),
]
operations = [
migrations.RemoveField(
model_name='order',
name='Factuur_ID',
),
]

View File

@ -0,0 +1,25 @@
# Generated by Django 3.0.6 on 2020-05-24 18:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('markt', '0007_remove_order_factuur_id'),
]
operations = [
migrations.AddField(
model_name='order',
name='Factuur_ID',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='markt.Factuur'),
preserve_default=False,
),
migrations.AlterField(
model_name='factuur',
name='Orders',
field=models.ManyToManyField(blank=True, null=True, to='markt.Order'),
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.0.6 on 2020-05-24 18:28
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('markt', '0008_auto_20200524_1522'),
]
operations = [
migrations.RemoveField(
model_name='factuur',
name='Orders',
),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 3.0.6 on 2020-05-24 18:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('markt', '0009_remove_factuur_orders'),
]
operations = [
migrations.RemoveField(
model_name='order',
name='Factuur_ID',
),
migrations.AddField(
model_name='factuur',
name='Orders',
field=models.ManyToManyField(blank=True, null=True, to='markt.Order'),
),
]

View File

@ -16,6 +16,7 @@ class Houtsoort(models.Model):
def __str__(self):
"""String for representing the Model object."""
return self.Houtsoort_naam
class Meta:
db_table = "Houtsoort"
verbose_name_plural = "Houtsoorten"
@ -33,6 +34,7 @@ class Formaat(models.Model):
def __str__(self):
"""String for representing the Model object."""
return self.Formaat + " " + str(self.Lengte) + "m"
class Meta:
db_table = "Formaat"
verbose_name_plural = "Formaten"
@ -60,6 +62,7 @@ class Houtmarkt(models.Model):
def __str__(self):
"""String for representing the Model object."""
return self.Houtmarkt_naam
class Meta:
db_table = "Houtmarkt"
verbose_name_plural = "Houtmarkten"
@ -79,7 +82,8 @@ class Voorraad(models.Model):
def __str__(self):
"""String for representing the Model object."""
return str(self.Format_ID) + " " + self.Hout_ID.Houtsoort_naam
return str(self.Format_ID) + " " + self.Hout_ID.Houtsoort_naam
class Meta:
db_table = "Voorraad"
verbose_name_plural = "Voorraad"
@ -100,17 +104,20 @@ class Klant(models.Model):
def __str__(self):
"""String for representing the Model object."""
return self.Klant_naam
class Meta:
db_table = "Klant"
verbose_name_plural = "Klanten"
class Order(models.Model):
Order_ID = models.AutoField(primary_key=True)
Order_ID = models.AutoField(primary_key=True)
Voorraad_ID = models.ForeignKey("Voorraad", on_delete=models.PROTECT)
Factuur_ID = models.ForeignKey("Factuur", on_delete=models.PROTECT)
# Factuur_ID = models.ForeignKey("Factuur", on_delete=models.PROTECT)
Amount = models.IntegerField()
Prijs = 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.Order_ID)])
@ -118,12 +125,17 @@ class Order(models.Model):
def __str__(self):
"""String for representing the Model object."""
return "{} {}".format(self.Amount, self.Voorraad_ID)
class Meta:
db_table = "Order"
verbose_name_plural = "Orders"
def save(self, *args, **kwargs):
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))
self.Voorraad_ID.Voorraad_Amount -= self.Amount
self.Voorraad_ID.save()
return super(Order, self).save(*args, **kwargs)
@ -132,7 +144,7 @@ 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")
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)
@ -144,11 +156,14 @@ class Factuur(models.Model):
def __str__(self):
"""String for representing the Model object."""
return str(self.Factuur_ID)
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"