u
This commit is contained in:
@@ -45,7 +45,7 @@ import {
|
||||
alpha,
|
||||
} from '../../../colors';
|
||||
|
||||
function getVariantDetails(child, allArticles, defaultTaxRate) {
|
||||
function getVariantDetails(child, allArticles, defaultTaxRate, parentArticle) {
|
||||
const cached = child?.sku ? getArticle(child.sku) : null;
|
||||
const fromIndex = !cached && child?.sku
|
||||
? (allArticles || []).find((a) => a.sku === child.sku)
|
||||
@@ -56,8 +56,23 @@ function getVariantDetails(child, allArticles, defaultTaxRate) {
|
||||
const gross = getArticleGross(merged, defaultTaxRate);
|
||||
const priceDisplay = gross != null && Number.isFinite(gross) ? formatPrice(gross) : null;
|
||||
|
||||
// 2. Stock & Unit
|
||||
// 2. Stock tracking
|
||||
const rawTrack =
|
||||
merged.track_stock ??
|
||||
merged.trackStock ??
|
||||
child?.trackStock ??
|
||||
child?.track_stock ??
|
||||
parentArticle?.track_stock ??
|
||||
parentArticle?.trackStock;
|
||||
|
||||
const trackStock =
|
||||
rawTrack !== undefined
|
||||
? rawTrack !== false && rawTrack !== 0 && rawTrack !== '0'
|
||||
: true;
|
||||
|
||||
// 3. Stock & Unit
|
||||
let stockVal = null;
|
||||
if (trackStock) {
|
||||
if (Array.isArray(merged.warehouses) && merged.warehouses.length > 0) {
|
||||
stockVal = merged.warehouses.reduce((sum, wh) => sum + (Number(wh.stock) || 0), 0);
|
||||
} else if (merged.stock != null && !Number.isNaN(Number(merged.stock))) {
|
||||
@@ -65,6 +80,7 @@ function getVariantDetails(child, allArticles, defaultTaxRate) {
|
||||
} else if (child?.stock != null && !Number.isNaN(Number(child.stock))) {
|
||||
stockVal = Number(child.stock);
|
||||
}
|
||||
}
|
||||
|
||||
const rawUnit =
|
||||
merged.unit?.symbol ||
|
||||
@@ -76,9 +92,9 @@ function getVariantDetails(child, allArticles, defaultTaxRate) {
|
||||
rawUnit && !['stk', 'stück', 'pc', 'stk.'].includes(rawUnit.trim().toLowerCase())
|
||||
? ` ${rawUnit}`
|
||||
: '';
|
||||
const stockDisplay = stockVal != null ? `${formatStock(stockVal)}${unit}` : null;
|
||||
const stockDisplay = trackStock && stockVal != null ? `${formatStock(stockVal)}${unit}` : null;
|
||||
|
||||
// 3. EAN(s)
|
||||
// 4. EAN(s)
|
||||
const eanCandidates = [];
|
||||
const rawEans = merged.eans ?? child?.eans;
|
||||
if (Array.isArray(rawEans)) {
|
||||
@@ -103,6 +119,7 @@ function getVariantDetails(child, allArticles, defaultTaxRate) {
|
||||
stockDisplay,
|
||||
primaryEan,
|
||||
allEans: eanCandidates,
|
||||
trackStock,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -199,7 +216,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
if (!this._cancelled && parent?.children) {
|
||||
this.ensureChildren(parent.children);
|
||||
}
|
||||
}).catch(() => {});
|
||||
}).catch(() => { });
|
||||
}
|
||||
|
||||
void this.loadAllArticles();
|
||||
@@ -220,7 +237,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
if (!this._cancelled && parent?.children) {
|
||||
this.ensureChildren(parent.children);
|
||||
}
|
||||
}).catch(() => {});
|
||||
}).catch(() => { });
|
||||
} else {
|
||||
const parent = getArticle(this.props.article.parentSku);
|
||||
if (parent?.children) {
|
||||
@@ -268,7 +285,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
if (!Array.isArray(children)) return;
|
||||
for (const child of children) {
|
||||
if (child?.sku && !getArticle(child.sku)) {
|
||||
void artikelAutomat.actions.loadArticle(child.sku).catch(() => {});
|
||||
void artikelAutomat.actions.loadArticle(child.sku).catch(() => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,30 +410,41 @@ export default class ArticleViewLists extends PureComponent {
|
||||
const { selectedChildValueId, newChildText, isCustomChildValue, busy } = this.state;
|
||||
if (busy || !article?.sku) return;
|
||||
|
||||
const payload = {};
|
||||
if (isCustomChildValue) {
|
||||
const val = newChildText.trim();
|
||||
if (!val) return;
|
||||
const payload = {};
|
||||
|
||||
if (val && (isCustomChildValue || !selectedChildValueId)) {
|
||||
payload.value = val;
|
||||
} else if (selectedChildValueId) {
|
||||
payload.attributeValueId = Number(selectedChildValueId);
|
||||
} else if (val) {
|
||||
payload.value = val;
|
||||
} else {
|
||||
if (!selectedChildValueId) return;
|
||||
payload.attributeValueId = Number(selectedChildValueId);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ busy: true });
|
||||
try {
|
||||
const api = this.getApi();
|
||||
await api.addChild(article.sku, payload);
|
||||
const res = await api.addChild(article.sku, payload);
|
||||
if (this._cancelled) return;
|
||||
|
||||
if (res?.sku) {
|
||||
void artikelAutomat.actions.loadArticle(res.sku).catch(() => { });
|
||||
}
|
||||
|
||||
await artikelAutomat.actions.reloadArticle(article.sku);
|
||||
if (this._cancelled) return;
|
||||
|
||||
void articleIndexAutomat.actions.reload().catch(() => { });
|
||||
void companyAutomat.actions.loadAttributes?.().catch?.(() => { });
|
||||
|
||||
enqueueSnackbar('Variante erfolgreich angelegt.', { variant: 'success' });
|
||||
this.setState({
|
||||
busy: false,
|
||||
selectedChildValueId: '',
|
||||
newChildText: '',
|
||||
isCustomChildValue: false,
|
||||
});
|
||||
} catch (err) {
|
||||
if (this._cancelled) return;
|
||||
@@ -1348,7 +1376,8 @@ export default class ArticleViewLists extends PureComponent {
|
||||
stockDisplay,
|
||||
primaryEan,
|
||||
allEans,
|
||||
} = getVariantDetails(sibling, allArticles, defaultTaxRate);
|
||||
trackStock,
|
||||
} = getVariantDetails(sibling, allArticles, defaultTaxRate, parentArticle);
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -1465,7 +1494,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
sx={{
|
||||
fontSize: '0.74rem',
|
||||
fontWeight: 600,
|
||||
color: stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
color: !trackStock || stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
@@ -1584,7 +1613,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
sx={{
|
||||
fontSize: '0.74rem',
|
||||
fontWeight: 600,
|
||||
color: stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
color: !trackStock || stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
@@ -1908,11 +1937,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
<Typography variant="caption" sx={{ fontWeight: 600, color: 'text.secondary' }}>
|
||||
Varianten:
|
||||
</Typography>
|
||||
{children.length === 0 ? (
|
||||
<Typography variant="body2" color="text.secondary" sx={{ py: 1, fontSize: '0.8rem' }}>
|
||||
Noch keine Varianten angelegt.
|
||||
</Typography>
|
||||
) : (
|
||||
{children.length === 0 ? null : (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
|
||||
{children.map((child) => {
|
||||
const defaultTaxRate = this.state.company?.taxrate ?? companyAutomat.state.current?.taxrate ?? 19;
|
||||
@@ -1922,7 +1947,8 @@ export default class ArticleViewLists extends PureComponent {
|
||||
stockDisplay,
|
||||
primaryEan,
|
||||
allEans,
|
||||
} = getVariantDetails(child, allArticles, defaultTaxRate);
|
||||
trackStock,
|
||||
} = getVariantDetails(child, allArticles, defaultTaxRate, articleData);
|
||||
|
||||
return (
|
||||
<Box
|
||||
@@ -2064,7 +2090,7 @@ export default class ArticleViewLists extends PureComponent {
|
||||
sx={{
|
||||
fontSize: '0.74rem',
|
||||
fontWeight: 600,
|
||||
color: stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
color: !trackStock || stockVal == null ? 'text.disabled' : stockVal > 0 ? 'success.dark' : 'error.main',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
@@ -2077,7 +2103,6 @@ export default class ArticleViewLists extends PureComponent {
|
||||
size="small"
|
||||
disabled={busy}
|
||||
onClick={() => this.handleOpenRemoveDialog(child)}
|
||||
title="Variante entfernen"
|
||||
sx={{
|
||||
p: 0.35,
|
||||
color: 'text.secondary',
|
||||
@@ -2098,7 +2123,6 @@ export default class ArticleViewLists extends PureComponent {
|
||||
{isCustomChildValue || availableParentValues.length === 0 ? (
|
||||
<TextInput
|
||||
label="Neuer Wert"
|
||||
placeholder="Neuer Wert..."
|
||||
value={newChildText}
|
||||
disabled={busy}
|
||||
onChange={(e) => this.setState({ newChildText: e.target.value })}
|
||||
@@ -2143,11 +2167,10 @@ export default class ArticleViewLists extends PureComponent {
|
||||
</TextInput>
|
||||
)}
|
||||
|
||||
<Tooltip title="Variante hinzufügen">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
color="primary"
|
||||
aria-label="Variante hinzufügen"
|
||||
disabled={
|
||||
busy ||
|
||||
(isCustomChildValue || availableParentValues.length === 0
|
||||
@@ -2169,8 +2192,6 @@ export default class ArticleViewLists extends PureComponent {
|
||||
>
|
||||
{busy ? <CircularProgress size={16} color="inherit" /> : <AddIcon fontSize="small" />}
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
|
||||
{/* Toggle custom value / predefined value if values exist */}
|
||||
|
||||
Reference in New Issue
Block a user