Change item quantity field from PositiveInteger to Decimal

- Allow 'partial' quantity e.g. '0.45kg'
- Need to change some maths functions as Decimal type is pernickity
This commit is contained in:
Oliver Walters 2019-11-19 08:49:54 +11:00
parent 81a226c760
commit 400941c10f
4 changed files with 41 additions and 3 deletions

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.5 on 2019-11-18 21:39
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0023_auto_20190913_1401'),
]
operations = [
migrations.AlterField(
model_name='bomitem',
name='quantity',
field=models.DecimalField(decimal_places=5, default=1.0, help_text='BOM quantity for this BOM item', max_digits=15, validators=[django.core.validators.MinValueValidator(0)]),
),
]

View File

@ -517,7 +517,7 @@ class Part(models.Model):
# Calculate the minimum number of parts that can be built using each sub-part
for item in self.bom_items.all().prefetch_related('sub_part__stock_items'):
stock = item.sub_part.available_stock
n = int(1.0 * stock / item.quantity)
n = int(stock / item.quantity)
if total is None or n < total:
total = n
@ -1064,7 +1064,7 @@ class BomItem(models.Model):
})
# Quantity required
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)], help_text='BOM quantity for this BOM item')
quantity = models.DecimalField(default=1.0, max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], help_text=_('BOM quantity for this BOM item'))
overage = models.CharField(max_length=24, blank=True, validators=[validators.validate_overage],
help_text=_('Estimated build wastage quantity (absolute or percentage)')

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.5 on 2019-11-18 21:46
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('stock', '0015_auto_20190913_1407'),
]
operations = [
migrations.AlterField(
model_name='stockitem',
name='quantity',
field=models.DecimalField(decimal_places=5, default=1, max_digits=15, validators=[django.core.validators.MinValueValidator(0)]),
),
]

View File

@ -323,7 +323,7 @@ class StockItem(models.Model):
batch = models.CharField(max_length=100, blank=True, null=True,
help_text=_('Batch code for this stock item'))
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)], default=1)
quantity = models.DecimalField(max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], default=1)
updated = models.DateField(auto_now=True, null=True)