u
This commit is contained in:
@@ -131,6 +131,26 @@ export default function add(provider) {
|
|||||||
throw new Error('Manifest article not found');
|
throw new Error('Manifest article not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stock guard: warehouse-scoped ledger entries affect article stock
|
||||||
|
// (stock is SUM(ledger.amount) GROUP BY warehouse). Reject bookings for
|
||||||
|
// articles with stock tracking disabled before anything is written.
|
||||||
|
if (warehouseId != null) {
|
||||||
|
const sku = manifestArticle.sku ? String(manifestArticle.sku).trim() : '';
|
||||||
|
if (sku) {
|
||||||
|
const trackRes = await runner.query(
|
||||||
|
`SELECT a.sku, a.track_stock FROM article a
|
||||||
|
WHERE a.company_id = @companyId
|
||||||
|
AND (a.sku = @sku
|
||||||
|
OR EXISTS (SELECT 1 FROM articlesupplier asup WHERE asup.article_id = a.id AND asup.sku = @sku))`,
|
||||||
|
{ companyId, sku },
|
||||||
|
);
|
||||||
|
const disabled = (trackRes.rows ?? []).find((r) => Number(r.track_stock ?? 1) === 0);
|
||||||
|
if (disabled) {
|
||||||
|
throw new Error(`Stock tracking is disabled for article (${sku})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let warehouseName = null;
|
let warehouseName = null;
|
||||||
if (warehouseId != null) {
|
if (warehouseId != null) {
|
||||||
const whCheck = await runner.query(queries.CHECK_WAREHOUSE_ACCESS, {
|
const whCheck = await runner.query(queries.CHECK_WAREHOUSE_ACCESS, {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export default function adjust(provider) {
|
|||||||
const resolvedArticles = [];
|
const resolvedArticles = [];
|
||||||
for (const item of normalizedLines) {
|
for (const item of normalizedLines) {
|
||||||
const resolved = await resolveArticle(googleAuthId, item.sku, activeTx);
|
const resolved = await resolveArticle(googleAuthId, item.sku, activeTx);
|
||||||
const artRes = await runner.query('SELECT is_father, articlelist_id FROM article WHERE id = @articleId', {
|
const artRes = await runner.query('SELECT is_father, articlelist_id, track_stock FROM article WHERE id = @articleId', {
|
||||||
articleId: resolved.articleId,
|
articleId: resolved.articleId,
|
||||||
});
|
});
|
||||||
if (artRes.rows[0]?.is_father) {
|
if (artRes.rows[0]?.is_father) {
|
||||||
@@ -127,6 +127,10 @@ export default function adjust(provider) {
|
|||||||
throw new Error(`A Stückliste cannot have manual stock adjustments (${item.sku})`);
|
throw new Error(`A Stückliste cannot have manual stock adjustments (${item.sku})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Number(artRes.rows[0]?.track_stock ?? 1) === 0) {
|
||||||
|
throw new Error(`Stock tracking is disabled for article (${item.sku})`);
|
||||||
|
}
|
||||||
|
|
||||||
const nameRes = await runner.query(GET_ARTICLE_NAME_SQL, {
|
const nameRes = await runner.query(GET_ARTICLE_NAME_SQL, {
|
||||||
articleId: resolved.articleId,
|
articleId: resolved.articleId,
|
||||||
languageId: resolved.languageId,
|
languageId: resolved.languageId,
|
||||||
|
|||||||
Reference in New Issue
Block a user