From 5226f1e1ff8439f5dfddf93728fa804e995e03ce Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 22 May 2023 00:06:54 +1000 Subject: [PATCH] Add "pack_units_native" field to company.SupplierPart model --- .../company/migrations/0059_supplierpart_pack_units.py | 7 +++++++ InvenTree/company/migrations/0060_auto_20230519_0344.py | 5 ++++- InvenTree/company/models.py | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/migrations/0059_supplierpart_pack_units.py b/InvenTree/company/migrations/0059_supplierpart_pack_units.py index 94a1070b9e..80118cc0bb 100644 --- a/InvenTree/company/migrations/0059_supplierpart_pack_units.py +++ b/InvenTree/company/migrations/0059_supplierpart_pack_units.py @@ -2,6 +2,8 @@ from django.db import migrations, models +import InvenTree.fields + class Migration(migrations.Migration): @@ -15,4 +17,9 @@ class Migration(migrations.Migration): name='pack_units', field=models.CharField(blank=True, help_text='Units of measure for this supplier part', max_length=25, verbose_name='Packaging Units'), ), + migrations.AddField( + model_name='supplierpart', + name='pack_units_native', + field=InvenTree.fields.RoundingDecimalField(decimal_places=10, default=1, max_digits=20, null=True), + ), ] diff --git a/InvenTree/company/migrations/0060_auto_20230519_0344.py b/InvenTree/company/migrations/0060_auto_20230519_0344.py index 8d3ff1aae7..64c5da75ec 100644 --- a/InvenTree/company/migrations/0060_auto_20230519_0344.py +++ b/InvenTree/company/migrations/0060_auto_20230519_0344.py @@ -13,7 +13,9 @@ def update_supplier_part_units(apps, schema_editor): supplier_parts = SupplierPart.objects.all() for sp in supplier_parts: - sp.pack_units = str(normalize(sp.pack_size)) + pack_size = normalize(sp.pack_size) + sp.pack_units = str(pack_size) + sp.pack_units_native = pack_size sp.save() if supplier_parts.count() > 0: @@ -24,6 +26,7 @@ class Migration(migrations.Migration): dependencies = [ ('company', '0059_supplierpart_pack_units'), + ('part', '0111_auto_20230521_1350'), ] operations = [ diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index d85fbb3f1b..7350195d0c 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -26,7 +26,7 @@ import InvenTree.ready import InvenTree.tasks import InvenTree.validators from common.settings import currency_code_default -from InvenTree.fields import InvenTreeURLField +from InvenTree.fields import InvenTreeURLField, RoundingDecimalField from InvenTree.models import (InvenTreeAttachment, InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin) from InvenTree.status_codes import PurchaseOrderStatus @@ -438,6 +438,7 @@ class SupplierPart(MetadataMixin, InvenTreeBarcodeMixin, common.models.MetaMixin lead_time: Supplier lead time packaging: packaging that the part is supplied in, e.g. "Reel" pack_units: Quantity of item supplied in a single pack (e.g. 30ml in a single tube) + pack_units_native: Pack units, converted to "native" units of the referenced part updated: Date that the SupplierPart was last updated """ @@ -578,6 +579,11 @@ class SupplierPart(MetadataMixin, InvenTreeBarcodeMixin, common.models.MetaMixin blank=True, ) + pack_units_native = RoundingDecimalField( + max_digits=20, decimal_places=10, default=1, + null=True, + ) + multiple = models.PositiveIntegerField(default=1, validators=[MinValueValidator(1)], verbose_name=_('multiple'), help_text=_('Order multiple')) # TODO - Reimplement lead-time as a charfield with special validation (pattern matching).