From d00d472d35844e54102ce5b6cb729b8d93ecaa6e Mon Sep 17 00:00:00 2001 From: Tom Murray <53475898+tomermurray@users.noreply.github.com> Date: Fri, 30 Jan 2026 01:42:30 +0200 Subject: [PATCH] Patch Sales Order line items progress bar to count fully allocated line items (#11102) * Added "allocated_lines" to the backend and frontend tables * Remove incorrectly added UI panels from Sales Order Detail * bump api version --------- Co-authored-by: Oliver --- .../InvenTree/InvenTree/api_version.py | 5 ++++- src/backend/InvenTree/order/serializers.py | 19 +++++++++++++++++++ src/frontend/src/tables/ColumnRenderers.tsx | 19 +++++++++++++++++++ .../src/tables/sales/SalesOrderTable.tsx | 4 ++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index 97c2697fc3..0f25bc724e 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 444 +INVENTREE_API_VERSION = 445 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v445 -> 2026-01-29 : https://github.com/inventree/InvenTree/pull/11102 + - Added "allocated_lines" field to SalesOrderSerializer to track fully allocated line items + v444 -> 2026-01-27 : https://github.com/inventree/InvenTree/pull/11208 - Add customize option to disable theme loading from user profile (mainly for demo site use) diff --git a/src/backend/InvenTree/order/serializers.py b/src/backend/InvenTree/order/serializers.py index 33e5b6cf6f..85b4b91d5f 100644 --- a/src/backend/InvenTree/order/serializers.py +++ b/src/backend/InvenTree/order/serializers.py @@ -1025,6 +1025,7 @@ class SalesOrderSerializer( 'order_currency', 'shipments_count', 'completed_shipments_count', + 'allocated_lines', ]) read_only_fields = ['status', 'creation_date', 'shipment_date'] extra_kwargs = {'order_currency': {'required': False}} @@ -1040,6 +1041,7 @@ class SalesOrderSerializer( """Add extra information to the queryset. - Number of line items in the SalesOrder + - Number of fully allocated line items - Number of completed line items in the SalesOrder - Overdue status of the SalesOrder """ @@ -1049,6 +1051,19 @@ class SalesOrderSerializer( completed_lines=SubqueryCount('lines', filter=Q(quantity__lte=F('shipped'))) ) + queryset = queryset.annotate( + allocated_lines=SubqueryCount( + 'lines', + filter=Q(part__virtual=True) + | Q(shipped__gte=F('quantity')) + | Q( + quantity__lte=Coalesce( + SubquerySum('allocations__quantity'), Decimal(0) + ) + ), + ) + ) + queryset = queryset.annotate( overdue=Case( When( @@ -1084,6 +1099,10 @@ class SalesOrderSerializer( read_only=True, allow_null=True, label=_('Completed Shipments') ) + allocated_lines = serializers.IntegerField( + read_only=True, allow_null=True, label=_('Allocated Lines') + ) + class SalesOrderIssueSerializer(OrderAdjustSerializer): """Serializer for issuing a SalesOrder.""" diff --git a/src/frontend/src/tables/ColumnRenderers.tsx b/src/frontend/src/tables/ColumnRenderers.tsx index 73ccd8ef04..b38c125fd8 100644 --- a/src/frontend/src/tables/ColumnRenderers.tsx +++ b/src/frontend/src/tables/ColumnRenderers.tsx @@ -351,6 +351,25 @@ export function LineItemsProgressColumn(props: TableColumnProps): TableColumn { }; } +export function AllocatedLinesProgressColumn( + props: TableColumnProps +): TableColumn { + return { + accessor: 'allocated_lines', + sortable: true, + title: t`Allocated Lines`, + minWidth: 125, + render: (record: any) => ( + + ), + ...props + }; +} + export function ProjectCodeColumn(props: TableColumnProps): TableColumn { const globalSettings = useGlobalSettingsState.getState(); const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true); diff --git a/src/frontend/src/tables/sales/SalesOrderTable.tsx b/src/frontend/src/tables/sales/SalesOrderTable.tsx index 01249aad03..c1e9b0124a 100644 --- a/src/frontend/src/tables/sales/SalesOrderTable.tsx +++ b/src/frontend/src/tables/sales/SalesOrderTable.tsx @@ -14,6 +14,7 @@ import { useCreateApiFormModal } from '../../hooks/UseForm'; import { useTable } from '../../hooks/UseTable'; import { useUserState } from '../../states/UserState'; import { + AllocatedLinesProgressColumn, CompanyColumn, CreatedByColumn, CreationDateColumn, @@ -142,6 +143,9 @@ export function SalesOrderTable({ }, DescriptionColumn({}), LineItemsProgressColumn({}), + AllocatedLinesProgressColumn({ + defaultVisible: false + }), { accessor: 'shipments_count', title: t`Shipments`,