u
This commit is contained in:
@@ -131,6 +131,26 @@ export default function add(provider) {
|
||||
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;
|
||||
if (warehouseId != null) {
|
||||
const whCheck = await runner.query(queries.CHECK_WAREHOUSE_ACCESS, {
|
||||
|
||||
Reference in New Issue
Block a user