u
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import * as mssqlQueries from '../../providers/mssql/queries/articlesupplier.js';
|
||||
import * as sqliteQueries from '../../providers/sqlite3/queries/articlesupplier.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 taxEnsure from '../tax/ensure.js';
|
||||
import {
|
||||
@@ -10,6 +8,7 @@ import {
|
||||
resolveCompanyDefaultTax,
|
||||
shapeArticleSupplier,
|
||||
} from './helpers.js';
|
||||
import { recordSupplierAddHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function create(provider) {
|
||||
@@ -18,7 +17,6 @@ export default function create(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
|
||||
const queries = isSqlite ? sqliteQueries : mssqlQueries;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Assigns a supplier to an article, optionally creating a purchase price.
|
||||
@@ -150,21 +148,15 @@ export default function create(provider) {
|
||||
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, {
|
||||
await recordSupplierAddHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Lieferant "${supplierName}" hinzugefügt${suffix}`,
|
||||
supplierName,
|
||||
supplierSku: actualSku,
|
||||
netPrice: actualPrice,
|
||||
});
|
||||
|
||||
return shapeArticleSupplier(supplierRow);
|
||||
|
||||
Reference in New Issue
Block a user