This commit is contained in:
seb
2026-10-12 17:29:29 +02:00
parent 3d6bc97411
commit 2e961252f7
44 changed files with 1166 additions and 374 deletions

View File

@@ -4,10 +4,12 @@ import { GET_CHILD_COUNT as MSSQL_GET_CHILD_COUNT } from '../../providers/mssql/
import { GET_CHILD_COUNT as SQLITE_GET_CHILD_COUNT } from '../../providers/sqlite3/queries/articleDelete.js';
import * as mssqlAttr from '../../providers/mssql/queries/attributename.js';
import * as sqliteAttr from '../../providers/sqlite3/queries/attributename.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 resolveArticleBySku from './resolveArticleBySku.js';
import getBySku from './getBySku.js';
import {
recordParentConvertedHistory,
recordParentDeactivatedHistory,
} from '../articlehistory/record.js';
import makeRunner from '../runner.js';
export default function toggleParent(provider) {
@@ -18,7 +20,6 @@ export default function toggleParent(provider) {
const queries = isSqlite ? sqliteArticle : mssqlArticle;
const getChildCountSql = isSqlite ? SQLITE_GET_CHILD_COUNT : MSSQL_GET_CHILD_COUNT;
const attrQueries = isSqlite ? sqliteAttr : mssqlAttr;
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
/**
* Toggles an article into or out of parent mode.
@@ -142,32 +143,11 @@ export default function toggleParent(provider) {
});
// Add history entry recording parent conversion and deleted prices
const historyLines = [
`Artikel zu Vaterartikel konvertiert (Varianten-Attribut: "${attributeName}")`,
];
if (existingPrices.length > 0) {
const priceParts = existingPrices.map((p) => {
let str = `${p.net} €`;
if (p.taxRate != null) {
str += ` (${p.taxRate}% MwSt.)`;
}
if (p.minmultiplier > 1) {
str += ` ab ${p.minmultiplier} Stk.`;
}
if (p.customerGroupName) {
str += ` [${p.customerGroupName}]`;
}
return str;
});
const label = existingPrices.length === 1 ? 'Bisheriger Preis gelöscht' : 'Bisherige Preise gelöscht';
historyLines.push(`${label}: ${priceParts.join(', ')}`);
}
await runner.query(insertHistorySql, {
await recordParentConvertedHistory(runner, {
articleId,
companyuserId,
text: historyLines.join('\n'),
attributeName,
existingPrices,
});
} else {
// Disabling parent: verify zero children
@@ -183,10 +163,9 @@ export default function toggleParent(provider) {
parentAttributeNameId: null,
});
await runner.query(insertHistorySql, {
await recordParentDeactivatedHistory(runner, {
articleId,
companyuserId,
text: 'Vaterartikel-Modus deaktiviert',
});
}