This commit is contained in:
seb
2026-09-30 09:48:01 +02:00
parent 9885c489f0
commit 280a45a11f
28 changed files with 539 additions and 16 deletions

View File

@@ -53,6 +53,26 @@ export default function toggleFather(provider) {
throw new Error('An article with options cannot become a father');
}
const stockRes = await runner.query(
'SELECT COALESCE(SUM(l.amount), 0) AS totalStock FROM ledger l WHERE l.article_id = @articleId',
{ articleId },
);
const totalStock = Number(stockRes.rows[0]?.totalStock ?? 0);
if (totalStock !== 0) {
throw new Error('An article with existing stock cannot become a father article');
}
const supRes = await runner.query(
'SELECT COUNT(*) AS count FROM articlesupplier WHERE article_id = @articleId',
{ articleId },
);
if ((supRes.rows[0]?.count ?? 0) > 0) {
throw new Error('An article with assigned suppliers cannot become a father article');
}
await runner.query('DELETE FROM price WHERE article_id = @articleId', { articleId });
await runner.query('UPDATE article SET track_stock = 0 WHERE id = @articleId', { articleId });
// If article is a child, verify attribute is not used by father or any father up the chain
let currentFatherId = currentArt?.fatherarticle_id;
const visited = new Set();