This commit is contained in:
seb
2026-10-18 18:38:38 +02:00
parent 9cb93bddeb
commit c15fa0a53e
4 changed files with 18 additions and 5 deletions

View File

@@ -14,6 +14,7 @@
import { Automat } from 'react-automat';
import { article as articleApi, supplier as supplierApi } from '../api';
import { todayInputValue } from '../components/manifest/manifestConfig';
/**
* @typedef {Object} DeliveryLine
@@ -155,7 +156,7 @@ export function buildSupplierArticlesMap(articles = [], existingMap = {}) {
export const initialDelivery = {
id: null,
deliveryId: null,
date: null,
date: todayInputValue(),
deliveryEntity: null,
partyId: null,
externalNumber: null,
@@ -226,12 +227,14 @@ export function createDeliveryEditorAutomat(options = {}) {
: delivery.notes ? [delivery.notes] : [];
const rawAttachments = delivery.attachments ?? delivery.files ?? [];
const attachments = Array.isArray(rawAttachments) ? rawAttachments : [];
const date = delivery.date !== undefined ? delivery.date : (id != null ? null : (automat.state.date || todayInputValue()));
automat.setState({
...initialDelivery,
...delivery,
id,
deliveryId: id,
date,
partyId,
deliveryEntity: partyId,
externalNumber: extNum,
@@ -670,6 +673,7 @@ export function createDeliveryEditorAutomat(options = {}) {
resetDelivery() {
automat.setState({
...initialDelivery,
date: todayInputValue(),
});
},
@@ -677,6 +681,7 @@ export function createDeliveryEditorAutomat(options = {}) {
resetDeliveryEditor() {
automat.setState({
...initialState,
date: todayInputValue(),
});
},
@@ -718,7 +723,7 @@ export function createDeliveryEditorAutomat(options = {}) {
basedata.invoiceNumber ??
basedata.invoice_number ??
null;
const date = basedata.date ?? null;
const date = basedata.date ?? automat.state.date ?? todayInputValue();
const type = basedata.manifestType ?? basedata.type ?? 'rechnung';
let matchedPartyId = partyId != null && partyId !== '' ? partyId : null;

View File

@@ -26,7 +26,7 @@ export function createInitialManifestDraftState(kind) {
kind,
mode: 'create',
id: null,
date: kind === 'quote' ? todayInputValue() : '',
date: todayInputValue(),
partyId: null,
number: '',
externalNumber: '',

View File

@@ -62,11 +62,10 @@ class ManifestForm extends PureComponent {
const initialDate =
initialDoc?.date ||
(props.mode === 'create' && props.kind === 'quote' ? todayInputValue() : '');
(props.mode === 'create' ? todayInputValue() : '');
if (
props.mode === 'create' &&
props.kind === 'quote' &&
this.draftAutomat &&
!this.draftAutomat.state.date
) {

View File

@@ -28,6 +28,7 @@ import {
buildManifestBody,
restoreAttachmentsFromApi,
dateInputValue,
todayInputValue,
emptyLine,
lineFromApi,
manifestConfig,
@@ -107,8 +108,13 @@ class LieferungNeuPage extends PureComponent {
super(props);
this.cfg = manifestConfig('delivery');
this.automat = getDeliveryEditorAutomat(props.docId);
const initialDate = this.automat.state.date || (props.docId == null ? todayInputValue() : null);
if (props.docId == null && !this.automat.state.date) {
this.automat.actions.setDate(initialDate);
}
this.state = {
...this.automat.state,
date: initialDate,
status: props.docId != null ? 'loading' : 'loadingParties',
error: null,
partiesLoading: true,
@@ -199,6 +205,9 @@ class LieferungNeuPage extends PureComponent {
if (this.props.docId != null) {
void this.loadEdit();
} else {
if (!this.automat.state.date) {
this.automat.actions.setDate(todayInputValue());
}
void this.loadPartiesOnly();
if (this.props.initialDelivery) {
this.automat.actions.setDelivery(this.props.initialDelivery);