Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle negative state tax #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/sales_tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion res/sales_tax_rates.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
41 changes: 41 additions & 0 deletions test/sales_tax-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down