diff --git a/lib/sales_tax.js b/lib/sales_tax.js index e351785..d6c7914 100644 --- a/lib/sales_tax.js +++ b/lib/sales_tax.js @@ -498,18 +498,29 @@ SalesTax.prototype.__buildSalesTaxContext = function( var taxDetails = []; if (isExempt !== true) { - if (countryTax.rate > 0) { + // if country has tax and no negative state rate (e.g. FR) + if (countryTax.rate > 0 && (!stateTax.rate || stateTax.rate > 0)) { taxDetails.push({ type : countryTax.type, rate : countryTax.rate }); } - if (stateTax.rate > 0) { + + // if state has tax (e.g. US-HI) + if (stateTax.rate && stateTax.rate > 0) { taxDetails.push({ type : stateTax.type, rate : stateTax.rate }); } + + // if state has a negative tax, substract it from country's tax (e.g. PT-20) + if (stateTax.rate && stateTax.rate < 0) { + taxDetails.push({ + type : stateTax.type, + rate : countryTax.rate + stateTax.rate + }); + } } // Build sales tax context diff --git a/res/sales_tax_rates.json b/res/sales_tax_rates.json index e2d2db1..0404020 100644 --- a/res/sales_tax_rates.json +++ b/res/sales_tax_rates.json @@ -502,7 +502,17 @@ "PT": { "type": "vat", - "rate": 0.23 + "rate": 0.23, + "states": { + "20": { + "rate": -0.05, + "type": "vat" + }, + "30": { + "rate": -0.01, + "type": "vat" + } + } }, "PR": { diff --git a/test/sales_tax-test.js b/test/sales_tax-test.js index 4888a08..f013a1b 100644 --- a/test/sales_tax-test.js +++ b/test/sales_tax-test.js @@ -843,6 +843,47 @@ describe("node-sales-tax", function() { ); }); }); + + it("🇵🇹 should succeed acquiring Açores state sales tax [no tax origin]", function() { + return SalesTax.getSalesTax("PT","20") + .then(function(tax) { + assert.equal( + tax.type, "vat", "Tax type should be VAT" + ); + + assert.equal( + tax.rate, 0.18, "Tax rate should be 18%" + ); + + assert.equal( + tax.area, "worldwide", "Tax area should be WORLDWIDE" + ); + + assert.equal( + tax.exchange, "consumer", "Tax exchange should be CONSUMER" + ); + + assert.equal( + tax.charge.direct, true, "Should perform a direct charge" + ); + + assert.equal( + tax.charge.reverse, false, "Should not perform a reverse charge" + ); + + assert.equal( + tax.details.length, 1, "Tax details should contain 1 tax rate" + ); + + assert.equal( + tax.details[0].type, "vat", "Tax details #1 type should be VAT" + ); + + assert.equal( + tax.details[0].rate, 0.18, "Tax details #1 rate should be 18%" + ); + }); + }); }); describe("getAmountWithSalesTax", function() {