This commit is contained in:
seb
2026-10-17 03:57:36 +02:00
parent e63abfe2c0
commit 6df833b362
4 changed files with 40 additions and 26 deletions

View File

@@ -82,7 +82,7 @@ class ManifestForm extends PureComponent {
partyId: initialDoc?.partyId ?? null,
number: initialDoc?.number || '',
externalNumber: initialDoc?.externalNumber || '',
lines: initialDoc?.lines?.length > 0 ? initialDoc.lines : [emptyLine()],
lines: Array.isArray(initialDoc?.lines) ? initialDoc.lines : (props.mode === 'create' ? [emptyLine()] : []),
attachments: initialDoc?.attachments || [],
shipments: initialEdit?.shipments || [],
payments: initialEdit?.payments || [],
@@ -197,7 +197,7 @@ class ManifestForm extends PureComponent {
date: state.date || '',
partyId: state.partyId,
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
}));
}
@@ -209,7 +209,7 @@ class ManifestForm extends PureComponent {
date: state.date || '',
partyId: state.partyId,
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
shipments: state.shipments || [],
payments: state.payments || [],
@@ -371,8 +371,7 @@ class ManifestForm extends PureComponent {
requireObject(docRes[cfg.docField], cfg.docField);
const doc = docRes[cfg.docField];
const apiLines = requireArray(doc.lines, `${cfg.docField}.lines`);
const lines =
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()];
const lines = apiLines.map(lineFromApi);
// Restore attachments if available
const apiFiles = doc.files ?? [];
@@ -456,7 +455,7 @@ class ManifestForm extends PureComponent {
partyId: state.partyId,
number: state.number || '',
externalNumber: state.externalNumber || '',
lines: state.lines?.length > 0 ? state.lines : [emptyLine()],
lines: state.lines || [],
attachments: state.attachments || [],
isDirty: false,
dirtyFields: state.dirtyFields,
@@ -787,7 +786,7 @@ class ManifestForm extends PureComponent {
}
}
const next = prev.lines.filter((line) => line.key !== key);
return { lines: next.length > 0 ? next : [emptyLine()], isDirty: true };
return { lines: next, isDirty: true };
});
}
@@ -823,10 +822,10 @@ class ManifestForm extends PureComponent {
return null;
}
enqueueSnackbar('Nicht ausgelieferte Positionen wurden entfernt.', { variant: 'info' });
return { lines: remaining.length > 0 ? remaining : [emptyLine()], isDirty: true };
return { lines: remaining, isDirty: true };
}
}
return { lines: [emptyLine()], isDirty: true };
return { lines: [], isDirty: true };
});
}
@@ -1097,7 +1096,7 @@ class ManifestForm extends PureComponent {
if (this.state.saving) return false;
if (mode === 'edit' && docId == null) return false;
const requireAtLeastOne = mode === 'create';
const isEdit = mode === 'edit';
let body;
try {
body = await buildManifestBody(
@@ -1112,8 +1111,10 @@ class ManifestForm extends PureComponent {
{
kind: cfg.kind,
partyField: cfg.partyField,
requireAtLeastOne,
requireAtLeastOne: true,
externalNumber: cfg.externalNumber,
isUpdate: isEdit,
mode,
},
);
} catch (err) {
@@ -1151,8 +1152,7 @@ class ManifestForm extends PureComponent {
number: doc.number ?? '',
externalNumber:
doc.externalNumber != null ? String(doc.externalNumber) : '',
lines:
apiLines.length > 0 ? apiLines.map(lineFromApi) : [emptyLine()],
lines: apiLines.map(lineFromApi),
attachments: this.state.attachments,
};

View File

@@ -114,8 +114,21 @@ class ManifestLines extends PureComponent {
}
}
return Array.isArray(lines) &&
lines.map((line, index) => {
if (!lines || lines.length === 0) {
return (
<TableRow>
<TableCell
colSpan={columns.length + 1}
align="center"
sx={{ py: 3, color: 'text.secondary', fontSize: '0.82rem' }}
>
Keine Positionen vorhanden
</TableCell>
</TableRow>
);
}
return lines.map((line, index) => {
const lineKey = line.key ?? index;
const rawSku = line.sku != null ? String(line.sku).trim() : '';
const isOnShipment = kind === 'order' && Boolean(rawSku && shippedSkus.has(rawSku.toLowerCase()));

View File

@@ -454,12 +454,14 @@ export function collectFilesForUpload(attachments = [], { onlyNew = false } = {}
*/
export async function buildManifestBody(
form,
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind },
{ partyField, requireAtLeastOne, externalNumber: useExternalNumber, kind, isUpdate, mode },
) {
const date = form.date;
if (!date) throw new Error('Datum fehlt.');
const externalNumber = String(form.externalNumber ?? '').trim();
const isEdit = isUpdate != null ? Boolean(isUpdate) : (mode === 'edit' || !requireAtLeastOne);
const shouldRequireLine = requireAtLeastOne !== false;
let body;
if (kind === 'delivery') {
@@ -468,7 +470,7 @@ export async function buildManifestBody(
body = {
externalNumber: externalNumber || null,
date,
lines: buildLines(form.lines, { requireAtLeastOne }),
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
};
} else {
let number = String(form.number ?? '').trim();
@@ -479,7 +481,7 @@ export async function buildManifestBody(
body = {
number,
date,
lines: buildLines(form.lines, { requireAtLeastOne }),
lines: buildLines(form.lines, { requireAtLeastOne: shouldRequireLine }),
};
if (useExternalNumber || form.externalNumber != null) {
body.externalNumber = externalNumber || null;
@@ -490,14 +492,13 @@ export async function buildManifestBody(
if (!Number.isNaN(pid)) {
body[partyField] = pid;
}
} else if (!requireAtLeastOne) {
} else if (isEdit) {
body[partyField] = null;
}
// Add files if attachments exist
if (form.attachments && form.attachments.length > 0) {
const isUpdate = !requireAtLeastOne;
const filesToUpload = collectFilesForUpload(form.attachments, { onlyNew: isUpdate });
const filesToUpload = collectFilesForUpload(form.attachments, { onlyNew: isEdit });
if (filesToUpload.length > 0) {
const formData = new FormData();
body.filesMeta = filesToUpload.map((item) => ({