mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1231 from SchrodingersGat/slow-bom-fix
Add option to show part quantity in various forms
This commit is contained in:
commit
9efde9de29
@ -160,6 +160,13 @@ class InvenTreeSetting(models.Model):
|
|||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'PART_SHOW_QUANTITY_IN_FORMS': {
|
||||||
|
'name': _('Show Quantity in Forms'),
|
||||||
|
'description': _('Display available part quantity in some forms'),
|
||||||
|
'default': True,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
|
|
||||||
'STOCK_ENABLE_EXPIRY': {
|
'STOCK_ENABLE_EXPIRY': {
|
||||||
'name': _('Stock Expiry'),
|
'name': _('Stock Expiry'),
|
||||||
'description': _('Enable stock expiry functionality'),
|
'description': _('Enable stock expiry functionality'),
|
||||||
|
@ -13,6 +13,8 @@ from mptt.fields import TreeNodeChoiceField
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
import common.models
|
||||||
|
|
||||||
from .models import Part, PartCategory, PartAttachment, PartRelated
|
from .models import Part, PartCategory, PartAttachment, PartRelated
|
||||||
from .models import BomItem
|
from .models import BomItem
|
||||||
from .models import PartParameterTemplate, PartParameter
|
from .models import PartParameterTemplate, PartParameter
|
||||||
@ -23,8 +25,16 @@ from .models import PartSellPriceBreak
|
|||||||
|
|
||||||
class PartModelChoiceField(forms.ModelChoiceField):
|
class PartModelChoiceField(forms.ModelChoiceField):
|
||||||
""" Extending string representation of Part instance with available stock """
|
""" Extending string representation of Part instance with available stock """
|
||||||
|
|
||||||
def label_from_instance(self, part):
|
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):
|
class PartImageForm(HelperForm):
|
||||||
|
@ -1990,7 +1990,13 @@ class BomItem(models.Model):
|
|||||||
Return the available stock items for the referenced sub_part
|
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)
|
available=Coalesce(Sum('quantity'), 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_IPN_REGEX" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_IPN_REGEX" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_DUPLICATE_IPN" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_ALLOW_DUPLICATE_IPN" %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" %}
|
||||||
<tr><td colspan='5 '></td></tr>
|
<tr><td colspan='5 '></td></tr>
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_TEMPLATE" icon="fa-clone" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_TEMPLATE" icon="fa-clone" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="PART_ASSEMBLY" icon="fa-tools" %}
|
{% include "InvenTree/settings/setting.html" with key="PART_ASSEMBLY" icon="fa-tools" %}
|
||||||
|
Loading…
Reference in New Issue
Block a user