This commit is contained in:
seb
2026-10-01 07:12:39 +02:00
parent 9c770d765e
commit 62c3e69ed4
11 changed files with 273 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
import * as mssqlQueries from '../../providers/mssql/queries/manifestDoc.js';
import * as sqliteQueries from '../../providers/sqlite3/queries/manifestDoc.js';
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveArticleBySku from '../article/resolveArticleBySku.js';
import nextNumber from '../numbers/nextNumber.js';
@@ -23,6 +25,7 @@ export default function adjust(provider) {
const addLedger = ledgerAdd(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const queries = isSqlite ? sqliteQueries : mssqlQueries;
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
/**
* Adjusts article stock manually by creating an implicit manifest of type "adjustment",
@@ -107,7 +110,7 @@ export default function adjust(provider) {
});
const run = async (runner, activeTx) => {
const { companyId } = await access(googleAuthId, runner);
const { companyId, companyuserId } = await access(googleAuthId, runner);
// Validate all articles exist and belong to the user's company
const resolvedArticles = [];
@@ -228,6 +231,16 @@ export default function adjust(provider) {
});
createdLedgerEntries.push(ledgerRow);
// Write article history for the adjusted article
if (item.articleId) {
const sign = item.amount > 0 ? '+' : '';
await runner.query(insertHistorySql, {
articleId: item.articleId,
companyuserId,
text: `Bestandskorrektur ${sign}${item.amount} (${item.text})`,
});
}
}
return {