diff --git a/InvenTree/InvenTree/api_version.py b/InvenTree/InvenTree/api_version.py index d0e88bd57c..b4f8dcf98b 100644 --- a/InvenTree/InvenTree/api_version.py +++ b/InvenTree/InvenTree/api_version.py @@ -8,7 +8,7 @@ INVENTREE_API_VERSION = 117 Increment this API version number whenever there is a significant change to the API that any clients need to know about v117 -> 2023-05-22 : https://github.com/inventree/InvenTree/pull/4854 - - Replaces SupplierPart "pack_size" field with "pack_units" + - Replaces SupplierPart "pack_size" field with "pack_quantity" - New field supports physical units, and allows for conversion between compatible units v116 -> 2023-05-18 : https://github.com/inventree/InvenTree/pull/4823 diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index 5663727a76..aee0d59ae8 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -390,7 +390,7 @@ class SupplierPartList(ListCreateDestroyAPIView): 'manufacturer', 'MPN', 'packaging', - 'pack_units', + 'pack_quantity', 'in_stock', 'updated', ] @@ -400,7 +400,7 @@ class SupplierPartList(ListCreateDestroyAPIView): 'supplier': 'supplier__name', 'manufacturer': 'manufacturer_part__manufacturer__name', 'MPN': 'manufacturer_part__MPN', - 'pack_units': ['pack_units_native', 'pack_units'], + 'pack_quantity': ['pack_quantity_native', 'pack_quantity'], } search_fields = [ diff --git a/InvenTree/company/fixtures/supplier_part.yaml b/InvenTree/company/fixtures/supplier_part.yaml index 7ed59f0e81..419e54e280 100644 --- a/InvenTree/company/fixtures/supplier_part.yaml +++ b/InvenTree/company/fixtures/supplier_part.yaml @@ -66,4 +66,4 @@ part: 4 supplier: 2 SKU: 'R_4K7_0603.100PCK' - pack_units: '100' + pack_quantity: '100' diff --git a/InvenTree/company/migrations/0059_supplierpart_pack_units.py b/InvenTree/company/migrations/0059_supplierpart_pack_units.py index 80118cc0bb..864ebad772 100644 --- a/InvenTree/company/migrations/0059_supplierpart_pack_units.py +++ b/InvenTree/company/migrations/0059_supplierpart_pack_units.py @@ -14,12 +14,12 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( model_name='supplierpart', - name='pack_units', - field=models.CharField(blank=True, help_text='Units of measure for this supplier part', max_length=25, verbose_name='Packaging Units'), + name='pack_quantity', + field=models.CharField(blank=True, help_text='Total quantity supplied in a single pack. Leave empty for single items.', max_length=25, verbose_name='Pack Quantity'), ), migrations.AddField( model_name='supplierpart', - name='pack_units_native', + name='pack_quantity_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 64c5da75ec..25bca7b391 100644 --- a/InvenTree/company/migrations/0060_auto_20230519_0344.py +++ b/InvenTree/company/migrations/0060_auto_20230519_0344.py @@ -14,8 +14,8 @@ def update_supplier_part_units(apps, schema_editor): for sp in supplier_parts: pack_size = normalize(sp.pack_size) - sp.pack_units = str(pack_size) - sp.pack_units_native = pack_size + sp.pack_quantity = str(pack_size) + sp.pack_quantity_native = pack_size sp.save() if supplier_parts.count() > 0: diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index b204a7a9fa..c6a04eef9a 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -438,8 +438,8 @@ class SupplierPart(MetadataMixin, InvenTreeBarcodeMixin, common.models.MetaMixin multiple: Multiple that the part is provided in 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 + pack_quantity: Quantity of item supplied in a single pack (e.g. 30ml in a single tube) + pack_quantity_native: Pack quantity, converted to "native" units of the referenced part updated: Date that the SupplierPart was last updated """ @@ -478,38 +478,38 @@ class SupplierPart(MetadataMixin, InvenTreeBarcodeMixin, common.models.MetaMixin """ super().clean() - self.pack_units = self.pack_units.strip() + self.pack_quantity = self.pack_quantity.strip() - # An empty 'pack_units' value is equivalent to '1' - if self.pack_units == '': - self.pack_units = '1' + # An empty 'pack_quantity' value is equivalent to '1' + if self.pack_quantity == '': + self.pack_quantity = '1' # Validate that the UOM is compatible with the base part - if self.pack_units and self.part: + if self.pack_quantity and self.part: try: # Attempt conversion to specified unit native_value = InvenTree.conversion.convert_physical_value( - self.pack_units, self.part.units + self.pack_quantity, self.part.units ) # If part units are not provided, value must be dimensionless if not self.part.units and native_value.units not in ['', 'dimensionless']: raise ValidationError({ - 'pack_units': _("Pack units must be compatible with the base part units") + 'pack_quantity': _("Pack units must be compatible with the base part units") }) # Native value must be greater than zero if float(native_value.magnitude) <= 0: raise ValidationError({ - 'pack_units': _("Pack units must be greater than zero") + 'pack_quantity': _("Pack units must be greater than zero") }) # Update native pack units value - self.pack_units_native = Decimal(native_value.magnitude) + self.pack_quantity_native = Decimal(native_value.magnitude) except ValidationError as e: raise ValidationError({ - 'pack_units': e.messages + 'pack_quantity': e.messages }) # Ensure that the linked manufacturer_part points to the same part! @@ -601,14 +601,14 @@ class SupplierPart(MetadataMixin, InvenTreeBarcodeMixin, common.models.MetaMixin packaging = models.CharField(max_length=50, blank=True, null=True, verbose_name=_('Packaging'), help_text=_('Part packaging')) - pack_units = models.CharField( + pack_quantity = models.CharField( max_length=25, - verbose_name=_('Packaging Units'), - help_text=_('Units of measure for this supplier part'), + verbose_name=_('Pack Quantity'), + help_text=_('Total quantity supplied in a single pack. Leave empty for single items.'), blank=True, ) - pack_units_native = RoundingDecimalField( + pack_quantity_native = RoundingDecimalField( max_digits=20, decimal_places=10, default=1, null=True, ) diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 168334d885..f0833d18b0 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -265,7 +265,8 @@ class SupplierPartSerializer(InvenTreeTagModelSerializer): 'pk', 'barcode_hash', 'packaging', - 'pack_units', + 'pack_quantity', + 'pack_quantity_native', 'part', 'part_detail', 'pretty_name', diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 622bd147d0..4fc29abe38 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -162,7 +162,7 @@ src="{% static 'img/blank_image.png' %}"