u
This commit is contained in:
@@ -2,6 +2,8 @@ import * as mssqlQueries from '../../providers/mssql/queries/articlesupplier.js'
|
||||
import * as sqliteQueries from '../../providers/sqlite3/queries/articlesupplier.js';
|
||||
import { CREATE as MSSQL_CREATE_PRICE } from '../../providers/mssql/queries/price.js';
|
||||
import { CREATE as SQLITE_CREATE_PRICE } from '../../providers/sqlite3/queries/price.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 '../article/resolveArticleBySku.js';
|
||||
import ensureLieferantenGroup from '../supplier/ensureLieferantenGroup.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
@@ -20,6 +22,7 @@ export default function create(provider) {
|
||||
|
||||
const queries = isSqlite ? sqliteQueries : mssqlQueries;
|
||||
const createPriceSql = isSqlite ? SQLITE_CREATE_PRICE : MSSQL_CREATE_PRICE;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Assigns a supplier to an article, optionally creating a purchase price.
|
||||
@@ -82,7 +85,11 @@ export default function create(provider) {
|
||||
}
|
||||
|
||||
const runCreate = async (runner) => {
|
||||
const { articleId, companyId } = await resolve(googleAuthId, sku, runner);
|
||||
const { articleId, companyId, companyuserId } = await resolve(
|
||||
googleAuthId,
|
||||
sku,
|
||||
runner,
|
||||
);
|
||||
|
||||
await assertSupplier(runner, companyId, entityId);
|
||||
|
||||
@@ -153,7 +160,28 @@ export default function create(provider) {
|
||||
companyId,
|
||||
});
|
||||
|
||||
return shapeArticleSupplier(loadRes.rows[0]);
|
||||
const supplierRow = loadRes.rows[0];
|
||||
const supplierName =
|
||||
supplierRow?.supplierName ?? (entityId ? `Lieferant #${entityId}` : 'Lieferant');
|
||||
|
||||
const details = [];
|
||||
const actualSku = supplierRow?.sku ?? supplierSku;
|
||||
if (actualSku) {
|
||||
details.push(`Artikelnr: "${actualSku}"`);
|
||||
}
|
||||
const actualPrice = supplierRow?.priceNet ?? netPrice;
|
||||
if (actualPrice !== null && actualPrice !== undefined) {
|
||||
details.push(`EK: ${actualPrice}`);
|
||||
}
|
||||
const suffix = details.length ? ` (${details.join(', ')})` : '';
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Lieferant "${supplierName}" hinzugefügt${suffix}`,
|
||||
});
|
||||
|
||||
return shapeArticleSupplier(supplierRow);
|
||||
};
|
||||
|
||||
if (tx) {
|
||||
|
||||
Reference in New Issue
Block a user