diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 7b252067e8..a02a8da82c 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -196,11 +196,19 @@ class EditCategoryForm(HelperForm): ] +class PartModelChoiceField(forms.ModelChoiceField): + """ Extending string representation of Part instance with available stock """ + def label_from_instance(self, part): + return f'{part} - {part.available_stock}' + + class EditBomItemForm(HelperForm): """ Form for editing a BomItem object """ quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5) + sub_part = PartModelChoiceField(queryset=Part.objects.all()) + class Meta: model = BomItem fields = [ diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index cbc9f21572..e5b035f856 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -268,7 +268,7 @@ class Part(MPTTModel): super().save(*args, **kwargs) def __str__(self): - return f"{self.full_name} - {self.description} - {self.available_stock}" + return f"{self.full_name} - {self.description}" def checkAddToBOM(self, parent): """ diff --git a/InvenTree/part/templates/part/bom_upload/select_parts.html b/InvenTree/part/templates/part/bom_upload/select_parts.html index 1ee5e8821b..ede92c6c30 100644 --- a/InvenTree/part/templates/part/bom_upload/select_parts.html +++ b/InvenTree/part/templates/part/bom_upload/select_parts.html @@ -63,7 +63,7 @@ {% for part in row.part_options %} {% endfor %}