Merge pull request #921 from eeintech/show_potential_bom_items_stock

Show 'available_stock' in Part string representation
This commit is contained in:
Oliver 2020-08-26 09:36:55 +10:00 committed by GitHub
commit ee0df29af0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -200,11 +200,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 = [

View File

@ -268,7 +268,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}"
def checkAddToBOM(self, parent):
"""

View File

@ -63,7 +63,7 @@
<option value=''>--- {% trans "Select Part" %} ---</option>
{% for part in row.part_options %}
<option value='{{ part.id }}' {% if part.id == row.part.id %} selected='selected' {% elif part.id == row.part_match.id %} selected='selected' {% endif %}>
{{ part.full_name }} - {{ part.description }}
{{ part }} - {{ part.available_stock }}
</option>
{% endfor %}
</select>