u
This commit is contained in:
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user