diff --git a/bbs/migrations/0002_alter_inventorytransaction_amount_and_more.py b/bbs/migrations/0002_alter_inventorytransaction_amount_and_more.py new file mode 100644 index 0000000..f7d8a7d --- /dev/null +++ b/bbs/migrations/0002_alter_inventorytransaction_amount_and_more.py @@ -0,0 +1,63 @@ +# Generated by Django 4.0.2 on 2022-03-05 19:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bbs", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="inventorytransaction", + name="amount", + field=models.IntegerField(verbose_name="Antall"), + ), + migrations.AlterField( + model_name="inventorytransaction", + name="unit_price", + field=models.DecimalField(decimal_places=1, max_digits=9, verbose_name="Enhetspris"), + ), + migrations.AlterField( + model_name="orderline", + name="unit_price", + field=models.DecimalField(decimal_places=1, max_digits=9, verbose_name="Enhetspris"), + ), + migrations.AlterField( + model_name="product", + name="alcohol_percent", + field=models.DecimalField(decimal_places=1, max_digits=9, null=True), + ), + migrations.AlterField( + model_name="product", + name="inventory_amount", + field=models.IntegerField(default=0), + ), + migrations.AlterField( + model_name="product", + name="sale_price_ext", + field=models.DecimalField(decimal_places=1, max_digits=9), + ), + migrations.AlterField( + model_name="product", + name="sale_price_int", + field=models.DecimalField(decimal_places=1, max_digits=9), + ), + migrations.AlterField( + model_name="product", + name="volume_liter", + field=models.DecimalField(decimal_places=1, max_digits=9, null=True), + ), + migrations.AlterField( + model_name="transaction", + name="amount", + field=models.DecimalField(decimal_places=1, max_digits=9), + ), + migrations.AlterField( + model_name="userprofile", + name="balance", + field=models.DecimalField(decimal_places=1, default=0, max_digits=9), + ), + ] diff --git a/bbs/models.py b/bbs/models.py index 8ce9499..121a5fa 100755 --- a/bbs/models.py +++ b/bbs/models.py @@ -17,6 +17,8 @@ from django.db.models.functions import ( ) EXTERNAL_USER = "Ekstern" +MAX_DIGITS = 9 +DECIMAL_PLACES = 1 def _format_counts(per_user): @@ -36,14 +38,14 @@ def _format_counts(per_user): class Product(models.Model): name = models.CharField(max_length=64) - sale_price_int = models.FloatField() - sale_price_ext = models.FloatField() + sale_price_int = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES) + sale_price_ext = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES) description = models.CharField(max_length=256, blank=True) - volume_liter = models.FloatField(null=True) - alcohol_percent = models.FloatField(null=True) + volume_liter = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, null=True) + alcohol_percent = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, null=True) image = models.ImageField(upload_to="products", blank=True) customer_support = models.CharField(max_length=32, blank=True) - inventory_amount = models.FloatField(default=0) + inventory_amount = models.IntegerField(default=0) active = models.BooleanField(default=True) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) @@ -149,7 +151,7 @@ class OrderLine(models.Model): order = models.ForeignKey("bbs.Order", on_delete=models.CASCADE, related_name="orderlines") product = models.ForeignKey("bbs.Product", on_delete=models.CASCADE, related_name="orderlines") amount = models.IntegerField() - unit_price = models.FloatField(verbose_name="Enhetspris") + unit_price = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, verbose_name="Enhetspris") objects = OrderLineManager.as_manager() @@ -168,7 +170,7 @@ class Transaction(models.Model): """Money""" user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="transactions") - amount = models.FloatField() + amount = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES) created = models.DateTimeField(auto_now_add=True) def __str__(self): @@ -189,8 +191,8 @@ class InventoryTransaction(models.Model): related_name="transactions", verbose_name="Produkt", ) - amount = models.FloatField(verbose_name="Antall") - unit_price = models.FloatField(verbose_name="Enhetspris") + amount = models.IntegerField(verbose_name="Antall") + unit_price = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, verbose_name="Enhetspris") comment = models.TextField(verbose_name="Kommentar", blank=True) created = models.DateTimeField(auto_now_add=True) @@ -204,7 +206,7 @@ class InventoryTransaction(models.Model): class UserProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="profile") - balance = models.FloatField(default=0.0) + balance = models.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, default=0) image = models.URLField(blank=True) def last_purchase(self):