mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-07 04:12:11 +00:00
[Platform] BOM Table (#5876)
* Add generic BooleanColumn for tables * Edit BOM item * Add 'building' quantity to BomItemSerializer * Improve "available" column * Fix yesnobutton * Update 'available' and 'can_build' columns * Delete BOM item * Improve back-end ordering for BomItem list API * Table tweaks * Bump API version * Tweak API notes
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 148
|
||||
INVENTREE_API_VERSION = 149
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
v149 -> 2023-11-07 : https://github.com/inventree/InvenTree/pull/5876
|
||||
- Add 'building' quantity to BomItem serializer
|
||||
- Add extra ordering options for the BomItem list API
|
||||
|
||||
v148 -> 2023-11-06 : https://github.com/inventree/InvenTree/pull/5872
|
||||
- Allow "quantity" to be specified when installing an item into another item
|
||||
|
||||
|
@@ -1810,6 +1810,10 @@ class BomList(BomMixin, ListCreateDestroyAPIView):
|
||||
'quantity',
|
||||
'sub_part',
|
||||
'available_stock',
|
||||
'allow_variants',
|
||||
'inherited',
|
||||
'optional',
|
||||
'consumable',
|
||||
]
|
||||
|
||||
ordering_field_aliases = {
|
||||
|
@@ -1184,6 +1184,9 @@ class BomItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
|
||||
# Annotated field describing quantity on order
|
||||
'on_order',
|
||||
|
||||
# Annotated field describing quantity being built
|
||||
'building',
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -1228,6 +1231,7 @@ class BomItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
|
||||
|
||||
on_order = serializers.FloatField(read_only=True)
|
||||
building = serializers.FloatField(read_only=True)
|
||||
|
||||
# Cached pricing fields
|
||||
pricing_min = InvenTree.serializers.InvenTreeMoneySerializer(source='sub_part.pricing.overall_min', allow_null=True, read_only=True)
|
||||
@@ -1259,6 +1263,10 @@ class BomItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
'substitutes__part__stock_items',
|
||||
)
|
||||
|
||||
queryset = queryset.prefetch_related(
|
||||
'sub_part__builds',
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
@staticmethod
|
||||
@@ -1280,6 +1288,18 @@ class BomItemSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
on_order=part.filters.annotate_on_order_quantity(ref),
|
||||
)
|
||||
|
||||
# Annotate with the total "building" amount for the sub-part
|
||||
queryset = queryset.annotate(
|
||||
building=Coalesce(
|
||||
SubquerySum(
|
||||
'sub_part__builds__quantity',
|
||||
filter=Q(status__in=BuildStatusGroups.ACTIVE_CODES),
|
||||
),
|
||||
Decimal(0),
|
||||
output_field=models.DecimalField(),
|
||||
)
|
||||
)
|
||||
|
||||
# Calculate "total stock" for the referenced sub_part
|
||||
# Calculate the "build_order_allocations" for the sub_part
|
||||
# Note that these fields are only aliased, not annotated
|
||||
|
Reference in New Issue
Block a user