feat(core): improve in-memory validation, FatturaPA detection coverage, and published type compatibility
This commit is contained in:
@@ -194,7 +194,36 @@ export class XRechnungDecoder extends UBLBaseDecoder {
|
||||
const seller = this.extractParty('//cac:AccountingSupplierParty/cac:Party');
|
||||
const buyer = this.extractParty('//cac:AccountingCustomerParty/cac:Party');
|
||||
|
||||
// Create the common invoice data with metadata for business references
|
||||
const businessReferences = {
|
||||
buyerReference,
|
||||
orderReference,
|
||||
contractReference,
|
||||
projectReference
|
||||
};
|
||||
|
||||
const paymentInformation = {
|
||||
paymentMeansCode,
|
||||
paymentID,
|
||||
paymentDueDate,
|
||||
iban,
|
||||
bic,
|
||||
bankName,
|
||||
accountName,
|
||||
paymentTermsNote,
|
||||
discountPercent
|
||||
};
|
||||
|
||||
const dateInformation = {
|
||||
periodStart,
|
||||
periodEnd,
|
||||
deliveryDate
|
||||
};
|
||||
|
||||
const hasBusinessReferences = Object.values(businessReferences).some(value => Boolean(value));
|
||||
const hasPaymentInformation = Object.values(paymentInformation).some(value => Boolean(value));
|
||||
const hasDateInformation = Object.values(dateInformation).some(value => Boolean(value));
|
||||
|
||||
// Create the common invoice data with metadata only when the source XML actually contains it.
|
||||
const invoiceData: any = {
|
||||
type: 'accounting-doc' as const,
|
||||
accountingDocType: 'invoice' as const,
|
||||
@@ -216,36 +245,20 @@ export class XRechnungDecoder extends UBLBaseDecoder {
|
||||
reverseCharge: false,
|
||||
currency: currencyCode as finance.TCurrency,
|
||||
notes: notes,
|
||||
objectActions: [],
|
||||
metadata: {
|
||||
objectActions: []
|
||||
};
|
||||
|
||||
if (hasBusinessReferences || hasPaymentInformation || hasDateInformation) {
|
||||
invoiceData.metadata = {
|
||||
format: 'xrechnung' as any,
|
||||
version: '1.0.0',
|
||||
extensions: {
|
||||
businessReferences: {
|
||||
buyerReference,
|
||||
orderReference,
|
||||
contractReference,
|
||||
projectReference
|
||||
},
|
||||
paymentInformation: {
|
||||
paymentMeansCode,
|
||||
paymentID,
|
||||
paymentDueDate,
|
||||
iban,
|
||||
bic,
|
||||
bankName,
|
||||
accountName,
|
||||
paymentTermsNote,
|
||||
discountPercent
|
||||
},
|
||||
dateInformation: {
|
||||
periodStart,
|
||||
periodEnd,
|
||||
deliveryDate
|
||||
}
|
||||
...(hasBusinessReferences ? { businessReferences } : {}),
|
||||
...(hasPaymentInformation ? { paymentInformation } : {}),
|
||||
...(hasDateInformation ? { dateInformation } : {}),
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// Validate mandatory EN16931 fields unless validation is skipped
|
||||
if (!this.skipValidation) {
|
||||
@@ -255,7 +268,7 @@ export class XRechnungDecoder extends UBLBaseDecoder {
|
||||
return invoiceData;
|
||||
} catch (error) {
|
||||
// Re-throw validation errors
|
||||
if (error.message && error.message.includes('EN16931 validation failed')) {
|
||||
if (error instanceof Error && error.message.includes('EN16931 validation failed')) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user