fix(manifest): align buildLines validation with OpenAPI (require sku or name, parse pu)
This commit is contained in:
@@ -104,21 +104,23 @@ export function buildLines(lines, { requireAtLeastOne }) {
|
||||
const outLines = [];
|
||||
for (const line of lines) {
|
||||
const sku = String(line.sku ?? '').trim();
|
||||
const name = String(line.name ?? '').trim();
|
||||
const amount = parseNum(line.amount);
|
||||
const net = parseNum(line.net ?? line.netprice);
|
||||
const tax = parseNum(line.tax ?? line.taxrate);
|
||||
const rebate = parseNum(line.rebate);
|
||||
const pu = parseNum(line.pu);
|
||||
const blank =
|
||||
!sku && amount == null && net == null && tax == null && rebate == null;
|
||||
!sku && !name && amount == null && net == null && tax == null && rebate == null;
|
||||
if (blank) continue;
|
||||
if (!sku || amount == null || net == null || tax == null) {
|
||||
throw new Error('Jede Zeile braucht SKU, Amount, Net und Tax.');
|
||||
if ((!sku && !name) || amount == null || net == null || tax == null) {
|
||||
throw new Error('Jede Zeile braucht SKU oder Name, Amount, Net und Tax.');
|
||||
}
|
||||
const row = { sku, amount, net, tax };
|
||||
const row = { amount, net, tax };
|
||||
if (sku) row.sku = sku;
|
||||
if (name) row.name = name;
|
||||
if (rebate != null) row.rebate = rebate;
|
||||
if (line.name) row.name = line.name;
|
||||
if (line.pu != null) row.pu = line.pu;
|
||||
if (line.unit) row.unit = line.unit;
|
||||
if (pu != null) row.pu = pu;
|
||||
outLines.push(row);
|
||||
}
|
||||
if (requireAtLeastOne && outLines.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user