2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-01-28 17:13:44 +00:00

Enhance stock merge (#11141)

- Improve location selection
This commit is contained in:
Oliver
2026-01-16 11:26:38 +11:00
committed by GitHub
parent 9fa40ae572
commit c89e3bdfea

View File

@@ -1038,6 +1038,30 @@ function stockMergeFields(items: any[]): ApiFormFieldSet {
const records = Object.fromEntries(items.map((item) => [item.pk, item]));
// Extract all non-null location values from the items
const locationValues = [
...new Set(
items.filter((item) => item.location).map((item) => item.location)
)
];
// Extract all non-null default location values from the items
const defaultLocationValues = [
...new Set(
items
.filter((item) => item.part_detail?.default_location)
.map((item) => item.part_detail?.default_location)
)
];
// Select a default location value
const defaultLocation =
locationValues.length === 1
? locationValues[0]
: defaultLocationValues.length === 1
? defaultLocationValues[0]
: undefined;
const fields: ApiFormFieldSet = {
items: {
field_type: 'table',
@@ -1067,7 +1091,7 @@ function stockMergeFields(items: any[]): ApiFormFieldSet {
]
},
location: {
default: items[0]?.part_detail?.default_location,
default: defaultLocation,
filters: {
structural: false
}