fix(iva): exclude import-linked services from goods gift references

This commit is contained in:
2026-10-24 20:39:54 +02:00
parent f9fb04f947
commit 29e708ba2d
2 changed files with 4 additions and 2 deletions
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import fs from 'node:fs';
import { newImportExemption,evaluateImportExemption,recordImportExemptions,saveImportExemptionBook,importExemptionBook,importExemptionCurrent,importExemptionRules,importServiceSource } from '../../resources/js/lib/iva-import-exemptions.ts';
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
import { offerReusableData } from '../../resources/js/lib/iva-offer-preparations.ts';
const frozen=JSON.parse(fs.readFileSync(new URL('./fixtures/iva-offer-paths-inputs.json',import.meta.url),'utf8'));
const rules=importExemptionRules.filter(r=>r.branch==='P050');
const row=rule=>({...newImportExemption('g6f-'+rule.id,'MZN'),treatment:rule.id,description:'SYNTHETIC QA '+rule.label,period:'2026-12',declaredValue:'5000',importer:'SYNTHETIC QA importador destinatário',documentRef:'SYNTHETIC QA G6F '+rule.id,documentDate:'2026-11-14',evidence:'SYNTHETIC QA serviço e montante integral incluídos na base identificada, conforme artigo16; pressuposto expresso, não documento real',serviceImportRef:'SYNTHETIC QA importação DU-A,2026-12',serviceBaseRef:'SYNTHETIC QA base DU-A,linha serviço5000MZN',serviceProvider:'SYNTHETIC QA prestador',...(rule.id==='accessory_service_first_destination'?{serviceFirstDestination:'SYNTHETIC QA Manica,primeiro destino no documento de transporte'}:{}),conditions:Object.fromEntries(rule.conditions.map(([key])=>[key,'yes']))});
@@ -25,4 +26,5 @@ test('save/recovery/report preserve27fiscalbooks and946fc089scenarios/requests/h
test('old goods rows keep own tax representation and malformed optional service references cannot overwrite saved originals',()=>{
const d=draft(),prior=JSON.parse(d.modelo_a_snapshot);for(const book of Object.values(prior.importExemptions))assert.ok(book.result.rows.every(row=>!Object.hasOwn(row,'serviceVat')));
assert.throws(()=>saveImportExemptionBook(d,{rows:[{...row(rules[0]),serviceBaseRef:42}]}),/Referências do serviço/);
const serviceOnly={...d,context_opportunity:'opportunity:336'};serviceOnly.modelo_a_snapshot=saveImportExemptionBook(serviceOnly,{rows:rules.map(row)});assert.equal(offerReusableData(serviceOnly).length,0,'P050 services cannot be reused as imported goods in P084');
});