diff --git a/src/components/manifest/ArticleSearchDialog.jsx b/src/components/manifest/ArticleSearchDialog.jsx index d3f1fea..fc9df9d 100644 --- a/src/components/manifest/ArticleSearchDialog.jsx +++ b/src/components/manifest/ArticleSearchDialog.jsx @@ -19,17 +19,18 @@ export default class ArticleSearchDialog extends PureComponent { this.state = { assigningSku: null, error: null, + showAllArticles: false, }; } componentDidUpdate(prevProps) { if (!prevProps.open && this.props.open) { - this.setState({ assigningSku: null, error: null }); + this.setState({ assigningSku: null, error: null, showAllArticles: false }); } } handleClose = () => { - this.setState({ assigningSku: null, error: null }); + this.setState({ assigningSku: null, error: null, showAllArticles: false }); this.props.onClose?.(); }; @@ -61,9 +62,9 @@ export default class ArticleSearchDialog extends PureComponent { render() { const { open, onClose, line, kind = 'delivery', supplierArticles: propSupplierArticles } = this.props; - const { assigningSku, error } = this.state; + const { assigningSku, error, showAllArticles } = this.state; const isDelivery = kind === 'delivery'; - const onlySupplierArticles = isDelivery && !line; + const onlySupplierArticles = isDelivery && !line && !showAllArticles; const rawSku = line?.sku != null ? String(line.sku).trim() : ''; const supplierArticlesList = onlySupplierArticles @@ -122,7 +123,7 @@ export default class ArticleSearchDialog extends PureComponent { {line - ? 'Existierenden Artikel zuordnen' + ? (isDelivery ? 'Artikel neu zuordnen' : 'Existierenden Artikel zuordnen') : isDelivery ? 'Lieferanten-Artikel auswählen' : 'Artikel auswählen'} @@ -134,7 +135,21 @@ export default class ArticleSearchDialog extends PureComponent { {line?.name ? ` · ${line.name}` : ''} ) : isDelivery ? ( - 'Nur mit dem ausgewählten Lieferanten verknüpfte Artikel' + + + {showAllArticles + ? 'Alle Artikel im Katalog durchsuchen' + : 'Nur mit dem ausgewählten Lieferanten verknüpfte Artikel'} + + + ) : ( 'Artikel für Beleg auswählen' )} diff --git a/src/components/manifest/ManifestFormLine.jsx b/src/components/manifest/ManifestFormLine.jsx index 4ec9bda..202b3ff 100644 --- a/src/components/manifest/ManifestFormLine.jsx +++ b/src/components/manifest/ManifestFormLine.jsx @@ -766,6 +766,30 @@ class ManifestFormLine extends PureComponent { /> )} + {this.props.onSearchArticle && ( + + )} + {/* Brand */} {cachedArticle.brand?.name && ( )} + {this.props.onSearchArticle && ( + + )} + {/* Brand */} {(fullArticle.brand?.name || article.brand?.name) && ( + + + ); + } + return null; } diff --git a/src/routes/lieferung/neu.jsx b/src/routes/lieferung/neu.jsx index d1a4ead..cd6dcdb 100644 --- a/src/routes/lieferung/neu.jsx +++ b/src/routes/lieferung/neu.jsx @@ -576,6 +576,20 @@ class LieferungNeuPage extends PureComponent { } try { + // If this line was previously mapped to a different article, unlink the old supplier article + const existingSupplierArticle = + (line?.key != null ? this.state.supplierArticlesByLineKey?.[line.key] : null) || + (supplierSku ? (this.state.supplierArticlesMap?.[supplierSku.toLowerCase()] || this.state.supplierArticlesMap?.[supplierSku]) : null); + const oldInternalSku = existingSupplierArticle?.article?.sku; + const oldAssignmentId = existingSupplierArticle?.id; + if (oldInternalSku && oldAssignmentId != null && String(oldInternalSku).toLowerCase() !== String(internalSku).toLowerCase()) { + try { + await this.automat.actions.unlinkSupplierArticle(oldInternalSku, oldAssignmentId, line?.key); + } catch (unlinkErr) { + console.warn('Vorherige Lieferanten-Zuordnung konnte nicht gelöst werden:', unlinkErr); + } + } + await articleApi.addSupplier(internalSku, { entityId: partyId, sku: supplierSku || undefined, @@ -587,13 +601,16 @@ class LieferungNeuPage extends PureComponent { if (supplierSku) { await this.automat.actions.fetchSupplierArticleForSku(supplierSku, line.key); + } else { + await this.automat.actions.fetchSupplierArticleForSku(internalSku, line.key); } await this.automat.actions.fetchSupplierArticles(partyId); - if (!line.name && article.name) { + if (!line.name || (existingSupplierArticle?.article?.name && line.name === existingSupplierArticle.article.name)) { this.automat.actions.updateLineitem({ ...line, - name: article.name, + name: article.name || line.name, + ...(!line.sku ? { sku: internalSku } : {}), }); }