diff --git a/db.sqlite3 b/db.sqlite3 index df2e02a..cd19cc0 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/markt/__pycache__/admin.cpython-38.pyc b/markt/__pycache__/admin.cpython-38.pyc index 0df4f36..5e1ab1c 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 89787cf..fe50b7b 100644 Binary files a/markt/__pycache__/models.cpython-38.pyc and b/markt/__pycache__/models.cpython-38.pyc differ diff --git a/markt/admin.py b/markt/admin.py index dba76c4..ba45202 100644 --- a/markt/admin.py +++ b/markt/admin.py @@ -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" ) diff --git a/markt/migrations/0004_auto_20200524_1506.py b/markt/migrations/0004_auto_20200524_1506.py new file mode 100644 index 0000000..c58ed15 --- /dev/null +++ b/markt/migrations/0004_auto_20200524_1506.py @@ -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), + ), + ] diff --git a/markt/migrations/0005_remove_order_factuur_id.py b/markt/migrations/0005_remove_order_factuur_id.py new file mode 100644 index 0000000..eb525b5 --- /dev/null +++ b/markt/migrations/0005_remove_order_factuur_id.py @@ -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', + ), + ] diff --git a/markt/migrations/0006_order_factuur_id.py b/markt/migrations/0006_order_factuur_id.py new file mode 100644 index 0000000..aba70e7 --- /dev/null +++ b/markt/migrations/0006_order_factuur_id.py @@ -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, + ), + ] diff --git a/markt/migrations/0007_remove_order_factuur_id.py b/markt/migrations/0007_remove_order_factuur_id.py new file mode 100644 index 0000000..64d88bf --- /dev/null +++ b/markt/migrations/0007_remove_order_factuur_id.py @@ -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', + ), + ] diff --git a/markt/migrations/0008_auto_20200524_1522.py b/markt/migrations/0008_auto_20200524_1522.py new file mode 100644 index 0000000..392cc0a --- /dev/null +++ b/markt/migrations/0008_auto_20200524_1522.py @@ -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'), + ), + ] diff --git a/markt/migrations/0009_remove_factuur_orders.py b/markt/migrations/0009_remove_factuur_orders.py new file mode 100644 index 0000000..c7ac524 --- /dev/null +++ b/markt/migrations/0009_remove_factuur_orders.py @@ -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', + ), + ] diff --git a/markt/migrations/0010_auto_20200524_1530.py b/markt/migrations/0010_auto_20200524_1530.py new file mode 100644 index 0000000..37dc6eb --- /dev/null +++ b/markt/migrations/0010_auto_20200524_1530.py @@ -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'), + ), + ] diff --git a/markt/migrations/__pycache__/0004_auto_20200524_1506.cpython-38.pyc b/markt/migrations/__pycache__/0004_auto_20200524_1506.cpython-38.pyc new file mode 100644 index 0000000..7c73846 Binary files /dev/null and b/markt/migrations/__pycache__/0004_auto_20200524_1506.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0005_remove_order_factuur_id.cpython-38.pyc b/markt/migrations/__pycache__/0005_remove_order_factuur_id.cpython-38.pyc new file mode 100644 index 0000000..d851586 Binary files /dev/null and b/markt/migrations/__pycache__/0005_remove_order_factuur_id.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0006_order_factuur_id.cpython-38.pyc b/markt/migrations/__pycache__/0006_order_factuur_id.cpython-38.pyc new file mode 100644 index 0000000..a06ff5a Binary files /dev/null and b/markt/migrations/__pycache__/0006_order_factuur_id.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0007_remove_order_factuur_id.cpython-38.pyc b/markt/migrations/__pycache__/0007_remove_order_factuur_id.cpython-38.pyc new file mode 100644 index 0000000..76a1aed Binary files /dev/null and b/markt/migrations/__pycache__/0007_remove_order_factuur_id.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0008_auto_20200524_1522.cpython-38.pyc b/markt/migrations/__pycache__/0008_auto_20200524_1522.cpython-38.pyc new file mode 100644 index 0000000..e03cd16 Binary files /dev/null and b/markt/migrations/__pycache__/0008_auto_20200524_1522.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0009_remove_factuur_orders.cpython-38.pyc b/markt/migrations/__pycache__/0009_remove_factuur_orders.cpython-38.pyc index 306b726..d714d54 100644 Binary files a/markt/migrations/__pycache__/0009_remove_factuur_orders.cpython-38.pyc and b/markt/migrations/__pycache__/0009_remove_factuur_orders.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0010_auto_20200524_1530.cpython-38.pyc b/markt/migrations/__pycache__/0010_auto_20200524_1530.cpython-38.pyc new file mode 100644 index 0000000..be47d1b Binary files /dev/null and b/markt/migrations/__pycache__/0010_auto_20200524_1530.cpython-38.pyc differ diff --git a/markt/models.py b/markt/models.py index 4f23799..f8086ce 100644 --- a/markt/models.py +++ b/markt/models.py @@ -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"