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

View File

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

View File

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

View File

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