u
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user