2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-02 03:14:56 +00:00

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 <oliver.henry.walters@gmail.com>
This commit is contained in:
Tom Murray
2026-01-30 01:42:30 +02:00
committed by GitHub
parent e554cf2a58
commit d00d472d35
4 changed files with 46 additions and 1 deletions

View File

@@ -1,11 +1,14 @@
"""InvenTree API version information.""" """InvenTree API version information."""
# InvenTree API version # 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.""" """Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """ 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 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) - Add customize option to disable theme loading from user profile (mainly for demo site use)

View File

@@ -1025,6 +1025,7 @@ class SalesOrderSerializer(
'order_currency', 'order_currency',
'shipments_count', 'shipments_count',
'completed_shipments_count', 'completed_shipments_count',
'allocated_lines',
]) ])
read_only_fields = ['status', 'creation_date', 'shipment_date'] read_only_fields = ['status', 'creation_date', 'shipment_date']
extra_kwargs = {'order_currency': {'required': False}} extra_kwargs = {'order_currency': {'required': False}}
@@ -1040,6 +1041,7 @@ class SalesOrderSerializer(
"""Add extra information to the queryset. """Add extra information to the queryset.
- Number of line items in the SalesOrder - Number of line items in the SalesOrder
- Number of fully allocated line items
- Number of completed line items in the SalesOrder - Number of completed line items in the SalesOrder
- Overdue status of the SalesOrder - Overdue status of the SalesOrder
""" """
@@ -1049,6 +1051,19 @@ class SalesOrderSerializer(
completed_lines=SubqueryCount('lines', filter=Q(quantity__lte=F('shipped'))) 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( queryset = queryset.annotate(
overdue=Case( overdue=Case(
When( When(
@@ -1084,6 +1099,10 @@ class SalesOrderSerializer(
read_only=True, allow_null=True, label=_('Completed Shipments') 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): class SalesOrderIssueSerializer(OrderAdjustSerializer):
"""Serializer for issuing a SalesOrder.""" """Serializer for issuing a SalesOrder."""

View File

@@ -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) => (
<ProgressBar
progressLabel={true}
value={record.allocated_lines}
maximum={record.line_items}
/>
),
...props
};
}
export function ProjectCodeColumn(props: TableColumnProps): TableColumn { export function ProjectCodeColumn(props: TableColumnProps): TableColumn {
const globalSettings = useGlobalSettingsState.getState(); const globalSettings = useGlobalSettingsState.getState();
const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true); const enabled = globalSettings.isSet('PROJECT_CODES_ENABLED', true);

View File

@@ -14,6 +14,7 @@ import { useCreateApiFormModal } from '../../hooks/UseForm';
import { useTable } from '../../hooks/UseTable'; import { useTable } from '../../hooks/UseTable';
import { useUserState } from '../../states/UserState'; import { useUserState } from '../../states/UserState';
import { import {
AllocatedLinesProgressColumn,
CompanyColumn, CompanyColumn,
CreatedByColumn, CreatedByColumn,
CreationDateColumn, CreationDateColumn,
@@ -142,6 +143,9 @@ export function SalesOrderTable({
}, },
DescriptionColumn({}), DescriptionColumn({}),
LineItemsProgressColumn({}), LineItemsProgressColumn({}),
AllocatedLinesProgressColumn({
defaultVisible: false
}),
{ {
accessor: 'shipments_count', accessor: 'shipments_count',
title: t`Shipments`, title: t`Shipments`,