feat: support public-payer treaty exemption and exact economic adjustments
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -98,7 +98,7 @@ void test('economic inclusion does not add amounts already considered and can co
|
||||
});
|
||||
assert.deepEqual(m.taxableProfit, { numerator: '6642', denominator: '1' });
|
||||
});
|
||||
void test('economic inclusion rejects contradictory prior inclusion, duplicate origins, different taxpayers and unsupported fractional cents', () => {
|
||||
void test('economic inclusion rejects contradictory prior inclusion, duplicate origins, different taxpayers and invalid underlying amounts', () => {
|
||||
const c = caseInput();
|
||||
const contradiction = structuredClone(c.inclusion);
|
||||
contradiction.source.incomeIncluded = 'yes';
|
||||
@@ -125,9 +125,9 @@ void test('economic inclusion rejects contradictory prior inclusion, duplicate o
|
||||
other.source.subjectNuit = '987654321';
|
||||
assert.throws(() => prepareEconomicInclusion(c.normal, other));
|
||||
const partial = structuredClone(c.inclusion);
|
||||
partial.source.taxAmount = '20.01';
|
||||
partial.source.proofAmount = '20.01';
|
||||
assert.throws(() => prepareEconomicInclusion(c.normal, partial), /cêntimo/);
|
||||
partial.source.taxAmount = '-20.01';
|
||||
partial.source.proofAmount = '-20.01';
|
||||
assert.throws(() => prepareEconomicInclusion(c.normal, partial));
|
||||
});
|
||||
void test('economic inclusion keeps recovery, previous result and reports while making the old L8 origin stale', () => {
|
||||
const c = caseInput(),
|
||||
@@ -217,3 +217,69 @@ void test('association inclusion requires its specific evidence and does not inf
|
||||
{ numerator: '112', denominator: '1' },
|
||||
);
|
||||
});
|
||||
|
||||
void test('fractional-cent economic inclusion keeps exact base and collection and does not accumulate on repeat', () => {
|
||||
const c = caseInput();
|
||||
c.inclusion.source.taxAmount = c.inclusion.source.proofAmount = '20.01';
|
||||
const b = prepareEconomicInclusion(c.normal, c.inclusion),
|
||||
m = calculateNormal(c.d, b);
|
||||
assert.equal(b.profit.topics.incomeCorrections.amount, '112.006');
|
||||
assert.deepEqual(m.economicInclusions.net, {
|
||||
numerator: '56003',
|
||||
denominator: '500',
|
||||
});
|
||||
assert.deepEqual(m.taxableBase, {
|
||||
numerator: '2256003',
|
||||
denominator: '500',
|
||||
});
|
||||
assert.deepEqual(m.colecta, { numerator: '4512006', denominator: '3125' });
|
||||
assert.deepEqual(prepareEconomicInclusion(b, c.inclusion), b);
|
||||
assert.match(
|
||||
m.economicInclusions.effects[1].reason,
|
||||
/IRPC-economic-inclusion-exact\/1/,
|
||||
);
|
||||
});
|
||||
void test('fractional economic reconciliation cannot treat0.006 as zero or accept a truncated topic amount', () => {
|
||||
const c = caseInput();
|
||||
Object.assign(c.inclusion.source, {
|
||||
income: '1',
|
||||
incomeIncluded: 'yes',
|
||||
taxAmount: '0.01',
|
||||
proofAmount: '0.01',
|
||||
attributionReference:
|
||||
'SYNTHETIC tax0.01 actually corresponding to included income1',
|
||||
});
|
||||
c.inclusion.profitAlreadyIncluded = '1';
|
||||
const b = prepareEconomicInclusion(c.normal, c.inclusion);
|
||||
assert.equal(b.profit.topics.incomeCorrections.amount, '0.006');
|
||||
assert.deepEqual(calculateNormal(c.d, b).economicInclusions.net, {
|
||||
numerator: '3',
|
||||
denominator: '500',
|
||||
});
|
||||
b.profit.topics.incomeCorrections.amount = '0.00';
|
||||
assert.equal(calculateNormal(c.d, b).taxableProfit, null);
|
||||
});
|
||||
void test('documented prior rational additions and repeating fractions recover without decimal rounding', () => {
|
||||
const c = caseInput();
|
||||
c.inclusion.source.taxAmount = c.inclusion.source.proofAmount = '20.01';
|
||||
c.inclusion.creditAlreadyIncluded = '1/3';
|
||||
c.inclusion.source.grossUpIncluded = '1/3';
|
||||
c.inclusion.source.grossUpReference =
|
||||
'SYNTHETIC previous exact1/3 already added to fiscal base';
|
||||
const b = prepareEconomicInclusion(c.normal, c.inclusion);
|
||||
assert.equal(b.profit.topics.incomeCorrections.amount, '167509/1500');
|
||||
const d = {
|
||||
...c.d,
|
||||
modelo_a_snapshot: saveNormalBook(
|
||||
c.d,
|
||||
recordNormal(c.d, b, '2026-11-10T18:10:00+02:00'),
|
||||
),
|
||||
},
|
||||
back = normalBook(d);
|
||||
assert.equal(normalCurrent(d, back), true);
|
||||
assert.deepEqual(
|
||||
calculateNormal(d, back).economicInclusions,
|
||||
back.result.model.economicInclusions,
|
||||
);
|
||||
assert.match(normalHtml(d), /IRPC-economic-inclusion-exact\/1/);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { internationalCase } from './helpers/irpc-international-case.mjs';
|
||||
import { newPtMzRoyaltyPreparation } from '../../resources/js/lib/irpc-international-credit.ts';
|
||||
import {
|
||||
calculateAnnual,
|
||||
recordAnnual,
|
||||
saveAnnualBook,
|
||||
annualBook,
|
||||
annualCurrent,
|
||||
annualHtml,
|
||||
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
function governmentCase(payer = 'state') {
|
||||
const c = internationalCase();
|
||||
Object.assign(c.b.internationalCredits.positions[0], {
|
||||
country: 'PT',
|
||||
qualificationCountry: 'PT',
|
||||
incomeAmount: '40',
|
||||
treaty: 'yes',
|
||||
treatyMethod: 'ptMzInterest',
|
||||
treatyReference:
|
||||
'SYNTHETIC QA PT-MZ11(3)a and23(3)a, not a real entitlement assertion',
|
||||
treatyPreparation: {
|
||||
...newPtMzRoyaltyPreparation(),
|
||||
gross: '60',
|
||||
from: '2026-01-01',
|
||||
to: '2026-12-31',
|
||||
reference:
|
||||
'SYNTHETIC residence, interest and nonlinked EP conditions documented',
|
||||
residentMz: 'yes',
|
||||
beneficialOwner: 'yes',
|
||||
sourcePortugal: 'yes',
|
||||
payerResidentPt: 'yes',
|
||||
noLinkedEstablishment: 'yes',
|
||||
armLength: 'yes',
|
||||
capitalDefinition: 'yes',
|
||||
governmentInterestExemption: 'yes',
|
||||
governmentPayer: payer,
|
||||
governmentPayerReference:
|
||||
'SYNTHETIC Portuguese public payer identified by supported legal status',
|
||||
},
|
||||
});
|
||||
return c;
|
||||
}
|
||||
void test('documented Portuguese state,subdivision and local public payers yield zero treaty ceiling,not a tax refund', () => {
|
||||
for (const payer of ['state', 'subdivision', 'local']) {
|
||||
const c = governmentCase(payer),
|
||||
before = c.d.modelo_a_snapshot,
|
||||
m = calculateAnnual(c.d, c.b),
|
||||
p = m.internationalCredit.positions[0];
|
||||
assert.deepEqual(m.pending, []);
|
||||
assert.deepEqual(p.treatyLimit, { numerator: '0', denominator: '1' });
|
||||
assert.deepEqual(p.eligible, { numerator: '0', denominator: '1' });
|
||||
assert.deepEqual(p.aboveLimit, { numerator: '10', denominator: '1' });
|
||||
assert.deepEqual(m.arithmeticBalance, {
|
||||
numerator: '708',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.equal(p.treatyDerivation.rate, '0');
|
||||
assert.equal(c.d.modelo_a_snapshot, before);
|
||||
assert.equal(m.internationalCredit.carryCreated, false);
|
||||
}
|
||||
});
|
||||
void test('government exemption cannot be inferred from a flag,name,unknown payer or undocumented classification', () => {
|
||||
for (const patch of [
|
||||
{ governmentPayer: '' },
|
||||
{ governmentPayerReference: '' },
|
||||
{ governmentInterestExemption: '' },
|
||||
{ capitalDefinition: '' },
|
||||
{ noLinkedEstablishment: '' },
|
||||
]) {
|
||||
const c = governmentCase();
|
||||
Object.assign(
|
||||
c.b.internationalCredits.positions[0].treatyPreparation,
|
||||
patch,
|
||||
);
|
||||
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
||||
}
|
||||
});
|
||||
void test('documented absence of governmental exemption keeps the accepted ordinary10percent path', () => {
|
||||
const c = governmentCase();
|
||||
c.b.internationalCredits.positions[0].treatyPreparation.governmentInterestExemption =
|
||||
'no';
|
||||
const p = calculateAnnual(c.d, c.b).internationalCredit.positions[0];
|
||||
assert.deepEqual(p.treatyLimit, { numerator: '6', denominator: '1' });
|
||||
assert.equal(p.treatyDerivation.governmentExemption, undefined);
|
||||
});
|
||||
void test('government exemption and noncreditable paid tax recover into HTML and dossier without rewriting L6', () => {
|
||||
const c = governmentCase(),
|
||||
b = recordAnnual(c.d, c.b, '2026-11-10T18:00:00+02:00'),
|
||||
d = JSON.parse(
|
||||
JSON.stringify({
|
||||
...c.d,
|
||||
modelo_a_snapshot: saveAnnualBook(c.d, b),
|
||||
}),
|
||||
),
|
||||
back = annualBook(d);
|
||||
assert.equal(annualCurrent(d, back), true);
|
||||
assert.deepEqual(
|
||||
calculateAnnual(d, back).internationalCredit,
|
||||
back.result.model.internationalCredit,
|
||||
);
|
||||
assert.match(annualHtml(d), /IRPC-PT-MZ-government-interest\/1/);
|
||||
assert.match(annualHtml(d), /SYNTHETIC Portuguese public payer identified/);
|
||||
assert.match(
|
||||
JSON.stringify(
|
||||
createProjectDossierReport(d, {
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-10T18:00:00+02:00',
|
||||
}),
|
||||
),
|
||||
/IRPC-PT-MZ-government-interest\/1/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user