mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Build order improvements (#6343)
* Auto-fill project code When creating a new child build order, copy project code from parent build * Auto-fill project code for sales orders * Annotate "building" quantity to BuildLine serializer - So we know how many units are in production * Display building quantity in build line table * Update API version info * Skeleton for BuildLineTable - No content yet (needs work) * Refactor part hovercard * Navigate to part * Add actions for build line table * Display more information for "available stock" column * More updates * Fix "building" filter - Rename to "in_production" * Add filters * Remove unused imports
This commit is contained in:
		| @@ -1,5 +1,7 @@ | ||||
| """JSON serializers for Build API.""" | ||||
|  | ||||
| from decimal import Decimal | ||||
|  | ||||
| from django.db import transaction | ||||
| from django.core.exceptions import ValidationError as DjangoValidationError | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| @@ -7,18 +9,20 @@ from django.utils.translation import gettext_lazy as _ | ||||
| from django.db import models | ||||
| from django.db.models import ExpressionWrapper, F, FloatField | ||||
| from django.db.models import Case, Sum, When, Value | ||||
| from django.db.models import BooleanField | ||||
| from django.db.models import BooleanField, Q | ||||
| from django.db.models.functions import Coalesce | ||||
|  | ||||
| from rest_framework import serializers | ||||
| from rest_framework.serializers import ValidationError | ||||
|  | ||||
| from sql_util.utils import SubquerySum | ||||
|  | ||||
| from InvenTree.serializers import InvenTreeModelSerializer, InvenTreeAttachmentSerializer | ||||
| from InvenTree.serializers import UserSerializer | ||||
|  | ||||
| import InvenTree.helpers | ||||
| from InvenTree.serializers import InvenTreeDecimalField | ||||
| from InvenTree.status_codes import StockStatus | ||||
| from InvenTree.status_codes import BuildStatusGroups, StockStatus | ||||
|  | ||||
| from stock.models import generate_batch_code, StockItem, StockLocation | ||||
| from stock.serializers import StockItemSerializerBrief, LocationSerializer | ||||
| @@ -1055,6 +1059,7 @@ class BuildLineSerializer(InvenTreeModelSerializer): | ||||
|  | ||||
|             # Annotated fields | ||||
|             'allocated', | ||||
|             'in_production', | ||||
|             'on_order', | ||||
|             'available_stock', | ||||
|             'available_substitute_stock', | ||||
| @@ -1078,6 +1083,7 @@ class BuildLineSerializer(InvenTreeModelSerializer): | ||||
|     # Annotated (calculated) fields | ||||
|     allocated = serializers.FloatField(read_only=True) | ||||
|     on_order = serializers.FloatField(read_only=True) | ||||
|     in_production = serializers.FloatField(read_only=True) | ||||
|     available_stock = serializers.FloatField(read_only=True) | ||||
|     available_substitute_stock = serializers.FloatField(read_only=True) | ||||
|     available_variant_stock = serializers.FloatField(read_only=True) | ||||
| @@ -1090,6 +1096,7 @@ class BuildLineSerializer(InvenTreeModelSerializer): | ||||
|         - allocated: Total stock quantity allocated against this build line | ||||
|         - available: Total stock available for allocation against this build line | ||||
|         - on_order: Total stock on order for this build line | ||||
|         - in_production: Total stock currently in production for this build line | ||||
|         """ | ||||
|         queryset = queryset.select_related( | ||||
|             'build', 'bom_item', | ||||
| @@ -1126,6 +1133,11 @@ class BuildLineSerializer(InvenTreeModelSerializer): | ||||
|  | ||||
|         ref = 'bom_item__sub_part__' | ||||
|  | ||||
|         # Annotate the "in_production" quantity | ||||
|         queryset = queryset.annotate( | ||||
|             in_production=part.filters.annotate_in_production_quantity(reference=ref) | ||||
|         ) | ||||
|  | ||||
|         # Annotate the "on_order" quantity | ||||
|         # Difficulty: Medium | ||||
|         queryset = queryset.annotate( | ||||
|   | ||||
| @@ -373,7 +373,11 @@ onPanelLoad('allocate', function() { | ||||
|     loadBuildLineTable( | ||||
|         "#build-lines-table", | ||||
|         {{ build.pk }}, | ||||
|         {} | ||||
|         { | ||||
|             {% if build.project_code %} | ||||
|             project_code: {{ build.project_code.pk }}, | ||||
|             {% endif %} | ||||
|         } | ||||
|     ); | ||||
| }); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user