refactor(manifestLines): standardize on taxrate and change schema type to float
This commit is contained in:
@@ -5,7 +5,7 @@ import request from './request.js';
|
||||
* Normalizes and validates an array of manifest line inputs.
|
||||
*
|
||||
* @param {Array<object>} lines - The raw line inputs.
|
||||
* @returns {Array<{sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, tax: number, comment: string|null}>} The normalized lines.
|
||||
* @returns {Array<{sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>} The normalized lines.
|
||||
* @throws {Error} If the lines are invalid.
|
||||
*/
|
||||
export function normalizeLines(lines) {
|
||||
@@ -28,7 +28,7 @@ export function normalizeLines(lines) {
|
||||
const net = entry?.net;
|
||||
const rebate =
|
||||
entry?.rebate === undefined || entry?.rebate === null ? 0 : entry.rebate;
|
||||
const tax = entry?.tax;
|
||||
const taxrate = entry?.taxrate;
|
||||
const comment =
|
||||
entry?.comment === undefined || entry?.comment === null
|
||||
? null
|
||||
@@ -39,12 +39,12 @@ export function normalizeLines(lines) {
|
||||
!Number.isFinite(amount) ||
|
||||
!Number.isFinite(net) ||
|
||||
!Number.isFinite(rebate) ||
|
||||
!Number.isFinite(tax)
|
||||
!Number.isFinite(taxrate)
|
||||
) {
|
||||
throw new Error('Invalid lines');
|
||||
}
|
||||
|
||||
return { sku, name, pu, amount, net, rebate, tax, comment };
|
||||
return { sku, name, pu, amount, net, rebate, taxrate, comment };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export function parseDate(value) {
|
||||
* @returns {object} The shaped line.
|
||||
*/
|
||||
export function shapeLine(row) {
|
||||
const tax = Number(row.tax);
|
||||
const taxrate = Number(row.taxrate);
|
||||
return {
|
||||
id: row.id,
|
||||
sku: row.sku ?? null,
|
||||
@@ -83,7 +83,7 @@ export function shapeLine(row) {
|
||||
amount: row.amount,
|
||||
net: row.net,
|
||||
rebate: row.rebate,
|
||||
tax,
|
||||
taxrate,
|
||||
comment: row.comment ?? null,
|
||||
};
|
||||
}
|
||||
@@ -107,7 +107,7 @@ export async function insertLines(
|
||||
) {
|
||||
for (const line of lines) {
|
||||
if (ensureTax) {
|
||||
await ensureTax(line.tax, tx);
|
||||
await ensureTax(line.taxrate, tx);
|
||||
}
|
||||
|
||||
await request(pool, tx)
|
||||
@@ -119,7 +119,7 @@ export async function insertLines(
|
||||
.input('net', line.net)
|
||||
.input('comment', line.comment)
|
||||
.input('rebate', line.rebate)
|
||||
.input('taxrate', line.tax)
|
||||
.input('taxrate', line.taxrate)
|
||||
.query(CREATE_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user