u
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
CHECK_ARTICLE_IS_FATHER as MSSQL_CHECK_ARTICLE_IS_FATHER,
|
||||
CHECK_ARTICLE_IS_PARENT as MSSQL_CHECK_ARTICLE_IS_PARENT,
|
||||
CREATE_LINE as MSSQL_CREATE_LINE,
|
||||
} from '../providers/mssql/queries/manifestDoc.js';
|
||||
import {
|
||||
CHECK_ARTICLE_IS_FATHER as SQLITE_CHECK_ARTICLE_IS_FATHER,
|
||||
CHECK_ARTICLE_IS_PARENT as SQLITE_CHECK_ARTICLE_IS_PARENT,
|
||||
CREATE_LINE as SQLITE_CREATE_LINE,
|
||||
} from '../providers/sqlite3/queries/manifestDoc.js';
|
||||
import makeRunner from './runner.js';
|
||||
@@ -122,20 +122,20 @@ export async function insertLines(
|
||||
const { manifestId, lines, ensureTax } = params;
|
||||
const isSqlite = runner?.dialect === 'sqlite3';
|
||||
const createLineSql = isSqlite ? SQLITE_CREATE_LINE : MSSQL_CREATE_LINE;
|
||||
const checkFatherSql = isSqlite ? SQLITE_CHECK_ARTICLE_IS_FATHER : MSSQL_CHECK_ARTICLE_IS_FATHER;
|
||||
const checkParentSql = isSqlite ? SQLITE_CHECK_ARTICLE_IS_PARENT : MSSQL_CHECK_ARTICLE_IS_PARENT;
|
||||
|
||||
for (const line of lines) {
|
||||
let resolvedName = line.name;
|
||||
let resolvedPu = line.pu;
|
||||
|
||||
if (line.sku) {
|
||||
const fatherCheck = await runner.query(checkFatherSql, {
|
||||
const parentCheck = await runner.query(checkParentSql, {
|
||||
manifestId,
|
||||
sku: line.sku,
|
||||
});
|
||||
const art = fatherCheck.rows[0];
|
||||
if (art?.isFather) {
|
||||
throw new Error(`A father article cannot be booked on documents (${line.sku})`);
|
||||
const art = parentCheck.rows[0];
|
||||
if (art?.isParent) {
|
||||
throw new Error(`A parent article cannot be booked on documents (${line.sku})`);
|
||||
}
|
||||
if (!resolvedName && art?.articleName) {
|
||||
resolvedName = art.articleName;
|
||||
|
||||
Reference in New Issue
Block a user