u
This commit is contained in:
@@ -126,6 +126,19 @@ export default function adjust(provider) {
|
||||
const text = input.text ?? input.transactionText ?? input.transaction_text ??
|
||||
(amount > 0 ? `Stock addition (+${amount})` : `Stock deduction (${amount})`);
|
||||
|
||||
if (amount < 0) {
|
||||
const stockRes = await runner.query(ledgerQueries.GET_ARTICLE_WAREHOUSE_STOCK, {
|
||||
warehouseId,
|
||||
companyId,
|
||||
sku,
|
||||
articleId: art.id,
|
||||
});
|
||||
const currentStock = Number(stockRes.rows[0]?.stock ?? 0);
|
||||
if (currentStock + amount < 0) {
|
||||
throw new Error(`Insufficient stock for article (${sku}): available ${currentStock}, requested ${Math.abs(amount)}`);
|
||||
}
|
||||
}
|
||||
|
||||
const latest = await runner.query(ledgerQueries.GET_LATEST_ROW);
|
||||
const prevRow = latest.rows[0];
|
||||
const prevHash = computePrevHash(prevRow);
|
||||
@@ -301,6 +314,19 @@ export default function adjust(provider) {
|
||||
const createdLedgerEntries = [];
|
||||
|
||||
for (const item of resolvedArticles) {
|
||||
if (item.amount < 0) {
|
||||
const stockRes = await runner.query(ledgerQueries.GET_ARTICLE_WAREHOUSE_STOCK, {
|
||||
warehouseId: item.warehouseId,
|
||||
companyId,
|
||||
sku: item.sku,
|
||||
articleId: item.articleId,
|
||||
});
|
||||
const currentStock = Number(stockRes.rows[0]?.stock ?? 0);
|
||||
if (currentStock + item.amount < 0) {
|
||||
throw new Error(`Insufficient stock for article (${item.sku}): available ${currentStock}, requested ${Math.abs(item.amount)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Create manifestarticle row
|
||||
const lineRes = await runner.query(queries.CREATE_LINE, {
|
||||
manifestId,
|
||||
|
||||
Reference in New Issue
Block a user