diff --git a/src/automats/deliveryEditorAutomat.js b/src/automats/deliveryEditorAutomat.js index c47d8d0..1f92a8a 100644 --- a/src/automats/deliveryEditorAutomat.js +++ b/src/automats/deliveryEditorAutomat.js @@ -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; diff --git a/src/automats/manifestDraftAutomat.js b/src/automats/manifestDraftAutomat.js index 4308845..e616d74 100644 --- a/src/automats/manifestDraftAutomat.js +++ b/src/automats/manifestDraftAutomat.js @@ -26,7 +26,7 @@ export function createInitialManifestDraftState(kind) { kind, mode: 'create', id: null, - date: kind === 'quote' ? todayInputValue() : '', + date: todayInputValue(), partyId: null, number: '', externalNumber: '', diff --git a/src/components/manifest/ManifestForm.jsx b/src/components/manifest/ManifestForm.jsx index 7bfbb4a..1b80dc0 100644 --- a/src/components/manifest/ManifestForm.jsx +++ b/src/components/manifest/ManifestForm.jsx @@ -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 ) { diff --git a/src/routes/lieferung/neu.jsx b/src/routes/lieferung/neu.jsx index 516fd22..6ddc2f8 100644 --- a/src/routes/lieferung/neu.jsx +++ b/src/routes/lieferung/neu.jsx @@ -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);