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