This commit is contained in:
seb
2026-10-18 19:10:43 +02:00
parent 596d0dc6f1
commit 199bf869a6
7 changed files with 143 additions and 18 deletions

View File

@@ -23,6 +23,10 @@ import {
/** Groups that are not sales customers (filter client-side). */
export const EXCLUDED_CUSTOMER_GROUP_NAMES = new Set(['Lieferanten', 'POS']);
export function isSupplierCustomerGroup(group) {
return String(group?.name ?? '').trim().toLowerCase() === 'lieferanten';
}
export function entityDisplayName(entity) {
if (!entity) return '';
const fullName = [entity.firstName, entity.name].filter(Boolean).join(' ');
@@ -37,6 +41,31 @@ export function sortEntities(entities) {
});
}
/**
* Customers = entities whose customergroup is not Lieferanten.
*/
export function filterNonSupplierEntities(entities, groups) {
const supplierIds = new Set(
(groups || [])
.filter(isSupplierCustomerGroup)
.map((g) => g.id),
);
return sortEntities(
(entities || []).filter((e) => !supplierIds.has(e.customergroupId)),
);
}
/**
* Returns the customer group with the lowest sort number that is not Lieferanten.
*/
export function getLowestSortNonSupplierCustomerGroup(groups) {
const nonSuppliers = (groups || []).filter((g) => !isSupplierCustomerGroup(g));
if (nonSuppliers.length === 0) return null;
return [...nonSuppliers].sort(
(a, b) => (Number(a.sort) || 0) - (Number(b.sort) || 0),
)[0];
}
/**
* Customers = entities whose customergroup.name is not Lieferanten/POS.
*/
@@ -588,8 +617,13 @@ export async function loadParties(cfgOrKind) {
const list = await supplierAutomat.actions.load();
return sortSuppliers(list);
}
const entities = await entityAutomat.actions.ensureLoaded();
return entities ?? entityAutomat.state.items ?? [];
const [entities, groups] = await Promise.all([
entityAutomat.actions.ensureLoaded(),
customergroupAutomat.actions.ensureLoaded(),
]);
const entityList = entities ?? entityAutomat.state.items ?? [];
const groupList = groups ?? customergroupAutomat.state.items ?? [];
return filterNonSupplierEntities(entityList, groupList);
}
export function partyDisplayName(cfgOrKind, party) {