u
This commit is contained in:
@@ -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 {
|
||||
<Box>
|
||||
<Typography variant="h6" component="div" fontWeight={600}>
|
||||
{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'
|
||||
<Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', gap: 1 }}>
|
||||
<span>
|
||||
{showAllArticles
|
||||
? 'Alle Artikel im Katalog durchsuchen'
|
||||
: 'Nur mit dem ausgewählten Lieferanten verknüpfte Artikel'}
|
||||
</span>
|
||||
<Button
|
||||
size="small"
|
||||
variant="text"
|
||||
onClick={() => this.setState({ showAllArticles: !showAllArticles })}
|
||||
sx={{ fontSize: '0.72rem', py: 0, px: 0.75, textTransform: 'none', minWidth: 'auto', fontWeight: 600 }}
|
||||
>
|
||||
{showAllArticles ? 'Nur Lieferanten-Artikel' : 'Alle Artikel durchsuchen'}
|
||||
</Button>
|
||||
</Box>
|
||||
) : (
|
||||
'Artikel für Beleg auswählen'
|
||||
)}
|
||||
|
||||
@@ -766,6 +766,30 @@ class ManifestFormLine extends PureComponent {
|
||||
/>
|
||||
)}
|
||||
|
||||
{this.props.onSearchArticle && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="text"
|
||||
startIcon={<SearchIcon sx={{ fontSize: 14 }} />}
|
||||
disabled={this.props.saving || this.props.supplierArticleBusy || this.isFullyLedgered()}
|
||||
onClick={this.handleSearchArticle}
|
||||
sx={{
|
||||
fontSize: '0.7rem',
|
||||
fontWeight: 600,
|
||||
textTransform: 'none',
|
||||
minWidth: 'auto',
|
||||
py: 0.25,
|
||||
px: 1,
|
||||
color: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'primary.50',
|
||||
},
|
||||
}}
|
||||
>
|
||||
Artikel neu zuordnen
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Brand */}
|
||||
{cachedArticle.brand?.name && (
|
||||
<BrandLabel
|
||||
@@ -1124,6 +1148,30 @@ class ManifestFormLine extends PureComponent {
|
||||
/>
|
||||
)}
|
||||
|
||||
{this.props.onSearchArticle && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="text"
|
||||
startIcon={<SearchIcon sx={{ fontSize: 14 }} />}
|
||||
disabled={this.props.saving || this.props.supplierArticleBusy || this.isFullyLedgered()}
|
||||
onClick={this.handleSearchArticle}
|
||||
sx={{
|
||||
fontSize: '0.7rem',
|
||||
fontWeight: 600,
|
||||
textTransform: 'none',
|
||||
minWidth: 'auto',
|
||||
py: 0.25,
|
||||
px: 1,
|
||||
color: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'primary.50',
|
||||
},
|
||||
}}
|
||||
>
|
||||
Artikel neu zuordnen
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Brand */}
|
||||
{(fullArticle.brand?.name || article.brand?.name) && (
|
||||
<BrandLabel
|
||||
@@ -1307,6 +1355,34 @@ class ManifestFormLine extends PureComponent {
|
||||
);
|
||||
}
|
||||
|
||||
if (this.props.onSearchArticle) {
|
||||
return (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.75, py: 0.25 }}>
|
||||
<Button
|
||||
size="small"
|
||||
variant="text"
|
||||
startIcon={<SearchIcon sx={{ fontSize: 14 }} />}
|
||||
disabled={this.isFullyLedgered()}
|
||||
onClick={this.handleSearchArticle}
|
||||
sx={{
|
||||
fontSize: '0.7rem',
|
||||
fontWeight: 600,
|
||||
textTransform: 'none',
|
||||
minWidth: 'auto',
|
||||
py: 0.25,
|
||||
px: 1,
|
||||
color: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'primary.50',
|
||||
},
|
||||
}}
|
||||
>
|
||||
Artikel suchen
|
||||
</Button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user