factuur works
This commit is contained in:
parent
ce1080d7f2
commit
265f7611df
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
|
118
markt/migrations/0002_auto_20200524_1448.py
Normal file
118
markt/migrations/0002_auto_20200524_1448.py
Normal file
@ -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',
|
||||
},
|
||||
),
|
||||
]
|
18
markt/migrations/0003_factuur_orders.py
Normal file
18
markt/migrations/0003_factuur_orders.py
Normal file
@ -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'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
markt/migrations/__pycache__/0003_factuur_orders.cpython-38.pyc
Normal file
BIN
markt/migrations/__pycache__/0003_factuur_orders.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
markt/migrations/__pycache__/0008_factuur_orders.cpython-38.pyc
Normal file
BIN
markt/migrations/__pycache__/0008_factuur_orders.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
markt/migrations/__pycache__/0010_factuur_orders.cpython-38.pyc
Normal file
BIN
markt/migrations/__pycache__/0010_factuur_orders.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user