From 9fa13aeae36e960b3add6dbde674c53bbe28e1f1 Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 20 Aug 2020 15:38:41 -0500 Subject: [PATCH 1/2] Show 'available_stock' in Part string representation --- InvenTree/part/models.py | 2 +- InvenTree/part/templates/part/bom_upload/select_parts.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index dd126d5730..4001ad4558 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -269,7 +269,7 @@ class Part(MPTTModel): super().save(*args, **kwargs) def __str__(self): - return "{n} - {d}".format(n=self.full_name, d=self.description) + return f"{self.full_name} - {self.description} - {self.available_stock}" 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 d84cb0262f..1ee5e8821b 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 %} From 946d8249957aaa28a0d2088332282a5ae90ad864 Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 24 Aug 2020 11:41:14 -0500 Subject: [PATCH 2/2] Switched to ModelChoiceField --- InvenTree/part/forms.py | 8 ++++++++ InvenTree/part/models.py | 2 +- .../part/templates/part/bom_upload/select_parts.html | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) 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 %}