diff --git a/imports/plugins/included/taxes-avalara/server/hooks/hooks.js b/imports/plugins/included/taxes-avalara/server/hooks/hooks.js index c615ca971c9..6d8e32860f2 100644 --- a/imports/plugins/included/taxes-avalara/server/hooks/hooks.js +++ b/imports/plugins/included/taxes-avalara/server/hooks/hooks.js @@ -27,9 +27,9 @@ MethodHooks.after("taxes/calculate", (options) => { Logger.debug("Avalara triggered on taxes/calculate for cartId:", cartId); if (pkg && pkg.settings.avalara.enabled && pkg.settings.avalara.performTaxCalculation) { taxCalc.estimateCart(cartToCalc, function (result) { - const taxes = linesToTaxes(result.lines); - if (result && result.totalTax && typeof result.totalTax === "number") { - // we don't use totalTax, that just tells us we have a valid tax calculation + // we don't use totalTax, that just tells us we have a valid tax calculation + if (result && result.totalTax && typeof result.totalTax === "number" && result.lines) { + const taxes = linesToTaxes(result.lines); const taxAmount = taxes.reduce((totalTaxes, tax) => totalTaxes + tax.tax, 0); const taxRate = taxAmount / taxCalc.calcTaxable(cartToCalc); Meteor.call("taxes/setRate", cartId, taxRate, taxes); diff --git a/imports/plugins/included/taxes-avalara/server/methods/taxCalc.js b/imports/plugins/included/taxes-avalara/server/methods/taxCalc.js index 1d380f70cc5..461bfbab04c 100644 --- a/imports/plugins/included/taxes-avalara/server/methods/taxCalc.js +++ b/imports/plugins/included/taxes-avalara/server/methods/taxCalc.js @@ -369,7 +369,6 @@ function cartToSalesOrder(cart) { const salesOrder = { companyCode: companyCode, type: "SalesOrder", - code: cart._id, customerCode: cart.userId, date: cartDate, currencyCode: currencyCode, @@ -471,7 +470,7 @@ function orderToSalesInvoice(order) { companyCode: companyCode, type: documentType, commit: commitDocuments, - code: order.cartId, + code: order._id, customerCode: order.userId, date: orderDate, currencyCode: currencyCode,