This commit is contained in:
seb
2026-10-04 21:04:40 +02:00
parent 669954b496
commit f765b87336
59 changed files with 1491 additions and 2045 deletions

View File

@@ -1,4 +1,14 @@
import {
delivery as deliveryApi,
quote as quoteApi,
order as orderApi,
} from '../../api';
import supplierAutomat from '../../automats/supplierAutomat';
import entityAutomat from '../../automats/entityAutomat';
import customergroupAutomat from '../../automats/customergroupAutomat';
import deliveryAutomat from '../../automats/deliveryAutomat';
import quoteAutomat from '../../automats/quoteAutomat';
import orderAutomat from '../../automats/orderAutomat';
/** Groups that are not sales customers (filter client-side). */
export const EXCLUDED_CUSTOMER_GROUP_NAMES = new Set(['Lieferanten', 'POS']);
@@ -481,12 +491,27 @@ export const DELIVERY_LINE_COLUMNS = [
/** @typedef {'delivery'|'quote'|'order'} ManifestKind */
/**
* Resolves the api namespace for a manifest kind.
*
* Delivery, quote, and order share one editor/list shape but talk to three
* different endpoints.
*
* @param {ManifestKind} kind Manifest kind.
* @returns {{get: Function, create: Function, update: Function, delete: Function}}
*/
export function apiFor(kind) {
if (kind === 'delivery') return deliveryApi;
if (kind === 'quote') return quoteApi;
if (kind === 'order') return orderApi;
throw new Error(`Unknown manifest kind: ${kind}`);
}
/**
* Load party options for Autocomplete / list name lookup.
* @param {ManifestKind} kind
* @param {object} ctx StorageManager instance
*/
export async function loadParties(kind, ctx) {
export async function loadParties(kind) {
if (kind === 'delivery') {
if (supplierAutomat.state.status === 'ready') {
return sortSuppliers(supplierAutomat.state.suppliers);
@@ -495,8 +520,8 @@ export async function loadParties(kind, ctx) {
return sortSuppliers(list);
}
const [entities, groups] = await Promise.all([
ctx.entities ?? ctx.entityPromise,
ctx.customergroups ?? ctx.customergroupPromise,
entityAutomat.actions.ensureLoaded(),
customergroupAutomat.actions.ensureLoaded(),
]);
return filterCustomerEntities(entities, groups);
}
@@ -538,8 +563,7 @@ export function manifestConfig(kind) {
headerColor: '#fed7aa',
linesColor: '#bbf7d0',
requirePartyBeforeLines: false,
updateCache: 'updateDelivery',
listPromise: (ctx) => ctx.deliveries ?? ctx.deliveryPromise,
listAutomat: deliveryAutomat,
partiesByIdFromList: (parties) =>
Object.fromEntries(parties.map((row) => [row.id, row])),
// Delivery uses a server-allocated read-only number plus an optional
@@ -575,8 +599,7 @@ export function manifestConfig(kind) {
headerColor: '#fde68a',
linesColor: '#bbf7d0',
requirePartyBeforeLines: false,
updateCache: 'updateQuote',
listPromise: (ctx) => ctx.quotes ?? ctx.quotePromise,
listAutomat: quoteAutomat,
partiesByIdFromList: (parties) =>
Object.fromEntries(parties.map((row) => [row.id, row])),
columns: LINE_COLUMNS,
@@ -609,8 +632,7 @@ export function manifestConfig(kind) {
headerColor: '#c4b5fd',
linesColor: '#bbf7d0',
requirePartyBeforeLines: false,
updateCache: 'updateOrder',
listPromise: (ctx) => ctx.orders ?? ctx.orderPromise,
listAutomat: orderAutomat,
partiesByIdFromList: (parties) =>
Object.fromEntries(parties.map((row) => [row.id, row])),
columns: LINE_COLUMNS,