diff --git a/db.sqlite3 b/db.sqlite3 index e5ff86e..df2e02a 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/houtmarkt/__pycache__/settings.cpython-38.pyc b/houtmarkt/__pycache__/settings.cpython-38.pyc index a221595..a9ba383 100644 Binary files a/houtmarkt/__pycache__/settings.cpython-38.pyc and b/houtmarkt/__pycache__/settings.cpython-38.pyc differ diff --git a/markt/__pycache__/admin.cpython-38.pyc b/markt/__pycache__/admin.cpython-38.pyc index 518e713..0df4f36 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 bd6c83b..89787cf 100644 Binary files a/markt/__pycache__/models.cpython-38.pyc and b/markt/__pycache__/models.cpython-38.pyc differ diff --git a/markt/__pycache__/urls.cpython-38.pyc b/markt/__pycache__/urls.cpython-38.pyc index b9738b8..f47f0fd 100644 Binary files a/markt/__pycache__/urls.cpython-38.pyc and b/markt/__pycache__/urls.cpython-38.pyc differ diff --git a/markt/admin.py b/markt/admin.py index 54d7d64..dba76c4 100644 --- a/markt/admin.py +++ b/markt/admin.py @@ -1,9 +1,40 @@ from django.contrib import admin -from .models import Factuur, Formaat, Houtmarkt, Houtsoort, Klant, Voorraad +from .models import Factuur, Formaat, Houtmarkt, Houtsoort, Klant, Voorraad, Order + +@admin.register(Order) +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" ) + + + +@admin.register(Formaat) +class FormaatAdmin(admin.ModelAdmin): + list_display = ("Format_ID", "Formaat") + + +@admin.register(Houtsoort) +class HoutsoortAdmin(admin.ModelAdmin): + list_display = ("Hout_ID", "Houtsoort_naam") + + +@admin.register(Houtmarkt) +class HoutmarktAdmin(admin.ModelAdmin): + list_display = ("Houtmarkt_ID", "Houtmarkt_naam") + + +@admin.register(Klant) +class KlantAdmin(admin.ModelAdmin): + list_display = ("Klant_ID", "Klant_naam") + + +@admin.register(Voorraad) +class VoorraadAdmin(admin.ModelAdmin): + list_display = ("Voorraad_ID", "Houtmarkt_ID","Hout_ID" , "Format_ID", "Prijs", "Voorraad_Amount" ) + + -admin.site.register(Factuur) -admin.site.register(Formaat) -admin.site.register(Houtsoort) -admin.site.register(Houtmarkt) -admin.site.register(Klant) -admin.site.register(Voorraad) diff --git a/markt/migrations/0002_auto_20200524_1448.py b/markt/migrations/0002_auto_20200524_1448.py new file mode 100644 index 0000000..a6e6e18 --- /dev/null +++ b/markt/migrations/0002_auto_20200524_1448.py @@ -0,0 +1,118 @@ +# Generated by Django 3.0.6 on 2020-05-24 17:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('markt', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='factuur', + options={'verbose_name_plural': 'Facturen'}, + ), + migrations.AlterModelOptions( + name='formaat', + options={'verbose_name_plural': 'Formaten'}, + ), + migrations.AlterModelOptions( + name='houtmarkt', + options={'verbose_name_plural': 'Houtmarkten'}, + ), + migrations.AlterModelOptions( + name='houtsoort', + options={'verbose_name_plural': 'Houtsoorten'}, + ), + migrations.AlterModelOptions( + name='klant', + options={'verbose_name_plural': 'Klanten'}, + ), + migrations.AlterModelOptions( + name='voorraad', + options={'verbose_name_plural': 'Voorraad'}, + ), + migrations.RenameField( + model_name='voorraad', + old_name='prijs', + new_name='Prijs', + ), + migrations.RemoveField( + model_name='factuur', + name='AMT_Sold', + ), + migrations.RemoveField( + model_name='factuur', + name='Houtmarkt_ID', + ), + migrations.RemoveField( + model_name='factuur', + name='Voorraad_ID', + ), + migrations.AlterField( + model_name='factuur', + name='Klant_ID', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Klant'), + ), + migrations.AlterField( + model_name='houtmarkt', + name='Houtmarkt_type', + field=models.CharField(choices=[('RE', 'Reseller'), ('SE', 'Seller')], max_length=2), + ), + migrations.AlterField( + model_name='voorraad', + name='Format_ID', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Formaat'), + ), + migrations.AlterField( + model_name='voorraad', + name='Hout_ID', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Houtsoort'), + ), + migrations.AlterField( + model_name='voorraad', + name='Houtmarkt_ID', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Houtmarkt'), + ), + migrations.AlterModelTable( + name='factuur', + table='Factuur', + ), + migrations.AlterModelTable( + name='formaat', + table='Formaat', + ), + migrations.AlterModelTable( + name='houtmarkt', + table='Houtmarkt', + ), + migrations.AlterModelTable( + name='houtsoort', + table='Houtsoort', + ), + migrations.AlterModelTable( + name='klant', + table='Klant', + ), + migrations.AlterModelTable( + name='voorraad', + table='Voorraad', + ), + migrations.CreateModel( + name='Order', + fields=[ + ('Order_ID', models.AutoField(primary_key=True, serialize=False)), + ('Amount', models.IntegerField()), + ('Prijs', models.FloatField(blank=True, null=True)), + ('Factuur_ID', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Factuur')), + ('Voorraad_ID', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='markt.Voorraad')), + ], + options={ + 'verbose_name_plural': 'Orders', + 'db_table': 'Order', + }, + ), + ] diff --git a/markt/migrations/0003_factuur_orders.py b/markt/migrations/0003_factuur_orders.py new file mode 100644 index 0000000..02ed1eb --- /dev/null +++ b/markt/migrations/0003_factuur_orders.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.6 on 2020-05-24 17:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('markt', '0002_auto_20200524_1448'), + ] + + operations = [ + migrations.AddField( + model_name='factuur', + name='Orders', + field=models.ManyToManyField(to='markt.Order'), + ), + ] diff --git a/markt/migrations/__pycache__/0002_auto_20200524_1251.cpython-38.pyc b/markt/migrations/__pycache__/0002_auto_20200524_1251.cpython-38.pyc new file mode 100644 index 0000000..b4b23b8 Binary files /dev/null and b/markt/migrations/__pycache__/0002_auto_20200524_1251.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0002_auto_20200524_1448.cpython-38.pyc b/markt/migrations/__pycache__/0002_auto_20200524_1448.cpython-38.pyc new file mode 100644 index 0000000..e8947a2 Binary files /dev/null and b/markt/migrations/__pycache__/0002_auto_20200524_1448.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0003_auto_20200524_1304.cpython-38.pyc b/markt/migrations/__pycache__/0003_auto_20200524_1304.cpython-38.pyc new file mode 100644 index 0000000..401e0d3 Binary files /dev/null and b/markt/migrations/__pycache__/0003_auto_20200524_1304.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0003_factuur_orders.cpython-38.pyc b/markt/migrations/__pycache__/0003_factuur_orders.cpython-38.pyc new file mode 100644 index 0000000..af612a2 Binary files /dev/null and b/markt/migrations/__pycache__/0003_factuur_orders.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0004_auto_20200524_1307.cpython-38.pyc b/markt/migrations/__pycache__/0004_auto_20200524_1307.cpython-38.pyc new file mode 100644 index 0000000..f825a80 Binary files /dev/null and b/markt/migrations/__pycache__/0004_auto_20200524_1307.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0005_auto_20200524_1354.cpython-38.pyc b/markt/migrations/__pycache__/0005_auto_20200524_1354.cpython-38.pyc new file mode 100644 index 0000000..f223687 Binary files /dev/null and b/markt/migrations/__pycache__/0005_auto_20200524_1354.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0006_auto_20200524_1403.cpython-38.pyc b/markt/migrations/__pycache__/0006_auto_20200524_1403.cpython-38.pyc new file mode 100644 index 0000000..323ffce Binary files /dev/null and b/markt/migrations/__pycache__/0006_auto_20200524_1403.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0007_auto_20200524_1405.cpython-38.pyc b/markt/migrations/__pycache__/0007_auto_20200524_1405.cpython-38.pyc new file mode 100644 index 0000000..19eaafe Binary files /dev/null and b/markt/migrations/__pycache__/0007_auto_20200524_1405.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0008_factuur_orders.cpython-38.pyc b/markt/migrations/__pycache__/0008_factuur_orders.cpython-38.pyc new file mode 100644 index 0000000..47bb51d Binary files /dev/null and b/markt/migrations/__pycache__/0008_factuur_orders.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 new file mode 100644 index 0000000..306b726 Binary files /dev/null and b/markt/migrations/__pycache__/0009_remove_factuur_orders.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0010_factuur_orders.cpython-38.pyc b/markt/migrations/__pycache__/0010_factuur_orders.cpython-38.pyc new file mode 100644 index 0000000..b0ba2a4 Binary files /dev/null and b/markt/migrations/__pycache__/0010_factuur_orders.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0011_remove_factuur_orders.cpython-38.pyc b/markt/migrations/__pycache__/0011_remove_factuur_orders.cpython-38.pyc new file mode 100644 index 0000000..475bfee Binary files /dev/null and b/markt/migrations/__pycache__/0011_remove_factuur_orders.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0012_order_factuur_id.cpython-38.pyc b/markt/migrations/__pycache__/0012_order_factuur_id.cpython-38.pyc new file mode 100644 index 0000000..e3cc25c Binary files /dev/null and b/markt/migrations/__pycache__/0012_order_factuur_id.cpython-38.pyc differ diff --git a/markt/migrations/__pycache__/0013_auto_20200524_1434.cpython-38.pyc b/markt/migrations/__pycache__/0013_auto_20200524_1434.cpython-38.pyc new file mode 100644 index 0000000..ac16d78 Binary files /dev/null and b/markt/migrations/__pycache__/0013_auto_20200524_1434.cpython-38.pyc differ diff --git a/markt/models.py b/markt/models.py index 2dfbdec..4f23799 100644 --- a/markt/models.py +++ b/markt/models.py @@ -16,6 +16,9 @@ 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" class Formaat(models.Model): @@ -29,7 +32,10 @@ class Formaat(models.Model): def __str__(self): """String for representing the Model object.""" - return self.Formaat + return self.Formaat + " " + str(self.Lengte) + "m" + class Meta: + db_table = "Formaat" + verbose_name_plural = "Formaten" class Houtmarkt(models.Model): @@ -38,7 +44,14 @@ class Houtmarkt(models.Model): max_length=255, help_text='Houtmarkt naam') Houtmarkt_tel = models.IntegerField() Houtmarkt_addr = models.CharField(max_length=255) - Houtmarkt_type = models.BooleanField() + TYPES = ( + ("RE", "Reseller"), + ("SE", "Seller") + ) + Houtmarkt_type = models.CharField( + max_length=2, + choices=TYPES + ) def get_absolute_url(self): """Returns the url to access a particular instance of the model.""" @@ -47,14 +60,17 @@ 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" class Voorraad(models.Model): Voorraad_ID = models.AutoField(primary_key=True) - Houtmarkt_ID = models.ForeignKey("Houtmarkt", on_delete=models.CASCADE) - Hout_ID = models.ForeignKey("Houtsoort", on_delete=models.CASCADE) - Format_ID = models.ForeignKey("Formaat", on_delete=models.CASCADE) - prijs = models.FloatField() + Houtmarkt_ID = models.ForeignKey("Houtmarkt", on_delete=models.PROTECT) + Hout_ID = models.ForeignKey("Houtsoort", on_delete=models.PROTECT) + Format_ID = models.ForeignKey("Formaat", on_delete=models.PROTECT) + Prijs = models.FloatField() Voorraad_Amount = models.IntegerField() def get_absolute_url(self): @@ -63,7 +79,10 @@ class Voorraad(models.Model): def __str__(self): """String for representing the Model object.""" - return self.Voorraad_ID + return str(self.Format_ID) + " " + self.Hout_ID.Houtsoort_naam + class Meta: + db_table = "Voorraad" + verbose_name_plural = "Voorraad" class Klant(models.Model): @@ -81,17 +100,42 @@ 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) + Voorraad_ID = models.ForeignKey("Voorraad", 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)]) + + 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 + self.Voorraad_ID.Voorraad_Amount -= self.Amount + self.Voorraad_ID.save() + return super(Order, self).save(*args, **kwargs) class Factuur(models.Model): Factuur_ID = models.AutoField(primary_key=True) - Voorraad_ID = models.ForeignKey("Voorraad", on_delete=models.CASCADE) - Klant_ID = models.ForeignKey("Klant", on_delete=models.CASCADE) - Houtmarkt_ID = models.ForeignKey("Houtmarkt", on_delete=models.CASCADE) + Klant_ID = models.ForeignKey("Klant", on_delete=models.PROTECT) + Orders = models.ManyToManyField("Order") Korting_percent = models.FloatField() - AMT_Sold = models.IntegerField() - Subtotal = models.FloatField() - total = models.FloatField() + 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.""" @@ -99,4 +143,12 @@ class Factuur(models.Model): def __str__(self): """String for representing the Model object.""" - return self.Factuur_ID + return str(self.Factuur_ID) + def save(self, *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"