u
This commit is contained in:
@@ -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