2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-21 06:16:29 +00:00

Merged changes from master

This commit is contained in:
eeintech
2021-01-14 08:52:56 -05:00
34 changed files with 2765 additions and 3357 deletions

View File

@ -13,6 +13,8 @@ from mptt.fields import TreeNodeChoiceField
from django import forms
from django.utils.translation import ugettext as _
import common.models
from .models import Part, PartCategory, PartAttachment, PartRelated
from .models import BomItem
from .models import PartParameterTemplate, PartParameter
@ -23,8 +25,16 @@ from .models import PartSellPriceBreak
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}'
label = str(part)
# Optionally display available part quantity
if common.models.InvenTreeSetting.get_setting('PART_SHOW_QUANTITY_IN_FORMS'):
label += f" - {part.available_stock}"
return label
class PartImageForm(HelperForm):

View File

@ -1990,7 +1990,13 @@ class BomItem(models.Model):
Return the available stock items for the referenced sub_part
"""
query = self.sub_part.stock_items.filter(StockModels.StockItem.IN_STOCK_FILTER).aggregate(
query = self.sub_part.stock_items.all()
query = query.prefetch_related([
'sub_part__stock_items',
])
query = query.filter(StockModels.StockItem.IN_STOCK_FILTER).aggregate(
available=Coalesce(Sum('quantity'), 0)
)

View File

@ -214,9 +214,9 @@
<tr>
<td>
{% if part.active %}
<span class='fas fa-check-square'></span>
<span class='fas fa-check-circle icon-green'></span>
{% else %}
<span class='fas fa-times-square'></span>
<span class='fas fa-times-circle icon-red'></span>
{% endif %}
</td>
<td><b>{% trans "Active" %}</b></td>

View File

@ -1320,7 +1320,7 @@ class BomUpload(InvenTreeRoleMixin, FormView):
# Otherwise, check to see if there is a matching IPN
try:
if row['part_ipn']:
part_matches = [part for part in self.allowed_parts if row['part_ipn'].lower() == part.IPN.lower()]
part_matches = [part for part in self.allowed_parts if part.IPN and row['part_ipn'].lower() == str(part.IPN.lower())]
# Check for single match
if len(part_matches) == 1: