From 17547a1343265f0062d07e113976c7ab17b788a2 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 10 Nov 2026 15:27:26 +0000 Subject: [PATCH 01/73] Add PINT AE tax combo rules Add the AE regime guards to the PINT addon and validate AE tax combos: - Category code must be S, Z, E, O or AE (IBR-139-AE). - Standard rate must be greater than zero (ALIGNED-IBRP-S-05/06/07). - Standard rate must be exactly 5% (IBR-190-AE). - Zero rate must be 0% (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE). The rate rules apply to AE only for now. The margin scheme category (N) comes with the BTAE extensions. --- addon/pint/pint.go | 12 ++++++- addon/pint/tax_combo.go | 52 ++++++++++++++++++++++++++++ addon/pint/tax_combo_test.go | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) diff --git a/addon/pint/pint.go b/addon/pint/pint.go index ed76db3..440d80c 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -28,6 +28,12 @@ const ( // regimesAUNZ lists the tax regimes the PINT A-NZ jurisdiction rules apply to. var regimesAUNZ = []l10n.TaxCountryCode{l10n.AU.Tax(), l10n.NZ.Tax()} +// regimesAE lists the tax regimes the PINT AE jurisdiction rules apply to. +var regimesAE = []l10n.TaxCountryCode{l10n.AE.Tax()} + +// regimesAUNZAE lists the tax regimes the PINT A-NZ and PINT AE jurisdictions rules apply to. +var regimesAUNZAE = []l10n.TaxCountryCode{l10n.AU.Tax(), l10n.NZ.Tax(), l10n.AE.Tax()} + func init() { tax.RegisterAddonDef(newV1Addon()) rules.RegisterWithGuard( @@ -68,7 +74,7 @@ func newV1Addon() *tax.AddonDef { Jurisdiction-specific requirements are applied according to the document's tax regime: Australian and New Zealand documents are also - validated against the PINT A-NZ rules. + validated against the PINT A-NZ rules; and UAE documents are validated against the PINT AE rules. `), }, Sources: []*cbc.Source{ @@ -84,6 +90,10 @@ func newV1Addon() *tax.AddonDef { Title: i18n.NewString("PINT A-NZ jurisdiction-aligned rules"), URL: "https://docs.peppol.eu/poac/aunz/pint-aunz/trn-invoice/rule/PINT-jurisdiction-aligned-rules/", }, + { + Title: i18n.NewString("PINT AE jurisdiction-aligned rules"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/rule/PINT-jurisdiction-aligned-rules/", + }, }, } } diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 981bfc0..fff89b9 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -4,6 +4,7 @@ import ( "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/num" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/rules/is" "github.com/invopop/gobl/tax" @@ -31,6 +32,16 @@ var taxCategoryCodesAUNZ = []cbc.Code{ en16931.TaxCategoryOutsideScope, } +// taxCategoryCodesAE lists the subset of UNTDID 5305 tax category codes +// accepted by the AE PINT specification. +var taxCategoryCodesAE = []cbc.Code{ + en16931.TaxCategoryExempt, + en16931.TaxCategoryStandard, + en16931.TaxCategoryZero, + en16931.TaxCategoryOutsideScope, + en16931.TaxCategoryReverseCharge, +} + // normalizeTaxCombo re-maps the UNTDID tax category code from the tax combo's // key using the EN 16931 key-to-code mapping. func normalizeTaxCombo(tc *tax.Combo) { @@ -62,5 +73,46 @@ func taxComboRules() *rules.Set { ), ), ), + + // TODO: rules 04 and 06 should also apply to AUNZ. + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.Field("ext", + rules.Assert("03", "tax category code must be an AE UNCL5305 code: E, S, Z, O or AE (IBR-139-AE)", + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesAE...), + ), + ), + + rules.When( + is.Func("tax combo is standard rated", taxComboIsStandard), + rules.Field("percent", + rules.Assert("04", "tax percentage must be a positive number (ALIGNED-IBRP-S-05/06/07)", + num.Positive, + ), + rules.Assert("05", "tax percentage must be 5.00 (IBR-190-AE)", + num.Equals(num.MakePercentage(5, 2)), + ), + ), + ), + + rules.When( + is.Func("tax combo is zero rated", taxComboIsZero), + rules.Field("percent", + rules.Assert("06", "tax percentage must be 0.00 (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", + num.Equals(num.MakePercentage(0, 2)), + ), + ), + ), + ), ) } + +func taxComboIsStandard(val any) bool { + tc, ok := val.(*tax.Combo) + return ok && tc != nil && tc.Key == tax.KeyStandard +} + +func taxComboIsZero(val any) bool { + tc, ok := val.(*tax.Combo) + return ok && tc != nil && tc.Key == tax.KeyZero +} diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index a03877f..45a0f86 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -94,3 +94,70 @@ func TestTaxComboRules(t *testing.T) { assert.NoError(t, err) }) } + +func vatCombo(key cbc.Key, category string, percent *num.Percentage) *tax.Combo { + return &tax.Combo{ + Category: tax.CategoryVAT, + Key: key, + Percent: percent, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: cbc.Code(category)}), + } +} + +func validateIn(tc *tax.Combo, regime l10n.TaxCountryCode) error { + return rules.Validate(tc, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) +} + +func TestTaxComboRulesAE(t *testing.T) { + ae := l10n.AE.Tax() + + t.Run("AE subset categories are accepted (IBR-139-AE)", func(t *testing.T) { + for _, cat := range []string{"E", "O", "AE"} { + err := validateIn(vatCombo(cbc.KeyEmpty, cat, nil), ae) + assert.NoError(t, err, "category %s", cat) + } + assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) + assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) + }) + + t.Run("categories outside the AE subset are rejected (IBR-139-AE)", func(t *testing.T) { + for _, cat := range []string{"G", "K", "L", "M"} { + err := validateIn(vatCombo(cbc.KeyEmpty, cat, nil), ae) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-03", "category %s", cat) + } + }) + + t.Run("AE subset does not apply outside AE", func(t *testing.T) { + assert.NoError(t, validateIn(vatCombo(cbc.KeyEmpty, "K", nil), l10n.SG.Tax())) + }) + + t.Run("standard rate must be greater than zero (ALIGNED-IBRP-S-05/06/07)", func(t *testing.T) { + err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(0, 2)), ae) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-04") + // The Schematron reports both S-05 and IBR-190 for a 0% standard rate. + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") + }) + + t.Run("standard rate must be 5% (IBR-190-AE)", func(t *testing.T) { + err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(10, 2)), ae) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") + assert.NotContains(t, err.Error(), "GOBL-PEPPOL-PINT-TAX-COMBO-04") + }) + + t.Run("5% check compares numbers, not strings", func(t *testing.T) { + assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(50, 3)), ae)) + }) + + t.Run("zero rate must be 0% (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", func(t *testing.T) { + err := validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), ae) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-06") + }) + + t.Run("rate rules do not apply outside AE", func(t *testing.T) { + for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { + assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(0, 2)), regime), regime) + assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(10, 2)), regime), regime) + assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), regime), regime) + } + }) +} From 915b6281d1df458bf9ade7e38bb945bef5a0ce23 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:36:27 +0000 Subject: [PATCH 02/73] Add PINT AE payment and currency rules Validate AE payment instructions and exchange rates: - Credit transfers (means 30) must include an IBAN or account number (IBR-192-AE). - Payment instructions are required, except on credit notes (IBR-191-AE). - Invoices not in AED must have an exchange rate to AED (IBR-159-AE). - Exchange rates must have at most 6 decimals (IBR-002-AE). The deemed supply exception of IBR-191-AE comes with the BTAE extensions. --- addon/pint/bill.go | 60 ++++++++++++++++++++ addon/pint/bill_test.go | 120 ++++++++++++++++++++++++++++++++++++++++ addon/pint/pay.go | 44 ++++++++++++++- addon/pint/pay_test.go | 55 ++++++++++++++++++ 4 files changed, 277 insertions(+), 2 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 2ac53b3..4a031de 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -2,9 +2,12 @@ package pint import ( "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" ) func billInvoiceRules() *rules.Set { @@ -23,6 +26,27 @@ func billInvoiceRules() *rules.Set { rules.Assert("04", "invoice customer electronic address is required (IBR-080)", is.Present), ), ), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.Assert("05", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + is.Func("has AED exchange rate", exchangeRateHasAED), + ), + rules.Field("exchange_rates", + rules.Each(rules.Field("amount", + rules.Assert("06", "exchange rate must have at most 6 decimals (IBR-002-AE)", + is.Func("has at most 6 decimals", amountHasAtMost6Decimals), + ), + )), + ), + // TODO: IBR-191-AE also exempts deemed supplies (transaction type + // BTAE-02 X1XXXXXX). Add the exception with the BTAE extensions (task J). + rules.When( + is.Not(is.Func("credit note", invoiceIsCreditNote)), + rules.Assert("07", "payment instructions required, except on credit notes (IBR-191-AE)", + is.Func("has payment instructions", invoiceHasPaymentInstructions), + ), + ), + ), ) } @@ -32,3 +56,39 @@ func partyHasIdentifier(val any) bool { p, ok := val.(*org.Party) return ok && p != nil && ((p.TaxID != nil && p.TaxID.Code != "") || len(p.Identities) > 0) } + +// exchangeRateHasAED reports whether an invoice not in AED has an exchange +// rate from its currency to AED, the rate written as cbc:CalculationRate in the +// tax exchange rate (IBR-159-AE). AED invoices need no rate. +func exchangeRateHasAED(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return true + } + return inv.Currency == currency.AED || + currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) != nil +} + +// amountHasAtMost6Decimals reports whether an exchange rate amount has at +// most 6 decimals, the limit for cbc:CalculationRate (IBR-002-AE). The rules +// engine passes struct fields as pointers, hence *num.Amount. +func amountHasAtMost6Decimals(val any) bool { + a, ok := val.(*num.Amount) + return ok && a != nil && a.Exp() <= 6 +} + +// invoiceIsCreditNote reports whether the invoice is a credit note. The EN +// 16931 scenarios map this type to the document type codes 381, and 261 when +// self-billed, the codes IBR-191-AE exempts. +func invoiceIsCreditNote(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Type == bill.InvoiceTypeCreditNote +} + +// invoiceHasPaymentInstructions reports whether the invoice has payment +// instructions. It is checked on the invoice rather than with nested fields, +// because the rules engine skips the fields of a nil payment. +func invoiceHasPaymentInstructions(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Payment != nil && inv.Payment.Instructions != nil +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index aa744a9..629da91 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -6,7 +6,11 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pay" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" @@ -87,3 +91,119 @@ func TestBillInvoiceRules(t *testing.T) { } }) } + +// aeInvoice is a skeleton UAE invoice in AED with payment instructions, which +// passes the AE invoice rules. Like baseInvoice, it trips unrelated core rules, +// so the tests check for specific fault codes. +func aeInvoice() *bill.Invoice { + inv := baseInvoice() + inv.Type = bill.InvoiceTypeStandard + inv.Currency = currency.AED + inv.Payment = &bill.PaymentDetails{ + Instructions: &pay.Instructions{Key: pay.MeansKeyCreditTransfer}, + } + return inv +} + +func usdToAED(amount num.Amount) []*currency.ExchangeRate { + return []*currency.ExchangeRate{{From: currency.USD, To: currency.AED, Amount: amount}} +} + +func TestBillInvoiceRulesAE(t *testing.T) { + const ( + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + ) + validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) + if err == nil { + return "" + } + return err.Error() + } + validate := func(inv *bill.Invoice) string { + return validateIn(inv, l10n.AE.Tax()) + } + + t.Run("valid AE invoice raises no AE invoice faults", func(t *testing.T) { + out := validate(aeInvoice()) + assert.NotContains(t, out, faultRate) + assert.NotContains(t, out, faultDecimals) + assert.NotContains(t, out, faultPayment) + }) + + t.Run("AED invoice needs no exchange rate (IBR-159-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.ExchangeRates = nil + assert.NotContains(t, validate(inv), faultRate) + }) + + t.Run("non-AED invoice with a rate to AED is accepted (IBR-159-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = usdToAED(num.MakeAmount(3672500, 6)) + assert.NotContains(t, validate(inv), faultRate) + }) + + t.Run("non-AED invoice without a rate is rejected (IBR-159-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + assert.Contains(t, validate(inv), faultRate) + }) + + t.Run("non-AED invoice with a rate to another currency is rejected (IBR-159-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = []*currency.ExchangeRate{ + {From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(92, 2)}, + } + assert.Contains(t, validate(inv), faultRate) + }) + + t.Run("exchange rate with 6 decimals is accepted (IBR-002-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = usdToAED(num.MakeAmount(3672500, 6)) + assert.NotContains(t, validate(inv), faultDecimals) + }) + + t.Run("exchange rate with 7 decimals is rejected (IBR-002-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = usdToAED(num.MakeAmount(36725000, 7)) + assert.Contains(t, validate(inv), faultDecimals) + }) + + t.Run("invoice without payment is rejected (IBR-191-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Payment = nil + assert.Contains(t, validate(inv), faultPayment) + }) + + t.Run("invoice with payment but no instructions is rejected (IBR-191-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Payment = &bill.PaymentDetails{} + assert.Contains(t, validate(inv), faultPayment) + }) + + t.Run("credit note without payment is accepted (IBR-191-AE)", func(t *testing.T) { + inv := aeInvoice() + inv.Type = bill.InvoiceTypeCreditNote + inv.Payment = nil + assert.NotContains(t, validate(inv), faultPayment) + }) + + t.Run("AE invoice rules do not apply outside AE", func(t *testing.T) { + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = usdToAED(num.MakeAmount(36725000, 7)) + inv.Payment = nil + for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { + out := validateIn(inv, regime) + assert.NotContains(t, out, faultRate, "regime %s", regime) + assert.NotContains(t, out, faultDecimals, "regime %s", regime) + assert.NotContains(t, out, faultPayment, "regime %s", regime) + } + }) +} diff --git a/addon/pint/pay.go b/addon/pint/pay.go index 45549a6..b0417d8 100644 --- a/addon/pint/pay.go +++ b/addon/pint/pay.go @@ -16,8 +16,9 @@ const ( meansCodeSEPACreditTransfer cbc.Code = "58" ) -// payInstructionsRules enforces the A-NZ payment instruction rules on -// Australian and New Zealand documents. +// payInstructionsRules enforces the payment instruction rules of the +// jurisdictions: A-NZ on Australian and New Zealand documents, and AE on UAE +// documents. func payInstructionsRules() *rules.Set { return rules.For(new(pay.Instructions), rules.When( @@ -28,11 +29,21 @@ func payInstructionsRules() *rules.Set { ), ), ), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When(is.Func("payment means is credit transfer", instructionsMeanCreditTransferAE), + rules.Assert("02", "credit transfer must include an IBAN or account number (IBR-192-AE)", + is.Func("has a payment account identifier", instructionsHaveAccountID), + ), + ), + ), ) } // creditTransferRules enforces that any credit transfer information provided // on Australian and New Zealand documents carries a payment account identifier. +// AE has no such rule: IBR-192-AE only applies to credit transfer means (30), +// so it is checked from the payment instructions instead. func creditTransferRules() *rules.Set { return rules.For(new(pay.CreditTransfer), rules.When( @@ -56,6 +67,18 @@ func instructionsMeanCreditTransfer(val any) bool { return code == meansCodeCreditTransfer || code == meansCodeSEPACreditTransfer } +// instructionsMeanCreditTransferAE reports whether the payment means code +// (ibt-081) of the instructions is 30, a credit transfer. Unlike the A-NZ +// predicate, SEPA (58) is not included, as IBR-192-AE only checks 30. +func instructionsMeanCreditTransferAE(val any) bool { + instr, ok := val.(*pay.Instructions) + if !ok || instr == nil { + return false + } + code := instr.Ext.Get(untdid.ExtKeyPaymentMeans) + return code == meansCodeCreditTransfer +} + // creditTransferHasAccountID reports whether the credit transfer carries an // account identifier (ibt-084), either an IBAN or an account number. func creditTransferHasAccountID(val any) bool { @@ -65,3 +88,20 @@ func creditTransferHasAccountID(val any) bool { } return ct.IBAN != "" || ct.Number != "" } + +// instructionsHaveAccountID reports whether at least one of the instructions' +// credit transfers carries an account identifier (ibt-084), either an IBAN or +// an account number. A missing credit transfer list fails, so one check covers +// both cases of IBR-192-AE. +func instructionsHaveAccountID(val any) bool { + instr, ok := val.(*pay.Instructions) + if !ok || instr == nil { + return true + } + for _, ct := range instr.CreditTransfer { + if ct != nil && (ct.IBAN != "" || ct.Number != "") { + return true + } + } + return false +} diff --git a/addon/pint/pay_test.go b/addon/pint/pay_test.go index 59f835a..3a7cdc2 100644 --- a/addon/pint/pay_test.go +++ b/addon/pint/pay_test.go @@ -87,3 +87,58 @@ func TestPayInstructionsRules(t *testing.T) { assert.NoError(t, err) }) } + +func TestPayInstructionsRulesAE(t *testing.T) { + validate := func(instr *pay.Instructions) error { + return rules.Validate(instr, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) + } + + t.Run("credit transfer with IBAN is accepted", func(t *testing.T) { + instr := instructionsWithMeansCode("30") + instr.CreditTransfer = []*pay.CreditTransfer{{IBAN: "AE070331234567890123456"}} + assert.NoError(t, validate(instr)) + }) + + t.Run("credit transfer with account number is accepted", func(t *testing.T) { + instr := instructionsWithMeansCode("30") + instr.CreditTransfer = []*pay.CreditTransfer{{Number: "1234567890"}} + assert.NoError(t, validate(instr)) + }) + + t.Run("credit transfer without credit transfer details is rejected (IBR-192-AE)", func(t *testing.T) { + err := validate(instructionsWithMeansCode("30")) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + }) + + t.Run("credit transfer without IBAN or account number is rejected (IBR-192-AE)", func(t *testing.T) { + instr := instructionsWithMeansCode("30") + instr.CreditTransfer = []*pay.CreditTransfer{{BIC: "EBILAEAD", Name: "Emirates NBD"}} + err := validate(instr) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + }) + + t.Run("other payment means are not checked", func(t *testing.T) { + for _, code := range []string{"58", "31"} { + instr := instructionsWithMeansCode(code) + assert.NoError(t, validate(instr), "means %s", code) + instr.CreditTransfer = []*pay.CreditTransfer{{BIC: "EBILAEAD"}} + assert.NoError(t, validate(instr), "means %s with BIC only", code) + } + }) + + t.Run("the A-NZ account rules do not apply", func(t *testing.T) { + instr := &pay.Instructions{ + Key: pay.MeansKeyOnline, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyPaymentMeans: "68"}), + CreditTransfer: []*pay.CreditTransfer{{Name: "Emirates NBD"}}, + } + assert.NoError(t, validate(instr)) + }) + + t.Run("the AE rule does not apply outside AE", func(t *testing.T) { + instr := instructionsWithMeansCode("30") + instr.CreditTransfer = []*pay.CreditTransfer{{BIC: "EBILAEAD"}} + err := rules.Validate(instr, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.SG.Tax())) + assert.NoError(t, err) + }) +} From 09ada3e25c4cf5d47da3421f844a365a6bc87082 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:19:55 +0000 Subject: [PATCH 03/73] Add the PINT AE out-of-scope document types Add an outside-scope tag to the PINT addon. On UAE documents it sets the UNTDID 1001 document type to 480 on invoices and 81 on credit notes, replacing EN 16931's 380 and 381. 480 is defined in PINT, as the EN 16931 code list doesn't include it. --- addon/pint/pint.go | 9 ++++ addon/pint/scenarios.go | 73 +++++++++++++++++++++++++++++ addon/pint/scenarios_test.go | 91 ++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 addon/pint/scenarios.go create mode 100644 addon/pint/scenarios_test.go diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 440d80c..7396cb2 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -75,6 +75,9 @@ func newV1Addon() *tax.AddonDef { Jurisdiction-specific requirements are applied according to the document's tax regime: Australian and New Zealand documents are also validated against the PINT A-NZ rules; and UAE documents are validated against the PINT AE rules. + + UAE documents out of scope of VAT use the "outside-scope" tag, which + sets the document type to 480 on invoices and 81 on credit notes. `), }, Sources: []*cbc.Source{ @@ -95,5 +98,11 @@ func newV1Addon() *tax.AddonDef { URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/rule/PINT-jurisdiction-aligned-rules/", }, }, + Tags: []*tax.TagSet{ + invoiceTags, + }, + Scenarios: []*tax.ScenarioSet{ + invoiceScenarios, + }, } } diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go new file mode 100644 index 0000000..8703028 --- /dev/null +++ b/addon/pint/scenarios.go @@ -0,0 +1,73 @@ +package pint + +import ( + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/untdid" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/i18n" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/tax" +) + +// Document tags and the UNTDID 1001 codes they map to. +const ( + // TagOutsideScope marks a PINT AE document as out of scope of VAT, + // the UAE "commercial invoice". + TagOutsideScope cbc.Key = "outside-scope" + + // UNTDID 1001 codes PINT AE uses for out-of-scope documents. 480 is in + // UNTDID D.23A but not in the EN 16931 code list, so it lives here. + docTypeOutsideScopeInvoice cbc.Code = "480" + docTypeOutsideScopeCreditNote cbc.Code = "81" +) + +// invoiceTags are the document tags the PINT addon adds to invoices. +var invoiceTags = &tax.TagSet{ + Schema: bill.ShortSchemaInvoice, + List: []*cbc.Definition{ + { + Key: TagOutsideScope, + Name: i18n.String{ + i18n.EN: "Outside Scope", + }, + Desc: i18n.String{ + i18n.EN: "Marks a PINT AE document as out of scope of VAT, the UAE 'commercial invoice'. Invoices are sent with document type 480 and credit notes with 81. Has no effect outside the UAE.", + }, + }, + }, +} + +// invoiceScenarios set the UNTDID 1001 document type for PINT AE's +// out-of-scope documents. EN 16931's scenarios run first and set 380 or 381 +// from the invoice type; these match afterwards and replace the code, the same +// way EN maps the self-billed tag to 389. +var invoiceScenarios = &tax.ScenarioSet{ + Schema: bill.ShortSchemaInvoice, + List: []*tax.Scenario{ + // ** Out of scope of VAT (UAE only) ** + { + Types: []cbc.Key{bill.InvoiceTypeStandard}, + Tags: []cbc.Key{TagOutsideScope}, + Filter: invoiceIsAE, + Ext: tax.ExtensionsOf(cbc.CodeMap{ + untdid.ExtKeyDocumentType: docTypeOutsideScopeInvoice, + }), + }, + { + Types: []cbc.Key{bill.InvoiceTypeCreditNote}, + Tags: []cbc.Key{TagOutsideScope}, + Filter: invoiceIsAE, + Ext: tax.ExtensionsOf(cbc.CodeMap{ + untdid.ExtKeyDocumentType: docTypeOutsideScopeCreditNote, + }), + }, + }, +} + +// invoiceIsAE reports whether the scenario document is a UAE invoice. Tags and +// scenarios belong to the addon, which runs for every regime, so the AE-only +// scenarios use it as their filter. +func invoiceIsAE(doc any) bool { + inv, ok := doc.(*bill.Invoice) + return ok && inv != nil && inv.GetRegime() == l10n.AE.Tax() +} diff --git a/addon/pint/scenarios_test.go b/addon/pint/scenarios_test.go new file mode 100644 index 0000000..e9e4412 --- /dev/null +++ b/addon/pint/scenarios_test.go @@ -0,0 +1,91 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/untdid" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/num" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// scenarioInvoice is a minimal invoice for the given regime that can be +// calculated, so the regime and addon scenarios run on it. +func scenarioInvoice(regime l10n.TaxCountryCode, typ cbc.Key, tags ...cbc.Key) *bill.Invoice { + category, cur := tax.CategoryVAT, currency.AED + if regime == l10n.AU.Tax() { + category, cur = tax.CategoryGST, currency.AUD + } + return &bill.Invoice{ + Regime: tax.WithRegime(regime), + Addons: tax.WithAddons(pint.V1), + Tags: tax.WithTags(tags...), + Type: typ, + Currency: cur, + Series: "TEST", + Code: "0001", + IssueDate: cal.MakeDate(2026, 11, 10), + Supplier: &org.Party{Name: "Supplier"}, + Customer: &org.Party{Name: "Customer"}, + Lines: []*bill.Line{ + { + Quantity: num.MakeAmount(1, 0), + Item: &org.Item{Name: "Item", Price: num.NewAmount(10000, 2)}, + Taxes: tax.Set{{Category: category, Key: tax.KeyOutsideScope}}, + }, + }, + } +} + +func documentType(t *testing.T, inv *bill.Invoice) cbc.Code { + t.Helper() + require.NoError(t, inv.Calculate()) + require.NotNil(t, inv.Tax) + return inv.Tax.Ext.Get(untdid.ExtKeyDocumentType) +} + +func TestInvoiceScenarios(t *testing.T) { + ae := l10n.AE.Tax() + + t.Run("AE out-of-scope invoice is 480", func(t *testing.T) { + inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideScope) + assert.Equal(t, cbc.Code("480"), documentType(t, inv)) + }) + + t.Run("AE out-of-scope credit note is 81", func(t *testing.T) { + inv := scenarioInvoice(ae, bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + assert.Equal(t, cbc.Code("81"), documentType(t, inv)) + }) + + t.Run("AE invoice without the tag keeps EN's 380", func(t *testing.T) { + inv := scenarioInvoice(ae, bill.InvoiceTypeStandard) + assert.Equal(t, cbc.Code("380"), documentType(t, inv)) + }) + + t.Run("AE credit note without the tag keeps EN's 381", func(t *testing.T) { + inv := scenarioInvoice(ae, bill.InvoiceTypeCreditNote) + assert.Equal(t, cbc.Code("381"), documentType(t, inv)) + }) + + t.Run("a hand-set code is replaced by the scenario", func(t *testing.T) { + inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideScope) + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyDocumentType: "380"})} + assert.Equal(t, cbc.Code("480"), documentType(t, inv)) + }) + + t.Run("the tag has no effect outside AE", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, pint.TagOutsideScope) + assert.Equal(t, cbc.Code("380"), documentType(t, inv)) + + inv = scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + assert.Equal(t, cbc.Code("381"), documentType(t, inv)) + }) +} From 386a1622f41139785c668f28e34198e150f741f9 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:29:46 +0000 Subject: [PATCH 04/73] Add PINT AE invoice, line and address rules Validate UAE documents against the PINT AE invoice, party and line rules: - Lines must have a VAT combo (IBR-145-AE) and an item description (IBR-125-AE). - The seller TRN is required, except on 480 and 81 (IBR-134-AE). - Reverse charge needs a buyer tax registration (IBR-103-AE). - 480 and 81 need a buyer legal identity (IBR-136-AE) and only allow the E, Z and O categories on lines, discounts and charges (IBR-122-AE). - 380 and 381 need at least one line that is not E or O (IBR-151-AE). - The VAT point date is not allowed on 381 and 81 (IBR-124-AE) and must be before the issue date (IBR-141-AE). - A due date is required when an amount is due, except on 381, 81 and 261 (IBR-127-AE). 261 follows the Schematron test, not the rule text. - UAE TRNs must be 15 digits, start with 1 and end with 03 (IBR-132-AE). - Supplier and customer addresses need a street, city and region (IBR-143-AE, IBR-144-AE), and UAE addresses an emirate code (IBR-128-AE). --- addon/pint/bill.go | 341 ++++++++++++++++++++++++++++ addon/pint/bill_test.go | 382 ++++++++++++++++++++++++++++++++ addon/pint/pint.go | 2 + addon/pint/scenarios.go | 16 +- addon/pint/tax_identity.go | 24 ++ addon/pint/tax_identity_test.go | 54 +++++ 6 files changed, 815 insertions(+), 4 deletions(-) create mode 100644 addon/pint/tax_identity.go create mode 100644 addon/pint/tax_identity_test.go diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 4a031de..c158cef 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -1,8 +1,12 @@ package pint import ( + "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/untdid" + "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/rules" @@ -10,6 +14,23 @@ import ( "github.com/invopop/gobl/tax" ) +// taxCategoryCodesOutsideScope are the VAT category codes allowed on 480 and +// 81 documents: exempt (E), zero rated (Z) and not subject to VAT (O) +// (IBR-122-AE). +var taxCategoryCodesOutsideScope = []cbc.Code{ + en16931.TaxCategoryExempt, + en16931.TaxCategoryZero, + en16931.TaxCategoryOutsideScope, +} + +// emirateCodes are the country subdivision codes PINT AE accepts for UAE +// addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. +var emirateCodes = []cbc.Code{ + "AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK", +} + +// billInvoiceRules enforces the PINT invoice rules shared by every +// jurisdiction, and the PINT AE rules on UAE documents. func billInvoiceRules() *rules.Set { return rules.For(new(bill.Invoice), rules.Field("supplier", @@ -46,10 +67,154 @@ func billInvoiceRules() *rules.Set { is.Func("has payment instructions", invoiceHasPaymentInstructions), ), ), + rules.When( + is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", + documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), + rules.Field("supplier", + rules.Assert("08", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + is.Func("has tax ID code", partyHasTaxIDCode), + ), + ), + ), + rules.When( + is.Func("has reverse charge lines", invoiceHasReverseChargeLine), + rules.Field("customer", + rules.Assert("09", "customer tax registration is required with reverse charge (IBR-103-AE)", + is.Func("has tax registration", partyHasTaxRegistration), + ), + ), + ), + rules.When( + is.Func("document type is invoice outside scope or credit note related to goods and services", + documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), + rules.Field("customer", + // TODO: also check the identity type code (TL, EID, PAS or CD) + // once decision 6 is settled (task I). + rules.Assert("10", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + is.Func("has legal identity", partyHasLegalIdentity), + ), + ), + rules.Field("lines", rules.Each( + rules.Field("taxes", rules.Each( + rules.Assert("11", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + ), + )), + )), + rules.Field("discounts", rules.Each( + rules.Field("taxes", rules.Each( + rules.Assert("12", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + ), + )), + )), + rules.Field("charges", rules.Each( + rules.Field("taxes", rules.Each( + rules.Assert("13", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + ), + )), + )), + ), + rules.When( + is.Func("document type is 380 or 381", + documentTypeIn(docTypeCommercialInvoice, docTypeCreditNote)), + rules.Assert("14", "at least one line combo must be something other than E or O (IBR-151-AE)", + is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), + ), + ), + rules.When( + is.Func("document type is credit note or credit note related to goods and services", + documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices)), + rules.Field("value_date", + rules.Assert("15", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + is.Not(is.Present), + ), + ), + ), + rules.Assert("16", "VAT point date must be before the invoice issue date (IBR-141-AE)", + is.Func("VAT point date before issue date", pointDateBeforeIssueDate), + ), + // TODO: IBR-127-AE also exempts deemed supplies: invoices whose + // transaction type (BTAE-02, written as cbc:ProfileExecutionID) matches + // X1XXXXXX, a 1 in the second of its 8 flags. GOBL has no field for + // BTAE-02 yet, so add the exception with the BTAE extensions (task J). + // Self-billed credit notes (261) are exempt too. The rule text only + // names 381 and 81, but the Schematron test also exempts 261, and we + // follow the test. + rules.When( + is.Not(is.Func("document type is 381, 81 or 261", + documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote))), + rules.When( + is.Func("amount is due", invoiceIsDue), + rules.Assert("17", "payment due date is required when an amount is due (IBR-127-AE)", + is.Func("has due date", invoiceHasDueDate), + ), + ), + ), + rules.Field("supplier", + rules.Assert("18", "supplier address must have a street, city and region (IBR-143-AE)", + is.Func("first address has street, city and region", partyAddressIsComplete), + ), + rules.Assert("19", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + ), + rules.Field("customer", + rules.Assert("20", "customer address must have a street, city and region (IBR-144-AE)", + is.Func("first address has street, city and region", partyAddressIsComplete), + ), + rules.Assert("21", "customer region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + ), + rules.Field("ordering", + rules.Field("seller", + rules.Assert("22", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + ), + ), + ), + ) +} + +// billLineRules enforces the PINT AE line rules on UAE documents. +func billLineRules() *rules.Set { + return rules.For(new(bill.Line), + // TODO: IBR-145-AE matches ALIGNED-IBRP-050/059-AUNZ (GST). Extend to + // A-NZ after discussing it with colleagues. + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.Field("taxes", + rules.Assert("01", "line must have a VAT tax combo (IBR-145-AE)", + is.Func("has VAT combo", taxesHaveVAT), + ), + ), + rules.Field("item", + rules.Field("description", + rules.Assert("02", "item description is required (IBR-125-AE)", is.Present), + ), + ), ), ) } +// documentType returns the UNTDID 1001 document type code (ibt-003) that the +// scenarios set on the invoice, or an empty code if none is set. +func documentType(inv *bill.Invoice) cbc.Code { + return inv.Tax.GetExt(untdid.ExtKeyDocumentType) +} + +// documentTypeIn returns a predicate that reports whether the invoice's +// document type is one of the given codes. +func documentTypeIn(codes ...cbc.Code) func(any) bool { + return func(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && documentType(inv).In(codes...) + } +} + // partyHasIdentifier reports whether the party can be identified through a tax // identity code or at least one organisation identity. func partyHasIdentifier(val any) bool { @@ -92,3 +257,179 @@ func invoiceHasPaymentInstructions(val any) bool { inv, ok := val.(*bill.Invoice) return ok && inv != nil && inv.Payment != nil && inv.Payment.Instructions != nil } + +// partyHasTaxIDCode reports whether the party has a tax ID with a code, the +// TRN written as the seller's PartyTaxScheme/CompanyID (IBR-134-AE). +func partyHasTaxIDCode(val any) bool { + p, ok := val.(*org.Party) + return ok && p != nil && p.TaxID != nil && p.TaxID.Code != "" +} + +// invoiceHasReverseChargeLine reports whether any line of the invoice has a +// VAT combo with the reverse charge key, category AE (IBR-103-AE). +func invoiceHasReverseChargeLine(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + for _, l := range inv.Lines { + if l == nil { + continue + } + if c := l.Taxes.Get(tax.CategoryVAT); c != nil && c.Key == tax.KeyReverseCharge { + return true + } + } + return false +} + +// partyHasTaxRegistration reports whether the party has a tax registration: +// a tax ID code or an identity with the tax scope. IBR-103-AE accepts any +// buyer PartyTaxScheme/CompanyID, and gobl.ubl writes either one there. +func partyHasTaxRegistration(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + if p.TaxID != nil && p.TaxID.Code != "" { + return true + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeTax { + return true + } + } + return false +} + +// partyHasLegalIdentity reports whether the party has an identity with the +// legal scope. gobl.ubl writes the first one as +// PartyLegalEntity/CompanyID, the buyer legal registration identifier +// IBR-136-AE requires on 480 and 81. +func partyHasLegalIdentity(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeLegal { + return true + } + } + return false +} + +// comboCategoryIn returns a predicate that reports whether a VAT combo's +// UNTDID 5305 category code is one of the given codes. Combos of other taxes +// pass, and any value that is not a combo fails, so a misplaced rule cannot +// pass silently. +func comboCategoryIn(codes ...cbc.Code) func(any) bool { + return func(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && + (c.Category != tax.CategoryVAT || c.Ext.Get(untdid.ExtKeyTaxCategory).In(codes...)) + } +} + +// invoiceHasLineComboOtherThanEorO reports whether at least one line has a VAT +// combo whose category is neither exempt (E) nor not subject to VAT (O) +// (IBR-151-AE). Combos of other taxes are ignored, as they carry no VAT +// category. +func invoiceHasLineComboOtherThanEorO(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + for _, l := range inv.Lines { + if l == nil { + continue + } + for _, c := range l.Taxes { + if c == nil || c.Category != tax.CategoryVAT { + continue + } + if cat := c.Ext.Get(untdid.ExtKeyTaxCategory); cat != en16931.TaxCategoryExempt && cat != en16931.TaxCategoryOutsideScope { + return true + } + } + } + return false +} + +// pointDateBeforeIssueDate reports whether the invoice's value date, written as +// the VAT point date cbc:TaxPointDate, is strictly before the issue date +// (IBR-141-AE). Invoices without a value date pass. +func pointDateBeforeIssueDate(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil || inv.ValueDate == nil { + return true + } + return inv.IssueDate.Date.DaysSince(inv.ValueDate.Date) > 0 +} + +// invoiceIsDue reports whether the invoice has an amount due for payment: the +// due total when set, the payable total otherwise. It follows isDue in the +// EN 16931 addon, which is not exported. +func invoiceIsDue(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + return inv.Totals != nil && + ((inv.Totals.Due != nil && !inv.Totals.Due.IsZero()) || + (inv.Totals.Due == nil && !inv.Totals.Payable.IsZero())) +} + +// invoiceHasDueDate reports whether the invoice's payment terms have a due date, +// which gobl.ubl writes as cbc:DueDate (IBR-127-AE). Missing payment details or +// terms fail. +func invoiceHasDueDate(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil || inv.Payment == nil || inv.Payment.Terms == nil { + return false + } + + dueDates := inv.Payment.Terms.DueDates + + for _, dd := range dueDates { + if dd != nil && dd.Date != nil { + return true + } + } + return false +} + +// partyFirstAddress returns the party's first address, the only one gobl.ubl +// writes as cac:PostalAddress, or nil if there is none. +func partyFirstAddress(val any) *org.Address { + p, ok := val.(*org.Party) + if !ok || p == nil || len(p.Addresses) == 0 { + return nil + } + return p.Addresses[0] +} + +// partyAddressIsComplete reports whether the party's first address has a +// street, city and region, written as cbc:StreetName, cbc:CityName and +// cbc:CountrySubentity (IBR-143-AE, IBR-144-AE). A party without an address +// passes: EN 16931 already requires supplier and customer addresses (BR-8, +// BR-10). +func partyAddressIsComplete(val any) bool { + a := partyFirstAddress(val) + return a == nil || (a.Street != "" && a.Locality != "" && a.Region != "") +} + +// partyAddressHasEmirate reports whether the party's first address, when in +// the UAE, has an emirate code as its region (IBR-128-AE). Addresses in other +// countries pass. +func partyAddressHasEmirate(val any) bool { + a := partyFirstAddress(val) + return a == nil || a.Country != l10n.AE.ISO() || cbc.Code(a.Region).In(emirateCodes...) +} + +// taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). +// It fails on any other value, so a type mismatch can't pass silently. +func taxesHaveVAT(val any) bool { + set, ok := val.(tax.Set) + return ok && set.Get(tax.CategoryVAT) != nil +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 629da91..3d1f0a7 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -5,6 +5,8 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" @@ -14,6 +16,7 @@ import ( "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func validEndpoints(code string) []*org.Endpoint { @@ -207,3 +210,382 @@ func TestBillInvoiceRulesAE(t *testing.T) { } }) } + +// aeDocument is an uncalculated UAE document of the given type and tags that +// passes every PINT AE rule: AE parties with valid TRNs and full addresses, a +// standard-rated line with a description, payment instructions and a due date. +// Out-of-scope documents get an outside-scope line and a customer legal +// identity. Tests change one thing and check for that rule's fault code. +func aeDocument(typ cbc.Key, tags ...cbc.Key) *bill.Invoice { + inv := scenarioInvoice(l10n.AE.Tax(), typ, tags...) + inv.Supplier = &org.Party{ + Name: "Seller LLC", + TaxID: &tax.Identity{Country: "AE", Code: "100000000000003"}, + Endpoints: validEndpoints("100000000000003"), + Addresses: aeAddress("DXB"), + } + inv.Customer = &org.Party{ + Name: "Buyer LLC", + TaxID: &tax.Identity{Country: "AE", Code: "100000000000103"}, + Endpoints: validEndpoints("100000000000103"), + Addresses: aeAddress("AUH"), + } + inv.Lines[0].Item.Description = "Consulting services" + inv.Lines[0].Taxes = tax.Set{standardVAT()} + if inv.HasTags(pint.TagOutsideScope) { + inv.Lines[0].Taxes = tax.Set{{Category: tax.CategoryVAT, Key: tax.KeyOutsideScope}} + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} + } + if typ == bill.InvoiceTypeCreditNote { + inv.Preceding = []*org.DocumentRef{{Code: "INV-001"}} + } + due := cal.MakeDate(2026, 12, 10) + inv.Payment = &bill.PaymentDetails{ + Instructions: &pay.Instructions{ + Key: pay.MeansKeyCreditTransfer, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyPaymentMeans: "30"}), + CreditTransfer: []*pay.CreditTransfer{{IBAN: "AE070331234567890123456"}}, + }, + Terms: &pay.Terms{ + DueDates: []*pay.DueDate{{Date: &due, Percent: num.NewPercentage(100, 2)}}, + }, + } + return inv +} + +// aeAddress is a complete UAE address in the given emirate. +func aeAddress(emirate string) []*org.Address { + return []*org.Address{{ + Street: "Sheikh Zayed Road", + Locality: "Dubai", + Region: emirate, + Country: "AE", + }} +} + +// standardVAT returns a standard-rated VAT combo at 5%, the UAE rate. +func standardVAT() *tax.Combo { + return &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyStandard, Percent: num.NewPercentage(5, 2)} +} + +// lineCombo returns a VAT combo with the given key and no rate, for the +// zero, exempt, outside-scope and reverse charge keys. +func lineCombo(key cbc.Key) *tax.Combo { + return &tax.Combo{Category: tax.CategoryVAT, Key: key} +} + +// aeFaults calculates the document, so the scenarios set its document type, and +// returns the faults raised under the AE regime, or "" if there are none. +func aeFaults(t *testing.T, inv *bill.Invoice) string { + t.Helper() + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) + if err == nil { + return "" + } + return err.Error() +} + +func TestBillDocumentRulesAE(t *testing.T) { + const ( + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + ) + standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } + outsideScope := func() *bill.Invoice { + return aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope) + } + outsideScopeCredit := func() *bill.Invoice { + return aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + } + + t.Run("valid documents raise no PINT faults", func(t *testing.T) { + for name, inv := range map[string]*bill.Invoice{ + "380": standard(), + "381": aeDocument(bill.InvoiceTypeCreditNote), + "480": outsideScope(), + "81": outsideScopeCredit(), + } { + assert.NotContains(t, aeFaults(t, inv), "GOBL-PEPPOL-PINT", name) + } + }) + + t.Run("seller TRN is required (IBR-134-AE)", func(t *testing.T) { + inv := standard() + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} + assert.Contains(t, aeFaults(t, inv), faultSellerTRN) + }) + + t.Run("seller TRN is not required on 480 and 81 (IBR-134-AE)", func(t *testing.T) { + for _, inv := range []*bill.Invoice{outsideScope(), outsideScopeCredit()} { + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} + assert.NotContains(t, aeFaults(t, inv), faultSellerTRN) + } + }) + + t.Run("reverse charge needs a buyer tax registration (IBR-103-AE)", func(t *testing.T) { + inv := standard() + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} + inv.Customer.TaxID = nil + assert.Contains(t, aeFaults(t, inv), faultReverseCharge) + }) + + t.Run("reverse charge accepts a tax scope identity (IBR-103-AE)", func(t *testing.T) { + inv := standard() + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} + inv.Customer.TaxID = nil + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000000000103"}} + assert.NotContains(t, aeFaults(t, inv), faultReverseCharge) + }) + + t.Run("buyer tax registration is not required without reverse charge (IBR-103-AE)", func(t *testing.T) { + inv := standard() + inv.Customer.TaxID = nil + assert.NotContains(t, aeFaults(t, inv), faultReverseCharge) + }) + + t.Run("480 and 81 need a buyer legal identity (IBR-136-AE)", func(t *testing.T) { + for _, inv := range []*bill.Invoice{outsideScope(), outsideScopeCredit()} { + inv.Customer.Identities = nil + assert.Contains(t, aeFaults(t, inv), faultBuyerLegalID) + } + }) + + t.Run("a tax scope identity is not a legal identity (IBR-136-AE)", func(t *testing.T) { + inv := outsideScope() + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000000000103"}} + assert.Contains(t, aeFaults(t, inv), faultBuyerLegalID) + }) + + t.Run("buyer legal identity is not required on 380 (IBR-136-AE)", func(t *testing.T) { + assert.NotContains(t, aeFaults(t, standard()), faultBuyerLegalID) + }) + + t.Run("480 and 81 accept E, Z and O lines (IBR-122-AE)", func(t *testing.T) { + for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyZero, tax.KeyOutsideScope} { + inv := outsideScope() + inv.Lines[0].Taxes = tax.Set{lineCombo(key)} + assert.NotContains(t, aeFaults(t, inv), faultLineCategory, key) + } + }) + + t.Run("480 and 81 reject standard rated lines (IBR-122-AE)", func(t *testing.T) { + for _, inv := range []*bill.Invoice{outsideScope(), outsideScopeCredit()} { + inv.Lines[0].Taxes = tax.Set{standardVAT()} + assert.Contains(t, aeFaults(t, inv), faultLineCategory) + } + }) + + t.Run("480 rejects standard rated discounts and charges (IBR-122-AE)", func(t *testing.T) { + inv := outsideScope() + inv.Discounts = []*bill.Discount{{ + Reason: "Loyalty", Amount: num.MakeAmount(1000, 2), + Taxes: tax.Set{standardVAT()}, + }} + inv.Charges = []*bill.Charge{{ + Reason: "Shipping", Amount: num.MakeAmount(1000, 2), + Taxes: tax.Set{standardVAT()}, + }} + out := aeFaults(t, inv) + assert.Contains(t, out, faultDiscountCat) + assert.Contains(t, out, faultChargeCategory) + }) + + t.Run("380 rejects only exempt and outside scope lines (IBR-151-AE)", func(t *testing.T) { + inv := standard() + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyExempt)} + inv.Lines = append(inv.Lines, &bill.Line{ + Quantity: num.MakeAmount(1, 0), + Item: &org.Item{Name: "Other", Description: "Other", Price: num.NewAmount(100, 2)}, + Taxes: tax.Set{lineCombo(tax.KeyOutsideScope)}, + }) + assert.Contains(t, aeFaults(t, inv), faultOnlyExempt) + }) + + t.Run("380 accepts a zero rated line (IBR-151-AE)", func(t *testing.T) { + inv := standard() + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyZero)} + assert.NotContains(t, aeFaults(t, inv), faultOnlyExempt) + }) + + t.Run("381 and 81 reject a VAT point date (IBR-124-AE)", func(t *testing.T) { + for _, inv := range []*bill.Invoice{aeDocument(bill.InvoiceTypeCreditNote), outsideScopeCredit()} { + vd := cal.MakeDate(2026, 11, 1) + inv.ValueDate = &vd + assert.Contains(t, aeFaults(t, inv), faultCreditPointDate) + } + }) + + t.Run("380 accepts a VAT point date before the issue date (IBR-124-AE, IBR-141-AE)", func(t *testing.T) { + inv := standard() + vd := cal.MakeDate(2026, 11, 1) + inv.ValueDate = &vd + out := aeFaults(t, inv) + assert.NotContains(t, out, faultCreditPointDate) + assert.NotContains(t, out, faultPointDate) + }) + + t.Run("VAT point date on or after the issue date is rejected (IBR-141-AE)", func(t *testing.T) { + for _, day := range []int{10, 20} { + inv := standard() + vd := cal.MakeDate(2026, 11, day) + inv.ValueDate = &vd + assert.Contains(t, aeFaults(t, inv), faultPointDate, "day %d", day) + } + }) + + t.Run("due date is required when an amount is due (IBR-127-AE)", func(t *testing.T) { + inv := standard() + inv.Payment.Terms = nil + assert.Contains(t, aeFaults(t, inv), faultDueDate) + + inv = standard() + inv.Payment = nil + assert.Contains(t, aeFaults(t, inv), faultDueDate) + }) + + t.Run("due date is not required when nothing is due (IBR-127-AE)", func(t *testing.T) { + inv := standard() + inv.Payment.Terms = nil + inv.Payment.Advances = []*pay.Record{{Description: "Paid in full", Percent: num.NewPercentage(100, 2)}} + assert.NotContains(t, aeFaults(t, inv), faultDueDate) + }) + + t.Run("due date is not required on 381, 81 and 261 (IBR-127-AE)", func(t *testing.T) { + for name, inv := range map[string]*bill.Invoice{ + "381": aeDocument(bill.InvoiceTypeCreditNote), + "81": outsideScopeCredit(), + "261": aeDocument(bill.InvoiceTypeCreditNote, tax.TagSelfBilled), + } { + inv.Payment.Terms = nil + assert.NotContains(t, aeFaults(t, inv), faultDueDate, name) + } + }) + + t.Run("document rules do not apply outside AE", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + require.Error(t, err) + for _, code := range []string{faultSellerTRN, faultDueDate, faultOnlyExempt} { + assert.NotContains(t, err.Error(), code) + } + }) +} + +func TestBillAddressRulesAE(t *testing.T) { + const ( + faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + ) + standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } + + t.Run("supplier address needs street, city and region (IBR-143-AE)", func(t *testing.T) { + for _, clear := range []func(a *org.Address){ + func(a *org.Address) { a.Street = "" }, + func(a *org.Address) { a.Locality = "" }, + func(a *org.Address) { a.Region = "" }, + } { + inv := standard() + clear(inv.Supplier.Addresses[0]) + assert.Contains(t, aeFaults(t, inv), faultSupplierAddress) + } + }) + + t.Run("customer address needs street, city and region (IBR-144-AE)", func(t *testing.T) { + inv := standard() + inv.Customer.Addresses[0].Locality = "" + assert.Contains(t, aeFaults(t, inv), faultCustomerAddress) + }) + + t.Run("foreign customer address also needs a region (IBR-144-AE)", func(t *testing.T) { + inv := standard() + inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Country: "DE"}} + assert.Contains(t, aeFaults(t, inv), faultCustomerAddress) + }) + + t.Run("only the first address is checked (IBR-143-AE, IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Supplier.Addresses = append(inv.Supplier.Addresses, &org.Address{Country: "AE", Region: "Dubai"}) + out := aeFaults(t, inv) + assert.NotContains(t, out, faultSupplierAddress) + assert.NotContains(t, out, faultSupplierEmirate) + }) + + t.Run("party without addresses is left to EN 16931 (BR-8, BR-10)", func(t *testing.T) { + inv := standard() + inv.Customer.Addresses = nil + out := aeFaults(t, inv) + assert.Contains(t, out, "BR-10") + assert.NotContains(t, out, faultCustomerAddress) + assert.NotContains(t, out, faultCustomerEmirate) + }) + + t.Run("UAE address region must be an emirate code (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Supplier.Addresses[0].Region = "Dubai" + inv.Customer.Addresses[0].Region = "DBX" + inv.Ordering = &bill.Ordering{Seller: &org.Party{Name: "Tax Rep", Addresses: aeAddress("XXX")}} + out := aeFaults(t, inv) + assert.Contains(t, out, faultSupplierEmirate) + assert.Contains(t, out, faultCustomerEmirate) + assert.Contains(t, out, faultTaxRepEmirate) + }) + + t.Run("every emirate code is accepted (IBR-128-AE)", func(t *testing.T) { + for _, code := range []string{"AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK"} { + inv := standard() + inv.Supplier.Addresses[0].Region = code + assert.NotContains(t, aeFaults(t, inv), faultSupplierEmirate, code) + } + }) + + t.Run("foreign address region is not checked (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} + assert.NotContains(t, aeFaults(t, inv), faultCustomerEmirate) + }) +} + +func TestBillLineRulesAE(t *testing.T) { + const ( + faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" + faultLineDescription = "GOBL-PEPPOL-PINT-BILL-LINE-02" + ) + + t.Run("line without a VAT combo is rejected (IBR-145-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = nil + out := aeFaults(t, inv) + assert.Contains(t, out, faultLineVAT) + assert.Contains(t, out, "$.lines[0].taxes") + }) + + t.Run("item description is required (IBR-125-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Description = "" + out := aeFaults(t, inv) + assert.Contains(t, out, faultLineDescription) + assert.Contains(t, out, "$.lines[0].item.description") + }) + + t.Run("line rules do not apply outside AE", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + if err != nil { + assert.NotContains(t, err.Error(), faultLineDescription) + } + }) +} diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 7396cb2..7733559 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -41,8 +41,10 @@ func init() { rules.GOBL.Add(Namespace), is.InContext(tax.AddonIn(V1)), billInvoiceRules(), + billLineRules(), taxComboRules(), taxCategoryTotalRules(), + taxIdentityRules(), payInstructionsRules(), creditTransferRules(), ) diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index 8703028..f58bc0a 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -17,8 +17,16 @@ const ( // UNTDID 1001 codes PINT AE uses for out-of-scope documents. 480 is in // UNTDID D.23A but not in the EN 16931 code list, so it lives here. - docTypeOutsideScopeInvoice cbc.Code = "480" - docTypeOutsideScopeCreditNote cbc.Code = "81" + docTypeInvoiceOutsideScope cbc.Code = "480" + docTypeCreditNoteGoodsServices cbc.Code = "81" + + // UNTDID 1001 codes the EN 16931 scenarios set on standard invoices and + // credit notes, which some PINT AE rules check. + docTypeCommercialInvoice cbc.Code = "380" + docTypeCreditNote cbc.Code = "381" + // docTypeSelfBilledCreditNote is the code the EN 16931 scenarios set on + // self-billed credit notes. + docTypeSelfBilledCreditNote cbc.Code = "261" ) // invoiceTags are the document tags the PINT addon adds to invoices. @@ -50,7 +58,7 @@ var invoiceScenarios = &tax.ScenarioSet{ Tags: []cbc.Key{TagOutsideScope}, Filter: invoiceIsAE, Ext: tax.ExtensionsOf(cbc.CodeMap{ - untdid.ExtKeyDocumentType: docTypeOutsideScopeInvoice, + untdid.ExtKeyDocumentType: docTypeInvoiceOutsideScope, }), }, { @@ -58,7 +66,7 @@ var invoiceScenarios = &tax.ScenarioSet{ Tags: []cbc.Key{TagOutsideScope}, Filter: invoiceIsAE, Ext: tax.ExtensionsOf(cbc.CodeMap{ - untdid.ExtKeyDocumentType: docTypeOutsideScopeCreditNote, + untdid.ExtKeyDocumentType: docTypeCreditNoteGoodsServices, }), }, }, diff --git a/addon/pint/tax_identity.go b/addon/pint/tax_identity.go new file mode 100644 index 0000000..19f5edf --- /dev/null +++ b/addon/pint/tax_identity.go @@ -0,0 +1,24 @@ +package pint + +import ( + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" +) + +// taxIdentityRules enforces the UAE TRN format on every UAE tax identity of a +// UAE document (IBR-132-AE). The AE regime only checks for 15 digits; PINT AE +// also requires a leading 1 and a trailing 03. +func taxIdentityRules() *rules.Set { + return rules.For(new(tax.Identity), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When(tax.IdentityIn("AE"), + rules.Field("code", + rules.AssertIfPresent("01", "UAE TRN must be 15 digits, start with 1 and end with 03 (IBR-132-AE)", + is.Matches(`^1\d{12}03$`)), + ), + ), + ), + ) +} diff --git a/addon/pint/tax_identity_test.go b/addon/pint/tax_identity_test.go new file mode 100644 index 0000000..9c64573 --- /dev/null +++ b/addon/pint/tax_identity_test.go @@ -0,0 +1,54 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" +) + +func TestTaxIdentityRulesAE(t *testing.T) { + const faultTRN = "GOBL-PEPPOL-PINT-TAX-IDENTITY-01" + validateIn := func(id *tax.Identity, regime l10n.TaxCountryCode) error { + return rules.Validate(id, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) + } + validate := func(id *tax.Identity) error { return validateIn(id, l10n.AE.Tax()) } + + t.Run("valid TRN is accepted (IBR-132-AE)", func(t *testing.T) { + assert.NoError(t, validate(&tax.Identity{Country: "AE", Code: "100000000000003"})) + }) + + t.Run("malformed TRNs are rejected (IBR-132-AE)", func(t *testing.T) { + for name, code := range map[string]cbc.Code{ + "does not start with 1": "200000000000003", + "does not end with 03": "100000000000004", + "too short": "10000000000003", + "too long": "1000000000000003", + } { + err := validate(&tax.Identity{Country: "AE", Code: code}) + assert.ErrorContains(t, err, faultTRN, name) + } + }) + + t.Run("identity without a code is accepted (IBR-132-AE)", func(t *testing.T) { + assert.NoError(t, validate(&tax.Identity{Country: "AE"})) + }) + + t.Run("non-UAE identities are not checked (IBR-132-AE)", func(t *testing.T) { + err := validate(&tax.Identity{Country: "DE", Code: "111111125"}) + if err != nil { + assert.NotContains(t, err.Error(), faultTRN) + } + }) + + t.Run("the rule does not apply outside AE", func(t *testing.T) { + err := validateIn(&tax.Identity{Country: "AE", Code: "200000000000003"}, l10n.AU.Tax()) + if err != nil { + assert.NotContains(t, err.Error(), faultTRN) + } + }) +} From dc8ed3d56e79a631c8523148e3b89879196fbb5a Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:04:22 +0000 Subject: [PATCH 05/73] Remove the IBR-136-AE type code TODO --- addon/pint/bill.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index c158cef..08c7970 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -88,8 +88,6 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - // TODO: also check the identity type code (TL, EID, PAS or CD) - // once decision 6 is settled (task I). rules.Assert("10", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), From 80beb816aa0e8b176e1615c973b5f6934c8cdfb8 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:15:31 +0000 Subject: [PATCH 06/73] Add the Peppol PINT AE UBL format Add FormatAE (ubl+peppol+pint+ae-v1) for UAE e-invoicing, with PINT AE Billing and Self-Billing identifiers and the PINT AE 1.0.4 VESIDs, and adjust the exported XML to the PINT AE rules: - Write the invoice UUID (IBR-193-AE). - Add the price base quantity and gross price (IBR-126-AE). - Write UAE TRNs without the country prefix (IBR-132-AE). - Write no rate on exempt lines and breakdowns, and 5 on reverse charge ones (aligned-ibrp-e-05, IBR-121-AE, aligned-ibrp-ae-05-ae, IBR-119-AE). - Merge the VAT breakdowns of the same category and rate (aligned-ibrp-e-01, e-08). On import, read the out-of-scope type codes 480 and 81 back as the outside-scope tag. Add AE convert and parse fixtures, modelled on the official examples. With -validate, the AE convert fixtures still fail the rules that the AED line amounts (IBR-104, 162, 194), the legal identity types (IBR-173, 180, 181) and the BTAE extensions (IBR-055, 154, 158, 166, 167, 168, 174) will cover. --- README.md | 16 +- examples/invoice-ae.yaml | 70 +++++ examples/out/invoice-ae.json | 172 +++++++++++ ubl/ae.go | 258 +++++++++++++++++ ubl/ae_internal_test.go | 206 +++++++++++++ ubl/examples_test.go | 1 + .../convert/pint/ae/credit-note-ae.json | 168 +++++++++++ .../convert/pint/ae/invoice-ae-exempt.json | 270 ++++++++++++++++++ .../pint/ae/invoice-ae-outside-scope.json | 175 ++++++++++++ .../invoice-ae-reverse-charge-allowance.json | 208 ++++++++++++++ .../pint/ae/invoice-ae-reverse-charge.json | 172 +++++++++++ ubl/testdata/convert/pint/ae/invoice-ae.json | 172 +++++++++++ .../convert/pint/ae/out/credit-note-ae.xml | 123 ++++++++ .../convert/pint/ae/out/invoice-ae-exempt.xml | 203 +++++++++++++ .../pint/ae/out/invoice-ae-outside-scope.xml | 117 ++++++++ .../invoice-ae-reverse-charge-allowance.xml | 147 ++++++++++ .../pint/ae/out/invoice-ae-reverse-charge.xml | 119 ++++++++ .../convert/pint/ae/out/invoice-ae.xml | 118 ++++++++ .../parse/pint/ae/allowance-exempt.xml | 155 ++++++++++ .../parse/pint/ae/out/allowance-exempt.json | 227 +++++++++++++++ .../parse/pint/ae/out/reverse-charge.json | 221 ++++++++++++++ .../parse/pint/ae/out/standard-invoice.json | 166 +++++++++++ ubl/testdata/parse/pint/ae/reverse-charge.xml | 162 +++++++++++ .../parse/pint/ae/standard-invoice.xml | 124 ++++++++ ubl/ubl.go | 41 ++- ubl/ubl_test.go | 79 ++++- 26 files changed, 3885 insertions(+), 5 deletions(-) create mode 100644 examples/invoice-ae.yaml create mode 100644 examples/out/invoice-ae.json create mode 100644 ubl/ae.go create mode 100644 ubl/ae_internal_test.go create mode 100644 ubl/testdata/convert/pint/ae/credit-note-ae.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-exempt.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae.json create mode 100644 ubl/testdata/convert/pint/ae/out/credit-note-ae.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae.xml create mode 100644 ubl/testdata/parse/pint/ae/allowance-exempt.xml create mode 100644 ubl/testdata/parse/pint/ae/out/allowance-exempt.json create mode 100644 ubl/testdata/parse/pint/ae/out/reverse-charge.json create mode 100644 ubl/testdata/parse/pint/ae/out/standard-invoice.json create mode 100644 ubl/testdata/parse/pint/ae/reverse-charge.xml create mode 100644 ubl/testdata/parse/pint/ae/standard-invoice.xml diff --git a/README.md b/README.md index f554661..324ff49 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ This module implements the Peppol billing models as a set of GOBL tax addons: beyond VAT (such as GST). Jurisdiction-specific rules are applied according to the document's tax regime: Australian (`AU`) and New Zealand (`NZ`) documents are also validated against the - [PINT A-NZ](https://docs.peppol.eu/poac/aunz/pint-aunz/bis/) rules. + [PINT A-NZ](https://docs.peppol.eu/poac/aunz/pint-aunz/bis/) rules, and UAE + (`AE`) documents against the + [PINT AE](https://docs.peppol.eu/poac/ae/pint-ae/) rules. A document must declare the addon that applies to it. @@ -86,6 +88,7 @@ import, and the exported XML carries them back: | `FormatBIS` | `ubl+peppol+bis-v3` | `urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0` | `urn:fdc:peppol.eu:2017:poacc:billing:01:1.0` | | `FormatPINT` | `ubl+peppol+pint` | `urn:peppol:pint:billing-1` | `urn:peppol:bis:billing` | | `FormatAUNZ` | `ubl+peppol+pint+aunz` | `urn:peppol:pint:billing-1@aunz-1` | `urn:peppol:bis:billing` | +| `FormatAE` | `ubl+peppol+pint+ae` | `urn:peppol:pint:billing-1@ae-1` | `urn:peppol:bis:billing` | `FormatBIS` writes self-billed invoices with `SpecificationBISSelfBilling` (Peppol BIS Self-Billing 3.0) and statuses (`bill.Status`) as Peppol Invoice @@ -97,12 +100,19 @@ as Peppol BIS allows a single note. `FormatAUNZ` writes self-billed invoices (those tagged `self-billed`) with its `SpecificationAUNZSelfBilling` instead: `urn:peppol:pint:selfbilling-1@aunz-1` and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with -`FormatAUNZ`. +`FormatAUNZ`. `FormatAE` does the same with `SpecificationAESelfBilling` +(`urn:peppol:pint:selfbilling-1@ae-1`). + +`FormatAE` also adjusts the output to the PINT AE rules: it writes the +invoice UUID, the price base quantity and gross price, the UAE TRN without +its country prefix, the 5% rate on reverse charge lines and breakdowns, no +rate on exempt ones, and one VAT breakdown per category. On import, it reads +the out-of-scope type codes 480 and 81 back as the `outside-scope` tag. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, with `CreditNote-2::CreditNote` replacing `Invoice-2::Invoice` for credit notes. -The A-NZ formats also claim the wildcard customizations the SMP registrations +The A-NZ and AE formats also claim the wildcard customizations the SMP registrations are made under, and `FormatPINT` is the jurisdiction-neutral base: it takes any other `urn:peppol:pint:billing-1@…` specialization and validates it against the base PINT rule set. diff --git a/examples/invoice-ae.yaml b/examples/invoice-ae.yaml new file mode 100644 index 0000000..66ec9cd --- /dev/null +++ b/examples/invoice-ae.yaml @@ -0,0 +1,70 @@ +$schema: "https://gobl.org/draft-0/bill/invoice" +$regime: "AE" +$addons: + - "peppol-pint-v1" +uuid: "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2" +currency: "AED" +issue_date: "2025-01-30" +series: "AE" +code: "001" + +supplier: + name: "Supplier Legal Name" + tax_id: + country: "AE" + code: "135790246801003" + identities: + - scope: "legal" + code: "112345678900003" + inboxes: + - key: "peppol" + scheme: "0235" + code: "1357902468" + addresses: + - street: "Sheikh Zayed Road" + locality: "Dubai" + region: "DXB" + country: "AE" + +customer: + name: "Buyer Legal Name" + tax_id: + country: "AE" + code: "134567890123003" + identities: + - scope: "legal" + code: "112345679000001" + inboxes: + - key: "peppol" + scheme: "0235" + code: "1345678901" + addresses: + - street: "Corniche Road" + locality: "Abu Dhabi" + region: "AUH" + country: "AE" + +lines: + - quantity: "100" + item: + name: "Item Name" + description: "Item Description" + price: "10.00" + taxes: + - cat: VAT + key: standard + percent: "5%" + +payment: + terms: + key: "due-date" + due_dates: + - date: "2025-02-06" + percent: "100%" + instructions: + key: "credit-transfer" + ext: + untdid-payment-means: "30" + credit_transfer: + - iban: "AE070331234567890123456" + name: "Emirates NBD" diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json new file mode 100644 index 0000000..7320692 --- /dev/null +++ b/examples/out/invoice-ae.json @@ -0,0 +1,172 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", + "dig": { + "alg": "sha256", + "val": "a9971c414f59abc529620dc03bc5f294f91fea9918d4a01e51dec5dada0f92f3" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "001", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/ae.go b/ubl/ae.go new file mode 100644 index 0000000..b2e8328 --- /dev/null +++ b/ubl/ae.go @@ -0,0 +1,258 @@ +package ubl + +import ( + "github.com/invopop/gobl" + "github.com/invopop/gobl.peppol/addon/pint" + goblubl "github.com/invopop/gobl.ubl" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/num" + "github.com/invopop/gobl/tax" +) + +// UNTDID 5305 VAT category codes the AE format writes rates for. +const ( + taxCategoryExempt = "E" + taxCategoryReverseCharge = "AE" +) + +// aeReverseChargeRate is the rate PINT AE expects on reverse charge lines and +// breakdowns. GOBL keeps reverse charge without a percent, as no VAT is +// charged, but the PINT AE examples and the 5% standard rate (IBR-190-AE) +// write 5. +const aeReverseChargeRate = "5" + +// exportAE applies the Peppol PINT AE rules to an exported invoice. Each step +// only uses data GOBL already has; the AE amounts and the BTAE extensions are +// added by later steps. +func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error { + out, ok := doc.(*goblubl.Invoice) + inv, ok2 := env.Extract().(*bill.Invoice) + if !ok || !ok2 { + return nil + } + exportAEUUID(out, inv) + for i := range out.InvoiceLines { + exportAELine(&out.InvoiceLines[i]) + } + for i := range out.CreditNoteLines { + exportAELine(&out.CreditNoteLines[i]) + } + for _, p := range goblubl.InvoiceParties(inv, out) { + exportAEPartyTaxID(p.UBL, p.GOBL.TaxID) + } + for i := range out.TaxTotal { + exportAETaxTotal(&out.TaxTotal[i]) + } + return nil +} + +// importAE applies the Peppol PINT AE rules to an imported invoice. +func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error { + in, ok := doc.(*goblubl.Invoice) + inv, ok2 := env.Extract().(*bill.Invoice) + if !ok || !ok2 { + return nil + } + importAEOutsideScope(in, inv) + return nil +} + +// importAEOutsideScope reads the PINT AE out-of-scope document types, which +// gobl.ubl does not know and imports as "other": 480 becomes a standard +// invoice and 81 a credit note, both with the outside-scope tag. The PINT +// scenarios then set the type code back when the document is calculated. +func importAEOutsideScope(in *goblubl.Invoice, inv *bill.Invoice) { + code := in.InvoiceTypeCode + if code == nil { + code = in.CreditNoteTypeCode + } + if code == nil { + return + } + switch code.Value { + case "480": + inv.Type = bill.InvoiceTypeStandard + case "81": + inv.Type = bill.InvoiceTypeCreditNote + default: + return + } + if !inv.HasTags(pint.TagOutsideScope) { + inv.Tags.List = append(inv.Tags.List, pint.TagOutsideScope) + } +} + +// exportAEUUID writes the invoice's UUID as cbc:UUID, the unique identifier +// number BTAE-07 (IBR-193-AE). +func exportAEUUID(out *goblubl.Invoice, inv *bill.Invoice) { + if !inv.UUID.IsZero() { + out.UUID = inv.UUID.String() + } +} + +// exportAELine completes a line's price details and VAT rate. +func exportAELine(line *goblubl.InvoiceLine) { + exportAEPrice(line) + if line.Item != nil && line.Item.ClassifiedTaxCategory != nil { + c := line.Item.ClassifiedTaxCategory + c.Percent = aeRate(c.ID, c.Percent) + } +} + +// exportAEPrice adds the price base quantity (ibt-149) and the gross price +// (ibt-148) PINT AE requires on every line (IBR-126-AE). GOBL prices are per +// unit, so the base quantity is 1 in the line's unit. Without a list price, +// gobl.ubl writes no price allowance, so the gross price is the net price with +// a zero discount. The base quantity also lets IBR-147-AE compute the line net +// amount. +func exportAEPrice(line *goblubl.InvoiceLine) { + price := line.Price + if price == nil { + return + } + if price.BaseQuantity == nil { + price.BaseQuantity = &goblubl.Quantity{UnitCode: lineUnitCode(line), Value: "1"} + } + if price.AllowanceCharge == nil { + gross := price.PriceAmount + price.AllowanceCharge = &goblubl.AllowanceCharge{ + ChargeIndicator: false, + Amount: goblubl.Amount{CurrencyID: price.PriceAmount.CurrencyID, Value: "0"}, + BaseAmount: &gross, + } + } +} + +// lineUnitCode provides the unit code of the line's invoiced or credited +// quantity. +func lineUnitCode(line *goblubl.InvoiceLine) string { + if line.InvoicedQuantity != nil { + return line.InvoicedQuantity.UnitCode + } + if line.CreditedQuantity != nil { + return line.CreditedQuantity.UnitCode + } + return "" +} + +// aeRate provides the rate PINT AE expects for a line or breakdown VAT +// category. gobl.ubl writes 0 when a combo has no percent, which is right for +// A-NZ but not for AE: exempt must have no rate (aligned-ibrp-e-05, +// IBR-121-AE), and reverse charge must have one (aligned-ibrp-ae-05-ae, +// IBR-119-AE). Document allowances and charges keep gobl.ubl's 0, which is +// what PINT AE wants there for both (aligned-ibrp-e-06/07, ae-06/07). +func aeRate(id *goblubl.IDType, percent *string) *string { + if id == nil { + return percent + } + switch id.Value { + case taxCategoryExempt: + return nil + case taxCategoryReverseCharge: + rate := aeReverseChargeRate + return &rate + } + return percent +} + +// exportAEPartyTaxID writes a UAE TRN without the AE prefix gobl.ubl adds, +// the bare 15 digits IBR-132-AE checks on the seller, buyer and tax +// representative. Tax IDs from other countries keep their prefix, the usual +// VAT number format. +func exportAEPartyTaxID(out *goblubl.Party, tID *tax.Identity) { + if out == nil || tID == nil || tID.Code == "" || tID.Country.Code() != l10n.AE { + return + } + prefixed := tID.String() + for i := range out.PartyTaxScheme { + id := out.PartyTaxScheme[i].CompanyID + if id != nil && id.Value == prefixed { + id.Value = tID.Code.String() + } + } +} + +// exportAETaxTotal fixes the rates of the VAT breakdowns, and merges the ones +// left with the same category and rate. +func exportAETaxTotal(tt *goblubl.TaxTotal) { + for i := range tt.TaxSubtotal { + c := &tt.TaxSubtotal[i].TaxCategory + c.Percent = aeRate(c.ID, c.Percent) + } + tt.TaxSubtotal = mergeAETaxSubtotals(tt.TaxSubtotal) +} + +// mergeAETaxSubtotals merges the VAT breakdowns with the same category and +// rate. GOBL makes a breakdown per exemption code, so two exempt lines with +// different codes give two E breakdowns, but PINT AE wants exactly one per +// category (aligned-ibrp-e-01, o-01, z-01) with the taxable amount of all its +// lines (aligned-ibrp-e-08, o-08, ae-08-ae). Exemption codes and reasons that +// differ are dropped from the merged breakdown; the line keeps its own. +func mergeAETaxSubtotals(subtotals []goblubl.TaxSubtotal) []goblubl.TaxSubtotal { + var merged []goblubl.TaxSubtotal + for _, st := range subtotals { + i := indexAETaxSubtotal(merged, st.TaxCategory) + if i < 0 { + merged = append(merged, st) + continue + } + m := &merged[i] + m.TaxableAmount.Value = addAmounts(m.TaxableAmount.Value, st.TaxableAmount.Value) + m.TaxAmount.Value = addAmounts(m.TaxAmount.Value, st.TaxAmount.Value) + if !sameString(m.TaxCategory.TaxExemptionReasonCode, st.TaxCategory.TaxExemptionReasonCode) { + m.TaxCategory.TaxExemptionReasonCode = nil + } + if !sameString(m.TaxCategory.TaxExemptionReason, st.TaxCategory.TaxExemptionReason) { + m.TaxCategory.TaxExemptionReason = nil + } + } + return merged +} + +// indexAETaxSubtotal finds the breakdown with the same category ID, rate and +// tax scheme, or -1. +func indexAETaxSubtotal(list []goblubl.TaxSubtotal, c goblubl.TaxCategory) int { + for i, st := range list { + if sameID(st.TaxCategory.ID, c.ID) && + sameString(st.TaxCategory.Percent, c.Percent) && + sameScheme(st.TaxCategory.TaxScheme, c.TaxScheme) { + return i + } + } + return -1 +} + +func sameID(a, b *goblubl.IDType) bool { + if a == nil || b == nil { + return a == b + } + return a.Value == b.Value +} + +func sameString(a, b *string) bool { + if a == nil || b == nil { + return a == b + } + return *a == *b +} + +func sameScheme(a, b *goblubl.TaxScheme) bool { + if a == nil || b == nil { + return a == b + } + return a.ID.Value == b.ID.Value +} + +// addAmounts adds two decimal amounts, keeping the larger number of decimals. +func addAmounts(a, b string) string { + x, err := num.AmountFromString(a) + if err != nil { + return a + } + y, err := num.AmountFromString(b) + if err != nil { + return a + } + return x.MatchPrecision(y).Add(y).String() +} diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go new file mode 100644 index 0000000..40841a1 --- /dev/null +++ b/ubl/ae_internal_test.go @@ -0,0 +1,206 @@ +package ubl + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + goblubl "github.com/invopop/gobl.ubl" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/tax" + "github.com/invopop/gobl/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func strPtr(s string) *string { return &s } + +func aeCategory(id string, percent *string) goblubl.TaxCategory { + return goblubl.TaxCategory{ + ID: &goblubl.IDType{Value: id}, + Percent: percent, + TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}, + } +} + +func aeAmount(v string) goblubl.Amount { + return goblubl.Amount{CurrencyID: strPtr("AED"), Value: v} +} + +func TestExportAEUUID(t *testing.T) { + out := new(goblubl.Invoice) + inv := &bill.Invoice{} + exportAEUUID(out, inv) + assert.Empty(t, out.UUID, "no UUID to write") + + inv.UUID = uuid.MustParse("0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2") + exportAEUUID(out, inv) + assert.Equal(t, "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", out.UUID) +} + +func TestExportAEPrice(t *testing.T) { + t.Run("adds the base quantity and a zero discount on the net price", func(t *testing.T) { + line := &goblubl.InvoiceLine{ + InvoicedQuantity: &goblubl.Quantity{UnitCode: "HUR", Value: "10"}, + Price: &goblubl.Price{PriceAmount: aeAmount("100.00")}, + } + exportAEPrice(line) + require.NotNil(t, line.Price.BaseQuantity) + assert.Equal(t, goblubl.Quantity{UnitCode: "HUR", Value: "1"}, *line.Price.BaseQuantity) + ac := line.Price.AllowanceCharge + require.NotNil(t, ac) + assert.False(t, ac.ChargeIndicator) + assert.Equal(t, "0", ac.Amount.Value) + require.NotNil(t, ac.BaseAmount) + assert.Equal(t, "100.00", ac.BaseAmount.Value) + }) + + t.Run("uses the credited quantity's unit on credit notes", func(t *testing.T) { + line := &goblubl.InvoiceLine{ + CreditedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, + Price: &goblubl.Price{PriceAmount: aeAmount("5.00")}, + } + exportAEPrice(line) + assert.Equal(t, "C62", line.Price.BaseQuantity.UnitCode) + }) + + t.Run("keeps a price discount gobl.ubl already wrote", func(t *testing.T) { + existing := &goblubl.AllowanceCharge{Amount: aeAmount("20.00"), BaseAmount: &goblubl.Amount{Value: "120.00"}} + line := &goblubl.InvoiceLine{ + InvoicedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, + Price: &goblubl.Price{PriceAmount: aeAmount("100.00"), AllowanceCharge: existing}, + } + exportAEPrice(line) + assert.Same(t, existing, line.Price.AllowanceCharge) + }) + + t.Run("lines without a price are left alone", func(t *testing.T) { + line := &goblubl.InvoiceLine{} + exportAEPrice(line) + assert.Nil(t, line.Price) + }) +} + +func TestAERate(t *testing.T) { + zero := strPtr("0") + assert.Nil(t, aeRate(&goblubl.IDType{Value: "E"}, zero), "exempt has no rate") + rc := aeRate(&goblubl.IDType{Value: "AE"}, zero) + require.NotNil(t, rc) + assert.Equal(t, "5", *rc, "reverse charge is written at 5") + assert.Equal(t, strPtr("5"), aeRate(&goblubl.IDType{Value: "S"}, strPtr("5")), "standard keeps its rate") + assert.Nil(t, aeRate(&goblubl.IDType{Value: "O"}, nil), "outside scope keeps no rate") + assert.Equal(t, zero, aeRate(nil, zero), "no category, no change") +} + +func TestMergeAETaxSubtotals(t *testing.T) { + exempt := func(base, code string) goblubl.TaxSubtotal { + c := aeCategory("E", nil) + c.TaxExemptionReasonCode = strPtr(code) + return goblubl.TaxSubtotal{TaxableAmount: aeAmount(base), TaxAmount: aeAmount("0.00"), TaxCategory: c} + } + standard := goblubl.TaxSubtotal{ + TaxableAmount: aeAmount("1000.00"), + TaxAmount: aeAmount("50.00"), + TaxCategory: aeCategory("S", strPtr("5")), + } + + t.Run("merges breakdowns of the same category and drops differing codes", func(t *testing.T) { + out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{standard, exempt("200.00", "VATEX-1"), exempt("280.00", "VATEX-2")}) + require.Len(t, out, 2) + assert.Equal(t, "1000.00", out[0].TaxableAmount.Value) + assert.Equal(t, "480.00", out[1].TaxableAmount.Value) + assert.Equal(t, "0.00", out[1].TaxAmount.Value) + assert.Nil(t, out[1].TaxCategory.TaxExemptionReasonCode) + }) + + t.Run("keeps a code all merged breakdowns share", func(t *testing.T) { + out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{exempt("200.00", "VATEX-1"), exempt("100.00", "VATEX-1")}) + require.Len(t, out, 1) + assert.Equal(t, "300.00", out[0].TaxableAmount.Value) + assert.Equal(t, strPtr("VATEX-1"), out[0].TaxCategory.TaxExemptionReasonCode) + }) + + t.Run("does not merge different rates", func(t *testing.T) { + zero := goblubl.TaxSubtotal{TaxableAmount: aeAmount("10.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("S", strPtr("0"))} + out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{standard, zero}) + assert.Len(t, out, 2) + }) +} + +func TestExportAETaxTotal(t *testing.T) { + tt := &goblubl.TaxTotal{TaxSubtotal: []goblubl.TaxSubtotal{ + {TaxableAmount: aeAmount("100.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("AE", strPtr("0"))}, + {TaxableAmount: aeAmount("50.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("E", strPtr("0"))}, + }} + exportAETaxTotal(tt) + require.Len(t, tt.TaxSubtotal, 2) + assert.Equal(t, strPtr("5"), tt.TaxSubtotal[0].TaxCategory.Percent) + assert.Nil(t, tt.TaxSubtotal[1].TaxCategory.Percent) +} + +func TestExportAEPartyTaxID(t *testing.T) { + party := func(companyID string) *goblubl.Party { + return &goblubl.Party{PartyTaxScheme: []goblubl.PartyTaxScheme{{ + CompanyID: &goblubl.IDType{Value: companyID}, + TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}, + }}} + } + + t.Run("writes a UAE TRN without its prefix", func(t *testing.T) { + out := party("AE100000000000003") + exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000000000003"}) + assert.Equal(t, "100000000000003", out.PartyTaxScheme[0].CompanyID.Value) + }) + + t.Run("keeps the prefix of other countries' VAT numbers", func(t *testing.T) { + out := party("DE111111125") + exportAEPartyTaxID(out, &tax.Identity{Country: "DE", Code: "111111125"}) + assert.Equal(t, "DE111111125", out.PartyTaxScheme[0].CompanyID.Value) + }) + + t.Run("leaves other tax registrations alone", func(t *testing.T) { + out := party("1234567890") + exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000000000003"}) + assert.Equal(t, "1234567890", out.PartyTaxScheme[0].CompanyID.Value) + }) + + t.Run("parties without a tax ID are skipped", func(t *testing.T) { + out := party("AE100000000000003") + exportAEPartyTaxID(out, nil) + assert.Equal(t, "AE100000000000003", out.PartyTaxScheme[0].CompanyID.Value) + }) +} + +func TestImportAEOutsideScope(t *testing.T) { + importCode := func(invoiceCode, creditNoteCode string) *bill.Invoice { + in := new(goblubl.Invoice) + if invoiceCode != "" { + in.InvoiceTypeCode = &goblubl.IDType{Value: invoiceCode} + } + if creditNoteCode != "" { + in.CreditNoteTypeCode = &goblubl.IDType{Value: creditNoteCode} + } + inv := &bill.Invoice{Type: bill.InvoiceTypeOther} + importAEOutsideScope(in, inv) + return inv + } + + inv := importCode("480", "") + assert.Equal(t, bill.InvoiceTypeStandard, inv.Type) + assert.True(t, inv.HasTags(pint.TagOutsideScope)) + + inv = importCode("", "81") + assert.Equal(t, bill.InvoiceTypeCreditNote, inv.Type) + assert.True(t, inv.HasTags(pint.TagOutsideScope)) + + inv = importCode("380", "") + assert.Equal(t, bill.InvoiceTypeOther, inv.Type, "other codes are left to gobl.ubl") + assert.False(t, inv.HasTags(pint.TagOutsideScope)) + + t.Run("does not add the tag twice", func(t *testing.T) { + in := &goblubl.Invoice{InvoiceTypeCode: &goblubl.IDType{Value: "480"}} + inv := &bill.Invoice{Tags: tax.WithTags(pint.TagOutsideScope)} + importAEOutsideScope(in, inv) + assert.Equal(t, []cbc.Key{pint.TagOutsideScope}, inv.Tags.List) + }) +} diff --git a/ubl/examples_test.go b/ubl/examples_test.go index 6495718..a62033a 100644 --- a/ubl/examples_test.go +++ b/ubl/examples_test.go @@ -33,6 +33,7 @@ var exampleFormats = []struct { }{ {"bis", peppolubl.FormatBIS}, {"pint/aunz", peppolubl.FormatAUNZ}, + {"pint/ae", peppolubl.FormatAE}, {"pint", peppolubl.FormatPINT}, } diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json new file mode 100644 index 0000000..d20430e --- /dev/null +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -0,0 +1,168 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "83aa2c00b32d32761a89c65ec5e6d948c8112ea451179235a961bb09f75b50a6" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "series": "AE", + "code": "CN-001", + "issue_date": "2025-01-30", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-01-30", + "code": "AE-001" + } + ], + "tax": { + "ext": { + "untdid-document-type": "381" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json new file mode 100644 index 0000000..ac9d722 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -0,0 +1,270 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "3d3a04621f2e455641b507c8336c65706d3d24518c819c97814eb3590eb387e2" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "003", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + }, + { + "i": 2, + "quantity": "1", + "item": { + "name": "Financial service", + "description": "Margin-free financial service", + "price": "200.00", + "unit": "one" + }, + "sum": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + } + } + ], + "total": "200.00" + }, + { + "i": 3, + "quantity": "1", + "item": { + "name": "Residential rent", + "description": "Residential building lease", + "price": "300.00", + "unit": "one" + }, + "sum": "300.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-135-1L", + "untdid-tax-category": "E" + } + } + ], + "total": "300.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Loyalty discount", + "amount": "20.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + } + } + ] + } + ], + "charges": [ + { + "i": 1, + "reason": "Delivery", + "amount": "30.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ] + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1561.50", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1500.00", + "discount": "20.00", + "charge": "30.00", + "total": "1510.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1030.00", + "percent": "5%", + "amount": "51.50" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + }, + "base": "180.00", + "amount": "0.00" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-135-1L", + "untdid-tax-category": "E" + }, + "base": "300.00", + "amount": "0.00" + } + ], + "amount": "51.50" + } + ], + "sum": "51.50" + }, + "tax": "51.50", + "total_with_tax": "1561.50", + "payable": "1561.50" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json new file mode 100644 index 0000000..3532c39 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -0,0 +1,175 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "c0956f6f36cc507c74c03ef7c05ef02c534546e55569646d046827ffb45125e7" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "005", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "cef-vatex": "VATEX-EU-O", + "untdid-tax-category": "O" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1000.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "outside-scope", + "ext": { + "cef-vatex": "VATEX-EU-O", + "untdid-tax-category": "O" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json new file mode 100644 index 0000000..daaf913 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -0,0 +1,208 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "0a5fd01e4b6b1c604bb478bd2427cdd8ecfd3cc51be85d0deb439a6b11a9f070" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "004", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + } + } + ], + "total": "1000.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Volume discount", + "amount": "50.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + } + } + ] + } + ], + "charges": [ + { + "i": 1, + "reason": "Handling", + "amount": "25.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + } + } + ] + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "975.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "discount": "50.00", + "charge": "25.00", + "total": "975.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + }, + "base": "975.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "975.00", + "payable": "975.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json new file mode 100644 index 0000000..d4ca8db --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -0,0 +1,172 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "02bf266ce841a1a4c64fba01d6e859e751ab73cec534e39c71351ee49ef2e73e" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "002", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1000.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json new file mode 100644 index 0000000..64cd680 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -0,0 +1,172 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "a9971c414f59abc529620dc03bc5f294f91fea9918d4a01e51dec5dada0f92f3" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "001", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml new file mode 100644 index 0000000..3c90ced --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -0,0 +1,123 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-CN-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 381 + AED + + NA + + + + AE-001 + 2025-01-30 + + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml new file mode 100644 index 0000000..c63c5cf --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -0,0 +1,203 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-003 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + true + Delivery + 30.00 + + S + 5 + + VAT + + + + + false + Loyalty discount + 20.00 + + E + 0 + VATEX-EU-132-1I + + VAT + + + + + 51.50 + + 1030.00 + 51.50 + + S + 5 + + VAT + + + + + 480.00 + 0.00 + + E + + VAT + + + + + + 1500.00 + 1510.00 + 1561.50 + 20.00 + 30.00 + 1561.50 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + + 2 + 1 + 200.00 + + Margin-free financial service + Financial service + + E + + VAT + + + + + 200.00 + 1 + + false + 0 + 200.00 + + + + + 3 + 1 + 300.00 + + Residential building lease + Residential rent + + E + + VAT + + + + + 300.00 + 1 + + false + 0 + 300.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml new file mode 100644 index 0000000..9e0a4e2 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -0,0 +1,117 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-005 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 480 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 0.00 + + 1000.00 + 0.00 + + O + VATEX-EU-O + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + O + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml new file mode 100644 index 0000000..95f1cc6 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -0,0 +1,147 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-004 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + true + Handling + 25.00 + + AE + 0 + VATEX-EU-AE + + VAT + + + + + false + Volume discount + 50.00 + + AE + 0 + VATEX-EU-AE + + VAT + + + + + 0.00 + + 975.00 + 0.00 + + AE + 5 + VATEX-EU-AE + + VAT + + + + + + 1000.00 + 975.00 + 975.00 + 50.00 + 25.00 + 975.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + AE + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml new file mode 100644 index 0000000..47dfc50 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -0,0 +1,119 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-002 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 0.00 + + 1000.00 + 0.00 + + AE + 5 + VATEX-EU-AE + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + AE + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml new file mode 100644 index 0000000..b5e82dc --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -0,0 +1,118 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/allowance-exempt.xml b/ubl/testdata/parse/pint/ae/allowance-exempt.xml new file mode 100644 index 0000000..3a1fa47 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/allowance-exempt.xml @@ -0,0 +1,155 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-ALLOW-E-01 + a1b2c3d4-e5f6-7890-abcd-300000000003 + 2025-03-15 + 2025-03-30 + 480 + Exempt supply invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + false + 100 + Special Rebate + 100 + + E + 0 + + VAT + + + + + 0 + false + + 900 + 0 + + E + + VAT + + + + + + 1000 + 900 + 900 + 100 + 900 + + + 1 + 10 + 1000 + + Educational services exempt from VAT + Education Services + + E + VATEX-AE-EDU + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json new file mode 100644 index 0000000..162ebd8 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -0,0 +1,227 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "fcbad581ef55848a3d9113422d9953ffc8075628d488d8d4b66a961ca565a332" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-ALLOW-E-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Education Services", + "description": "Educational services exempt from VAT", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "untdid-tax-category": "E" + } + } + ], + "total": "1000.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "100.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "untdid-tax-category": "E" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "900.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "discount": "100.00", + "total": "900.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "exempt", + "ext": { + "untdid-tax-category": "E" + }, + "base": "900.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "900.00", + "payable": "900.00" + }, + "notes": [ + { + "text": "Exempt supply invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json new file mode 100644 index 0000000..0f5cbc3 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -0,0 +1,221 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "90331caa41959e413927081cbad2cdcae40fc83a2d785c4cfba1d599cea7f6c8" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-01RCTEST", + "issue_date": "2025-02-07", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "127890654301003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1278906543" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "emailAddress" + } + ], + "telephones": [ + { + "num": "Contact number" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134780954301003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1347809543" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Emailaddress" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "30", + "item": { + "name": "Item Name", + "identities": [ + { + "code": "324243424", + "ext": { + "iso-scheme-id": "0160" + } + }, + { + "label": "HS", + "code": "88098432324" + } + ], + "description": "Item Description", + "list": "100", + "discount": "1", + "price": "99.00", + "unit": "kl", + "ext": { + "untdid-unit": "K6" + } + }, + "sum": "2970.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "total": "2970.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-21", + "amount": "2970.00", + "percent": "100%" + } + ], + "notes": "Within 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "2970.00", + "total": "2970.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + }, + "base": "2970.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "2970.00", + "payable": "2970.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "DC", + "url": "https://www.site.ae/deliverychallans.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json new file mode 100644 index 0000000..8319f75 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -0,0 +1,166 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "fe61e4d3e34b8101edc26afe4b6579be325495cbfe70c97dd53c59fc76e1fac3" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE001-Test", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "City Name", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "CityName", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "aaa" + } + ], + "description": "Item Description", + "list": "10", + "price": "10.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/reverse-charge.xml b/ubl/testdata/parse/pint/ae/reverse-charge.xml new file mode 100644 index 0000000..0cec993 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/reverse-charge.xml @@ -0,0 +1,162 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-01RCTEST + 9281afd3-613b-44ef-96aa-37a46e42a88e + 2025-02-07 + 2025-02-21 + 380 + Tax invoice + AED + + DC + + + https://www.site.ae/deliverychallans.pdf + + + + + Delivery Challans + + PmFzZTY0IKNvbnRlbnQgZXhhbXBsZQ== + + + + + 1278906543 + + Supplier Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 127890654301003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact number + emailAddress + + + + + + 1347809543 + + Street Name + Sharjah + SHJ + + AE + + + + 134780954301003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Emailaddress + + + + + 30 + + AE0000000001 + current account + + 236000 + + + + + Within 15 days + + + 0 + false + + 2970 + 0 + + AE + 5 + + VAT + + + + + + 2970 + 2970 + 2970 + 2970 + + + 1 + 30 + 2970 + + Item Description + Item Name + + 324243424 + + + DL8.48.3.1 + 88098432324 + + + AE + 5 + + VAT + + + + + 99 + 1 + + false + 1 + 100 + + + + 2970 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/standard-invoice.xml b/ubl/testdata/parse/pint/ae/standard-invoice.xml new file mode 100644 index 0000000..07e027a --- /dev/null +++ b/ubl/testdata/parse/pint/ae/standard-invoice.xml @@ -0,0 +1,124 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE001-Test + 4b6000ca-0128-4bdc-99a6-406f2909247f + 2025-01-30 + 2025-02-06 + 380 + AED + + + 1357902468 + + Street Name + City Name + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + 1345678901 + + Street Name + CityName + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + 50 + false + + 1000 + 50 + + S + 5 + + VAT + + + + + + 1000 + 1000 + 1050 + 1050 + + + 1 + 100 + 1000 + + Item Description + Item Name + + G + aaa + + + S + 5 + + VAT + + + + + 10 + 1 + + false + 0 + 10 + + + + 1050 + + 50 + + + + \ No newline at end of file diff --git a/ubl/ubl.go b/ubl/ubl.go index 907aaad..e5de867 100644 --- a/ubl/ubl.go +++ b/ubl/ubl.go @@ -26,6 +26,8 @@ const ( KeyPINT cbc.Key = "ubl+peppol+pint-v1" // KeyAUNZ identifies the Peppol PINT A-NZ format. KeyAUNZ cbc.Key = "ubl+peppol+pint+aunz-v1" + // KeyAE identifies the Peppol PINT AE format. + KeyAE cbc.Key = "ubl+peppol+pint+ae-v1" ) var ( @@ -136,6 +138,43 @@ var SpecificationAUNZSelfBilling = goblubl.Specification{ Applies: isSelfBilled, } +// FormatAE defines the Peppol PINT AE format, for UAE e-invoicing. Invoices +// are written with PINT AE Billing, and self-billed invoices with PINT AE +// Self-Billing. The exported document is adjusted to the AE rules by exportAE. +var FormatAE = goblubl.Format{ + Key: KeyAE, + Name: i18n.NewString("UBL Peppol PINT AE 1"), + Countries: []l10n.Code{l10n.AE}, + Import: []schema.ID{invoiceSchema}, + Export: []schema.ID{invoiceSchema}, + CustomizationID: "urn:peppol:pint:billing-1@ae-1", + ProfileID: "urn:peppol:bis:billing", + Addons: []cbc.Key{pint.V1}, + VESIDs: goblubl.VESIDMapping{ + Invoice: "org.peppol.pint.ae:invoice:2026.5", + CreditNote: "org.peppol.pint.ae:creditnote:2026.5", + }, + Specifications: []goblubl.Specification{ + SpecificationAESelfBilling, + }, + ExportFuncs: []goblubl.ExportFunc{exportAE}, + ImportFuncs: []goblubl.ImportFunc{importPINT, importAE}, + Match: matchCustomization("urn:peppol:pint:billing-1@ae-1", "urn:peppol:pint:selfbilling-1@ae-1"), +} + +// SpecificationAESelfBilling is Peppol PINT AE Self-Billing, used for +// self-billed invoices. +var SpecificationAESelfBilling = goblubl.Specification{ + CustomizationID: "urn:peppol:pint:selfbilling-1@ae-1", + ProfileID: "urn:peppol:bis:selfbilling", + Addons: []cbc.Key{pint.V1}, + VESIDs: goblubl.VESIDMapping{ + Invoice: "org.peppol.pint.ae:invoice-self-billing:2026.5", + CreditNote: "org.peppol.pint.ae:creditnote-self-billing:2026.5", + }, + Applies: isSelfBilled, +} + // matchCustomization claims every document whose CustomizationID starts with // one of the given ones, the wildcard the Peppol SMP registrations are made // under. @@ -159,5 +198,5 @@ func isSelfBilled(doc any) bool { func init() { // gobl.ubl still registers its own ubl+peppol+bis-v3 format, so FormatBIS // is only registered once gobl.ubl drops it. - goblubl.RegisterFormats(FormatPINT, FormatAUNZ) + goblubl.RegisterFormats(FormatPINT, FormatAUNZ, FormatAE) } diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 82c179e..e87d8c1 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -64,7 +64,7 @@ func TestExport(t *testing.T) { } // TestDetectPINTFallback checks that a PINT jurisdiction with no dedicated -// format falls back to the base billing one, while A-NZ keeps its own. +// format falls back to the base billing one, while A-NZ and AE keep their own. func TestDetectPINTFallback(t *testing.T) { f := ubl.FindFormat(peppolubl.FormatPINT.CustomizationID+"@jp-1", peppolubl.FormatPINT.ProfileID) require.NotNil(t, f) @@ -77,6 +77,10 @@ func TestDetectPINTFallback(t *testing.T) { f = ubl.FindFormat(peppolubl.SpecificationAUNZSelfBilling.CustomizationID, peppolubl.SpecificationAUNZSelfBilling.ProfileID) require.NotNil(t, f) assert.Equal(t, peppolubl.KeyAUNZ, f.Key) + // AE has its own format now, so the fallback no longer claims it. + f = ubl.FindFormat(peppolubl.FormatPINT.CustomizationID+"@ae-1", peppolubl.FormatPINT.ProfileID) + require.NotNil(t, f) + assert.Equal(t, peppolubl.KeyAE, f.Key) } // TestSpecificationAUNZSelfBilling checks that self-billed invoices are @@ -97,3 +101,76 @@ func TestSpecificationAUNZSelfBilling(t *testing.T) { assert.Equal(t, peppolubl.SpecificationAUNZSelfBilling.CustomizationID, s.CustomizationID) assert.Equal(t, peppolubl.SpecificationAUNZSelfBilling.ProfileID, s.ProfileID) } + +// TestFormatAE checks that the PINT AE format is registered for the UAE and +// claims its own documents, both billing and self-billing. +func TestFormatAE(t *testing.T) { + f := convert.FormatFor(peppolubl.KeyAE) + require.NotNil(t, f) + assert.Equal(t, []l10n.Code{l10n.AE}, f.Countries) + + keys := make([]cbc.Key, 0) + for _, c := range convert.FormatsFor(l10n.AE) { + keys = append(keys, c.Key) + } + assert.Contains(t, keys, peppolubl.KeyAE) + + for _, id := range []string{peppolubl.FormatAE.CustomizationID, peppolubl.SpecificationAESelfBilling.CustomizationID} { + found := ubl.FindFormat(id, "") + require.NotNil(t, found, id) + assert.Equal(t, peppolubl.KeyAE, found.Key, id) + } +} + +// TestDetectAndImportAE checks that an official PINT AE example is detected +// as PINT AE and imported with the PINT addon. +func TestDetectAndImportAE(t *testing.T) { + data, err := testLoadXML("pint/ae/standard-invoice.xml") + require.NoError(t, err) + + f, err := convert.Detect(data) + require.NoError(t, err) + assert.Equal(t, peppolubl.KeyAE, f.Key) + + res, err := convert.Import(data) + require.NoError(t, err) + inv, ok := res.Envelope.Extract().(*bill.Invoice) + require.True(t, ok) + assert.Contains(t, inv.GetAddons(), pint.V1) + assert.Equal(t, l10n.TaxCountryCode("AE"), inv.GetRegime()) +} + +// TestExportAE checks that a UAE invoice is exported with the PINT AE +// identifiers and detected as PINT AE again. +func TestExportAE(t *testing.T) { + env := loadTestEnvelope(t, "pint/ae/invoice-ae.json") + out, err := convert.Export(env, peppolubl.KeyAE) + require.NoError(t, err) + assert.Equal(t, peppolubl.KeyAE, out.Format.Key) + assert.Contains(t, string(out.Data), ""+peppolubl.FormatAE.CustomizationID) + + f, err := convert.Detect(out.Data) + require.NoError(t, err) + assert.Equal(t, peppolubl.KeyAE, f.Key, "detected again") +} + +// TestSpecificationAESelfBilling checks that self-billed invoices are written +// with the AE self-billing identifiers and validated against its rule set. +func TestSpecificationAESelfBilling(t *testing.T) { + env := loadTestEnvelope(t, "pint/ae/invoice-ae.json") + inv, ok := env.Extract().(*bill.Invoice) + require.True(t, ok) + + f := peppolubl.FormatAE + assert.Equal(t, peppolubl.FormatAE.VESIDs.Invoice, f.VESID(inv)) + + inv.SetTags(tax.TagSelfBilled) + assert.Equal(t, peppolubl.SpecificationAESelfBilling.VESIDs.Invoice, f.VESID(inv)) + s := f.SpecificationFor(inv) + require.NotNil(t, s) + assert.Equal(t, peppolubl.SpecificationAESelfBilling.CustomizationID, s.CustomizationID) + assert.Equal(t, peppolubl.SpecificationAESelfBilling.ProfileID, s.ProfileID) + + inv.Type = bill.InvoiceTypeCreditNote + assert.Equal(t, peppolubl.SpecificationAESelfBilling.VESIDs.CreditNote, f.VESID(inv)) +} From ef403d49a43cdaebd364e1f5e43b58b1440b6865 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 14:52:51 +0000 Subject: [PATCH 07/73] Add the PINT AE line amounts and AED totals - Write each line's amount with VAT and VAT amount in cac:ItemPriceExtension (BTAE-10, BTAE-08; IBR-104-AE, IBR-194-AE): no VAT amount on exempt lines (IBR-163-AE), zero on zero rated and reverse charge ones (IBR-165-AE, IBR-162-AE). - For invoices not in AED, write the exchange rate to AED (IBR-153-AE, IBR-159-AE) and the total with VAT in AED (BTAE-20, IBR-175-AE). Needs a gobl.ubl with cac:ItemPriceExtension (gobl.ubl#189); the go.mod pin is bumped in a later commit. --- README.md | 4 +- ubl/ae.go | 108 ++++++- ubl/ae_internal_test.go | 123 +++++++- .../convert/pint/ae/invoice-ae-usd.json | 272 ++++++++++++++++++ .../convert/pint/ae/out/credit-note-ae.xml | 6 + .../convert/pint/ae/out/invoice-ae-exempt.xml | 12 + .../pint/ae/out/invoice-ae-outside-scope.xml | 6 + .../invoice-ae-reverse-charge-allowance.xml | 6 + .../pint/ae/out/invoice-ae-reverse-charge.xml | 6 + .../convert/pint/ae/out/invoice-ae-usd.xml | 261 +++++++++++++++++ .../convert/pint/ae/out/invoice-ae.xml | 6 + 11 files changed, 791 insertions(+), 19 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-usd.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml diff --git a/README.md b/README.md index 324ff49..af73818 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,9 @@ and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with `FormatAE` also adjusts the output to the PINT AE rules: it writes the invoice UUID, the price base quantity and gross price, the UAE TRN without its country prefix, the 5% rate on reverse charge lines and breakdowns, no -rate on exempt ones, and one VAT breakdown per category. On import, it reads +rate on exempt ones, one VAT breakdown per category, and each line's amount +with VAT and VAT amount. For invoices not in AED, it also writes the exchange +rate to AED and the total with VAT in AED. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag. Each one's Peppol document type identifier is diff --git a/ubl/ae.go b/ubl/ae.go index b2e8328..e225ad3 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -5,17 +5,23 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/tax" ) -// UNTDID 5305 VAT category codes the AE format writes rates for. +// UNTDID 5305 VAT category codes the AE format writes rates and amounts for. const ( + taxCategoryStandard = "S" taxCategoryExempt = "E" taxCategoryReverseCharge = "AE" ) +// aedTotalDocumentType is the document type code PINT AE gives the additional +// document reference that carries the total with VAT in AED (BTAE-20). +const aedTotalDocumentType = "aedtotal-incl-vat" + // aeReverseChargeRate is the rate PINT AE expects on reverse charge lines and // breakdowns. GOBL keeps reverse charge without a percent, as no VAT is // charged, but the PINT AE examples and the 5% standard rate (IBR-190-AE) @@ -32,18 +38,15 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error return nil } exportAEUUID(out, inv) - for i := range out.InvoiceLines { - exportAELine(&out.InvoiceLines[i]) - } - for i := range out.CreditNoteLines { - exportAELine(&out.CreditNoteLines[i]) - } + exportAELines(out.InvoiceLines, inv) + exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { exportAEPartyTaxID(p.UBL, p.GOBL.TaxID) } for i := range out.TaxTotal { exportAETaxTotal(&out.TaxTotal[i]) } + exportAEExchangeRate(out, inv) return nil } @@ -91,6 +94,17 @@ func exportAEUUID(out *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAELines completes the UBL lines, which gobl.ubl writes in the same +// order as the invoice's lines. +func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + for i := range lines { + exportAELine(&lines[i]) + if len(lines) == len(inv.Lines) { + exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) + } + } +} + // exportAELine completes a line's price details and VAT rate. func exportAELine(line *goblubl.InvoiceLine) { exportAEPrice(line) @@ -100,6 +114,86 @@ func exportAELine(line *goblubl.InvoiceLine) { } } +// exportAELineAmounts writes the line amount payable (BTAE-10) and the line VAT +// amount (BTAE-08) in cac:ItemPriceExtension, which every line needs +// (IBR-194-AE, IBR-104-AE). Despite their names, the official examples write +// both in the document currency, not in AED. GOBL keeps no VAT per line, so it +// is the line total at the line's rate, rounded to the currency. Exempt lines +// get no VAT amount (IBR-163-AE), and zero rated and reverse charge lines a +// zero one (IBR-165-AE, IBR-162-AE). +func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.Code) { + if l == nil || l.Total == nil { + return + } + def := cur.Def() + if def == nil { + return + } + total := def.Rescale(*l.Total) + ext := &goblubl.ItemPriceExtension{Amount: aeAmount(total, cur)} + if vat, ok := aeLineVAT(line, l); ok { + vat = def.Rescale(vat) + ext.Amount = aeAmount(total.Add(vat), cur) + ext.TaxTotal = []goblubl.TaxTotal{{TaxAmount: aeAmount(vat, cur)}} + } + line.ItemPriceExtension = ext +} + +// aeLineVAT provides the VAT charged on a line, and false for exempt lines, +// which must not have one. Only standard rated lines charge VAT: zero rated, +// reverse charge and outside scope lines charge none. +func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { + zero := num.MakeAmount(0, l.Total.Exp()) + if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || line.Item.ClassifiedTaxCategory.ID == nil { + return zero, true + } + switch line.Item.ClassifiedTaxCategory.ID.Value { + case taxCategoryExempt: + return zero, false + case taxCategoryStandard: + if c := l.Taxes.Get(tax.CategoryVAT); c != nil && c.Percent != nil { + return c.Percent.Of(*l.Total), true + } + } + return zero, true +} + +// exportAEExchangeRate writes, for invoices not in AED, the exchange rate to +// AED (BTAE-04, IBR-159-AE) as cac:TaxExchangeRate from the document currency +// to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, +// IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total +// in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-05) with at most 6 decimals (-06). +func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { + if inv.Currency == currency.AED { + return + } + rate := currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) + if rate == nil { + return + } + source, target, calc := inv.Currency.String(), currency.AED.String(), rate.Amount.String() + out.TaxExchangeRate = &goblubl.ExchangeRate{ + SourceCurrencyCode: &source, + TargetCurrencyCode: &target, + CalculationRate: &calc, + } + if inv.Totals != nil { + total := rate.Convert(inv.Totals.TotalWithTax) + out.AdditionalDocumentReference = append(out.AdditionalDocumentReference, goblubl.Reference{ + ID: goblubl.IDType{Value: currency.AED.String()}, + DocumentTypeCode: aedTotalDocumentType, + DocumentDescription: currency.AED.String() + " " + total.String(), + }) + } +} + +// aeAmount provides a UBL amount in the currency. +func aeAmount(a num.Amount, cur currency.Code) goblubl.Amount { + code := cur.String() + return goblubl.Amount{CurrencyID: &code, Value: a.String()} +} + // exportAEPrice adds the price base quantity (ibt-149) and the gross price // (ibt-148) PINT AE requires on every line (IBR-126-AE). GOBL prices are per // unit, so the base quantity is 1 in the line's unit. Without a list price, diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 40841a1..14a1736 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -7,6 +7,8 @@ import ( goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/num" "github.com/invopop/gobl/tax" "github.com/invopop/gobl/uuid" "github.com/stretchr/testify/assert" @@ -23,7 +25,7 @@ func aeCategory(id string, percent *string) goblubl.TaxCategory { } } -func aeAmount(v string) goblubl.Amount { +func aedAmount(v string) goblubl.Amount { return goblubl.Amount{CurrencyID: strPtr("AED"), Value: v} } @@ -42,7 +44,7 @@ func TestExportAEPrice(t *testing.T) { t.Run("adds the base quantity and a zero discount on the net price", func(t *testing.T) { line := &goblubl.InvoiceLine{ InvoicedQuantity: &goblubl.Quantity{UnitCode: "HUR", Value: "10"}, - Price: &goblubl.Price{PriceAmount: aeAmount("100.00")}, + Price: &goblubl.Price{PriceAmount: aedAmount("100.00")}, } exportAEPrice(line) require.NotNil(t, line.Price.BaseQuantity) @@ -58,17 +60,17 @@ func TestExportAEPrice(t *testing.T) { t.Run("uses the credited quantity's unit on credit notes", func(t *testing.T) { line := &goblubl.InvoiceLine{ CreditedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, - Price: &goblubl.Price{PriceAmount: aeAmount("5.00")}, + Price: &goblubl.Price{PriceAmount: aedAmount("5.00")}, } exportAEPrice(line) assert.Equal(t, "C62", line.Price.BaseQuantity.UnitCode) }) t.Run("keeps a price discount gobl.ubl already wrote", func(t *testing.T) { - existing := &goblubl.AllowanceCharge{Amount: aeAmount("20.00"), BaseAmount: &goblubl.Amount{Value: "120.00"}} + existing := &goblubl.AllowanceCharge{Amount: aedAmount("20.00"), BaseAmount: &goblubl.Amount{Value: "120.00"}} line := &goblubl.InvoiceLine{ InvoicedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, - Price: &goblubl.Price{PriceAmount: aeAmount("100.00"), AllowanceCharge: existing}, + Price: &goblubl.Price{PriceAmount: aedAmount("100.00"), AllowanceCharge: existing}, } exportAEPrice(line) assert.Same(t, existing, line.Price.AllowanceCharge) @@ -96,11 +98,11 @@ func TestMergeAETaxSubtotals(t *testing.T) { exempt := func(base, code string) goblubl.TaxSubtotal { c := aeCategory("E", nil) c.TaxExemptionReasonCode = strPtr(code) - return goblubl.TaxSubtotal{TaxableAmount: aeAmount(base), TaxAmount: aeAmount("0.00"), TaxCategory: c} + return goblubl.TaxSubtotal{TaxableAmount: aedAmount(base), TaxAmount: aedAmount("0.00"), TaxCategory: c} } standard := goblubl.TaxSubtotal{ - TaxableAmount: aeAmount("1000.00"), - TaxAmount: aeAmount("50.00"), + TaxableAmount: aedAmount("1000.00"), + TaxAmount: aedAmount("50.00"), TaxCategory: aeCategory("S", strPtr("5")), } @@ -121,7 +123,7 @@ func TestMergeAETaxSubtotals(t *testing.T) { }) t.Run("does not merge different rates", func(t *testing.T) { - zero := goblubl.TaxSubtotal{TaxableAmount: aeAmount("10.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("S", strPtr("0"))} + zero := goblubl.TaxSubtotal{TaxableAmount: aedAmount("10.00"), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("S", strPtr("0"))} out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{standard, zero}) assert.Len(t, out, 2) }) @@ -129,8 +131,8 @@ func TestMergeAETaxSubtotals(t *testing.T) { func TestExportAETaxTotal(t *testing.T) { tt := &goblubl.TaxTotal{TaxSubtotal: []goblubl.TaxSubtotal{ - {TaxableAmount: aeAmount("100.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("AE", strPtr("0"))}, - {TaxableAmount: aeAmount("50.00"), TaxAmount: aeAmount("0.00"), TaxCategory: aeCategory("E", strPtr("0"))}, + {TaxableAmount: aedAmount("100.00"), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("AE", strPtr("0"))}, + {TaxableAmount: aedAmount("50.00"), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("E", strPtr("0"))}, }} exportAETaxTotal(tt) require.Len(t, tt.TaxSubtotal, 2) @@ -204,3 +206,102 @@ func TestImportAEOutsideScope(t *testing.T) { assert.Equal(t, []cbc.Key{pint.TagOutsideScope}, inv.Tags.List) }) } + +func TestExportAELineAmounts(t *testing.T) { + line := func(category string) *goblubl.InvoiceLine { + return &goblubl.InvoiceLine{Item: &goblubl.Item{ + ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ID: &goblubl.IDType{Value: category}}, + }} + } + goblLine := func(total string, key cbc.Key, percent *num.Percentage) *bill.Line { + a, err := num.AmountFromString(total) + require.NoError(t, err) + return &bill.Line{Total: &a, Taxes: tax.Set{{Category: tax.CategoryVAT, Key: key, Percent: percent}}} + } + + t.Run("standard rated line gets its VAT and the total with VAT", func(t *testing.T) { + out := line("S") + exportAELineAmounts(out, goblLine("10486.00", tax.KeyStandard, num.NewPercentage(5, 2)), currency.AED) + ext := out.ItemPriceExtension + require.NotNil(t, ext) + assert.Equal(t, "11010.30", ext.Amount.Value) + assert.Equal(t, "AED", *ext.Amount.CurrencyID) + require.Len(t, ext.TaxTotal, 1) + assert.Equal(t, "524.30", ext.TaxTotal[0].TaxAmount.Value) + }) + + t.Run("line VAT is rounded to the currency", func(t *testing.T) { + out := line("S") + exportAELineAmounts(out, goblLine("99.99", tax.KeyStandard, num.NewPercentage(5, 2)), currency.USD) + assert.Equal(t, "5.00", out.ItemPriceExtension.TaxTotal[0].TaxAmount.Value) + assert.Equal(t, "104.99", out.ItemPriceExtension.Amount.Value) + assert.Equal(t, "USD", *out.ItemPriceExtension.Amount.CurrencyID, "document currency, as in the examples") + }) + + t.Run("zero rated and reverse charge lines get a zero VAT amount", func(t *testing.T) { + for _, c := range []struct { + category string + key cbc.Key + }{{"Z", tax.KeyZero}, {"AE", tax.KeyReverseCharge}} { + out := line(c.category) + exportAELineAmounts(out, goblLine("200.00", c.key, nil), currency.AED) + ext := out.ItemPriceExtension + assert.Equal(t, "200.00", ext.Amount.Value, c.category) + require.Len(t, ext.TaxTotal, 1, c.category) + assert.Equal(t, "0.00", ext.TaxTotal[0].TaxAmount.Value, c.category) + } + }) + + t.Run("exempt lines get no VAT amount", func(t *testing.T) { + out := line("E") + exportAELineAmounts(out, goblLine("120.00", tax.KeyExempt, nil), currency.AED) + assert.Equal(t, "120.00", out.ItemPriceExtension.Amount.Value) + assert.Empty(t, out.ItemPriceExtension.TaxTotal) + }) + + t.Run("lines without a total are left alone", func(t *testing.T) { + out := line("S") + exportAELineAmounts(out, &bill.Line{}, currency.AED) + assert.Nil(t, out.ItemPriceExtension) + }) +} + +func TestExportAEExchangeRate(t *testing.T) { + invoice := func(cur currency.Code, rates ...*currency.ExchangeRate) *bill.Invoice { + return &bill.Invoice{ + Currency: cur, + ExchangeRates: rates, + Totals: &bill.Totals{TotalWithTax: num.MakeAmount(24875000, 2)}, + } + } + + t.Run("writes the rate and the AED total with VAT", func(t *testing.T) { + out := new(goblubl.Invoice) + inv := invoice(currency.USD, ¤cy.ExchangeRate{From: currency.USD, To: currency.AED, Amount: num.MakeAmount(367285, 5)}) + exportAEExchangeRate(out, inv) + require.NotNil(t, out.TaxExchangeRate) + assert.Equal(t, "USD", *out.TaxExchangeRate.SourceCurrencyCode) + assert.Equal(t, "AED", *out.TaxExchangeRate.TargetCurrencyCode) + assert.Equal(t, "3.67285", *out.TaxExchangeRate.CalculationRate) + require.Len(t, out.AdditionalDocumentReference, 1) + ref := out.AdditionalDocumentReference[0] + assert.Equal(t, "AED", ref.ID.Value) + assert.Equal(t, "aedtotal-incl-vat", ref.DocumentTypeCode) + assert.Equal(t, "AED 913621.44", ref.DocumentDescription, "the Exports.xml example: 248750 USD at 3.67285") + }) + + t.Run("AED invoices need neither", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEExchangeRate(out, invoice(currency.AED)) + assert.Nil(t, out.TaxExchangeRate) + assert.Empty(t, out.AdditionalDocumentReference) + }) + + t.Run("invoices without a rate to AED are left to the PINT addon", func(t *testing.T) { + out := new(goblubl.Invoice) + inv := invoice(currency.USD, ¤cy.ExchangeRate{From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(92, 2)}) + exportAEExchangeRate(out, inv) + assert.Nil(t, out.TaxExchangeRate) + assert.Empty(t, out.AdditionalDocumentReference) + }) +} diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json new file mode 100644 index 0000000..e28a210 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -0,0 +1,272 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "5fece2baa64586bcbc6e5745758a2922f2d07451f7803c46b6f15bad0a23559b" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "006", + "issue_date": "2025-01-30", + "currency": "USD", + "exchange_rates": [ + { + "from": "USD", + "to": "AED", + "amount": "3.67285" + } + ], + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345678900003" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "code": "112345679000001" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + }, + { + "i": 2, + "quantity": "2", + "item": { + "name": "Export goods", + "description": "Zero rated supply", + "price": "250.00", + "unit": "one" + }, + "sum": "500.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "500.00" + }, + { + "i": 3, + "quantity": "1", + "item": { + "name": "Financial service", + "description": "Exempt supply", + "price": "120.00", + "unit": "one" + }, + "sum": "120.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + } + } + ], + "total": "120.00" + }, + { + "i": 4, + "quantity": "3", + "item": { + "name": "Imported service", + "description": "Reverse charge supply", + "price": "33.33", + "unit": "one" + }, + "sum": "99.99", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + } + } + ], + "total": "99.99" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1769.99", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1719.99", + "total": "1719.99", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + }, + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "500.00", + "percent": "0%", + "amount": "0.00" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + }, + "base": "120.00", + "amount": "0.00" + }, + { + "key": "reverse-charge", + "ext": { + "cef-vatex": "VATEX-EU-AE", + "untdid-tax-category": "AE" + }, + "base": "99.99", + "amount": "0.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1769.99", + "payable": "1769.99" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index 3c90ced..a99ee96 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -119,5 +119,11 @@ 10.00 + + 1050.00 + + 50.00 + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index c63c5cf..e746ae2 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -151,6 +151,12 @@ 10.00 + + 1050.00 + + 50.00 + + 2 @@ -175,6 +181,9 @@ 200.00 + + 200.00 + 3 @@ -199,5 +208,8 @@ 300.00 + + 300.00 + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 9e0a4e2..68344c0 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -113,5 +113,11 @@ 10.00 + + 1000.00 + + 0.00 + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 95f1cc6..4548eda 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -143,5 +143,11 @@ 10.00 + + 1000.00 + + 0.00 + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 47dfc50..9ee4c97 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -115,5 +115,11 @@ 10.00 + + 1000.00 + + 0.00 + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml new file mode 100644 index 0000000..4ece96c --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -0,0 +1,261 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-006 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + USD + AED + + NA + + + AED + aedtotal-incl-vat + AED 6500.91 + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + USD + AED + 3.67285 + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + 500.00 + 0.00 + + Z + 0 + + VAT + + + + + 120.00 + 0.00 + + E + VATEX-EU-132-1I + + VAT + + + + + 99.99 + 0.00 + + AE + 5 + VATEX-EU-AE + + VAT + + + + + + 183.64 + + + 1719.99 + 1719.99 + 1769.99 + 1769.99 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + + 2 + 2 + 500.00 + + Zero rated supply + Export goods + + Z + 0 + + VAT + + + + + 250.00 + 1 + + false + 0 + 250.00 + + + + 500.00 + + 0.00 + + + + + 3 + 1 + 120.00 + + Exempt supply + Financial service + + E + + VAT + + + + + 120.00 + 1 + + false + 0 + 120.00 + + + + 120.00 + + + + 4 + 3 + 99.99 + + Reverse charge supply + Imported service + + AE + 5 + + VAT + + + + + 33.33 + 1 + + false + 0 + 33.33 + + + + 99.99 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index b5e82dc..980a31f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -114,5 +114,11 @@ 10.00 + + 1050.00 + + 50.00 + + \ No newline at end of file From 351e199dd1c68e18423afada31511b5cdd346223 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:17:50 +0000 Subject: [PATCH 08/73] Add the PINT AE identity rules and types - Require a typed legal identity with a UAE (0235) endpoint (IBR-150-AE, IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE), the issuing country on passports (IBR-010-AE, IBR-012-AE) and the authority on trade licences (IBR-101-AE, IBR-172-AE). - Check the seller TIN (IBR-148-AE, IBR-178-AE) and the buyer tax registrations (IBR-149-AE, IBR-179-AE, IBR-133-AE). - Write the identity type, authority or passport country as @schemeAgencyID and @schemeAgencyName, and the seller TIN under the TIN tax scheme; read them back on import, with CL as a trade licence. Needs the AE identity keys and scopes from gobl#1033 and cac:ItemPriceExtension from gobl.ubl#189; the go.mod pins are bumped in a later commit. --- README.md | 10 +- addon/pint/bill.go | 207 +++++++++++++++++ addon/pint/bill_test.go | 181 +++++++++++++++ addon/pint/org_identity.go | 58 +++++ addon/pint/org_identity_test.go | 40 ++++ addon/pint/pint.go | 3 + addon/pint/tax_combo_test.go | 8 +- examples/invoice-ae.yaml | 6 +- examples/out/invoice-ae.json | 10 +- ubl/ae.go | 138 +++++++++++ ubl/ae_internal_test.go | 177 ++++++++++++++ .../convert/pint/ae/credit-note-ae.json | 10 +- .../convert/pint/ae/invoice-ae-exempt.json | 10 +- .../pint/ae/invoice-ae-outside-scope.json | 10 +- .../invoice-ae-reverse-charge-allowance.json | 10 +- .../pint/ae/invoice-ae-reverse-charge.json | 10 +- .../pint/ae/invoice-ae-tin-passport.json | 181 +++++++++++++++ .../convert/pint/ae/invoice-ae-usd.json | 10 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 10 +- .../convert/pint/ae/out/credit-note-ae.xml | 4 +- .../convert/pint/ae/out/invoice-ae-exempt.xml | 4 +- .../pint/ae/out/invoice-ae-outside-scope.xml | 4 +- .../invoice-ae-reverse-charge-allowance.xml | 4 +- .../pint/ae/out/invoice-ae-reverse-charge.xml | 4 +- .../pint/ae/out/invoice-ae-tin-passport.xml | 130 +++++++++++ .../convert/pint/ae/out/invoice-ae-usd.xml | 4 +- .../convert/pint/ae/out/invoice-ae.xml | 4 +- .../parse/pint/ae/buyer-pas-identifier.xml | 145 ++++++++++++ .../parse/pint/ae/out/allowance-exempt.json | 10 +- .../pint/ae/out/buyer-pas-identifier.json | 210 +++++++++++++++++ .../parse/pint/ae/out/reverse-charge.json | 10 +- .../pint/ae/out/seller-pas-identifier.json | 210 +++++++++++++++++ .../pint/ae/out/seller-tin-identifier.json | 216 ++++++++++++++++++ .../parse/pint/ae/out/standard-invoice.json | 10 +- .../parse/pint/ae/seller-pas-identifier.xml | 145 ++++++++++++ .../parse/pint/ae/seller-tin-identifier.xml | 151 ++++++++++++ 36 files changed, 2301 insertions(+), 53 deletions(-) create mode 100644 addon/pint/org_identity.go create mode 100644 addon/pint/org_identity_test.go create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml create mode 100644 ubl/testdata/parse/pint/ae/buyer-pas-identifier.xml create mode 100644 ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json create mode 100644 ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json create mode 100644 ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json create mode 100644 ubl/testdata/parse/pint/ae/seller-pas-identifier.xml create mode 100644 ubl/testdata/parse/pint/ae/seller-tin-identifier.xml diff --git a/README.md b/README.md index af73818..364c62f 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,14 @@ invoice UUID, the price base quantity and gross price, the UAE TRN without its country prefix, the 5% rate on reverse charge lines and breakdowns, no rate on exempt ones, one VAT breakdown per category, and each line's amount with VAT and VAT amount. For invoices not in AED, it also writes the exchange -rate to AED and the total with VAT in AED. On import, it reads -the out-of-scope type codes 480 and 81 back as the `outside-scope` tag. +rate to AED and the total with VAT in AED. The seller and buyer legal +identities get their PINT AE type (`TL`, `EID`, `PAS` or `CD`, from the AE +regime's identity keys and `passport`), with the trade licence authority +(the identity's description) or the passport's issuing country, and the +seller's TIN goes under the `TIN` tax scheme. On import, it reads +the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and +the identity types, authorities, passport countries and seller TIN back as +identity keys and fields. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 08c7970..8e3f00a 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -1,14 +1,18 @@ package pint import ( + "strings" + "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/rules/is" "github.com/invopop/gobl/tax" @@ -29,6 +33,10 @@ var emirateCodes = []cbc.Code{ "AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK", } +// endpointSchemeUAE is the Peppol participant identifier scheme for UAE +// endpoints, which the PINT AE legal registration rules depend on. +const endpointSchemeUAE cbc.Code = "0235" + // billInvoiceRules enforces the PINT invoice rules shared by every // jurisdiction, and the PINT AE rules on UAE documents. func billInvoiceRules() *rules.Set { @@ -173,6 +181,66 @@ func billInvoiceRules() *rules.Set { ), ), ), + rules.Field("supplier", + rules.When( + is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), + rules.Assert("23", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", + is.Func("has legal identity", partyHasLegalIdentity), + ), + rules.Assert("24", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", + is.Func("legal identity has a PINT AE type", partyLegalIdentityHasTypeAE), + ), + ), + rules.Assert("25", "supplier passport must have the issuing country (IBR-012-AE)", + is.Func("passport has country", partyPassportHasCountry), + ), + rules.Assert("26", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", + is.Func("trade license has authority", partyTradeLicenseHasAuthority), + ), + rules.Assert("27", "supplier must have at most one tax scope identity (IBR-178-AE)", + is.Func("at most one tax scope identity", partyHasAtMostOneTaxIdentity), + ), + rules.Field("identities", rules.Each( + rules.When( + is.Func("tax scope", identityHasTaxScope), + rules.Field("code", + rules.Assert("28", "supplier tax scope identity must be a TIN of 10 digits starting with 1 (IBR-148-AE)", + is.Matches(`^1\d{9}$`), + ), + ), + ), + )), + ), + rules.Field("customer", + // IBR-183-AE's test also accepts CL, which only its rule text's + // "Commercial/Trade license" explains. FormatAE reads CL as a + // trade licence on import, but GOBL writes TL, which is valid for + // both seller and buyer. + rules.When( + is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), + rules.Assert("29", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", + is.Func("legal identity has a PINT AE type", partyLegalIdentityHasTypeAE), + ), + ), + rules.Assert("30", "customer passport must have the issuing country (IBR-010-AE)", + is.Func("passport has country", partyPassportHasCountry), + ), + rules.Assert("31", "customer trade license must have the issuing authority in the description (IBR-101-AE)", + is.Func("trade license has authority", partyTradeLicenseHasAuthority), + ), + rules.When( + is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), + rules.Assert("32", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", + is.Func("has tax registration", partyHasTaxRegistration), + ), + ), + rules.Assert("33", "customer must have at most one tax registration (IBR-179-AE)", + is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), + ), + ), + rules.Assert("34", "customer tax scope identities require a supplier TIN (IBR-133-AE)", + is.Func("customer tax scope identities with supplier TIN", customerTaxIdentitiesHaveSupplierTIN), + ), ), ) } @@ -425,6 +493,145 @@ func partyAddressHasEmirate(val any) bool { return a == nil || a.Country != l10n.AE.ISO() || cbc.Code(a.Region).In(emirateCodes...) } +// partyEndpointID returns the scheme and code of the party's electronic +// address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 +// endpoint, or else the first inbox with a scheme. +func partyEndpointID(p *org.Party) (cbc.Code, string) { + if e := p.Endpoint(iso.ActorIDScheme); e != nil { + // An ISO 6523 URI reads "iso6523-actorid-upis:::". + scheme, code, ok := strings.Cut(strings.TrimPrefix(e.URI.Opaque(), ":"), ":") + if ok && scheme != "" && code != "" { + return cbc.Code(scheme), code + } + } + for _, ib := range p.Inboxes { + if ib != nil && ib.Email == "" && ib.Scheme != "" { + return ib.Scheme, ib.Code.String() + } + } + return "", "" +} + +// partyHasUAEEndpoint reports whether the party's electronic address uses the +// UAE Peppol scheme 0235, the condition of the legal registration rules. +func partyHasUAEEndpoint(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + scheme, _ := partyEndpointID(p) + return scheme == endpointSchemeUAE +} + +// partyHasUAEEndpointNotStartingWith1or9 reports whether the party's +// electronic address uses the UAE Peppol scheme 0235 with a code that doesn't +// start with 1 or 9 (IBR-149-AE). +func partyHasUAEEndpointNotStartingWith1or9(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + scheme, code := partyEndpointID(p) + return scheme == endpointSchemeUAE && !strings.HasPrefix(code, "1") && !strings.HasPrefix(code, "9") +} + +// partyFirstLegalIdentity returns the party's first identity with the legal +// scope, the one gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID, or nil +// if there is none. +func partyFirstLegalIdentity(val any) *org.Identity { + p, ok := val.(*org.Party) + if !ok || p == nil { + return nil + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeLegal { + return id + } + } + return nil +} + +// partyLegalIdentityHasTypeAE reports whether the party's legal identity has +// a PINT AE legal registration identifier type: trade licence, Emirates ID, +// passport or Cabinet Decision. A party without a legal identity passes. +func partyLegalIdentityHasTypeAE(val any) bool { + id := partyFirstLegalIdentity(val) + return id == nil || IdentityTypeAE(id.Key) != "" +} + +// partyPassportHasCountry reports whether the party's legal identity, when a +// passport, has the issuing country, written as @schemeAgencyName (BTAE-18, +// BTAE-19). GOBL already checks the country is an ISO 3166-1 code +// (IBR-011-AE, IBR-013-AE). +func partyPassportHasCountry(val any) bool { + id := partyFirstLegalIdentity(val) + return id == nil || id.Key != org.IdentityKeyPassport || id.Country != "" +} + +// partyTradeLicenseHasAuthority reports whether the party's legal identity, +// when a trade licence, has the issuing authority in its description, written +// as @schemeAgencyName (BTAE-11, BTAE-12). +func partyTradeLicenseHasAuthority(val any) bool { + id := partyFirstLegalIdentity(val) + return id == nil || id.Key != ae.IdentityKeyTradeLicense || id.Description != "" +} + +// partyTaxIdentityCount returns how many of the party's identities have the +// tax scope. gobl.ubl writes each one as a cac:PartyTaxScheme. +func partyTaxIdentityCount(p *org.Party) int { + n := 0 + for _, id := range p.Identities { + if identityHasTaxScope(id) { + n++ + } + } + return n +} + +// identityHasTaxScope reports whether an identity has the tax scope. +func identityHasTaxScope(val any) bool { + id, ok := val.(*org.Identity) + return ok && id != nil && id.Scope == org.IdentityScopeTax +} + +// partyHasAtMostOneTaxIdentity reports whether the party has at most one tax +// scope identity. With the TRN, that makes at most two seller PartyTaxSchemes, +// only one of them VAT (IBR-178-AE). +func partyHasAtMostOneTaxIdentity(val any) bool { + p, ok := val.(*org.Party) + return ok && p != nil && partyTaxIdentityCount(p) <= 1 +} + +// partyHasAtMostOneTaxRegistration reports whether the party has at most one +// tax registration, counting the tax ID code and the tax scope identities, as +// the buyer can only have one PartyTaxScheme/CompanyID (IBR-179-AE). +func partyHasAtMostOneTaxRegistration(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + n := partyTaxIdentityCount(p) + if p.TaxID != nil && p.TaxID.Code != "" { + n++ + } + return n <= 1 +} + +// customerTaxIdentitiesHaveSupplierTIN reports whether the supplier has a tax +// scope identity, the TIN (IBT-032), whenever the customer has one. gobl.ubl +// writes a customer tax scope identity under a tax scheme other than VAT, +// which PINT AE only allows when the seller has a TIN (IBR-133-AE). +func customerTaxIdentitiesHaveSupplierTIN(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + if inv.Customer == nil || partyTaxIdentityCount(inv.Customer) == 0 { + return true + } + return inv.Supplier != nil && partyTaxIdentityCount(inv.Supplier) > 0 +} + // taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). // It fails on any other value, so a type mismatch can't pass silently. func taxesHaveVAT(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 3d1f0a7..4aeb107 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -13,6 +13,7 @@ import ( "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/pay" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" @@ -558,6 +559,186 @@ func TestBillAddressRulesAE(t *testing.T) { }) } +func uaeEndpoints(code string) []*org.Endpoint { + return []*org.Endpoint{{URI: cbc.URI("iso6523-actorid-upis::0235:" + code)}} +} + +func tradeLicense(code string) *org.Identity { + return &org.Identity{Key: ae.IdentityKeyTradeLicense, Code: cbc.Code(code), Description: "Dubai Economy and Tourism"} +} + +// aeIdentityDocument returns a valid UAE invoice whose parties have UAE Peppol +// endpoints and trade licences, the case the legal registration rules apply to. +func aeIdentityDocument() *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Supplier.Endpoints = uaeEndpoints("1357902468") + inv.Supplier.Identities = []*org.Identity{tradeLicense("112345678900003")} + inv.Customer.Endpoints = uaeEndpoints("1345678901") + inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} + return inv +} + +func TestBillIdentityRulesAE(t *testing.T) { + const ( + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultSupplierTaxIdentities = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultCustomerTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + ) + + t.Run("trade licences with authorities pass", func(t *testing.T) { + assert.Empty(t, aeFaults(t, aeIdentityDocument())) + }) + + t.Run("supplier with a UAE endpoint needs a legal identity (IBR-150-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = nil + assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) + }) + + t.Run("supplier without a UAE endpoint needs no legal identity (IBR-150-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = nil + inv.Supplier.Endpoints = validEndpoints("1357902468") + assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalRequired) + }) + + t.Run("UAE endpoint in an inbox counts too (IBR-150-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = nil + inv.Supplier.Endpoints = nil + inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1357902468"}} + assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) + }) + + t.Run("legal identity needs a PINT AE type with a UAE endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} + out := aeFaults(t, inv) + assert.Contains(t, out, faultSupplierLegalType) + assert.Contains(t, out, faultCustomerLegalType) + }) + + t.Run("legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Endpoints = validEndpoints("1357902468") + inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} + inv.Customer.Endpoints = validEndpoints("1345678901") + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} + out := aeFaults(t, inv) + assert.NotContains(t, out, faultSupplierLegalType) + assert.NotContains(t, out, faultCustomerLegalType) + }) + + t.Run("each PINT AE type is accepted (IBR-173-AE, IBR-183-AE)", func(t *testing.T) { + for _, id := range []*org.Identity{ + {Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"}, + {Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"}, + {Key: ae.IdentityKeyCabinetDecision, Code: "CD-12-2020"}, + } { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{id} + assert.Empty(t, aeFaults(t, inv), id.Key) + } + }) + + t.Run("only the first legal identity is checked (IBR-173-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) + assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalType) + }) + + t.Run("passport needs the issuing country (IBR-012-AE, IBR-010-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P9876543210"}} + inv.Customer.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P1234567890"}} + out := aeFaults(t, inv) + assert.Contains(t, out, faultSupplierPassport) + assert.Contains(t, out, faultCustomerPassport) + }) + + t.Run("trade licence needs the issuing authority (IBR-172-AE, IBR-101-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities[0].Description = "" + inv.Customer.Identities[0].Description = "" + out := aeFaults(t, inv) + assert.Contains(t, out, faultSupplierAuthority) + assert.Contains(t, out, faultCustomerAuthority) + }) + + t.Run("supplier TIN is accepted, before or after the legal identity (IBR-148-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = append([]*org.Identity{ + {Key: ae.IdentityKeyTIN, Code: "1234567890"}, + }, inv.Supplier.Identities...) + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("supplier tax identity must be a TIN starting with 1 (IBR-148-AE)", func(t *testing.T) { + for _, code := range []cbc.Code{"2234567890", "123456789"} { + inv := aeIdentityDocument() + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Scope: org.IdentityScopeTax, Type: "TIN", Code: code}) + assert.Contains(t, aeFaults(t, inv), faultSupplierTIN, code) + } + }) + + t.Run("supplier has at most one tax identity (IBR-178-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}, + &org.Identity{Scope: org.IdentityScopeTax, Type: "TIN", Code: "1234567891"}) + assert.Contains(t, aeFaults(t, inv), faultSupplierTaxIdentities) + }) + + t.Run("customer with a UAE endpoint not starting with 1 or 9 needs a tax registration (IBR-149-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints("2345678901") + assert.Contains(t, aeFaults(t, inv), faultCustomerTaxRequired) + }) + + t.Run("customer with a UAE endpoint starting with 1 or 9 needs no tax registration (IBR-149-AE)", func(t *testing.T) { + for _, code := range []string{"1345678901", "9345678901"} { + inv := aeIdentityDocument() + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints(code) + assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxRequired, code) + } + }) + + t.Run("customer has at most one tax registration (IBR-179-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}) + inv.Customer.Identities = append(inv.Customer.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) + }) + + t.Run("customer tax identity needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = nil + inv.Customer.Identities = append(inv.Customer.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}) + assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + }) +} + func TestBillLineRulesAE(t *testing.T) { const ( faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go new file mode 100644 index 0000000..e2b4aa0 --- /dev/null +++ b/addon/pint/org_identity.go @@ -0,0 +1,58 @@ +package pint + +import ( + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" +) + +// PINT AE legal registration identifier types, written as @schemeAgencyID on +// the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The Ministry of +// Finance lists the same four types of commercial registration number. +const ( + // IdentityTypeTradeLicense is a commercial or trade licence. + IdentityTypeTradeLicense cbc.Code = "TL" + // IdentityTypeEmiratesID is an Emirates ID. + IdentityTypeEmiratesID cbc.Code = "EID" + // IdentityTypePassport is a passport. + IdentityTypePassport cbc.Code = "PAS" + // IdentityTypeCabinetDecision is a Cabinet Decision. + IdentityTypeCabinetDecision cbc.Code = "CD" + // identityTypeCommercialLicense is only accepted by IBR-183-AE's test, for + // the buyer. No other source lists it; its rule text names + // "Commercial/Trade license", so it is read as a trade licence and never + // written: TL is valid for both seller and buyer. + identityTypeCommercialLicense cbc.Code = "CL" +) + +// IdentityTypeAE returns the PINT AE legal registration identifier type for an +// identity key, or an empty code if the key has none. +func IdentityTypeAE(key cbc.Key) cbc.Code { + switch key { + case ae.IdentityKeyTradeLicense: + return IdentityTypeTradeLicense + case ae.IdentityKeyEmiratesID: + return IdentityTypeEmiratesID + case org.IdentityKeyPassport: + return IdentityTypePassport + case ae.IdentityKeyCabinetDecision: + return IdentityTypeCabinetDecision + } + return "" +} + +// IdentityKeyAE returns the identity key for a PINT AE legal registration +// identifier type, or an empty key if the type is unknown. +func IdentityKeyAE(typ cbc.Code) cbc.Key { + switch typ { + case IdentityTypeTradeLicense, identityTypeCommercialLicense: + return ae.IdentityKeyTradeLicense + case IdentityTypeEmiratesID: + return ae.IdentityKeyEmiratesID + case IdentityTypePassport: + return org.IdentityKeyPassport + case IdentityTypeCabinetDecision: + return ae.IdentityKeyCabinetDecision + } + return "" +} diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go new file mode 100644 index 0000000..531bd69 --- /dev/null +++ b/addon/pint/org_identity_test.go @@ -0,0 +1,40 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" + "github.com/stretchr/testify/assert" +) + +func TestIdentityTypeAE(t *testing.T) { + tests := map[cbc.Key]cbc.Code{ + ae.IdentityKeyTradeLicense: pint.IdentityTypeTradeLicense, + ae.IdentityKeyEmiratesID: pint.IdentityTypeEmiratesID, + org.IdentityKeyPassport: pint.IdentityTypePassport, + ae.IdentityKeyCabinetDecision: pint.IdentityTypeCabinetDecision, + ae.IdentityKeyTIN: "", + cbc.KeyEmpty: "", + } + for key, want := range tests { + assert.Equal(t, want, pint.IdentityTypeAE(key), key) + } +} + +func TestIdentityKeyAE(t *testing.T) { + tests := map[cbc.Code]cbc.Key{ + "TL": ae.IdentityKeyTradeLicense, + "CL": ae.IdentityKeyTradeLicense, + "EID": ae.IdentityKeyEmiratesID, + "PAS": org.IdentityKeyPassport, + "CD": ae.IdentityKeyCabinetDecision, + "XYZ": "", + "": "", + } + for typ, want := range tests { + assert.Equal(t, want, pint.IdentityKeyAE(typ), typ) + } +} diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 7733559..7c9064e 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -80,6 +80,9 @@ func newV1Addon() *tax.AddonDef { UAE documents out of scope of VAT use the "outside-scope" tag, which sets the document type to 480 on invoices and 81 on credit notes. + + UAE trade licences carry their issuing authority in the description, + and passports their issuing country. `), }, Sources: []*cbc.Source{ diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index 45a0f86..e50c28d 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -112,8 +112,12 @@ func TestTaxComboRulesAE(t *testing.T) { ae := l10n.AE.Tax() t.Run("AE subset categories are accepted (IBR-139-AE)", func(t *testing.T) { - for _, cat := range []string{"E", "O", "AE"} { - err := validateIn(vatCombo(cbc.KeyEmpty, cat, nil), ae) + for cat, key := range map[string]cbc.Key{ + "E": tax.KeyExempt, + "O": tax.KeyOutsideScope, + "AE": tax.KeyReverseCharge, + } { + err := validateIn(vatCombo(key, cat, nil), ae) assert.NoError(t, err, "category %s", cat) } assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) diff --git a/examples/invoice-ae.yaml b/examples/invoice-ae.yaml index 66ec9cd..ac03e21 100644 --- a/examples/invoice-ae.yaml +++ b/examples/invoice-ae.yaml @@ -14,8 +14,9 @@ supplier: country: "AE" code: "135790246801003" identities: - - scope: "legal" + - key: "ae-trade-license" code: "112345678900003" + description: "Trade License issuing Authority" inboxes: - key: "peppol" scheme: "0235" @@ -32,8 +33,9 @@ customer: country: "AE" code: "134567890123003" identities: - - scope: "legal" + - key: "ae-trade-license" code: "112345679000001" + description: "Trade License issuing Authority" inboxes: - key: "peppol" scheme: "0235" diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index 7320692..50a75dc 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "a9971c414f59abc529620dc03bc5f294f91fea9918d4a01e51dec5dada0f92f3" + "val": "15d328d7e69c3a6e4c13bccadd18b70601356caa61020bd251cf59835d3fbabc" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -36,7 +36,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -69,7 +71,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/ae.go b/ubl/ae.go index e225ad3..f453e66 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1,13 +1,18 @@ package ubl import ( + "strings" + "github.com/invopop/gobl" "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" ) @@ -28,6 +33,9 @@ const aedTotalDocumentType = "aedtotal-incl-vat" // write 5. const aeReverseChargeRate = "5" +// taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. +const taxSchemeTIN = "TIN" + // exportAE applies the Peppol PINT AE rules to an exported invoice. Each step // only uses data GOBL already has; the AE amounts and the BTAE extensions are // added by later steps. @@ -43,6 +51,8 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error for _, p := range goblubl.InvoiceParties(inv, out) { exportAEPartyTaxID(p.UBL, p.GOBL.TaxID) } + exportAEPartyIdentities(out.AccountingSupplierParty.Party, inv.Supplier) + exportAEPartyIdentities(out.AccountingCustomerParty.Party, inv.Customer) for i := range out.TaxTotal { exportAETaxTotal(&out.TaxTotal[i]) } @@ -58,6 +68,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } importAEOutsideScope(in, inv) + importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) + importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil } @@ -267,6 +279,132 @@ func exportAEPartyTaxID(out *goblubl.Party, tID *tax.Identity) { } } +// exportAEPartyIdentities writes the PINT AE details of the seller and buyer +// identities that gobl.ubl has no place for. +func exportAEPartyIdentities(out *goblubl.Party, p *org.Party) { + if out == nil || p == nil { + return + } + exportAELegalIdentity(out, p) + exportAETINScheme(out, p) +} + +// exportAELegalIdentity writes the legal registration identifier type of the +// party's legal identity as @schemeAgencyID (BTAE-15, BTAE-16), and, as +// @schemeAgencyName, the issuing country of a passport (BTAE-18, BTAE-19) or +// the issuing authority of a trade licence, taken from its description +// (BTAE-11, BTAE-12; IBR-101-AE, IBR-172-AE). The syntax binding also allows +// an authority on Emirates IDs and Cabinet Decisions, but no rule or text asks +// for one, so none is written. gobl.ubl writes the first legal identity as +// cac:PartyLegalEntity/cbc:CompanyID, so that is the one described here. +func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { + if out.PartyLegalEntity == nil || out.PartyLegalEntity.CompanyID == nil { + return + } + var id *org.Identity + for _, i := range p.Identities { + if i != nil && i.Scope == org.IdentityScopeLegal { + id = i + break + } + } + if id == nil { + return + } + typ := pint.IdentityTypeAE(id.Key) + if typ == "" { + return + } + cid := out.PartyLegalEntity.CompanyID + agencyID := typ.String() + cid.SchemeAgencyID = &agencyID + switch typ { + case pint.IdentityTypePassport: + if id.Country != "" { + name := id.Country.String() + cid.SchemeAgencyName = &name + } + case pint.IdentityTypeTradeLicense: + if id.Description != "" { + name := id.Description + cid.SchemeAgencyName = &name + } + } +} + +// importAEPartyIdentities reads back what exportAEPartyIdentities writes: +// the legal identity's key from @schemeAgencyID, with @schemeAgencyName as +// the passport's country or the trade licence's description, and, for the +// supplier, the TIN key on the tax registration that is not VAT, as PINT AE +// defines IBT-032 as the seller TIN. +func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { + if in == nil || p == nil { + return + } + if le := in.PartyLegalEntity; le != nil && le.CompanyID != nil && le.CompanyID.SchemeAgencyID != nil { + cid := le.CompanyID + for _, id := range p.Identities { + if id == nil || id.Scope != org.IdentityScopeLegal || id.Code.String() != cid.Value { + continue + } + importAELegalIdentity(id, cid) + break + } + } + if supplier { + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeTax && id.Key == "" && id.Type == "" { + id.Key = ae.IdentityKeyTIN + } + } + } +} + +// importAELegalIdentity sets the identity's key and, from @schemeAgencyName, +// its issuing country or description. +func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { + key := pint.IdentityKeyAE(cbc.Code(strings.TrimSpace(*cid.SchemeAgencyID))) + if key == "" { + return + } + id.Key = key + if cid.SchemeAgencyName == nil { + return + } + name := strings.TrimSpace(*cid.SchemeAgencyName) + switch key { + case org.IdentityKeyPassport: + id.Country = l10n.ISOCountryCode(name) + case ae.IdentityKeyTradeLicense: + id.Description = name + } +} + +// exportAETINScheme writes the TIN tax scheme on the party tax schemes that +// gobl.ubl writes for the party's TIN identities, which it gives the generic +// LOC scheme. +// +// No rule asks for TIN: the BIS only says the scheme of the seller TIN +// (IBT-032) must not be VAT, the syntax binding gives no code list, and +// IBR-133-AE and IBR-178-AE only check for "not VAT", so LOC would pass too. +// TIN is the value the only official example with a seller TIN uses +// (Seller-TIN-identifier.xml), so receivers are most likely to expect it. +// It is not the TIN of UNCL 1153, which is a transport instruction number. +func exportAETINScheme(out *goblubl.Party, p *org.Party) { + for _, id := range p.Identities { + if id == nil || id.Key != ae.IdentityKeyTIN || id.Scope != org.IdentityScopeTax { + continue + } + for i := range out.PartyTaxScheme { + pts := &out.PartyTaxScheme[i] + if pts.CompanyID != nil && pts.CompanyID.Value == id.Code.String() && + pts.TaxScheme != nil && pts.TaxScheme.ID.Value != goblubl.TaxSchemeVAT { + pts.TaxScheme.ID.Value = taxSchemeTIN + } + } + } +} + // exportAETaxTotal fixes the rates of the VAT breakdowns, and merges the ones // left with the same category and rate. func exportAETaxTotal(tt *goblubl.TaxTotal) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 14a1736..97300bd 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -8,7 +8,10 @@ import ( "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" "github.com/invopop/gobl/uuid" "github.com/stretchr/testify/assert" @@ -173,6 +176,180 @@ func TestExportAEPartyTaxID(t *testing.T) { }) } +func TestExportAEPartyIdentities(t *testing.T) { + // export builds the UBL party the way gobl.ubl does, then adds the AE + // details. + export := func(p *org.Party) *goblubl.Party { + out := goblubl.NewParty(p) + exportAEPartyIdentities(out, p) + return out + } + legal := func(key cbc.Key, code string) *org.Identity { + return &org.Identity{Key: key, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} + } + + t.Run("trade licence gets TL and its authority", func(t *testing.T) { + id := legal(ae.IdentityKeyTradeLicense, "112345678900003") + id.Description = "Trade License issuing Authority" + cid := export(&org.Party{Name: "Seller", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID + assert.Equal(t, "112345678900003", cid.Value) + assert.Equal(t, "TL", *cid.SchemeAgencyID) + assert.Equal(t, "Trade License issuing Authority", *cid.SchemeAgencyName) + }) + + t.Run("passport gets PAS and its issuing country", func(t *testing.T) { + id := legal(org.IdentityKeyPassport, "P1234567890") + id.Country = "IN" + cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID + assert.Equal(t, "PAS", *cid.SchemeAgencyID) + assert.Equal(t, "IN", *cid.SchemeAgencyName) + }) + + t.Run("Emirates ID and Cabinet Decision get their type only", func(t *testing.T) { + for key, typ := range map[cbc.Key]string{ + ae.IdentityKeyEmiratesID: "EID", + ae.IdentityKeyCabinetDecision: "CD", + } { + id := legal(key, "784199012345671") + id.Description = "not an authority" + cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID + assert.Equal(t, typ, *cid.SchemeAgencyID, key) + assert.Nil(t, cid.SchemeAgencyName, key) + } + }) + + t.Run("passport ignores the description", func(t *testing.T) { + id := legal(org.IdentityKeyPassport, "P1234567890") + id.Description = "not a country" + cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID + assert.Nil(t, cid.SchemeAgencyName) + }) + + t.Run("legal identity without a PINT AE type is left alone", func(t *testing.T) { + cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-1234567"}, + }}).PartyLegalEntity.CompanyID + assert.Nil(t, cid.SchemeAgencyID) + assert.Nil(t, cid.SchemeAgencyName) + }) + + t.Run("the first legal identity is described, after a tax one", func(t *testing.T) { + cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ + {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567890"}, + legal(ae.IdentityKeyEmiratesID, "784199012345671"), + legal(ae.IdentityKeyCabinetDecision, "CD-1"), + }}).PartyLegalEntity.CompanyID + assert.Equal(t, "784199012345671", cid.Value) + assert.Equal(t, "EID", *cid.SchemeAgencyID) + }) + + t.Run("TIN is written under the TIN scheme, next to the VAT TRN", func(t *testing.T) { + out := export(&org.Party{ + Name: "Seller", + TaxID: &tax.Identity{Country: "AE", Code: "100000000000003"}, + Identities: []*org.Identity{ + {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567890"}, + }, + }) + require.Len(t, out.PartyTaxScheme, 2) + assert.Equal(t, "VAT", out.PartyTaxScheme[0].TaxScheme.ID.Value) + assert.Equal(t, "1234567890", out.PartyTaxScheme[1].CompanyID.Value) + assert.Equal(t, "TIN", out.PartyTaxScheme[1].TaxScheme.ID.Value) + }) + + t.Run("other tax identities keep the scheme gobl.ubl gives them", func(t *testing.T) { + out := export(&org.Party{Name: "Seller", Identities: []*org.Identity{ + {Scope: org.IdentityScopeTax, Code: "1234567890"}, + }}) + require.Len(t, out.PartyTaxScheme, 1) + assert.Equal(t, goblubl.TaxSchemeTaxRegistration, out.PartyTaxScheme[0].TaxScheme.ID.Value) + }) + + t.Run("nil parties are skipped", func(t *testing.T) { + assert.NotPanics(t, func() { + exportAEPartyIdentities(nil, &org.Party{}) + exportAEPartyIdentities(&goblubl.Party{}, nil) + }) + }) +} + +func TestImportAEPartyIdentities(t *testing.T) { + companyID := func(agencyID, agencyName string) *goblubl.Party { + cid := &goblubl.IDType{Value: "112345678900003"} + if agencyID != "" { + cid.SchemeAgencyID = &agencyID + } + if agencyName != "" { + cid.SchemeAgencyName = &agencyName + } + return &goblubl.Party{PartyLegalEntity: &goblubl.PartyLegalEntity{CompanyID: cid}} + } + // imported builds the GOBL party the way gobl.ubl imports it, then reads + // the AE details. + imported := func(in *goblubl.Party, supplier bool) *org.Party { + p := goblubl.ParseParty(in) + importAEPartyIdentities(in, p, supplier) + return p + } + + t.Run("trade licence with its authority", func(t *testing.T) { + id := imported(companyID("TL", "Trade License issuing Authority"), false).Identities[0] + assert.Equal(t, ae.IdentityKeyTradeLicense, id.Key) + assert.Equal(t, "Trade License issuing Authority", id.Description) + }) + + t.Run("CL is read as a trade licence", func(t *testing.T) { + id := imported(companyID("CL", "Dubai Economy and Tourism"), false).Identities[0] + assert.Equal(t, ae.IdentityKeyTradeLicense, id.Key) + assert.Equal(t, "Dubai Economy and Tourism", id.Description) + }) + + t.Run("passport with its issuing country", func(t *testing.T) { + id := imported(companyID("PAS", "IN"), false).Identities[0] + assert.Equal(t, org.IdentityKeyPassport, id.Key) + assert.Equal(t, l10n.ISOCountryCode("IN"), id.Country) + assert.Empty(t, id.Description) + }) + + t.Run("Emirates ID and Cabinet Decision, without an authority", func(t *testing.T) { + for typ, key := range map[string]cbc.Key{"EID": ae.IdentityKeyEmiratesID, "CD": ae.IdentityKeyCabinetDecision} { + id := imported(companyID(typ, "Some Authority"), false).Identities[0] + assert.Equal(t, key, id.Key, typ) + assert.Empty(t, id.Description, typ) + } + }) + + t.Run("unknown or missing types are left alone", func(t *testing.T) { + for _, typ := range []string{"XYZ", ""} { + id := imported(companyID(typ, "Some Authority"), false).Identities[0] + assert.Empty(t, id.Key, typ) + assert.Empty(t, id.Description, typ) + } + }) + + t.Run("supplier non-VAT tax registration is the TIN", func(t *testing.T) { + in := companyID("TL", "Authority") + in.PartyTaxScheme = []goblubl.PartyTaxScheme{ + {CompanyID: &goblubl.IDType{Value: "198765432102003"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}}, + {CompanyID: &goblubl.IDType{Value: "1234567890"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "TIN"}}}, + } + p := imported(in, true) + require.Len(t, p.Identities, 2) + assert.Equal(t, ae.IdentityKeyTIN, p.Identities[1].Key) + assert.Equal(t, cbc.Code("1234567890"), p.Identities[1].Code) + + p = imported(in, false) + assert.Empty(t, p.Identities[1].Key, "only the seller has a TIN") + }) + + t.Run("nil parties are skipped", func(t *testing.T) { + assert.NotPanics(t, func() { + importAEPartyIdentities(nil, &org.Party{}, true) + importAEPartyIdentities(&goblubl.Party{}, nil, true) + }) + }) +} + func TestImportAEOutsideScope(t *testing.T) { importCode := func(invoiceCode, creditNoteCode string) *bill.Invoice { in := new(goblubl.Invoice) diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index d20430e..1d85377 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "83aa2c00b32d32761a89c65ec5e6d948c8112ea451179235a961bb09f75b50a6" + "val": "3e6f3f13ecc2a37565e114fbcb5126cca99dc74674f8a0636fb4ce59b38e3111" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -42,7 +42,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -75,7 +77,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index ac9d722..4f04dcc 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3d3a04621f2e455641b507c8336c65706d3d24518c819c97814eb3590eb387e2" + "val": "92c69c6761d75690ded39c92a36a02a5c4804d4fdf8d851bb654909a076af2bb" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -36,7 +36,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -69,7 +71,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index 3532c39..e5c09bd 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c0956f6f36cc507c74c03ef7c05ef02c534546e55569646d046827ffb45125e7" + "val": "00b7bae531eea00de813a22caa17395b9806b312e3b5e461d876f7f1f22aca24" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -39,7 +39,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -72,7 +74,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index daaf913..1d12e7d 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0a5fd01e4b6b1c604bb478bd2427cdd8ecfd3cc51be85d0deb439a6b11a9f070" + "val": "a4356da693f260a4a73f9a916fc01556667a1a09429ac96c665a3194d4e79abb" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -36,7 +36,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -69,7 +71,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index d4ca8db..991b2b2 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "02bf266ce841a1a4c64fba01d6e859e751ab73cec534e39c71351ee49ef2e73e" + "val": "0961475eacec79b237cb363956a1e019a41e5680155d048b5cf66b266c6cbd1f" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -36,7 +36,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -69,7 +71,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json new file mode 100644 index 0000000..ed5600e --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -0,0 +1,181 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "6d73d12bd7734f5e18ad68f524a341a0284781ab4184e88394d5fd94290ca169" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "AE-TIN-PAS-01", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "tax", + "key": "ae-tin", + "code": "1234567890" + }, + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "country": "IN", + "key": "passport", + "code": "P1234567890" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index e28a210..2f18235 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5fece2baa64586bcbc6e5745758a2922f2d07451f7803c46b6f15bad0a23559b" + "val": "f25821e82fde28f7f2c23b2f569035e5e434fbcb3007b4369e5f6bc8aef73950" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -43,7 +43,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -76,7 +78,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 64cd680..17bc38e 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a9971c414f59abc529620dc03bc5f294f91fea9918d4a01e51dec5dada0f92f3" + "val": "15d328d7e69c3a6e4c13bccadd18b70601356caa61020bd251cf59835d3fbabc" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -36,7 +36,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "endpoints": [ @@ -69,7 +71,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index a99ee96..6564e99 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -38,7 +38,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -64,7 +64,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index e746ae2..cee7b6f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -33,7 +33,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -59,7 +59,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 68344c0..0fecc1d 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -33,7 +33,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -59,7 +59,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 4548eda..a020a08 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -33,7 +33,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -59,7 +59,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 9ee4c97..7ba6dfd 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -33,7 +33,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -59,7 +59,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml new file mode 100644 index 0000000..33a637c --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -0,0 +1,130 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + AE-AE-TIN-PAS-01 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + 1234567890 + + TIN + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + P1234567890 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 4ece96c..95b6fd2 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -39,7 +39,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -65,7 +65,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 980a31f..4c011a9 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -33,7 +33,7 @@ Supplier Legal Name - 112345678900003 + 112345678900003 @@ -59,7 +59,7 @@ Buyer Legal Name - 112345679000001 + 112345679000001 diff --git a/ubl/testdata/parse/pint/ae/buyer-pas-identifier.xml b/ubl/testdata/parse/pint/ae/buyer-pas-identifier.xml new file mode 100644 index 0000000..867e1c5 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/buyer-pas-identifier.xml @@ -0,0 +1,145 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-BUYER-PAS-01 + a1b2c3d4-e5f6-7890-abcd-900000000009 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + P1234567890 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + 50 + false + + 1000 + 50 + + S + 5 + + VAT + + + + + + 1000 + 1000 + 1050 + 1050 + + + 1 + 10 + 1000 + + Standard rated goods + Electronic Components + + S + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1050 + + 50 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 162ebd8..3d2aa60 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "fcbad581ef55848a3d9113422d9953ffc8075628d488d8d4b66a961ca565a332" + "val": "26852225cd40e952f34adbb5968fdfc855c438f2fc0e56352acc7a2bae60b57c" } }, "doc": { @@ -39,7 +39,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "people": [ @@ -84,7 +86,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "people": [ diff --git a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json new file mode 100644 index 0000000..c36a683 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json @@ -0,0 +1,210 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "fa655ef144d3127c20bbbd383e5bc5077f42bf1249f8feaf49fb8f31cf06e78a" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-BUYER-PAS-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "country": "IN", + "key": "passport", + "code": "P1234567890" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Electronic Components", + "description": "Standard rated goods", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1050.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 0f5cbc3..85c8bae 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "90331caa41959e413927081cbad2cdcae40fc83a2d785c4cfba1d599cea7f6c8" + "val": "c090983cfc354ad2f6c11752f73f1eff551897fa246ad51d121171c282118493" } }, "doc": { @@ -35,7 +35,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "people": [ @@ -79,7 +81,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "people": [ diff --git a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json new file mode 100644 index 0000000..0efa096 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json @@ -0,0 +1,210 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "75991753b00d053853430037bab2f81cbdd44f0fec6b6aa00844ef25d1cc437c" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-SELLER-PAS-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "country": "GB", + "key": "passport", + "code": "P9876543210" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Electronic Components", + "description": "Standard rated goods", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1050.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json new file mode 100644 index 0000000..e4ae1c6 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json @@ -0,0 +1,216 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "f54c8bbf372d9d4409c59110b5b98f4f12aced96e73d14c40bd21080203af780" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-SELLER-TIN-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "country": "AE", + "key": "ae-tin", + "code": "1234567890" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Electronic Components", + "description": "Standard rated goods", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1050.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json index 8319f75..ff2773f 100644 --- a/ubl/testdata/parse/pint/ae/out/standard-invoice.json +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "fe61e4d3e34b8101edc26afe4b6579be325495cbfe70c97dd53c59fc76e1fac3" + "val": "7ee647f445f574918e7d783b82fd3a3368263a7dd05486a632e38999b4683331" } }, "doc": { @@ -34,7 +34,9 @@ "identities": [ { "scope": "legal", - "code": "112345678900003" + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" } ], "inboxes": [ @@ -61,7 +63,9 @@ "identities": [ { "scope": "legal", - "code": "112345679000001" + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" } ], "inboxes": [ diff --git a/ubl/testdata/parse/pint/ae/seller-pas-identifier.xml b/ubl/testdata/parse/pint/ae/seller-pas-identifier.xml new file mode 100644 index 0000000..54836c1 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/seller-pas-identifier.xml @@ -0,0 +1,145 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-SELLER-PAS-01 + a1b2c3d4-e5f6-7890-abcd-110000000011 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + P9876543210 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + 50 + false + + 1000 + 50 + + S + 5 + + VAT + + + + + + 1000 + 1000 + 1050 + 1050 + + + 1 + 10 + 1000 + + Standard rated goods + Electronic Components + + S + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1050 + + 50 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/seller-tin-identifier.xml b/ubl/testdata/parse/pint/ae/seller-tin-identifier.xml new file mode 100644 index 0000000..dbb6c59 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/seller-tin-identifier.xml @@ -0,0 +1,151 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-SELLER-TIN-01 + a1b2c3d4-e5f6-7890-abcd-100000000010 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + 1234567890 + + TIN + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + 50 + false + + 1000 + 50 + + S + 5 + + VAT + + + + + + 1000 + 1000 + 1050 + 1050 + + + 1 + 10 + 1000 + + Standard rated goods + Electronic Components + + S + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1050 + + 50 + + + + \ No newline at end of file From 9bf2d93453c5408dbb57e96f6bb82374aeaf70d0 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:59:28 +0000 Subject: [PATCH 09/73] Add the PINT AE transaction type - Build the transaction type (BTAE-02) from new invoice tags, one per flag, into the peppol-pint-ae-transaction-type extension, and require it (IBR-154-AE). - Add the beneficiary (BTAE-01) and principal (BTAE-14) ID extensions, and the flag rules: IBR-007-AE, IBR-137-AE, IBR-138-AE, IBR-142-AE, IBR-152-AE, IBR-157-AE, IBR-176-AE, IBR-177-AE and IBR-135-AE. - Exempt deemed supplies from payment instructions and due dates (IBR-191-AE, IBR-127-AE). - Write the transaction type as cbc:ProfileExecutionID and the IDs as the buyer and seller parties, and read them back on import. --- README.md | 7 +- addon/pint/bill.go | 205 +++++++++++++- addon/pint/bill_test.go | 144 ++++++++++ addon/pint/extensions.go | 75 +++++ addon/pint/org_identity.go | 8 + addon/pint/pint.go | 9 + addon/pint/scenarios.go | 4 +- addon/pint/transaction_type.go | 207 ++++++++++++++ addon/pint/transaction_type_test.go | 79 ++++++ examples/out/invoice-ae.json | 3 +- ubl/ae.go | 68 +++++ ubl/ae_internal_test.go | 61 ++++ .../convert/pint/ae/credit-note-ae.json | 3 +- .../pint/ae/invoice-ae-deemed-supply.json | 161 +++++++++++ .../convert/pint/ae/invoice-ae-exempt.json | 3 +- .../pint/ae/invoice-ae-export-summary.json | 202 ++++++++++++++ .../ae/invoice-ae-free-trade-zone-agent.json | 183 ++++++++++++ .../pint/ae/invoice-ae-outside-scope.json | 3 +- .../invoice-ae-reverse-charge-allowance.json | 3 +- .../pint/ae/invoice-ae-reverse-charge.json | 3 +- .../pint/ae/invoice-ae-tin-passport.json | 3 +- .../convert/pint/ae/invoice-ae-usd.json | 3 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 3 +- .../convert/pint/ae/out/credit-note-ae.xml | 1 + .../pint/ae/out/invoice-ae-deemed-supply.xml | 120 ++++++++ .../convert/pint/ae/out/invoice-ae-exempt.xml | 1 + .../pint/ae/out/invoice-ae-export-summary.xml | 150 ++++++++++ .../out/invoice-ae-free-trade-zone-agent.xml | 139 +++++++++ .../pint/ae/out/invoice-ae-outside-scope.xml | 1 + .../invoice-ae-reverse-charge-allowance.xml | 1 + .../pint/ae/out/invoice-ae-reverse-charge.xml | 1 + .../pint/ae/out/invoice-ae-tin-passport.xml | 1 + .../convert/pint/ae/out/invoice-ae-usd.xml | 1 + .../convert/pint/ae/out/invoice-ae.xml | 1 + ubl/testdata/parse/pint/ae/deemed-supply.xml | 182 ++++++++++++ .../parse/pint/ae/out/allowance-exempt.json | 3 +- .../pint/ae/out/buyer-pas-identifier.json | 3 +- .../parse/pint/ae/out/deemed-supply.json | 230 +++++++++++++++ .../parse/pint/ae/out/reverse-charge.json | 3 +- .../pint/ae/out/seller-pas-identifier.json | 3 +- .../pint/ae/out/seller-tin-identifier.json | 3 +- .../parse/pint/ae/out/standard-invoice.json | 3 +- .../pint/ae/out/supply-free-trade-zone.json | 264 ++++++++++++++++++ .../parse/pint/ae/supply-free-trade-zone.xml | 188 +++++++++++++ 44 files changed, 2708 insertions(+), 31 deletions(-) create mode 100644 addon/pint/extensions.go create mode 100644 addon/pint/transaction_type.go create mode 100644 addon/pint/transaction_type_test.go create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml create mode 100644 ubl/testdata/parse/pint/ae/deemed-supply.xml create mode 100644 ubl/testdata/parse/pint/ae/out/deemed-supply.json create mode 100644 ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json create mode 100644 ubl/testdata/parse/pint/ae/supply-free-trade-zone.xml diff --git a/README.md b/README.md index 364c62f..1f0cddf 100644 --- a/README.md +++ b/README.md @@ -112,10 +112,13 @@ rate to AED and the total with VAT in AED. The seller and buyer legal identities get their PINT AE type (`TL`, `EID`, `PAS` or `CD`, from the AE regime's identity keys and `passport`), with the trade licence authority (the identity's description) or the passport's issuing country, and the -seller's TIN goes under the `TIN` tax scheme. On import, it reads +seller's TIN goes under the `TIN` tax scheme. It also writes the transaction +type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and +the disclosed agent's principal as the buyer and seller parties. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as -identity keys and fields. +identity keys and fields, and the transaction type back as its extension and +tags. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 8e3f00a..9a0b543 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -67,11 +67,12 @@ func billInvoiceRules() *rules.Set { ), )), ), - // TODO: IBR-191-AE also exempts deemed supplies (transaction type - // BTAE-02 X1XXXXXX). Add the exception with the BTAE extensions (task J). rules.When( - is.Not(is.Func("credit note", invoiceIsCreditNote)), - rules.Assert("07", "payment instructions required, except on credit notes (IBR-191-AE)", + is.Not(is.Or( + is.Func("credit note", invoiceIsCreditNote), + is.Func("deemed supply", invoiceIsDeemedSupply), + )), + rules.Assert("07", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Func("has payment instructions", invoiceHasPaymentInstructions), ), ), @@ -141,19 +142,18 @@ func billInvoiceRules() *rules.Set { rules.Assert("16", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), - // TODO: IBR-127-AE also exempts deemed supplies: invoices whose - // transaction type (BTAE-02, written as cbc:ProfileExecutionID) matches - // X1XXXXXX, a 1 in the second of its 8 flags. GOBL has no field for - // BTAE-02 yet, so add the exception with the BTAE extensions (task J). // Self-billed credit notes (261) are exempt too. The rule text only // names 381 and 81, but the Schematron test also exempts 261, and we // follow the test. rules.When( - is.Not(is.Func("document type is 381, 81 or 261", - documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote))), + is.Not(is.Or( + is.Func("document type is 381, 81 or 261", + documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote)), + is.Func("deemed supply", invoiceIsDeemedSupply), + )), rules.When( is.Func("amount is due", invoiceIsDue), - rules.Assert("17", "payment due date is required when an amount is due (IBR-127-AE)", + rules.Assert("17", "payment due date is required when an amount is due, except on credit notes and deemed supplies (IBR-127-AE)", is.Func("has due date", invoiceHasDueDate), ), ), @@ -205,7 +205,7 @@ func billInvoiceRules() *rules.Set { is.Func("tax scope", identityHasTaxScope), rules.Field("code", rules.Assert("28", "supplier tax scope identity must be a TIN of 10 digits starting with 1 (IBR-148-AE)", - is.Matches(`^1\d{9}$`), + is.MatchesRegexp(tinRegexp), ), ), ), @@ -241,6 +241,65 @@ func billInvoiceRules() *rules.Set { rules.Assert("34", "customer tax scope identities require a supplier TIN (IBR-133-AE)", is.Func("customer tax scope identities with supplier TIN", customerTaxIdentitiesHaveSupplierTIN), ), + rules.Assert("35", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + is.Func("has a valid transaction type", invoiceHasTransactionType), + ), + rules.When( + is.Func("free trade zone", invoiceIsFreeTradeZone), + rules.Assert("36", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + is.Func("has beneficiary ID", invoiceHasExt(ExtKeyBeneficiaryID)), + ), + ), + rules.When( + is.Func("summary invoice", invoiceIsSummary), + rules.Assert("37", "ordering period is required on summary invoices (IBR-138-AE)", + is.Func("has ordering period", invoiceHasOrderingPeriod), + ), + ), + rules.When( + is.Func("disclosed agent billing", invoiceIsDisclosedAgent), + rules.Assert("38", "principal ID is required on disclosed agent billing (IBR-137-AE)", + is.Func("has principal ID", invoiceHasExt(ExtKeyPrincipalID)), + ), + rules.Assert("39", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", + is.Func("principal ID is not the supplier tax ID", principalIsNotSupplier), + ), + rules.Field("supplier", + rules.Assert("40", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", + is.Func("has tax registration", partyHasTaxRegistration), + ), + ), + ), + rules.When( + is.Func("e-commerce supply", invoiceIsECommerce), + rules.Assert("41", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), + ), + ), + rules.When( + is.Func("export", invoiceIsExport), + rules.Assert("42", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), + ), + ), + rules.When( + is.Func("document type is invoice outside scope or credit note related to goods and services", + documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), + rules.Assert("43", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), + ), + ), + rules.When( + is.Not(is.Func("export", invoiceIsExport)), + rules.Field("customer", + rules.When( + is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), + rules.Assert("44", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), + ), + ), + ), + ), ), ) } @@ -632,6 +691,128 @@ func customerTaxIdentitiesHaveSupplierTIN(val any) bool { return inv.Supplier != nil && partyTaxIdentityCount(inv.Supplier) > 0 } +// invoiceHasTransactionType reports whether the invoice has a transaction +// type of 8 flags of 0 or 1, written as cbc:ProfileExecutionID (IBR-154-AE). +// GOBL doesn't check an extension's pattern on its own. +func invoiceHasTransactionType(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && transactionTypeRegexp.MatchString(inv.Tax.GetExt(ExtKeyTransactionType).String()) +} + +// invoiceHasExt returns a predicate that reports whether the invoice's tax +// extensions have a value for the key. +func invoiceHasExt(key cbc.Key) func(any) bool { + return func(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Tax.GetExt(key) != "" + } +} + +// invoiceHasOrderingPeriod reports whether the invoice has an ordering +// period, which gobl.ubl writes as cac:InvoicePeriod (IBR-138-AE). +func invoiceHasOrderingPeriod(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Ordering != nil && inv.Ordering.Period != nil +} + +// principalIsNotSupplier reports whether the principal ID differs from the +// supplier's tax registrations, the cbc:CompanyID values of its +// PartyTaxSchemes (IBR-176-AE). A missing principal ID or supplier tax +// registration passes, as rules 38 and 40 report those. +func principalIsNotSupplier(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + principal := inv.Tax.GetExt(ExtKeyPrincipalID) + if principal == "" || inv.Supplier == nil { + return true + } + var codes []cbc.Code + if inv.Supplier.TaxID != nil && inv.Supplier.TaxID.Code != "" { + codes = append(codes, inv.Supplier.TaxID.Code) + } + for _, id := range inv.Supplier.Identities { + if identityHasTaxScope(id) { + codes = append(codes, id.Code) + } + } + if len(codes) == 0 { + return true + } + for _, c := range codes { + if c != principal { + return true + } + } + return false +} + +// invoiceDeliveryAddress returns the first address of the delivery receiver, +// which gobl.ubl writes as cac:DeliveryLocation/cac:Address, or nil. +func invoiceDeliveryAddress(inv *bill.Invoice) *org.Address { + if inv == nil || inv.Delivery == nil || inv.Delivery.Receiver == nil { + return nil + } + return partyFirstAddress(inv.Delivery.Receiver) +} + +// invoiceDeliveryAddressIsComplete reports whether the invoice has a delivery +// address with a street, city and region (IBR-142-AE). +func invoiceDeliveryAddressIsComplete(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok { + return false + } + a := invoiceDeliveryAddress(inv) + return a != nil && a.Street != "" && a.Locality != "" && a.Region != "" +} + +// invoiceDeliveryAddressIsAEOrComplete reports whether the invoice has a +// delivery address in the UAE, or one with a street, city and region +// (IBR-152-AE). +func invoiceDeliveryAddressIsAEOrComplete(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok { + return false + } + a := invoiceDeliveryAddress(inv) + return a != nil && (a.Country == l10n.AE.ISO() || (a.Street != "" && a.Locality != "" && a.Region != "")) +} + +// partyHasUAEEndpointNotTIN reports whether the party's electronic address +// uses the UAE Peppol scheme 0235 with a code that is not a TIN, 1XXXXXXXXX +// (IBR-135-AE). +func partyHasUAEEndpointNotTIN(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + scheme, code := partyEndpointID(p) + return scheme == endpointSchemeUAE && !tinRegexp.MatchString(code) +} + +// partyHasIdentificationOrTaxRegistration reports whether the party has an +// identity gobl.ubl writes as cac:PartyIdentification (any identity that is +// neither a tax registration nor the first legal one) or a tax registration +// (IBR-135-AE). +func partyHasIdentificationOrTaxRegistration(val any) bool { + if partyHasTaxRegistration(val) { + return true + } + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + legal := partyFirstLegalIdentity(p) + for _, id := range p.Identities { + if id != nil && id != legal && id.Scope != org.IdentityScopeTax { + return true + } + } + return false +} + // taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). // It fails on any other value, so a type mismatch can't pass silently. func taxesHaveVAT(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 4aeb107..828efc2 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -739,6 +739,150 @@ func TestBillIdentityRulesAE(t *testing.T) { }) } +func TestBillTransactionTypeRulesAE(t *testing.T) { + const ( + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + ) + setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { + if inv.Tax == nil { + inv.Tax = new(bill.Tax) + } + inv.Tax.Ext = inv.Tax.Ext.Set(key, code) + } + receiver := func(a *org.Address) *bill.DeliveryDetails { + return &bill.DeliveryDetails{Receiver: &org.Party{Name: "Receiver", Addresses: []*org.Address{a}}} + } + foreign := &org.Address{Street: "Baker Street 221B", Locality: "London", Region: "Greater London", Country: "GB"} + + t.Run("transaction type is required (IBR-154-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyTransactionType) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) + require.Error(t, err) + assert.Contains(t, err.Error(), faultTransactionType) + }) + + t.Run("transaction type must be 8 flags (IBR-154-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + setExt(inv, pint.ExtKeyTransactionType, "0000002") + assert.Contains(t, aeFaults(t, inv), faultTransactionType) + }) + + t.Run("deemed supplies need no payment instructions or due date (IBR-191-AE, IBR-127-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) + inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{Notes: "No consideration"}} + out := aeFaults(t, inv) + assert.NotContains(t, out, faultPaymentInstructions) + assert.NotContains(t, out, faultDueDate) + + inv = aeDocument(bill.InvoiceTypeStandard) + inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{Notes: "No consideration"}} + out = aeFaults(t, inv) + assert.Contains(t, out, faultPaymentInstructions) + assert.Contains(t, out, faultDueDate) + }) + + t.Run("free trade zone needs the beneficiary ID (IBR-007-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagFreeTradeZone) + assert.Contains(t, aeFaults(t, inv), faultBeneficiary) + setExt(inv, pint.ExtKeyBeneficiaryID, "189098765401003") + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("summary invoice needs the ordering period (IBR-138-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagSummary) + assert.Contains(t, aeFaults(t, inv), faultSummaryPeriod) + start, end := cal.MakeDate(2026, 10, 1), cal.MakeDate(2026, 10, 31) + inv.Ordering = &bill.Ordering{Period: &cal.Period{Start: &start, End: &end}} + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("disclosed agent needs the principal ID (IBR-137-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) + assert.Contains(t, aeFaults(t, inv), faultPrincipal) + setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("principal ID must differ from the supplier TRN (IBR-176-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) + setExt(inv, pint.ExtKeyPrincipalID, inv.Supplier.TaxID.Code) + assert.Contains(t, aeFaults(t, inv), faultPrincipalSupplier) + }) + + t.Run("disclosed agent supplier needs a tax registration (IBR-177-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) + setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} + out := aeFaults(t, inv) + assert.Contains(t, out, faultAgentSupplierTax) + assert.NotContains(t, out, faultPrincipalSupplier) + }) + + t.Run("e-commerce needs a complete delivery address (IBR-142-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagECommerce) + assert.Contains(t, aeFaults(t, inv), faultECommerceDelivery) + inv.Delivery = receiver(&org.Address{Locality: "Dubai", Region: "DXB", Country: "AE"}) + assert.Contains(t, aeFaults(t, inv), faultECommerceDelivery) + inv.Delivery = receiver(aeAddress("DXB")[0]) + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("export needs a complete delivery address outside the UAE (IBR-152-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, tax.TagExport) + assert.Contains(t, aeFaults(t, inv), faultExportDelivery) + inv.Delivery = receiver(&org.Address{Locality: "London", Country: "GB"}) + assert.Contains(t, aeFaults(t, inv), faultExportDelivery) + inv.Delivery = receiver(foreign) + assert.Empty(t, aeFaults(t, inv)) + inv.Delivery = receiver(&org.Address{Locality: "Dubai", Country: "AE"}) + assert.NotContains(t, aeFaults(t, inv), faultExportDelivery) + }) + + t.Run("outside scope documents can't be summary, deemed supply or margin scheme (IBR-157-AE)", func(t *testing.T) { + for _, tag := range []cbc.Key{pint.TagSummary, pint.TagDeemedSupply, pint.TagMarginScheme} { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope, tag) + assert.Contains(t, aeFaults(t, inv), faultOutsideScopeFlags, tag) + } + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope, pint.TagContinuousSupply) + assert.NotContains(t, aeFaults(t, inv), faultOutsideScopeFlags) + }) + + t.Run("customer with a UAE endpoint not starting with 1 needs an identifier (IBR-135-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints("9345678901") + assert.Contains(t, aeFaults(t, inv), faultCustomerIdentifier) + + inv.Customer.Identities = []*org.Identity{{Type: "XYZ", Code: "12345"}} + assert.NotContains(t, aeFaults(t, inv), faultCustomerIdentifier) + }) + + t.Run("exports and endpoints starting with 1 need no customer identifier (IBR-135-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, tax.TagExport) + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints("9345678901") + assert.NotContains(t, aeFaults(t, inv), faultCustomerIdentifier) + + inv = aeDocument(bill.InvoiceTypeStandard) + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints("1345678901") + assert.NotContains(t, aeFaults(t, inv), faultCustomerIdentifier) + }) +} + func TestBillLineRulesAE(t *testing.T) { const ( faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go new file mode 100644 index 0000000..aa5f5e4 --- /dev/null +++ b/addon/pint/extensions.go @@ -0,0 +1,75 @@ +package pint + +import ( + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/i18n" + "github.com/invopop/gobl/pkg/here" +) + +// PINT AE extension keys, for the BTAE fields GOBL has no place for. +const ( + // ExtKeyTransactionType is the PINT AE invoice transaction type (BTAE-02). + ExtKeyTransactionType cbc.Key = "peppol-pint-ae-transaction-type" + // ExtKeyBeneficiaryID is the ID of the beneficiary of a supply in a free + // trade zone (BTAE-01). + ExtKeyBeneficiaryID cbc.Key = "peppol-pint-ae-beneficiary-id" + // ExtKeyPrincipalID is the ID of the principal a disclosed agent bills for + // (BTAE-14). + ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" +) + +// extensions are the extensions the PINT addon defines. They are only used +// on UAE documents. +var extensions = []*cbc.Definition{ + { + Key: ExtKeyTransactionType, + Name: i18n.String{ + i18n.EN: "PINT AE Transaction Type", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + PINT AE invoice transaction type (BTAE-02): 8 flags of 0 or 1, in this + order: free trade zone, deemed supply, profit margin scheme, summary + invoice, continuous supply, disclosed agent billing, supply through + e-commerce, and exports. "00000000" when none applies. + + It is built from the invoice tags with the same names + ("free-trade-zone", "deemed-supply", "margin-scheme", "summary", + "continuous-supply", "disclosed-agent", "e-commerce" and "export"). + Without any of those tags, a code set directly is kept. + `), + }, + Sources: []*cbc.Source{ + { + Title: i18n.NewString("Peppol PINT AE Billing specification"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/bis/", + }, + }, + Pattern: transactionTypePattern, + }, + { + Key: ExtKeyBeneficiaryID, + Name: i18n.String{ + i18n.EN: "PINT AE Beneficiary ID", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Identifier of the beneficiary of a supply in a free trade zone (BTAE-01), + required with the "free-trade-zone" transaction type (IBR-007-AE). + `), + }, + }, + { + Key: ExtKeyPrincipalID, + Name: i18n.String{ + i18n.EN: "PINT AE Principal ID", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Identifier of the principal a disclosed agent bills on behalf of + (BTAE-14), required with the "disclosed-agent" transaction type + (IBR-137-AE). It must differ from the supplier's tax ID (IBR-176-AE). + `), + }, + }, +} diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index e2b4aa0..da13598 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -1,11 +1,19 @@ package pint import ( + "regexp" + "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" ) +// tinRegexp matches a UAE TIN as PINT AE expects it: 10 digits starting with +// 1 (IBR-148-AE). The AE regime only checks the 10 digits; the leading 1 is +// PINT AE's. UAE Peppol endpoints (0235) are TINs too, so it also tells +// whether an endpoint is one (IBR-135-AE). +var tinRegexp = regexp.MustCompile(`^1\d{9}$`) + // PINT AE legal registration identifier types, written as @schemeAgencyID on // the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The Ministry of // Finance lists the same four types of commercial registration number. diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 7c9064e..1fe4df9 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -51,6 +51,10 @@ func init() { norm.RegisterWithGuard( is.InContext(tax.AddonIn(V1)), norm.For(normalizeTaxCombo), + norm.When( + is.InContext(tax.RegimeIn(regimesAE...)), + norm.For(normalizeTransactionType), + ), ) } @@ -83,6 +87,10 @@ func newV1Addon() *tax.AddonDef { UAE trade licences carry their issuing authority in the description, and passports their issuing country. + + UAE invoices get the PINT AE transaction type from their tags: + "free-trade-zone", "deemed-supply", "margin-scheme", "summary", + "continuous-supply", "disclosed-agent", "e-commerce" and "export". `), }, Sources: []*cbc.Source{ @@ -103,6 +111,7 @@ func newV1Addon() *tax.AddonDef { URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/rule/PINT-jurisdiction-aligned-rules/", }, }, + Extensions: extensions, Tags: []*tax.TagSet{ invoiceTags, }, diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index f58bc0a..c65d3d6 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -32,7 +32,7 @@ const ( // invoiceTags are the document tags the PINT addon adds to invoices. var invoiceTags = &tax.TagSet{ Schema: bill.ShortSchemaInvoice, - List: []*cbc.Definition{ + List: append([]*cbc.Definition{ { Key: TagOutsideScope, Name: i18n.String{ @@ -42,7 +42,7 @@ var invoiceTags = &tax.TagSet{ i18n.EN: "Marks a PINT AE document as out of scope of VAT, the UAE 'commercial invoice'. Invoices are sent with document type 480 and credit notes with 81. Has no effect outside the UAE.", }, }, - }, + }, transactionTypeTags...), } // invoiceScenarios set the UNTDID 1001 document type for PINT AE's diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go new file mode 100644 index 0000000..ef367e7 --- /dev/null +++ b/addon/pint/transaction_type.go @@ -0,0 +1,207 @@ +package pint + +import ( + "regexp" + + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/i18n" + "github.com/invopop/gobl/tax" +) + +// Invoice tags for the PINT AE transaction type flags (BTAE-02). Exports use +// GOBL's own "export" tag. +const ( + // TagFreeTradeZone marks a supply of goods or services in a free trade zone. + TagFreeTradeZone cbc.Key = "free-trade-zone" + // TagDeemedSupply marks a supply of goods or services without + // consideration. + TagDeemedSupply cbc.Key = "deemed-supply" + // TagMarginScheme marks a supply of goods under the profit margin scheme. + TagMarginScheme cbc.Key = "margin-scheme" + // TagSummary marks a summary invoice: more than one supply to the same + // person in the same calendar month. + TagSummary cbc.Key = "summary" + // TagContinuousSupply marks a supply made on a recurrent basis. + TagContinuousSupply cbc.Key = "continuous-supply" + // TagDisclosedAgent marks a supply an agent who is a registrant makes on + // behalf of a principal. + TagDisclosedAgent cbc.Key = "disclosed-agent" + // TagECommerce marks a supply of goods or services through e-commerce. + TagECommerce cbc.Key = "e-commerce" +) + +// transactionTypePattern is the format of the transaction type: 8 flags of +// 0 or 1 (IBR-154-AE). +const transactionTypePattern = `^[01]{8}$` + +var transactionTypeRegexp = regexp.MustCompile(transactionTypePattern) + +// TransactionType is a parsed PINT AE invoice transaction type (BTAE-02). +type TransactionType struct { + FreeTradeZone bool + DeemedSupply bool + MarginScheme bool + Summary bool + ContinuousSupply bool + DisclosedAgent bool + ECommerce bool + Export bool +} + +// transactionTypeFlags lists the flags in their order in the code, with the +// tag that sets each one. +var transactionTypeFlags = []struct { + tag cbc.Key + get func(*TransactionType) *bool +}{ + {TagFreeTradeZone, func(t *TransactionType) *bool { return &t.FreeTradeZone }}, + {TagDeemedSupply, func(t *TransactionType) *bool { return &t.DeemedSupply }}, + {TagMarginScheme, func(t *TransactionType) *bool { return &t.MarginScheme }}, + {TagSummary, func(t *TransactionType) *bool { return &t.Summary }}, + {TagContinuousSupply, func(t *TransactionType) *bool { return &t.ContinuousSupply }}, + {TagDisclosedAgent, func(t *TransactionType) *bool { return &t.DisclosedAgent }}, + {TagECommerce, func(t *TransactionType) *bool { return &t.ECommerce }}, + {tax.TagExport, func(t *TransactionType) *bool { return &t.Export }}, +} + +// ParseTransactionType reads the flags of a transaction type code. A flag is +// set when its position holds a 1; a missing or malformed code gives no +// flags, as IBR-154-AE checks the format. +func ParseTransactionType(code cbc.Code) TransactionType { + var t TransactionType + s := code.String() + for i, f := range transactionTypeFlags { + if len(s) > i && s[i] == '1' { + *f.get(&t) = true + } + } + return t +} + +// Code returns the 8-character transaction type code. +func (t TransactionType) Code() cbc.Code { + b := []byte("00000000") + for i, f := range transactionTypeFlags { + if *f.get(&t) { + b[i] = '1' + } + } + return cbc.Code(b) +} + +// Tags returns the invoice tags of the flags that are set. +func (t TransactionType) Tags() []cbc.Key { + var tags []cbc.Key + for _, f := range transactionTypeFlags { + if *f.get(&t) { + tags = append(tags, f.tag) + } + } + return tags +} + +// transactionTypeFromTags builds the transaction type from the invoice tags. +func transactionTypeFromTags(inv *bill.Invoice) TransactionType { + var t TransactionType + for _, f := range transactionTypeFlags { + if inv.HasTags(f.tag) { + *f.get(&t) = true + } + } + return t +} + +// invoiceTransactionType returns the parsed transaction type of an invoice. +func invoiceTransactionType(val any) TransactionType { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return TransactionType{} + } + return ParseTransactionType(inv.Tax.GetExt(ExtKeyTransactionType)) +} + +// normalizeTransactionType sets the transaction type of a UAE invoice. Every +// PINT AE document needs one (IBR-154-AE). When the invoice has any of the +// flag tags, the tags decide the code, so a code from an earlier calculation +// follows the tags when they change. Without tags, a code set directly is +// kept, and "00000000" is set when there is none. +func normalizeTransactionType(inv *bill.Invoice) { + if inv == nil { + return + } + t := transactionTypeFromTags(inv) + if len(t.Tags()) == 0 && inv.Tax.GetExt(ExtKeyTransactionType) != "" { + return + } + if inv.Tax == nil { + inv.Tax = new(bill.Tax) + } + inv.Tax.Ext = inv.Tax.Ext.Set(ExtKeyTransactionType, t.Code()) +} + +// transactionTypeTags are the invoice tags for the transaction type flags. +var transactionTypeTags = []*cbc.Definition{ + { + Key: TagFreeTradeZone, + Name: i18n.String{i18n.EN: "Free Trade Zone"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services in a free trade zone. Needs the beneficiary ID."}, + }, + { + Key: TagDeemedSupply, + Name: i18n.String{i18n.EN: "Deemed Supply"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services without consideration."}, + }, + { + Key: TagMarginScheme, + Name: i18n.String{i18n.EN: "Profit Margin Scheme"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods under the profit margin scheme."}, + }, + { + Key: TagSummary, + Name: i18n.String{i18n.EN: "Summary Invoice"}, + Desc: i18n.String{i18n.EN: "PINT AE: more than one supply of goods or services to the same person in the same calendar month. Needs the invoicing period."}, + }, + { + Key: TagContinuousSupply, + Name: i18n.String{i18n.EN: "Continuous Supply"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services made on a recurrent basis."}, + }, + { + Key: TagDisclosedAgent, + Name: i18n.String{i18n.EN: "Disclosed Agent Billing"}, + Desc: i18n.String{i18n.EN: "PINT AE: an agent who is a registrant makes a supply on behalf of the principal. Needs the principal ID."}, + }, + { + Key: TagECommerce, + Name: i18n.String{i18n.EN: "E-commerce"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services through e-commerce. Needs a complete delivery address."}, + }, + { + Key: tax.TagExport, + Name: i18n.String{i18n.EN: "Export"}, + Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services outside the country. Needs a complete delivery address outside the UAE."}, + }, +} + +// transactionTypeIs returns a predicate that reports whether an invoice's +// transaction type has the flag that check reads. +func transactionTypeIs(check func(TransactionType) bool) func(any) bool { + return func(val any) bool { + return check(invoiceTransactionType(val)) + } +} + +var ( + invoiceIsFreeTradeZone = transactionTypeIs(func(t TransactionType) bool { return t.FreeTradeZone }) + invoiceIsDeemedSupply = transactionTypeIs(func(t TransactionType) bool { return t.DeemedSupply }) + invoiceIsSummary = transactionTypeIs(func(t TransactionType) bool { return t.Summary }) + invoiceIsDisclosedAgent = transactionTypeIs(func(t TransactionType) bool { return t.DisclosedAgent }) + invoiceIsECommerce = transactionTypeIs(func(t TransactionType) bool { return t.ECommerce }) + invoiceIsExport = transactionTypeIs(func(t TransactionType) bool { return t.Export }) + // invoiceIsSummaryDeemedOrMargin reports the flags outside scope documents + // and credit notes related to goods and services can't have (IBR-157-AE). + invoiceIsSummaryDeemedOrMargin = transactionTypeIs(func(t TransactionType) bool { + return t.Summary || t.DeemedSupply || t.MarginScheme + }) +) diff --git a/addon/pint/transaction_type_test.go b/addon/pint/transaction_type_test.go new file mode 100644 index 0000000..eab5a2b --- /dev/null +++ b/addon/pint/transaction_type_test.go @@ -0,0 +1,79 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestTransactionType(t *testing.T) { + t.Run("each flag has its position", func(t *testing.T) { + tests := map[cbc.Code]pint.TransactionType{ + "10000000": {FreeTradeZone: true}, + "01000000": {DeemedSupply: true}, + "00100000": {MarginScheme: true}, + "00010000": {Summary: true}, + "00001000": {ContinuousSupply: true}, + "00000100": {DisclosedAgent: true}, + "00000010": {ECommerce: true}, + "00000001": {Export: true}, + "00000000": {}, + } + for code, want := range tests { + assert.Equal(t, want, pint.ParseTransactionType(code), code) + assert.Equal(t, code, want.Code(), code) + } + }) + + t.Run("several flags", func(t *testing.T) { + tt := pint.ParseTransactionType("10000101") + assert.Equal(t, pint.TransactionType{FreeTradeZone: true, DisclosedAgent: true, Export: true}, tt) + assert.Equal(t, []cbc.Key{pint.TagFreeTradeZone, pint.TagDisclosedAgent, tax.TagExport}, tt.Tags()) + }) + + t.Run("a missing or short code gives no flags beyond its length", func(t *testing.T) { + assert.Equal(t, pint.TransactionType{}, pint.ParseTransactionType("")) + assert.Equal(t, pint.TransactionType{FreeTradeZone: true}, pint.ParseTransactionType("1")) + }) +} + +func TestNormalizeTransactionType(t *testing.T) { + code := func(inv *bill.Invoice) cbc.Code { + t.Helper() + require.NoError(t, inv.Calculate()) + return inv.Tax.GetExt(pint.ExtKeyTransactionType) + } + + t.Run("no tags give 00000000", func(t *testing.T) { + assert.Equal(t, cbc.Code("00000000"), code(aeDocument(bill.InvoiceTypeStandard))) + }) + + t.Run("tags set their flags", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagSummary, pint.TagECommerce, tax.TagExport) + assert.Equal(t, cbc.Code("00010011"), code(inv)) + }) + + t.Run("a code set directly is kept without tags", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00001000"})} + assert.Equal(t, cbc.Code("00001000"), code(inv)) + }) + + t.Run("tags replace an earlier code", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagContinuousSupply) + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00000000"})} + assert.Equal(t, cbc.Code("00001000"), code(inv)) + }) + + t.Run("only under the AE regime", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + assert.Empty(t, inv.Tax.GetExt(pint.ExtKeyTransactionType)) + }) +} diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index 50a75dc..4e76f41 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "15d328d7e69c3a6e4c13bccadd18b70601356caa61020bd251cf59835d3fbabc" + "val": "5c0282d9bba5f8cdea7c7ed8c1c954e0ed1b54ce34af37afdcd51ca3ee2aa1af" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/ae.go b/ubl/ae.go index f453e66..09a1231 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -46,6 +46,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error return nil } exportAEUUID(out, inv) + exportAETransactionType(out, inv) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -68,6 +69,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } importAEOutsideScope(in, inv) + importAETransactionType(in, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -106,6 +108,72 @@ func exportAEUUID(out *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAETransactionType writes the transaction type as +// cbc:ProfileExecutionID (BTAE-02), and the beneficiary (BTAE-01) and +// principal (BTAE-14) IDs as the only identification of the buyer and seller +// parties, as the PINT AE examples do. +func exportAETransactionType(out *goblubl.Invoice, inv *bill.Invoice) { + out.ProfileExecutionID = inv.Tax.GetExt(pint.ExtKeyTransactionType).String() + if id := inv.Tax.GetExt(pint.ExtKeyBeneficiaryID); id != "" { + out.BuyerCustomerParty = &goblubl.CustomerParty{Party: identifiedParty(id)} + } + if id := inv.Tax.GetExt(pint.ExtKeyPrincipalID); id != "" { + out.SellerSupplierParty = &goblubl.SupplierParty{Party: identifiedParty(id)} + } +} + +// identifiedParty returns a party with only a cac:PartyIdentification. +func identifiedParty(id cbc.Code) *goblubl.Party { + return &goblubl.Party{PartyIdentification: []goblubl.Identification{ + {ID: &goblubl.IDType{Value: id.String()}}, + }} +} + +// importAETransactionType reads back what exportAETransactionType writes. The +// transaction type also sets its flags' tags, so the invoice reads the same +// way a user would write it. +func importAETransactionType(in *goblubl.Invoice, inv *bill.Invoice) { + code := cbc.Code(strings.TrimSpace(in.ProfileExecutionID)) + if code != "" { + setAEExt(inv, pint.ExtKeyTransactionType, code) + for _, tag := range pint.ParseTransactionType(code).Tags() { + if !inv.HasTags(tag) { + inv.Tags.List = append(inv.Tags.List, tag) + } + } + } + if in.BuyerCustomerParty != nil { + setAEExt(inv, pint.ExtKeyBeneficiaryID, partyIdentificationID(in.BuyerCustomerParty.Party)) + } + if in.SellerSupplierParty != nil { + setAEExt(inv, pint.ExtKeyPrincipalID, partyIdentificationID(in.SellerSupplierParty.Party)) + } +} + +// partyIdentificationID returns the party's first cac:PartyIdentification ID. +func partyIdentificationID(p *goblubl.Party) cbc.Code { + if p == nil { + return "" + } + for _, pi := range p.PartyIdentification { + if pi.ID != nil && strings.TrimSpace(pi.ID.Value) != "" { + return cbc.Code(strings.TrimSpace(pi.ID.Value)) + } + } + return "" +} + +// setAEExt sets a tax extension on the invoice, when the value isn't empty. +func setAEExt(inv *bill.Invoice, key cbc.Key, code cbc.Code) { + if code == "" { + return + } + if inv.Tax == nil { + inv.Tax = new(bill.Tax) + } + inv.Tax.Ext = inv.Tax.Ext.Set(key, code) +} + // exportAELines completes the UBL lines, which gobl.ubl writes in the same // order as the invoice's lines. func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 97300bd..5e57810 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -384,6 +384,67 @@ func TestImportAEOutsideScope(t *testing.T) { }) } +func TestExportAETransactionType(t *testing.T) { + invoice := func(ext cbc.CodeMap) *bill.Invoice { + return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(ext)}} + } + + t.Run("writes the code and the beneficiary and principal IDs", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAETransactionType(out, invoice(cbc.CodeMap{ + pint.ExtKeyTransactionType: "10000100", + pint.ExtKeyBeneficiaryID: "189098765401003", + pint.ExtKeyPrincipalID: "155667745601003", + })) + assert.Equal(t, "10000100", out.ProfileExecutionID) + assert.Equal(t, "189098765401003", out.BuyerCustomerParty.Party.PartyIdentification[0].ID.Value) + assert.Equal(t, "155667745601003", out.SellerSupplierParty.Party.PartyIdentification[0].ID.Value) + }) + + t.Run("writes no parties without IDs", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAETransactionType(out, invoice(cbc.CodeMap{pint.ExtKeyTransactionType: "00000000"})) + assert.Equal(t, "00000000", out.ProfileExecutionID) + assert.Nil(t, out.BuyerCustomerParty) + assert.Nil(t, out.SellerSupplierParty) + }) + + t.Run("invoices without tax details are skipped", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAETransactionType(out, new(bill.Invoice)) + assert.Empty(t, out.ProfileExecutionID) + }) +} + +func TestImportAETransactionType(t *testing.T) { + t.Run("reads the code as extension and tags, with the IDs", func(t *testing.T) { + in := &goblubl.Invoice{ + ProfileExecutionID: " 10000101 ", + BuyerCustomerParty: &goblubl.CustomerParty{Party: identifiedParty("189098765401003")}, + SellerSupplierParty: &goblubl.SupplierParty{Party: identifiedParty("155667745601003")}, + } + inv := new(bill.Invoice) + importAETransactionType(in, inv) + assert.Equal(t, cbc.Code("10000101"), inv.Tax.GetExt(pint.ExtKeyTransactionType)) + assert.Equal(t, cbc.Code("189098765401003"), inv.Tax.GetExt(pint.ExtKeyBeneficiaryID)) + assert.Equal(t, cbc.Code("155667745601003"), inv.Tax.GetExt(pint.ExtKeyPrincipalID)) + assert.Equal(t, []cbc.Key{pint.TagFreeTradeZone, pint.TagDisclosedAgent, tax.TagExport}, inv.Tags.List) + }) + + t.Run("existing tags are not repeated", func(t *testing.T) { + inv := &bill.Invoice{Tags: tax.WithTags(tax.TagExport)} + importAETransactionType(&goblubl.Invoice{ProfileExecutionID: "00000001"}, inv) + assert.Equal(t, []cbc.Key{tax.TagExport}, inv.Tags.List) + }) + + t.Run("nothing to read leaves the invoice alone", func(t *testing.T) { + inv := new(bill.Invoice) + importAETransactionType(&goblubl.Invoice{BuyerCustomerParty: &goblubl.CustomerParty{}}, inv) + assert.Nil(t, inv.Tax) + assert.Empty(t, inv.Tags.List) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index 1d85377..586b793 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3e6f3f13ecc2a37565e114fbcb5126cca99dc74674f8a0636fb4ce59b38e3111" + "val": "056e6cb4d6742609524284c496218db7ed6e69cf9e820250374bb4b2099f167e" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -30,6 +30,7 @@ ], "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "381" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json new file mode 100644 index 0000000..3129065 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -0,0 +1,161 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "5d4feec1d19e01d05cc517a85153126b227febba43b6435293f53a06f8bf03a4" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "deemed-supply" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "004", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-transaction-type": "01000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "notes": "Deemed supply, no consideration due" + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index 4f04dcc..bc679ca 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "92c69c6761d75690ded39c92a36a02a5c4804d4fdf8d851bb654909a076af2bb" + "val": "4d287783ced27ec47b8f05ad62b058ad399be54cf1d1787e59ea9e52f8136c6d" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json new file mode 100644 index 0000000..7171098 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -0,0 +1,202 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "16a378b3d56b58f36b3b4dc3cb95719607315b27122fc83a774766dad7dab3f5" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "export", + "summary", + "e-commerce" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "003", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-transaction-type": "00010011", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "1000.00" + } + ], + "ordering": { + "period": { + "start": "2025-01-01", + "end": "2025-01-31" + } + }, + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1000.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "delivery": { + "receiver": { + "name": "Buyer Warehouse", + "addresses": [ + { + "street": "Baker Street 221B", + "locality": "London", + "region": "Greater London", + "code": "NW1 6XE", + "country": "GB" + } + ] + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "1000.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json new file mode 100644 index 0000000..a0f5300 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -0,0 +1,183 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "02c76b4d4da6715d30ae2d9bf51cb81ae6967bf14fa7ad244c5e5417787194ed" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "free-trade-zone", + "disclosed-agent" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "002", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-beneficiary-id": "189098765401003", + "peppol-pint-ae-principal-id": "155667745601003", + "peppol-pint-ae-transaction-type": "10000100", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index e5c09bd..e85b0d0 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "00b7bae531eea00de813a22caa17395b9806b312e3b5e461d876f7f1f22aca24" + "val": "a64ee8d359ca2961aace3256846f379110e6b7a4e2cbd40a1953e94cc1d009b0" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -27,6 +27,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "480" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 1d12e7d..76adf2c 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a4356da693f260a4a73f9a916fc01556667a1a09429ac96c665a3194d4e79abb" + "val": "14bd99bcb0c6322bd83948861f4ac6cef7327f87d563e1ab08da213721774ff7" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 991b2b2..01ebc48 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0961475eacec79b237cb363956a1e019a41e5680155d048b5cf66b266c6cbd1f" + "val": "5d77d4c5781252e9922febdf9929c400ab3eeb7c1fe1ab770b91f53b44086ffa" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index ed5600e..3aa8222 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "6d73d12bd7734f5e18ad68f524a341a0284781ab4184e88394d5fd94290ca169" + "val": "f66432e26e2db15630aa470cee82076c3ea5055e70c43c9e9f6c56b853a46009" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index 2f18235..6de0b62 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f25821e82fde28f7f2c23b2f569035e5e434fbcb3007b4369e5f6bc8aef73950" + "val": "28e3a64f21dd911a12f8ed962bc0a39ee4e5db890f2e76dd0ab3c90cc41f3cb6" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -31,6 +31,7 @@ ], "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 17bc38e..9ace1e7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "15d328d7e69c3a6e4c13bccadd18b70601356caa61020bd251cf59835d3fbabc" + "val": "5c0282d9bba5f8cdea7c7ed8c1c954e0ed1b54ce34af37afdcd51ca3ee2aa1af" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -24,6 +24,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index 6564e99..ade3872 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-CN-001 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml new file mode 100644 index 0000000..3d45f0c --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -0,0 +1,120 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 01000000 + AE-004 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + Deemed supply, no consideration due + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index cee7b6f..833215f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-003 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml new file mode 100644 index 0000000..af68e57 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -0,0 +1,150 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00010011 + AE-003 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + 2025-01-01 + 2025-01-31 + + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + + + Baker Street 221B + London + NW1 6XE + Greater London + + GB + + + + + + Buyer Warehouse + + + Buyer Warehouse + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 0.00 + + 1000.00 + 0.00 + + Z + 0 + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + Z + 0 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1000.00 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml new file mode 100644 index 0000000..463f2ed --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -0,0 +1,139 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 10000100 + AE-002 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + + + 189098765401003 + + + + + + + 155667745601003 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 0fecc1d..406405f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-005 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index a020a08..9c6ab55 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-004 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 7ba6dfd..ca324df 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-002 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index 33a637c..afff5ce 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-AE-TIN-PAS-01 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 95b6fd2..301b5ba 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-006 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 4c011a9..52a6afb 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -2,6 +2,7 @@ urn:peppol:pint:billing-1@ae-1 urn:peppol:bis:billing + 00000000 AE-001 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 diff --git a/ubl/testdata/parse/pint/ae/deemed-supply.xml b/ubl/testdata/parse/pint/ae/deemed-supply.xml new file mode 100644 index 0000000..0ca3fa2 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/deemed-supply.xml @@ -0,0 +1,182 @@ + + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 01000000 + AE-001DS-Test + 08b06931-4698-4ff9-9862-2ebd2901a00c + 2025-02-07 + 380 + Tax invoice + AED + + Sample-05 + + + https://www.site.ae/Sample-05.pdf + + + + + Sample-05 + + KmJzZTY0IGNvbnRlbnQgZXhhbXBsZQ== + + + + + 1246801357 + + Street Name + Sharjah + SHJ + + AE + + + + 124680135701003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email address + + + + + + 1012345678 + + Street Name + Dubai + DXB + + AE + + + + 178901234501003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email Address + + + + + 1 + + + false + 100 + Special Rebate + 5 + 14 + 280 + + S + 5 + + VAT + + + + + 13.3 + false + + 266 + 13.3 + + S + 5 + + VAT + + + + + + 280 + 266 + 279.3 + 14 + 279.3 + + + 1 + 2 + 280 + + Item Description + Item Name + + Service + + + G + 88098432 + + + S + 5 + + VAT + + + + + + 140 + 1 + + false + 10 + 150 + + + + 294 + + 14 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 3d2aa60..ab7f084 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "26852225cd40e952f34adbb5968fdfc855c438f2fc0e56352acc7a2bae60b57c" + "val": "e2c4ce54911e8ac2218ce8390e4095053e79315d7eb4a5230cf22551eefbdbd6" } }, "doc": { @@ -26,6 +26,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "480" } }, diff --git a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json index c36a683..67cb7e0 100644 --- a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "fa655ef144d3127c20bbbd383e5bc5077f42bf1249f8feaf49fb8f31cf06e78a" + "val": "0943e2b9d2e7661f7da67c1932d737eb266483ca6ef8d3c2a46d3ddf6b24d6ce" } }, "doc": { @@ -23,6 +23,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json new file mode 100644 index 0000000..6637752 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -0,0 +1,230 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "bfb3aeb7bc32584b64e3a67be5516ee365f2c95908527df4c1eaf491cc8a251d" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "deemed-supply" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001DS-Test", + "issue_date": "2025-02-07", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "01000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "124680135701003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1246801357" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "178901234501003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1012345678" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2", + "item": { + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "88098432" + } + ], + "description": "Item Description", + "list": "150", + "discount": "10", + "price": "140.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "280.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "280.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "base": "280", + "percent": "5%", + "amount": "14", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "payment": { + "instructions": { + "key": "any", + "detail": "Instrument Not Defined", + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "280.00", + "discount": "14.00", + "total": "266.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "266.00", + "percent": "5%", + "amount": "13.30" + } + ], + "amount": "13.30" + } + ], + "sum": "13.30" + }, + "tax": "13.30", + "total_with_tax": "279.30", + "payable": "279.30" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "Sample-05", + "url": "https://www.site.ae/Sample-05.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 85c8bae..8d1bd3f 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c090983cfc354ad2f6c11752f73f1eff551897fa246ad51d121171c282118493" + "val": "a970b1ede98ea9a69dfa54dd67531235a63bfe52f9bb29e1a9cbf491b84349c8" } }, "doc": { @@ -22,6 +22,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json index 0efa096..22d93ca 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "75991753b00d053853430037bab2f81cbdd44f0fec6b6aa00844ef25d1cc437c" + "val": "d8858ddd18559301d6d750bc12ca4ae8b47f13c60c9b9df6cee38fbf98a2cd0c" } }, "doc": { @@ -23,6 +23,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json index e4ae1c6..c4f18ea 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f54c8bbf372d9d4409c59110b5b98f4f12aced96e73d14c40bd21080203af780" + "val": "ef828a7a23f309e10f072ccb254218defc1368976eccace823a97aff688cca02" } }, "doc": { @@ -23,6 +23,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json index ff2773f..532158c 100644 --- a/ubl/testdata/parse/pint/ae/out/standard-invoice.json +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7ee647f445f574918e7d783b82fd3a3368263a7dd05486a632e38999b4683331" + "val": "5274a8aa0a6a11c3d1796d2df3372bf4c3d9458babbfb972dd970e04f6bdcab7" } }, "doc": { @@ -22,6 +22,7 @@ "tax": { "rounding": "currency", "ext": { + "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" } }, diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json new file mode 100644 index 0000000..7736dff --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -0,0 +1,264 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "9049e38006f38c835aa5868ac295abed694f299b1770fb468dd5cbfc34da89a5" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "free-trade-zone" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001FTZ-TEST", + "issue_date": "2025-02-07", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-beneficiary-id": "189098765401003", + "peppol-pint-ae-transaction-type": "10000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "124680135701003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1246801357" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "178901234501003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1789012345" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "500", + "item": { + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "112233" + } + ], + "description": "Item Description", + "list": "150", + "discount": "10", + "price": "140.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "70000.00", + "charges": [ + { + "reason": "Technical Modification", + "base": "70000.00", + "percent": "1%", + "amount": "700.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "70700.00", + "notes": [ + { + "text": "Invoice line note" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "base": "70700", + "percent": "5%", + "amount": "3535", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-07", + "amount": "70523.25", + "percent": "100%" + } + ], + "notes": "1 month" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "70700.00", + "discount": "3535.00", + "total": "67165.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "67165.00", + "percent": "5%", + "amount": "3358.25" + } + ], + "amount": "3358.25" + } + ], + "sum": "3358.25" + }, + "tax": "3358.25", + "total_with_tax": "70523.25", + "payable": "70523.25" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "Sample-04", + "url": "https://www.site.ae/Sample-04.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/supply-free-trade-zone.xml b/ubl/testdata/parse/pint/ae/supply-free-trade-zone.xml new file mode 100644 index 0000000..4d19232 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/supply-free-trade-zone.xml @@ -0,0 +1,188 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 10000000 + AE-001FTZ-TEST + 3666341e-86b7-4f4d-a14f-dd56d59b7606 + 2025-02-07 + 2025-03-07 + 380 + Tax invoice + AED + + Sample-04 + + + https://www.site.ae/Sample-04.pdf + + + + + Sample-04 + + JmFzZTY0IKNvbnRlbnQgZXhhbXBsZQ== + + + + + 1246801357 + + Street Name + Sharjah + SHJ + + AE + + + + 124680135701003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email Address + + + + + + 1789012345 + + Street Name + Dubai + DXB + + AE + + + + 178901234501003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email address + + + + + + + 189098765401003 + + + + + 30 + + AE0000000001 + current account + + 236000 + + + + + 1 month + + + false + 100 + Special Rebate + 5 + 3535 + 70700 + + S + 5 + + VAT + + + + + 3358.25 + false + + 67165 + 3358.25 + + S + 5 + + VAT + + + + + + 70700 + 67165 + 70523.25 + 3535 + 70523.25 + + + 1 + Invoice line note + 500 + 70700 + + true + AAC + Technical Modification + 1 + 700 + 70000 + + + Item Description + Item Name + + G + 112233 + + + S + 5 + + VAT + + + + + 140 + 1 + + false + 10 + 150 + + + + 74235 + + 3535 + + + + \ No newline at end of file From 4855ee0d7008b39927be35b44f840002da72b1f9 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:21:29 +0000 Subject: [PATCH 10/73] Add the PINT AE credit note reason - Add the credit note reason extension (BTAE-03) with the Reasons for credit note code list (IBR-001-AE). - Require it on 381 and 81 credit notes (IBR-158-AE, IBR-055-AE), and require a preceding invoice except for volume discounts, which must have none (IBR-055-AE). - Write it as cac:DiscrepancyResponse on credit notes and read it back. Needs cac:DiscrepancyResponse from gobl.ubl#189. --- README.md | 7 +- addon/pint/bill.go | 55 ++++++ addon/pint/bill_test.go | 65 +++++++ addon/pint/extensions.go | 46 +++++ ubl/ae.go | 27 +++ ubl/ae_internal_test.go | 40 +++++ .../ae/credit-note-ae-volume-discount.json | 168 ++++++++++++++++++ .../convert/pint/ae/credit-note-ae.json | 3 +- .../ae/out/credit-note-ae-volume-discount.xml | 127 +++++++++++++ .../convert/pint/ae/out/credit-note-ae.xml | 3 + 10 files changed, 537 insertions(+), 4 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json create mode 100644 ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml diff --git a/README.md b/README.md index 1f0cddf..397a452 100644 --- a/README.md +++ b/README.md @@ -114,11 +114,12 @@ regime's identity keys and `passport`), with the trade licence authority (the identity's description) or the passport's issuing country, and the seller's TIN goes under the `TIN` tax scheme. It also writes the transaction type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and -the disclosed agent's principal as the buyer and seller parties. On import, it reads +the disclosed agent's principal as the buyer and seller parties, and the +credit note reason as `cac:DiscrepancyResponse`. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as -identity keys and fields, and the transaction type back as its extension and -tags. +identity keys and fields, the transaction type back as its extension and +tags, and the credit note reason back as its extension. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 9a0b543..236a540 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -300,6 +300,39 @@ func billInvoiceRules() *rules.Set { ), ), ), + // IBR-158-AE only names 381, but IBR-055-AE's test fails 81 credit + // notes without a reason too, whether or not they have a preceding + // invoice, so both need one. + rules.When( + is.Func("document type is credit note or credit note related to goods and services", + documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices)), + rules.Assert("45", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + is.Func("has credit note reason", invoiceHasExt(ExtKeyCreditNoteReason)), + ), + rules.When( + is.Func("credit note reason is not volume discount", creditNoteReasonIsNotVolumeDiscount), + rules.Field("preceding", + rules.Assert("46", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + is.Present, + ), + ), + ), + rules.When( + is.Func("credit note reason is volume discount", creditNoteReasonIs(CreditNoteReasonVolumeDiscount)), + rules.Field("preceding", + rules.Assert("47", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + is.Not(is.Present), + ), + ), + ), + ), + rules.Field("tax", + rules.Field("ext", + rules.Assert("48", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), + ), + ), + ), ), ) } @@ -813,6 +846,28 @@ func partyHasIdentificationOrTaxRegistration(val any) bool { return false } +// creditNoteReasonIsNotVolumeDiscount reports whether the invoice has a +// credit note reason other than volume discount, the reasons that need a +// preceding invoice (IBR-055-AE). Invoices without a reason fail, as rule 45 +// reports them. +func creditNoteReasonIsNotVolumeDiscount(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + reason := inv.Tax.GetExt(ExtKeyCreditNoteReason) + return reason != "" && reason != CreditNoteReasonVolumeDiscount +} + +// creditNoteReasonIs returns a predicate that reports whether the invoice's +// credit note reason is the given code. +func creditNoteReasonIs(code cbc.Code) func(any) bool { + return func(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Tax.GetExt(ExtKeyCreditNoteReason) == code + } +} + // taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). // It fails on any other value, so a type mismatch can't pass silently. func taxesHaveVAT(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 828efc2..29fc67f 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -239,6 +239,7 @@ func aeDocument(typ cbc.Key, tags ...cbc.Key) *bill.Invoice { } if typ == bill.InvoiceTypeCreditNote { inv.Preceding = []*org.DocumentRef{{Code: "INV-001"}} + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyCreditNoteReason: "DL8.61.1.E"})} } due := cal.MakeDate(2026, 12, 10) inv.Payment = &bill.PaymentDetails{ @@ -883,6 +884,70 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { }) } +func TestBillCreditNoteReasonRulesAE(t *testing.T) { + const ( + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + ) + withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { + if inv.Tax == nil { + inv.Tax = new(bill.Tax) + } + inv.Tax.Ext = inv.Tax.Ext.Set(pint.ExtKeyCreditNoteReason, code) + return inv + } + + t.Run("credit note needs a reason (IBR-158-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeCreditNote) + inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyCreditNoteReason) + out := aeFaults(t, inv) + assert.Contains(t, out, faultReasonRequired) + assert.NotContains(t, out, faultPrecedingMissing) + assert.NotContains(t, out, faultPrecedingVD) + }) + + t.Run("credit note related to goods and services needs a reason (IBR-055-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyCreditNoteReason) + assert.Contains(t, aeFaults(t, inv), faultReasonRequired) + }) + + t.Run("invoices and self-billed credit notes need no reason", func(t *testing.T) { + assert.NotContains(t, aeFaults(t, aeDocument(bill.InvoiceTypeStandard)), faultReasonRequired) + inv := aeDocument(bill.InvoiceTypeCreditNote, tax.TagSelfBilled) + inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyCreditNoteReason) + assert.NotContains(t, aeFaults(t, inv), faultReasonRequired) + }) + + t.Run("credit note needs a preceding invoice, except for volume discounts (IBR-055-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeCreditNote) + inv.Preceding = nil + assert.Contains(t, aeFaults(t, inv), faultPrecedingMissing) + + inv = withReason(aeDocument(bill.InvoiceTypeCreditNote), pint.CreditNoteReasonVolumeDiscount) + inv.Preceding = nil + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("volume discount credit note has no preceding invoice (IBR-055-AE)", func(t *testing.T) { + inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), pint.CreditNoteReasonVolumeDiscount) + out := aeFaults(t, inv) + assert.Contains(t, out, faultPrecedingVD) + assert.NotContains(t, out, faultPrecedingMissing) + }) + + t.Run("reason must be from the code list (IBR-001-AE)", func(t *testing.T) { + for _, code := range []cbc.Code{"DL8.61.1.A", "DL8.61.1.B", "DL8.61.1.C", "DL8.61.1.D", "DL8.61.1.E"} { + inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), code) + assert.Empty(t, aeFaults(t, inv), code) + } + inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), "DL8.61.1.F") + assert.Contains(t, aeFaults(t, inv), faultReasonCode) + }) +} + func TestBillLineRulesAE(t *testing.T) { const ( faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index aa5f5e4..73b06bd 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -16,8 +16,14 @@ const ( // ExtKeyPrincipalID is the ID of the principal a disclosed agent bills for // (BTAE-14). ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" + // ExtKeyCreditNoteReason is the reason for a PINT AE credit note (BTAE-03). + ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" ) +// CreditNoteReasonVolumeDiscount is the credit note reason for a volume +// discount, the only one that needs no preceding invoice (IBR-055-AE). +const CreditNoteReasonVolumeDiscount cbc.Code = "VD" + // extensions are the extensions the PINT addon defines. They are only used // on UAE documents. var extensions = []*cbc.Definition{ @@ -72,4 +78,44 @@ var extensions = []*cbc.Definition{ `), }, }, + { + Key: ExtKeyCreditNoteReason, + Name: i18n.String{ + i18n.EN: "PINT AE Credit Note Reason", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Reason for a PINT AE credit note (BTAE-03), from the Reasons for credit + note code list. Required on credit notes (IBR-158-AE). Volume discounts + ("VD") have no preceding invoice; every other reason needs one + (IBR-055-AE). + `), + }, + Values: []*cbc.Definition{ + { + Code: "DL8.61.1.A", + Name: i18n.String{i18n.EN: "If the supply was cancelled."}, + }, + { + Code: "DL8.61.1.B", + Name: i18n.String{i18n.EN: "If the tax treatment of the supply has changed due to a change in the nature of the supply."}, + }, + { + Code: "DL8.61.1.C", + Name: i18n.String{i18n.EN: "If the previously agreed consideration for the supply was altered for any reason (i.e. bad debt relief)."}, + }, + { + Code: "DL8.61.1.D", + Name: i18n.String{i18n.EN: "If the recipient of goods or recipient of services returned them to the registrant in full or in part and the Consideration was returned in full or in part."}, + }, + { + Code: "DL8.61.1.E", + Name: i18n.String{i18n.EN: "If the tax was charged or tax treatment was applied in error."}, + }, + { + Code: CreditNoteReasonVolumeDiscount, + Name: i18n.String{i18n.EN: "Volume Discount."}, + }, + }, + }, } diff --git a/ubl/ae.go b/ubl/ae.go index 09a1231..351900c 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -47,6 +47,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error } exportAEUUID(out, inv) exportAETransactionType(out, inv) + exportAECreditNoteReason(out, inv) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -70,6 +71,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error } importAEOutsideScope(in, inv) importAETransactionType(in, inv) + importAECreditNoteReason(in, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -174,6 +176,31 @@ func setAEExt(inv *bill.Invoice, key cbc.Key, code cbc.Code) { inv.Tax.Ext = inv.Tax.Ext.Set(key, code) } +// exportAECreditNoteReason writes the credit note reason as +// cac:DiscrepancyResponse/cbc:ResponseCode (BTAE-03). UBL 2.1 only allows it +// on credit notes. +func exportAECreditNoteReason(out *goblubl.Invoice, inv *bill.Invoice) { + reason := inv.Tax.GetExt(pint.ExtKeyCreditNoteReason) + if reason == "" || out.CreditNoteTypeCode == nil { + return + } + out.DiscrepancyResponse = []goblubl.Response{ + {ResponseCode: &goblubl.IDType{Value: reason.String()}}, + } +} + +// importAECreditNoteReason reads the first credit note reason back. PINT AE +// examples can repeat the element, as the volume discount one does with VD +// then DL8.61.1.E; GOBL keeps one reason, the first. +func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { + for _, r := range in.DiscrepancyResponse { + if r.ResponseCode != nil && strings.TrimSpace(r.ResponseCode.Value) != "" { + setAEExt(inv, pint.ExtKeyCreditNoteReason, cbc.Code(strings.TrimSpace(r.ResponseCode.Value))) + return + } + } +} + // exportAELines completes the UBL lines, which gobl.ubl writes in the same // order as the invoice's lines. func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 5e57810..2ca97a2 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -445,6 +445,46 @@ func TestImportAETransactionType(t *testing.T) { }) } +func TestAECreditNoteReason(t *testing.T) { + invoice := func(reason cbc.Code) *bill.Invoice { + return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyCreditNoteReason: reason})}} + } + creditNote := func() *goblubl.Invoice { + return &goblubl.Invoice{CreditNoteTypeCode: &goblubl.IDType{Value: "381"}} + } + + t.Run("writes the reason on credit notes", func(t *testing.T) { + out := creditNote() + exportAECreditNoteReason(out, invoice("VD")) + require.Len(t, out.DiscrepancyResponse, 1) + assert.Equal(t, "VD", out.DiscrepancyResponse[0].ResponseCode.Value) + }) + + t.Run("never on invoices, which UBL doesn't allow it on", func(t *testing.T) { + out := &goblubl.Invoice{InvoiceTypeCode: &goblubl.IDType{Value: "380"}} + exportAECreditNoteReason(out, invoice("VD")) + assert.Empty(t, out.DiscrepancyResponse) + }) + + t.Run("nothing without a reason", func(t *testing.T) { + out := creditNote() + exportAECreditNoteReason(out, new(bill.Invoice)) + assert.Empty(t, out.DiscrepancyResponse) + }) + + t.Run("reads the first reason back", func(t *testing.T) { + in := creditNote() + in.DiscrepancyResponse = []goblubl.Response{ + {}, + {ResponseCode: &goblubl.IDType{Value: " VD "}}, + {ResponseCode: &goblubl.IDType{Value: "DL8.61.1.E"}}, + } + inv := new(bill.Invoice) + importAECreditNoteReason(in, inv) + assert.Equal(t, cbc.Code("VD"), inv.Tax.GetExt(pint.ExtKeyCreditNoteReason)) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json new file mode 100644 index 0000000..4928100 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -0,0 +1,168 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "e7a15773211970c27660a0838c8448a9b57d9ddd60c4b8716a28edf8b1ef98b5" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "series": "AE", + "code": "CN-VD-001", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-credit-note-reason": "VD", + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "381" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index 586b793..2daa16b 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "056e6cb4d6742609524284c496218db7ed6e69cf9e820250374bb4b2099f167e" + "val": "24fcff53f09d9db79f270edf12997196e22b4419a9bc1eee1c632c9eee26e40d" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -30,6 +30,7 @@ ], "tax": { "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "381" } diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml new file mode 100644 index 0000000..cd36887 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -0,0 +1,127 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CN-VD-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 381 + AED + + VD + + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index ade3872..6083427 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -8,6 +8,9 @@ 2025-01-30 381 AED + + DL8.61.1.E + NA From 5e173e17004b0650196829aa1307626e4e33a8bd Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:33:05 +0000 Subject: [PATCH 11/73] Add the PINT AE billing frequency - Add the billing frequency extension (BTAE-06) with the frequency of billing code list (IBR-005-AE), and require a note with Others (IBR-160-AE). - Reject a tax point on UAE invoices: its code goes in the element that holds the billing frequency, which only accepts frequencies (IBR-005-AE). - Write it as cac:InvoicePeriod/cbc:DescriptionCode and read it back. --- README.md | 6 +- addon/pint/bill.go | 28 +++ addon/pint/bill_test.go | 43 ++++ addon/pint/extensions.go | 31 +++ ubl/ae.go | 27 +++ ubl/ae_internal_test.go | 38 ++++ .../pint/ae/invoice-ae-continuous-supply.json | 192 ++++++++++++++++++ .../ae/out/invoice-ae-continuous-supply.xml | 131 ++++++++++++ 8 files changed, 494 insertions(+), 2 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml diff --git a/README.md b/README.md index 397a452..c1867c8 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,13 @@ regime's identity keys and `passport`), with the trade licence authority seller's TIN goes under the `TIN` tax scheme. It also writes the transaction type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and the disclosed agent's principal as the buyer and seller parties, and the -credit note reason as `cac:DiscrepancyResponse`. On import, it reads +credit note reason as `cac:DiscrepancyResponse` and the billing frequency in +`cac:InvoicePeriod`. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and -tags, and the credit note reason back as its extension. +tags, and the credit note reason and billing frequency back as their +extensions. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 236a540..ca5ca8a 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -331,6 +331,25 @@ func billInvoiceRules() *rules.Set { rules.Assert("48", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), + rules.Assert("49", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + tax.ExtensionHasValidCode(ExtKeyBillingFrequency), + ), + ), + // PINT AE writes the billing frequency where EN writes the VAT + // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, + // and IBR-005-AE only accepts frequencies there. + rules.Field("point", + rules.Assert("50", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + is.Not(is.Present), + ), + ), + ), + rules.When( + is.Func("billing frequency is Others", billingFrequencyIs(BillingFrequencyOthers)), + rules.Field("notes", + rules.Assert("51", "a note is required with the billing frequency Others (IBR-160-AE)", + is.Present, + ), ), ), ), @@ -868,6 +887,15 @@ func creditNoteReasonIs(code cbc.Code) func(any) bool { } } +// billingFrequencyIs returns a predicate that reports whether the invoice's +// billing frequency is the given code. +func billingFrequencyIs(code cbc.Code) func(any) bool { + return func(val any) bool { + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.Tax.GetExt(ExtKeyBillingFrequency) == code + } +} + // taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). // It fails on any other value, so a type mismatch can't pass silently. func taxesHaveVAT(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 29fc67f..dbc64d9 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -948,6 +948,49 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { }) } +func TestBillBillingFrequencyRulesAE(t *testing.T) { + const ( + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + ) + withFrequency := func(code cbc.Code) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBillingFrequency: code})} + return inv + } + + t.Run("frequency must be from the code list (IBR-005-AE)", func(t *testing.T) { + for _, code := range []cbc.Code{"DLY", "WKY", "Q15", "MTH", "Q45", "Q60", "QTR", "YRL", "HYR"} { + assert.Empty(t, aeFaults(t, withFrequency(code)), code) + } + assert.Contains(t, aeFaults(t, withFrequency("FTN")), faultFrequencyCode) + }) + + t.Run("Others needs a note (IBR-160-AE)", func(t *testing.T) { + inv := withFrequency(pint.BillingFrequencyOthers) + assert.Contains(t, aeFaults(t, inv), faultOthersNote) + inv.Notes = []*org.Note{{Text: "Every 3 weeks"}} + assert.Empty(t, aeFaults(t, inv)) + }) + + t.Run("tax point can't be set, as it would take the frequency's place (IBR-005-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Tax = &bill.Tax{Point: tax.PointIssue} + assert.Contains(t, aeFaults(t, inv), faultTaxPoint) + }) + + t.Run("tax point is fine outside the UAE", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + inv.Tax = &bill.Tax{Point: tax.PointIssue} + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + if err != nil { + assert.NotContains(t, err.Error(), faultTaxPoint) + } + }) +} + func TestBillLineRulesAE(t *testing.T) { const ( faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 73b06bd..8e9f8f3 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -18,12 +18,18 @@ const ( ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" // ExtKeyCreditNoteReason is the reason for a PINT AE credit note (BTAE-03). ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" + // ExtKeyBillingFrequency is the frequency of billing (BTAE-06). + ExtKeyBillingFrequency cbc.Key = "peppol-pint-ae-billing-frequency" ) // CreditNoteReasonVolumeDiscount is the credit note reason for a volume // discount, the only one that needs no preceding invoice (IBR-055-AE). const CreditNoteReasonVolumeDiscount cbc.Code = "VD" +// BillingFrequencyOthers is the billing frequency "Others", whose value goes +// in an invoice note (IBR-160-AE). +const BillingFrequencyOthers cbc.Code = "OTH" + // extensions are the extensions the PINT addon defines. They are only used // on UAE documents. var extensions = []*cbc.Definition{ @@ -118,4 +124,29 @@ var extensions = []*cbc.Definition{ }, }, }, + { + Key: ExtKeyBillingFrequency, + Name: i18n.String{ + i18n.EN: "PINT AE Frequency of Billing", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Frequency of billing (BTAE-06), from the frequency of billing code list + (IBR-005-AE). With "OTH" (Others), the frequency is given in an invoice + note (IBR-160-AE). + `), + }, + Values: []*cbc.Definition{ + {Code: "DLY", Name: i18n.String{i18n.EN: "Daily"}}, + {Code: "WKY", Name: i18n.String{i18n.EN: "Weekly"}}, + {Code: "Q15", Name: i18n.String{i18n.EN: "Once in 15 days"}}, + {Code: "MTH", Name: i18n.String{i18n.EN: "Monthly"}}, + {Code: "Q45", Name: i18n.String{i18n.EN: "Once in 45 days"}}, + {Code: "Q60", Name: i18n.String{i18n.EN: "Once in 60 days"}}, + {Code: "QTR", Name: i18n.String{i18n.EN: "Quarterly"}}, + {Code: "YRL", Name: i18n.String{i18n.EN: "Yearly"}}, + {Code: "HYR", Name: i18n.String{i18n.EN: "Half-Yearly"}}, + {Code: BillingFrequencyOthers, Name: i18n.String{i18n.EN: "Others"}}, + }, + }, } diff --git a/ubl/ae.go b/ubl/ae.go index 351900c..5a13559 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -48,6 +48,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAEUUID(out, inv) exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) + exportAEBillingFrequency(out, inv) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -72,6 +73,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAEOutsideScope(in, inv) importAETransactionType(in, inv) importAECreditNoteReason(in, inv) + importAEBillingFrequency(in, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -201,6 +203,31 @@ func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAEBillingFrequency writes the billing frequency as +// cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl +// writes from the ordering period, or on its own: IBR-CO-19 accepts a period +// with only a description code. +func exportAEBillingFrequency(out *goblubl.Invoice, inv *bill.Invoice) { + freq := inv.Tax.GetExt(pint.ExtKeyBillingFrequency) + if freq == "" { + return + } + if len(out.InvoicePeriod) == 0 { + out.InvoicePeriod = []goblubl.Period{{}} + } + out.InvoicePeriod[0].DescriptionCode = freq.String() +} + +// importAEBillingFrequency reads the billing frequency back. The frequency +// codes don't overlap the VAT point date codes gobl.ubl reads from the same +// element, so it never sets a tax point from them. +func importAEBillingFrequency(in *goblubl.Invoice, inv *bill.Invoice) { + if len(in.InvoicePeriod) == 0 { + return + } + setAEExt(inv, pint.ExtKeyBillingFrequency, cbc.Code(strings.TrimSpace(in.InvoicePeriod[0].DescriptionCode))) +} + // exportAELines completes the UBL lines, which gobl.ubl writes in the same // order as the invoice's lines. func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 2ca97a2..a2ac7ac 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -485,6 +485,44 @@ func TestAECreditNoteReason(t *testing.T) { }) } +func TestAEBillingFrequency(t *testing.T) { + invoice := func(freq cbc.Code) *bill.Invoice { + return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBillingFrequency: freq})}} + } + + t.Run("writes the frequency on the ordering period", func(t *testing.T) { + out := &goblubl.Invoice{InvoicePeriod: []goblubl.Period{{StartDate: "2025-01-01", EndDate: "2025-01-31"}}} + exportAEBillingFrequency(out, invoice("MTH")) + require.Len(t, out.InvoicePeriod, 1) + assert.Equal(t, "MTH", out.InvoicePeriod[0].DescriptionCode) + assert.Equal(t, "2025-01-01", out.InvoicePeriod[0].StartDate) + }) + + t.Run("writes a period of its own without an ordering period", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEBillingFrequency(out, invoice("QTR")) + require.Len(t, out.InvoicePeriod, 1) + assert.Equal(t, "QTR", out.InvoicePeriod[0].DescriptionCode) + }) + + t.Run("nothing without a frequency", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEBillingFrequency(out, new(bill.Invoice)) + assert.Empty(t, out.InvoicePeriod) + }) + + t.Run("reads the frequency back", func(t *testing.T) { + in := &goblubl.Invoice{InvoicePeriod: []goblubl.Period{{DescriptionCode: " OTH "}}} + inv := new(bill.Invoice) + importAEBillingFrequency(in, inv) + assert.Equal(t, cbc.Code("OTH"), inv.Tax.GetExt(pint.ExtKeyBillingFrequency)) + + inv = new(bill.Invoice) + importAEBillingFrequency(new(goblubl.Invoice), inv) + assert.Nil(t, inv.Tax) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json new file mode 100644 index 0000000..e784376 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -0,0 +1,192 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "8fd1920993fcd36db4c3c18a41ce7cb7cc07d01d356285c856a13ef122d6530b" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "continuous-supply" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "005", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-billing-frequency": "OTH", + "peppol-pint-ae-transaction-type": "00001000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "ordering": { + "period": { + "start": "2025-01-01", + "end": "2025-01-21" + } + }, + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + }, + "notes": [ + { + "text": "Billed every 3 weeks" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml new file mode 100644 index 0000000..11e36f1 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -0,0 +1,131 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00001000 + AE-005 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + Billed every 3 weeks + AED + + 2025-01-01 + 2025-01-21 + OTH + + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file From ca2a6f0a87421b15f36e09bed5d87f8d0b3108a8 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:02:23 +0000 Subject: [PATCH 12/73] Add the PINT AE exemption reason codes - Add the UAE VAT exemption reason extension, and require it on exempt lines (IBR-167-AE). - Require a reason code on exempt discounts and charges, as the IBR-168-AE and IBR-169-AE tests check. - Write it as the line's tax exemption reason code and read it back. - Explain why the billing frequency is written as the period's description code. Needs the line exemption reason code from gobl.ubl#189. --- README.md | 8 +-- addon/pint/bill.go | 65 +++++++++++++++++++ addon/pint/bill_test.go | 60 +++++++++++++++++ addon/pint/extensions.go | 23 +++++++ ubl/ae.go | 42 ++++++++++++ ubl/ae_internal_test.go | 49 ++++++++++++++ .../convert/pint/ae/invoice-ae-exempt.json | 22 ++++++- .../convert/pint/ae/invoice-ae-usd.json | 4 +- .../convert/pint/ae/out/invoice-ae-exempt.xml | 3 + .../convert/pint/ae/out/invoice-ae-usd.xml | 1 + .../parse/pint/ae/out/allowance-exempt.json | 14 +++- 11 files changed, 281 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c1867c8..821ea04 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,13 @@ regime's identity keys and `passport`), with the trade licence authority seller's TIN goes under the `TIN` tax scheme. It also writes the transaction type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and the disclosed agent's principal as the buyer and seller parties, and the -credit note reason as `cac:DiscrepancyResponse` and the billing frequency in -`cac:InvoicePeriod`. On import, it reads +credit note reason as `cac:DiscrepancyResponse`, the billing frequency in +`cac:InvoicePeriod`, and the UAE VAT exemption reason of exempt lines. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and -tags, and the credit note reason and billing frequency back as their -extensions. +tags, and the credit note reason, billing frequency and line exemption +reasons back as their extensions. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index ca5ca8a..6e2637e 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -352,6 +352,29 @@ func billInvoiceRules() *rules.Set { ), ), ), + // IBR-168-AE and IBR-169-AE name the exemption reason code (IBT-196, + // IBT-198), but their tests check the allowance or charge reason code, + // cbc:AllowanceChargeReasonCode. We follow the tests. + rules.Field("discounts", rules.Each( + rules.When( + is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), + rules.Field("ext", + rules.Assert("52", "exempt discount needs an allowance reason code (IBR-168-AE)", + tax.ExtensionsRequire(untdid.ExtKeyAllowance), + ), + ), + ), + )), + rules.Field("charges", rules.Each( + rules.When( + is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), + rules.Field("ext", + rules.Assert("53", "exempt charge needs a charge reason code (IBR-169-AE)", + tax.ExtensionsRequire(untdid.ExtKeyCharge), + ), + ), + ), + )), ), ) } @@ -373,6 +396,16 @@ func billLineRules() *rules.Set { rules.Assert("02", "item description is required (IBR-125-AE)", is.Present), ), ), + rules.Field("taxes", rules.Each( + rules.When( + is.Func("exempt VAT", comboIsExemptVAT), + rules.Field("ext", + rules.Assert("03", "exempt line needs a UAE VAT exemption reason (IBR-167-AE)", + tax.ExtensionsRequire(ExtKeyExemption), + ), + ), + ), + )), ), ) } @@ -896,6 +929,38 @@ func billingFrequencyIs(code cbc.Code) func(any) bool { } } +// comboIsExemptVAT reports whether a tax combo is VAT with the exempt +// category code E. +func comboIsExemptVAT(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && c.Category == tax.CategoryVAT && + c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryExempt +} + +// taxesIn returns a predicate that reports whether a discount or charge has +// a tax combo that check accepts. +func taxesIn(check func(any) bool) func(any) bool { + return func(val any) bool { + var set tax.Set + switch v := val.(type) { + case *bill.Discount: + if v != nil { + set = v.Taxes + } + case *bill.Charge: + if v != nil { + set = v.Taxes + } + } + for _, c := range set { + if check(c) { + return true + } + } + return false + } +} + // taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). // It fails on any other value, so a type mismatch can't pass silently. func taxesHaveVAT(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index dbc64d9..00bc97a 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -991,6 +991,66 @@ func TestBillBillingFrequencyRulesAE(t *testing.T) { }) } +func TestBillExemptionRulesAE(t *testing.T) { + const ( + faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" + faultDiscountReason = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultChargeReason = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + ) + exempt := func(code cbc.Code) *tax.Combo { + c := lineCombo(tax.KeyExempt) + if code != "" { + c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + } + return c + } + + t.Run("exempt line needs a UAE exemption reason (IBR-167-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{exempt("")} + assert.Contains(t, aeFaults(t, inv), faultLineExemption) + + // IBR-167-AE only checks a code is there, so codes outside the AE + // list, like the official examples' VATEX-AE-EDU, are accepted. + for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4", "VATEX-AE-EDU"} { + inv = aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{exempt(code)} + assert.NotContains(t, aeFaults(t, inv), faultLineExemption, code) + } + }) + + t.Run("other categories need no exemption reason", func(t *testing.T) { + assert.NotContains(t, aeFaults(t, aeDocument(bill.InvoiceTypeStandard)), faultLineExemption) + }) + + t.Run("exempt discount needs an allowance reason code (IBR-168-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("DL8.46.1")}}} + assert.Contains(t, aeFaults(t, inv), faultDiscountReason) + + inv.Discounts[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyAllowance: "95"}) + assert.NotContains(t, aeFaults(t, inv), faultDiscountReason) + }) + + t.Run("exempt charge needs a charge reason code (IBR-169-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("DL8.46.1")}}} + assert.Contains(t, aeFaults(t, inv), faultChargeReason) + + inv.Charges[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyCharge: "AAT"}) + assert.NotContains(t, aeFaults(t, inv), faultChargeReason) + }) + + t.Run("standard rated discounts and charges need no reason code", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} + inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} + out := aeFaults(t, inv) + assert.NotContains(t, out, faultDiscountReason) + assert.NotContains(t, out, faultChargeReason) + }) +} + func TestBillLineRulesAE(t *testing.T) { const ( faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 8e9f8f3..217575f 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -20,6 +20,9 @@ const ( ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" // ExtKeyBillingFrequency is the frequency of billing (BTAE-06). ExtKeyBillingFrequency cbc.Key = "peppol-pint-ae-billing-frequency" + // ExtKeyExemption is the UAE VAT exemption reason of an exempt tax combo + // (IBT-186 on lines). + ExtKeyExemption cbc.Key = "peppol-pint-ae-exemption" ) // CreditNoteReasonVolumeDiscount is the credit note reason for a volume @@ -149,4 +152,24 @@ var extensions = []*cbc.Definition{ {Code: BillingFrequencyOthers, Name: i18n.String{i18n.EN: "Others"}}, }, }, + { + Key: ExtKeyExemption, + Name: i18n.String{ + i18n.EN: "PINT AE VAT Exemption Reason", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Reason a supply is exempt from UAE VAT, such as one of the PINT AE + "Reasons for exemption from tax" codes (DL8.46.1 to DL8.46.4). + Required on exempt lines (IBR-167-AE), where it is written as the + line's exemption reason code. + `), + }, + Sources: []*cbc.Source{ + { + Title: i18n.NewString("PINT AE Reasons for exemption from tax"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/codelist/Aligned-TaxExemptionCodes/", + }, + }, + }, } diff --git a/ubl/ae.go b/ubl/ae.go index 5a13559..22578ee 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -74,6 +74,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAETransactionType(in, inv) importAECreditNoteReason(in, inv) importAEBillingFrequency(in, inv) + importAELineExemptions(in.InvoiceLines, inv) + importAELineExemptions(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -203,10 +205,49 @@ func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAELineExemption writes the UAE VAT exemption reason of an exempt line +// as its cac:ClassifiedTaxCategory/cbc:TaxExemptionReasonCode (IBT-186, +// IBR-167-AE). +func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil || line.Item == nil || line.Item.ClassifiedTaxCategory == nil { + return + } + c := l.Taxes.Get(tax.CategoryVAT) + if c == nil { + return + } + if code := c.Ext.Get(pint.ExtKeyExemption); code != "" { + v := code.String() + line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &v + } +} + +// importAELineExemptions reads the line exemption reasons back onto the VAT +// combos of the invoice's lines, which gobl.ubl imports in the same order. +func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + if len(lines) == 0 || len(lines) != len(inv.Lines) { + return + } + for i, line := range lines { + if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || + line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode == nil { + continue + } + code := cbc.Code(strings.TrimSpace(*line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode)) + if c := inv.Lines[i].Taxes.Get(tax.CategoryVAT); c != nil && code != "" { + c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + } + } +} + // exportAEBillingFrequency writes the billing frequency as // cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl // writes from the ordering period, or on its own: IBR-CO-19 accepts a period // with only a description code. +// +// The PINT AE syntax binds BTAE-06 to cbc:Description, but the IBR-005-AE +// and IBR-160-AE tests read cbc:DescriptionCode, so we follow the tests. The +// official examples use both. func exportAEBillingFrequency(out *goblubl.Invoice, inv *bill.Invoice) { freq := inv.Tax.GetExt(pint.ExtKeyBillingFrequency) if freq == "" { @@ -235,6 +276,7 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { exportAELine(&lines[i]) if len(lines) == len(inv.Lines) { exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) + exportAELineExemption(&lines[i], inv.Lines[i]) } } } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index a2ac7ac..7aa396a 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -523,6 +523,55 @@ func TestAEBillingFrequency(t *testing.T) { }) } +func TestAELineExemption(t *testing.T) { + ublLine := func() goblubl.InvoiceLine { + return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ + ID: &goblubl.IDType{Value: "E"}, + }}} + } + goblLine := func(code cbc.Code) *bill.Line { + c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} + if code != "" { + c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + } + return &bill.Line{Taxes: tax.Set{c}} + } + + t.Run("writes the exemption reason on the line", func(t *testing.T) { + line := ublLine() + exportAELineExemption(&line, goblLine("DL8.46.2")) + require.NotNil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) + assert.Equal(t, "DL8.46.2", *line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) + }) + + t.Run("nothing without a reason", func(t *testing.T) { + line := ublLine() + exportAELineExemption(&line, goblLine("")) + assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) + exportAELineExemption(&line, nil) + assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) + }) + + t.Run("reads the reasons back onto the line combos", func(t *testing.T) { + code := " DL8.46.4 " + with := ublLine() + with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code + inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} + importAELineExemptions([]goblubl.InvoiceLine{ublLine(), with}, inv) + assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Equal(t, cbc.Code("DL8.46.4"), inv.Lines[1].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + }) + + t.Run("lines that don't match are skipped", func(t *testing.T) { + code := "DL8.46.4" + with := ublLine() + with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code + inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} + importAELineExemptions([]goblubl.InvoiceLine{with}, inv) + assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index bc679ca..188b931 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4d287783ced27ec47b8f05ad62b058ad399be54cf1d1787e59ea9e52f8136c6d" + "val": "03bf9ac5f7d915fc908695404b5e89fbb670cb11e6220c209cbf72d6a7f745df" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -137,6 +137,7 @@ "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-132-1I", + "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" } } @@ -159,6 +160,7 @@ "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-135-1L", + "peppol-pint-ae-exemption": "DL8.46.2", "untdid-tax-category": "E" } } @@ -180,7 +182,10 @@ "untdid-tax-category": "E" } } - ] + ], + "ext": { + "untdid-allowance": "95" + } } ], "charges": [ @@ -247,19 +252,30 @@ "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-132-1I", + "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" }, - "base": "180.00", + "base": "200.00", "amount": "0.00" }, { "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-135-1L", + "peppol-pint-ae-exemption": "DL8.46.2", "untdid-tax-category": "E" }, "base": "300.00", "amount": "0.00" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "VATEX-EU-132-1I", + "untdid-tax-category": "E" + }, + "base": "-20.00", + "amount": "0.00" } ], "amount": "51.50" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index 6de0b62..a30ce24 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "28e3a64f21dd911a12f8ed962bc0a39ee4e5db890f2e76dd0ab3c90cc41f3cb6" + "val": "61f1035d0de70f800c2148bdff809dddf5d721fe4e76c1fa9a077239ab883b29" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -166,6 +166,7 @@ "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-132-1I", + "peppol-pint-ae-exemption": "DL8.46.3", "untdid-tax-category": "E" } } @@ -249,6 +250,7 @@ "key": "exempt", "ext": { "cef-vatex": "VATEX-EU-132-1I", + "peppol-pint-ae-exemption": "DL8.46.3", "untdid-tax-category": "E" }, "base": "120.00", diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index 833215f..de16555 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -85,6 +85,7 @@ false + 95 Loyalty discount 20.00 @@ -168,6 +169,7 @@ Financial service E + DL8.46.1 VAT @@ -195,6 +197,7 @@ Residential rent E + DL8.46.2 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 301b5ba..ab3074d 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -210,6 +210,7 @@ Financial service E + DL8.46.3 VAT diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index ab7f084..00b4694 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e2c4ce54911e8ac2218ce8390e4095053e79315d7eb4a5230cf22551eefbdbd6" + "val": "b4032e917f8d9effdf3aa32eadc30ce30ea826ac049d48f8361675f9ce613fda" } }, "doc": { @@ -144,6 +144,7 @@ "cat": "VAT", "key": "exempt", "ext": { + "peppol-pint-ae-exemption": "VATEX-AE-EDU", "untdid-tax-category": "E" } } @@ -208,9 +209,18 @@ { "key": "exempt", "ext": { + "peppol-pint-ae-exemption": "VATEX-AE-EDU", "untdid-tax-category": "E" }, - "base": "900.00", + "base": "1000.00", + "amount": "0.00" + }, + { + "key": "exempt", + "ext": { + "untdid-tax-category": "E" + }, + "base": "-100.00", "amount": "0.00" } ], From 5dcc73d32244fb90dd4e7a695dc74d8b4cfdab4e Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:17:52 +0000 Subject: [PATCH 13/73] Add the PINT AE goods type and GTIN - Add the type of goods or services extension, with the PINT AE code list (IBR-006-AE), and require it on reverse charge items (IBR-166-AE). - Require a GTIN identity on reverse charge items (IBR-174-AE). - Write the goods type as the item's nature code and the GTIN as its standard identifier, and read the goods type back. - Link the PINT AE code list pages from the extensions' sources. Needs the commodity classification nature code from gobl.ubl#189. --- README.md | 8 ++- addon/pint/bill.go | 50 +++++++++++++ addon/pint/bill_test.go | 48 +++++++++++++ addon/pint/extensions.go | 41 +++++++++++ addon/pint/org_identity.go | 15 ++++ ubl/ae.go | 49 +++++++++++++ ubl/ae_internal_test.go | 72 +++++++++++++++++++ .../invoice-ae-reverse-charge-allowance.json | 15 +++- .../pint/ae/invoice-ae-reverse-charge.json | 15 +++- .../convert/pint/ae/invoice-ae-usd.json | 17 ++++- .../invoice-ae-reverse-charge-allowance.xml | 6 ++ .../pint/ae/out/invoice-ae-reverse-charge.xml | 6 ++ .../convert/pint/ae/out/invoice-ae-usd.xml | 8 ++- .../parse/pint/ae/out/reverse-charge.json | 3 +- 14 files changed, 341 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 821ea04..48c7171 100644 --- a/README.md +++ b/README.md @@ -116,12 +116,14 @@ seller's TIN goes under the `TIN` tax scheme. It also writes the transaction type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and the disclosed agent's principal as the buyer and seller parties, and the credit note reason as `cac:DiscrepancyResponse`, the billing frequency in -`cac:InvoicePeriod`, and the UAE VAT exemption reason of exempt lines. On import, it reads +`cac:InvoicePeriod`, the UAE VAT exemption reason of exempt lines, and each +item's type of goods or services subject to the reverse charge as its +`cbc:NatureCode`, with its GTIN as the standard identifier. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and -tags, and the credit note reason, billing frequency and line exemption -reasons back as their extensions. +tags, and the credit note reason, billing frequency, line exemption +reasons and item goods types back as their extensions. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 6e2637e..b60c71c 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -406,6 +406,35 @@ func billLineRules() *rules.Set { ), ), )), + rules.When( + is.Func("reverse charge VAT", lineHasReverseChargeVAT), + rules.Field("item", + rules.Field("ext", + rules.Assert("04", "reverse charge line item needs the type of goods or services (IBR-166-AE)", + tax.ExtensionsRequire(ExtKeyGoodsType), + ), + ), + ), + ), + // The IBR-006-AE test checks every goods type, not only those of + // reverse charge lines as its text says. + rules.Field("item", + rules.Field("ext", + rules.Assert("05", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", + tax.ExtensionHasValidCode(ExtKeyGoodsType), + ), + ), + ), + rules.When( + is.Func("reverse charge VAT", lineHasReverseChargeVAT), + rules.Field("item", + rules.Field("identities", + rules.Assert("06", "reverse charge line item needs a GTIN identity, scheme 0160 (IBR-174-AE)", + is.Func("has GTIN", identitiesHaveGTIN), + ), + ), + ), + ), ), ) } @@ -967,3 +996,24 @@ func taxesHaveVAT(val any) bool { set, ok := val.(tax.Set) return ok && set.Get(tax.CategoryVAT) != nil } + +// lineHasReverseChargeVAT reports whether a line's VAT combo is reverse +// charge. +func lineHasReverseChargeVAT(val any) bool { + l, ok := val.(*bill.Line) + if !ok || l == nil { + return false + } + c := l.Taxes.Get(tax.CategoryVAT) + return c != nil && c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryReverseCharge +} + +// identitiesHaveGTIN reports whether an item has an identity with the GTIN +// scheme, 0160, the one gobl.ubl writes as the standard item identifier. +func identitiesHaveGTIN(val any) bool { + ids, ok := val.([]*org.Identity) + if !ok { + return false + } + return GTINIdentity(ids) != nil +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 00bc97a..86963c0 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -6,6 +6,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -1082,3 +1083,50 @@ func TestBillLineRulesAE(t *testing.T) { } }) } + +func TestBillGoodsTypeRulesAE(t *testing.T) { + const ( + faultGoodsType = "GOBL-PEPPOL-PINT-BILL-LINE-04" + faultGoodsTypeValue = "GOBL-PEPPOL-PINT-BILL-LINE-05" + faultGTIN = "GOBL-PEPPOL-PINT-BILL-LINE-06" + ) + gtin := func(scheme cbc.Code) []*org.Identity { + return []*org.Identity{{Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})}} + } + reverseCharge := func(goodsType cbc.Code, ids []*org.Identity) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} + inv.Lines[0].Item.Identities = ids + if goodsType != "" { + inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: goodsType}) + } + return inv + } + + t.Run("reverse charge item needs the goods type (IBR-166-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("", gtin("0160"))), faultGoodsType) + out := aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0160"))) + assert.NotContains(t, out, faultGoodsType) + assert.NotContains(t, out, faultGoodsTypeValue) + assert.NotContains(t, out, faultGTIN) + }) + + t.Run("goods type must be from the AE list on any line (IBR-006-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.9", gtin("0160"))), faultGoodsTypeValue) + + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: "OTHER"}) + assert.Contains(t, aeFaults(t, inv), faultGoodsTypeValue) + }) + + t.Run("reverse charge item needs a GTIN (IBR-174-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", nil)), faultGTIN) + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0088"))), faultGTIN) + }) + + t.Run("other lines need neither", func(t *testing.T) { + out := aeFaults(t, aeDocument(bill.InvoiceTypeStandard)) + assert.NotContains(t, out, faultGoodsType) + assert.NotContains(t, out, faultGTIN) + }) +} diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 217575f..c843cae 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -23,6 +23,9 @@ const ( // ExtKeyExemption is the UAE VAT exemption reason of an exempt tax combo // (IBT-186 on lines). ExtKeyExemption cbc.Key = "peppol-pint-ae-exemption" + // ExtKeyGoodsType is the type of goods or services subject to the reverse + // charge mechanism, on the item (BTAE-09). + ExtKeyGoodsType cbc.Key = "peppol-pint-ae-goods-type" ) // CreditNoteReasonVolumeDiscount is the credit note reason for a volume @@ -100,6 +103,12 @@ var extensions = []*cbc.Definition{ (IBR-055-AE). `), }, + Sources: []*cbc.Source{ + { + Title: i18n.NewString("PINT AE Reasons for credit note"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-creditnote/codelist/CreditReason/", + }, + }, Values: []*cbc.Definition{ { Code: "DL8.61.1.A", @@ -139,6 +148,12 @@ var extensions = []*cbc.Definition{ note (IBR-160-AE). `), }, + Sources: []*cbc.Source{ + { + Title: i18n.NewString("PINT AE Frequency of billing codes"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/codelist/FreqBilling/", + }, + }, Values: []*cbc.Definition{ {Code: "DLY", Name: i18n.String{i18n.EN: "Daily"}}, {Code: "WKY", Name: i18n.String{i18n.EN: "Weekly"}}, @@ -172,4 +187,30 @@ var extensions = []*cbc.Definition{ }, }, }, + { + Key: ExtKeyGoodsType, + Name: i18n.String{ + i18n.EN: "PINT AE Type of Goods or Services", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Type of goods or services subject to the reverse charge mechanism + (BTAE-09), from the PINT AE code list (IBR-006-AE). Required on the + items of reverse charge lines (IBR-166-AE). + `), + }, + Sources: []*cbc.Source{ + { + Title: i18n.NewString("PINT AE Type of goods or services subject to RCM"), + URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/codelist/GoodsType/", + }, + }, + Values: []*cbc.Definition{ + {Code: "DL8.48.8.2", Name: i18n.String{i18n.EN: "Electronic Devices"}}, + {Code: "DL8.48.8.1", Name: i18n.String{i18n.EN: "Gold and Diamonds"}}, + {Code: "DL8.48.3.1", Name: i18n.String{i18n.EN: "Crude or refined oil"}}, + {Code: "DL8.48.3.2", Name: i18n.String{i18n.EN: "Unprocessed or processed natural gas"}}, + {Code: "DL8.48.3.3", Name: i18n.String{i18n.EN: "Pure hydrocarbons"}}, + }, + }, } diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index da13598..ab7db5b 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -3,6 +3,7 @@ package pint import ( "regexp" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" @@ -64,3 +65,17 @@ func IdentityKeyAE(typ cbc.Code) cbc.Key { } return "" } + +// IdentitySchemeGTIN is the ISO 6523 scheme of a GTIN, the item standard +// identifier reverse charge lines need (IBR-174-AE). +const IdentitySchemeGTIN cbc.Code = "0160" + +// GTINIdentity returns the first identity with the GTIN scheme, or nil. +func GTINIdentity(ids []*org.Identity) *org.Identity { + for _, id := range ids { + if id != nil && id.Ext.Get(iso.ExtKeySchemeID) == IdentitySchemeGTIN { + return id + } + } + return nil +} diff --git a/ubl/ae.go b/ubl/ae.go index 22578ee..fde3556 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -76,6 +76,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAEBillingFrequency(in, inv) importAELineExemptions(in.InvoiceLines, inv) importAELineExemptions(in.CreditNoteLines, inv) + importAELineGoods(in.InvoiceLines, inv) + importAELineGoods(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -240,6 +242,52 @@ func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } +// exportAELineGoods writes the type of goods or services (BTAE-09) as the +// item's cac:CommodityClassification/cbc:NatureCode, and the item's GTIN as +// its standard identifier (IBR-174-AE): gobl.ubl writes the first identity +// with a scheme there, which may not be the GTIN. +func exportAELineGoods(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil || l.Item == nil || line.Item == nil { + return + } + if code := l.Item.Ext.Get(pint.ExtKeyGoodsType); code != "" { + v := code.String() + if line.Item.CommodityClassification == nil || len(*line.Item.CommodityClassification) == 0 { + line.Item.CommodityClassification = &[]goblubl.CommodityClassification{{}} + } + (*line.Item.CommodityClassification)[0].NatureCode = &v + } + if id := pint.GTINIdentity(l.Item.Identities); id != nil { + scheme := pint.IdentitySchemeGTIN.String() + line.Item.StandardItemIdentification = &goblubl.ItemIdentification{ + ID: &goblubl.IDType{SchemeID: &scheme, Value: id.Code.String()}, + } + } +} + +// importAELineGoods reads the type of goods or services back onto the items +// of the invoice's lines, which gobl.ubl imports in the same order. gobl.ubl +// already reads the GTIN as an identity. +func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + if len(lines) == 0 || len(lines) != len(inv.Lines) { + return + } + for i, line := range lines { + if line.Item == nil || line.Item.CommodityClassification == nil || inv.Lines[i].Item == nil { + continue + } + for _, cc := range *line.Item.CommodityClassification { + if cc.NatureCode == nil { + continue + } + if code := cbc.Code(strings.TrimSpace(*cc.NatureCode)); code != "" { + inv.Lines[i].Item.Ext = inv.Lines[i].Item.Ext.Set(pint.ExtKeyGoodsType, code) + break + } + } + } +} + // exportAEBillingFrequency writes the billing frequency as // cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl // writes from the ordering period, or on its own: IBR-CO-19 accepts a period @@ -277,6 +325,7 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == len(inv.Lines) { exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) exportAELineExemption(&lines[i], inv.Lines[i]) + exportAELineGoods(&lines[i], inv.Lines[i]) } } } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 7aa396a..bb09c06 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -6,6 +6,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" @@ -572,6 +573,77 @@ func TestAELineExemption(t *testing.T) { }) } +func TestAELineGoods(t *testing.T) { + gtin := func(scheme cbc.Code, code cbc.Code) *org.Identity { + return &org.Identity{Code: code, Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})} + } + goblLine := func(goodsType cbc.Code, ids ...*org.Identity) *bill.Line { + it := &org.Item{Name: "Gold bars", Identities: ids} + if goodsType != "" { + it.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: goodsType}) + } + return &bill.Line{Item: it} + } + + t.Run("writes the goods type as the nature code", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{}} + exportAELineGoods(&line, goblLine("DL8.48.8.1")) + require.NotNil(t, line.Item.CommodityClassification) + require.Len(t, *line.Item.CommodityClassification, 1) + assert.Equal(t, "DL8.48.8.1", *(*line.Item.CommodityClassification)[0].NatureCode) + }) + + t.Run("on the first classification when there is one", func(t *testing.T) { + list := "HS" + line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ + {ItemClassificationCode: &goblubl.IDType{Value: "7108", ListID: &list}}, + }}} + exportAELineGoods(&line, goblLine("DL8.48.8.1")) + require.Len(t, *line.Item.CommodityClassification, 1) + cc := (*line.Item.CommodityClassification)[0] + assert.Equal(t, "DL8.48.8.1", *cc.NatureCode) + assert.Equal(t, "7108", cc.ItemClassificationCode.Value) + }) + + t.Run("writes the GTIN as the standard identifier", func(t *testing.T) { + other := "0088" + line := goblubl.InvoiceLine{Item: &goblubl.Item{StandardItemIdentification: &goblubl.ItemIdentification{ + ID: &goblubl.IDType{SchemeID: &other, Value: "5410000000000"}, + }}} + exportAELineGoods(&line, goblLine("", gtin("0088", "5410000000000"), gtin("0160", "4006381333931"))) + id := line.Item.StandardItemIdentification.ID + assert.Equal(t, "0160", *id.SchemeID) + assert.Equal(t, "4006381333931", id.Value) + }) + + t.Run("nothing without a goods type or GTIN", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{}} + exportAELineGoods(&line, goblLine("")) + assert.Nil(t, line.Item.CommodityClassification) + assert.Nil(t, line.Item.StandardItemIdentification) + exportAELineGoods(&line, nil) + assert.Nil(t, line.Item.CommodityClassification) + }) + + t.Run("reads the goods type back onto the items", func(t *testing.T) { + code := " DL8.48.3.2 " + with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{NatureCode: &code}}}} + without := goblubl.InvoiceLine{Item: &goblubl.Item{}} + inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} + importAELineGoods([]goblubl.InvoiceLine{without, with}, inv) + assert.Empty(t, inv.Lines[0].Item.Ext.Get(pint.ExtKeyGoodsType)) + assert.Equal(t, cbc.Code("DL8.48.3.2"), inv.Lines[1].Item.Ext.Get(pint.ExtKeyGoodsType)) + }) + + t.Run("lines that don't match are skipped", func(t *testing.T) { + code := "DL8.48.3.2" + with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{NatureCode: &code}}}} + inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} + importAELineGoods([]goblubl.InvoiceLine{with}, inv) + assert.Empty(t, inv.Lines[0].Item.Ext.Get(pint.ExtKeyGoodsType)) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 76adf2c..a604217 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "14bd99bcb0c6322bd83948861f4ac6cef7327f87d563e1ab08da213721774ff7" + "val": "894fe7b79f37056933f5da8a3555ae3a12f53507054151dbbdfe9e53b684b33d" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -104,9 +104,20 @@ "quantity": "100", "item": { "name": "Item Name", + "identities": [ + { + "code": "4006381333931", + "ext": { + "iso-scheme-id": "0160" + } + } + ], "description": "Item Description", "price": "10.00", - "unit": "one" + "unit": "one", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.8.1" + } }, "sum": "1000.00", "taxes": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 01ebc48..842b266 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5d77d4c5781252e9922febdf9929c400ab3eeb7c1fe1ab770b91f53b44086ffa" + "val": "7cc74f23a6c902c3c5897602c9d87caf13f55f11d840fbb8b14ce85dd1d5588a" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -104,9 +104,20 @@ "quantity": "100", "item": { "name": "Item Name", + "identities": [ + { + "code": "4006381333931", + "ext": { + "iso-scheme-id": "0160" + } + } + ], "description": "Item Description", "price": "10.00", - "unit": "one" + "unit": "one", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1" + } }, "sum": "1000.00", "taxes": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index a30ce24..bb6cc14 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "61f1035d0de70f800c2148bdff809dddf5d721fe4e76c1fa9a077239ab883b29" + "val": "68fe470bbd55f8fa912e75a928cf3277ae212d5b66153538a883accc1c79ede2" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -177,10 +177,21 @@ "i": 4, "quantity": "3", "item": { - "name": "Imported service", + "name": "Electronic devices", + "identities": [ + { + "code": "4006381333931", + "ext": { + "iso-scheme-id": "0160" + } + } + ], "description": "Reverse charge supply", "price": "33.33", - "unit": "one" + "unit": "one", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.8.2" + } }, "sum": "99.99", "taxes": [ diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 9c6ab55..50fb303 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -127,6 +127,12 @@ Item Description Item Name + + 4006381333931 + + + DL8.48.8.1 + AE 5 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index ca324df..58154e3 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -99,6 +99,12 @@ Item Description Item Name + + 4006381333931 + + + DL8.48.3.1 + AE 5 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index ab3074d..3754d59 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -235,7 +235,13 @@ 99.99 Reverse charge supply - Imported service + Electronic devices + + 4006381333931 + + + DL8.48.8.2 + AE 5 diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 8d1bd3f..7b3c321 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a970b1ede98ea9a69dfa54dd67531235a63bfe52f9bb29e1a9cbf491b84349c8" + "val": "5c83373a893c85d1ea86d5f174d41085dda3746576d927426bb9ff174da71812" } }, "doc": { @@ -143,6 +143,7 @@ "price": "99.00", "unit": "kl", "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1", "untdid-unit": "K6" } }, From f7fd9e112c8945761bf1ce05229c2cfa3a3b9867 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:30:40 +0000 Subject: [PATCH 14/73] Add the PINT AE item type - Write the item type from the item key: goods, services, or the new PINT goods-services key for both, and read it back. - Require an HS classification on goods (IBR-184-AE), a service accounting code on services (IBR-185-AE), and both on goods and services (IBR-186-AE), and only HS classifications (IBR-188-AE). - Write the identities labelled SAC as service accounting codes (IBR-189-AE), and read them back. Needs the commodity code and additional item identifiers from gobl.ubl#189. --- README.md | 7 +- addon/pint/bill.go | 87 +++++++++++++++++ addon/pint/bill_test.go | 52 ++++++++++ addon/pint/org_item.go | 54 +++++++++++ addon/pint/org_item_test.go | 36 +++++++ ubl/ae.go | 94 ++++++++++++++++++- ubl/ae_internal_test.go | 69 ++++++++++++++ .../pint/ae/invoice-ae-reverse-charge.json | 7 +- .../convert/pint/ae/invoice-ae-usd.json | 32 ++++++- .../pint/ae/out/invoice-ae-reverse-charge.xml | 2 + .../convert/pint/ae/out/invoice-ae-usd.xml | 19 ++++ .../parse/pint/ae/out/deemed-supply.json | 7 +- .../parse/pint/ae/out/standard-invoice.json | 3 +- .../pint/ae/out/supply-free-trade-zone.json | 3 +- 14 files changed, 461 insertions(+), 11 deletions(-) create mode 100644 addon/pint/org_item.go create mode 100644 addon/pint/org_item_test.go diff --git a/README.md b/README.md index 48c7171..0e8cf54 100644 --- a/README.md +++ b/README.md @@ -118,12 +118,15 @@ the disclosed agent's principal as the buyer and seller parties, and the credit note reason as `cac:DiscrepancyResponse`, the billing frequency in `cac:InvoicePeriod`, the UAE VAT exemption reason of exempt lines, and each item's type of goods or services subject to the reverse charge as its -`cbc:NatureCode`, with its GTIN as the standard identifier. On import, it reads +`cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed +`goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and +identities labelled `SAC` are written as service accounting codes. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption -reasons and item goods types back as their extensions. +reasons and item goods types back as their extensions, and the item +types and service accounting codes back as item keys and identities. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index b60c71c..a15e202 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -435,6 +435,40 @@ func billLineRules() *rules.Set { ), ), ), + rules.Field("item", + rules.When( + is.Func("goods", itemKeyIs(org.ItemKeyGoods)), + rules.Field("identities", + rules.Assert("07", "goods item needs an HS item classification (IBR-184-AE)", + is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), + ), + ), + ), + rules.When( + is.Func("services", itemKeyIs(org.ItemKeyServices)), + rules.Field("identities", + rules.Assert("08", "services item needs a service accounting code (IBR-185-AE)", + is.Func("has SAC", identitiesHaveLabel(IdentityLabelSAC)), + ), + ), + ), + rules.When( + is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), + rules.Field("identities", + rules.Assert("09", "goods and services item needs an HS item classification and a service accounting code (IBR-186-AE)", + is.Func("has HS and SAC", identitiesHaveLabel(IdentityLabelHS, IdentityLabelSAC)), + ), + ), + ), + // gobl.ubl writes identities with a label and no scheme ID as item + // classifications, with the label as their list. FormatAE writes the + // SAC ones as service accounting codes instead (IBR-189-AE). + rules.Field("identities", + rules.Assert("10", "item classifications must use the HS list (IBR-188-AE)", + is.Func("classifications are HS", identitiesClassifiedAsHS), + ), + ), + ), ), ) } @@ -1017,3 +1051,56 @@ func identitiesHaveGTIN(val any) bool { } return GTINIdentity(ids) != nil } + +// itemKeyIs returns a predicate that reports whether an item has the key. +func itemKeyIs(key cbc.Key) func(any) bool { + return func(val any) bool { + it, ok := val.(*org.Item) + return ok && it != nil && it.Key == key + } +} + +// identitiesHaveLabel returns a predicate that reports whether an item has +// identities with all the labels. +func identitiesHaveLabel(labels ...string) func(any) bool { + return func(val any) bool { + ids, ok := val.([]*org.Identity) + if !ok { + return false + } + for _, label := range labels { + if !identitiesHaveLabelOf(ids, label) { + return false + } + } + return true + } +} + +func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { + for _, id := range ids { + if id != nil && id.Label == label { + return true + } + } + return false +} + +// identitiesClassifiedAsHS reports whether the identities gobl.ubl writes as +// item classifications, those with a label and no scheme ID, are all HS ones, +// apart from the service accounting codes. +func identitiesClassifiedAsHS(val any) bool { + ids, ok := val.([]*org.Identity) + if !ok { + return false + } + for _, id := range ids { + if id == nil || id.Label == "" || id.Ext.Has(iso.ExtKeySchemeID) { + continue + } + if id.Label != IdentityLabelHS && id.Label != IdentityLabelSAC { + return false + } + } + return true +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 86963c0..44a98d1 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -1130,3 +1130,55 @@ func TestBillGoodsTypeRulesAE(t *testing.T) { assert.NotContains(t, out, faultGTIN) }) } + +func TestBillItemTypeRulesAE(t *testing.T) { + const ( + faultGoodsHS = "GOBL-PEPPOL-PINT-BILL-LINE-07" + faultServicesSAC = "GOBL-PEPPOL-PINT-BILL-LINE-08" + faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-09" + faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-10" + ) + hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} + sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} + item := func(key cbc.Key, ids ...*org.Identity) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Key = key + inv.Lines[0].Item.Identities = ids + return inv + } + + t.Run("goods need an HS classification (IBR-184-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) + assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) + }) + + t.Run("services need a service accounting code (IBR-185-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(org.ItemKeyServices)), faultServicesSAC) + assert.Contains(t, aeFaults(t, item(org.ItemKeyServices, hs)), faultServicesSAC) + assert.NotContains(t, aeFaults(t, item(org.ItemKeyServices, sac)), faultServicesSAC) + }) + + t.Run("goods and services need both (IBR-186-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) + assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs, sac)), faultGoodsServices) + }) + + t.Run("no item type needs neither", func(t *testing.T) { + out := aeFaults(t, item("")) + assert.NotContains(t, out, faultGoodsHS) + assert.NotContains(t, out, faultServicesSAC) + assert.NotContains(t, out, faultGoodsServices) + }) + + t.Run("item classifications must be HS (IBR-188-AE)", func(t *testing.T) { + cpv := &org.Identity{Label: "CPV", Code: "30200000"} + assert.Contains(t, aeFaults(t, item("", hs, cpv)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) + + // Identities with a scheme ID aren't classifications. + gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} + assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) + }) +} diff --git a/addon/pint/org_item.go b/addon/pint/org_item.go new file mode 100644 index 0000000..9eb5850 --- /dev/null +++ b/addon/pint/org_item.go @@ -0,0 +1,54 @@ +package pint + +import ( + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/org" +) + +// ItemKeyGoodsServices is the item key for an item that is both goods and +// services, PINT AE's item type "B". GOBL's own "goods" and "services" keys +// give the other two types. +const ItemKeyGoodsServices cbc.Key = "goods-services" + +// PINT AE item types, written as the item's +// cac:CommodityClassification/cbc:CommodityCode (BTAE-13). +const ( + ItemTypeGoods cbc.Code = "G" + ItemTypeServices cbc.Code = "S" + ItemTypeGoodsServices cbc.Code = "B" +) + +// Labels of the item identities PINT AE uses: the HS item classification +// (IBR-188-AE) and the service accounting code (BTAE-17, IBR-189-AE). +const ( + IdentityLabelHS = "HS" + IdentityLabelSAC = "SAC" +) + +// ItemTypeAE returns the PINT AE item type for an item key, or an empty code +// if the key has none. +func ItemTypeAE(key cbc.Key) cbc.Code { + switch key { + case org.ItemKeyGoods: + return ItemTypeGoods + case org.ItemKeyServices: + return ItemTypeServices + case ItemKeyGoodsServices: + return ItemTypeGoodsServices + } + return "" +} + +// ItemKeyAE returns the item key for a PINT AE item type, or an empty key if +// the type is unknown. +func ItemKeyAE(typ cbc.Code) cbc.Key { + switch typ { + case ItemTypeGoods: + return org.ItemKeyGoods + case ItemTypeServices: + return org.ItemKeyServices + case ItemTypeGoodsServices: + return ItemKeyGoodsServices + } + return "" +} diff --git a/addon/pint/org_item_test.go b/addon/pint/org_item_test.go new file mode 100644 index 0000000..7d45dc3 --- /dev/null +++ b/addon/pint/org_item_test.go @@ -0,0 +1,36 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/org" + "github.com/stretchr/testify/assert" +) + +func TestItemTypeAE(t *testing.T) { + tests := map[cbc.Key]cbc.Code{ + org.ItemKeyGoods: pint.ItemTypeGoods, + org.ItemKeyServices: pint.ItemTypeServices, + pint.ItemKeyGoodsServices: pint.ItemTypeGoodsServices, + "other": "", + cbc.KeyEmpty: "", + } + for key, want := range tests { + assert.Equal(t, want, pint.ItemTypeAE(key), key) + } +} + +func TestItemKeyAE(t *testing.T) { + tests := map[cbc.Code]cbc.Key{ + "G": org.ItemKeyGoods, + "S": org.ItemKeyServices, + "B": pint.ItemKeyGoodsServices, + "X": "", + "": "", + } + for typ, want := range tests { + assert.Equal(t, want, pint.ItemKeyAE(typ), typ) + } +} diff --git a/ubl/ae.go b/ubl/ae.go index fde3556..a6ee721 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -78,6 +78,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAELineExemptions(in.CreditNoteLines, inv) importAELineGoods(in.InvoiceLines, inv) importAELineGoods(in.CreditNoteLines, inv) + importAELineItems(in.InvoiceLines, inv) + importAELineItems(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) return nil @@ -252,10 +254,7 @@ func exportAELineGoods(line *goblubl.InvoiceLine, l *bill.Line) { } if code := l.Item.Ext.Get(pint.ExtKeyGoodsType); code != "" { v := code.String() - if line.Item.CommodityClassification == nil || len(*line.Item.CommodityClassification) == 0 { - line.Item.CommodityClassification = &[]goblubl.CommodityClassification{{}} - } - (*line.Item.CommodityClassification)[0].NatureCode = &v + aeCommodityClassification(line.Item).NatureCode = &v } if id := pint.GTINIdentity(l.Item.Identities); id != nil { scheme := pint.IdentitySchemeGTIN.String() @@ -265,6 +264,54 @@ func exportAELineGoods(line *goblubl.InvoiceLine, l *bill.Line) { } } +// aeCommodityClassification returns the item's first commodity +// classification, adding one if it has none, where the PINT AE item codes go +// alongside the item classification code, as in the official examples. +func aeCommodityClassification(it *goblubl.Item) *goblubl.CommodityClassification { + if it.CommodityClassification == nil || len(*it.CommodityClassification) == 0 { + it.CommodityClassification = &[]goblubl.CommodityClassification{{}} + } + return &(*it.CommodityClassification)[0] +} + +// exportAELineSAC moves the service accounting codes (BTAE-17), which +// gobl.ubl writes as item classifications listed "SAC" since their +// identities have that label, to cac:AdditionalItemIdentification with the +// SAC scheme (IBR-189-AE). +func exportAELineSAC(line *goblubl.InvoiceLine) { + if line.Item == nil || line.Item.CommodityClassification == nil { + return + } + var kept []goblubl.CommodityClassification + for _, cc := range *line.Item.CommodityClassification { + code := cc.ItemClassificationCode + if code == nil || code.ListID == nil || *code.ListID != pint.IdentityLabelSAC { + kept = append(kept, cc) + continue + } + scheme := pint.IdentityLabelSAC + line.Item.AdditionalItemIdentification = append(line.Item.AdditionalItemIdentification, + goblubl.ItemIdentification{ID: &goblubl.IDType{SchemeID: &scheme, Value: code.Value}}) + } + if len(kept) == 0 { + line.Item.CommodityClassification = nil + return + } + line.Item.CommodityClassification = &kept +} + +// exportAELineItemType writes the item type (BTAE-13) of the item's key as +// its cac:CommodityClassification/cbc:CommodityCode. +func exportAELineItemType(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil || l.Item == nil || line.Item == nil { + return + } + if typ := pint.ItemTypeAE(l.Item.Key); typ != "" { + v := typ.String() + aeCommodityClassification(line.Item).CommodityCode = &v + } +} + // importAELineGoods reads the type of goods or services back onto the items // of the invoice's lines, which gobl.ubl imports in the same order. gobl.ubl // already reads the GTIN as an identity. @@ -288,6 +335,43 @@ func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } +// importAELineItems reads back what exportAELineSAC and exportAELineItemType +// write: the service accounting codes as identities with their scheme as +// label, and the item type as the item's key. +func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + if len(lines) == 0 || len(lines) != len(inv.Lines) { + return + } + for i, line := range lines { + it := inv.Lines[i].Item + if line.Item == nil || it == nil { + continue + } + for _, ai := range line.Item.AdditionalItemIdentification { + if ai.ID == nil || strings.TrimSpace(ai.ID.Value) == "" { + continue + } + id := &org.Identity{Code: cbc.Code(strings.TrimSpace(ai.ID.Value))} + if ai.ID.SchemeID != nil { + id.Label = strings.TrimSpace(*ai.ID.SchemeID) + } + it.Identities = append(it.Identities, id) + } + if line.Item.CommodityClassification == nil { + continue + } + for _, cc := range *line.Item.CommodityClassification { + if cc.CommodityCode == nil { + continue + } + if key := pint.ItemKeyAE(cbc.Code(strings.TrimSpace(*cc.CommodityCode))); key != "" { + it.Key = key + break + } + } + } +} + // exportAEBillingFrequency writes the billing frequency as // cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl // writes from the ordering period, or on its own: IBR-CO-19 accepts a period @@ -325,7 +409,9 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == len(inv.Lines) { exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) exportAELineExemption(&lines[i], inv.Lines[i]) + exportAELineSAC(&lines[i]) exportAELineGoods(&lines[i], inv.Lines[i]) + exportAELineItemType(&lines[i], inv.Lines[i]) } } } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index bb09c06..9f73525 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -644,6 +644,75 @@ func TestAELineGoods(t *testing.T) { }) } +func TestAELineItems(t *testing.T) { + list := func(v string) *string { return &v } + classification := func(listID, code string) goblubl.CommodityClassification { + return goblubl.CommodityClassification{ItemClassificationCode: &goblubl.IDType{Value: code, ListID: list(listID)}} + } + + t.Run("moves the service accounting codes to additional identifiers", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ + classification("HS", "8471"), classification("SAC", "998713"), + }}} + exportAELineSAC(&line) + require.Len(t, *line.Item.CommodityClassification, 1) + assert.Equal(t, "8471", (*line.Item.CommodityClassification)[0].ItemClassificationCode.Value) + require.Len(t, line.Item.AdditionalItemIdentification, 1) + id := line.Item.AdditionalItemIdentification[0].ID + assert.Equal(t, "SAC", *id.SchemeID) + assert.Equal(t, "998713", id.Value) + }) + + t.Run("no classifications left when all were SAC", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ + classification("SAC", "998713"), + }}} + exportAELineSAC(&line) + assert.Nil(t, line.Item.CommodityClassification) + assert.Len(t, line.Item.AdditionalItemIdentification, 1) + }) + + t.Run("writes the item type on the first classification", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ + classification("HS", "8471"), + }}} + exportAELineItemType(&line, &bill.Line{Item: &org.Item{Key: pint.ItemKeyGoodsServices}}) + cc := (*line.Item.CommodityClassification)[0] + assert.Equal(t, "B", *cc.CommodityCode) + assert.Equal(t, "8471", cc.ItemClassificationCode.Value) + }) + + t.Run("nothing for items without an AE type", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{}} + exportAELineItemType(&line, &bill.Line{Item: &org.Item{Key: "other"}}) + assert.Nil(t, line.Item.CommodityClassification) + exportAELineItemType(&line, nil) + assert.Nil(t, line.Item.CommodityClassification) + }) + + t.Run("reads the item type and service accounting codes back", func(t *testing.T) { + with := goblubl.InvoiceLine{Item: &goblubl.Item{ + AdditionalItemIdentification: []goblubl.ItemIdentification{{ID: &goblubl.IDType{SchemeID: list("SAC"), Value: " 998713 "}}}, + CommodityClassification: &[]goblubl.CommodityClassification{{CommodityCode: list("S")}}, + }} + inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}, {Item: &org.Item{}}}} + importAELineItems([]goblubl.InvoiceLine{{Item: &goblubl.Item{}}, with}, inv) + assert.Empty(t, inv.Lines[0].Item.Key) + assert.Empty(t, inv.Lines[0].Item.Identities) + assert.Equal(t, org.ItemKeyServices, inv.Lines[1].Item.Key) + require.Len(t, inv.Lines[1].Item.Identities, 1) + assert.Equal(t, "SAC", inv.Lines[1].Item.Identities[0].Label) + assert.Equal(t, cbc.Code("998713"), inv.Lines[1].Item.Identities[0].Code) + }) + + t.Run("lines that don't match are skipped", func(t *testing.T) { + with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{CommodityCode: list("G")}}}} + inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}, {Item: &org.Item{}}}} + importAELineItems([]goblubl.InvoiceLine{with}, inv) + assert.Empty(t, inv.Lines[0].Item.Key) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 842b266..fd0cccd 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7cc74f23a6c902c3c5897602c9d87caf13f55f11d840fbb8b14ce85dd1d5588a" + "val": "6c1fddcee644f42bb3747b650d52fe8f218ac152b70ef7ae26e283d757c12ca9" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -103,8 +103,13 @@ "i": 1, "quantity": "100", "item": { + "key": "goods", "name": "Item Name", "identities": [ + { + "label": "HS", + "code": "2709" + }, { "code": "4006381333931", "ext": { diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index bb6cc14..7ace9f0 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "68fe470bbd55f8fa912e75a928cf3277ae212d5b66153538a883accc1c79ede2" + "val": "e9ea54853e92a354c970608a21f0cda350f27bd8ece85c00cfdd5ecefb8ff3d4" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -110,7 +110,18 @@ "i": 1, "quantity": "100", "item": { + "key": "goods-services", "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "8471" + }, + { + "label": "SAC", + "code": "998713" + } + ], "description": "Item Description", "price": "10.00", "unit": "one" @@ -132,7 +143,14 @@ "i": 2, "quantity": "2", "item": { + "key": "goods", "name": "Export goods", + "identities": [ + { + "label": "HS", + "code": "8471" + } + ], "description": "Zero rated supply", "price": "250.00", "unit": "one" @@ -154,7 +172,14 @@ "i": 3, "quantity": "1", "item": { + "key": "services", "name": "Financial service", + "identities": [ + { + "label": "SAC", + "code": "997113" + } + ], "description": "Exempt supply", "price": "120.00", "unit": "one" @@ -177,8 +202,13 @@ "i": 4, "quantity": "3", "item": { + "key": "goods", "name": "Electronic devices", "identities": [ + { + "label": "HS", + "code": "8517" + }, { "code": "4006381333931", "ext": { diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 58154e3..3a27fc7 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -104,6 +104,8 @@ DL8.48.3.1 + G + 2709 AE diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 3754d59..6df1ac7 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -146,6 +146,13 @@ Item Description Item Name + + 998713 + + + B + 8471 + S 5 @@ -177,6 +184,10 @@ Zero rated supply Export goods + + G + 8471 + Z 0 @@ -208,6 +219,12 @@ Exempt supply Financial service + + 997113 + + + S + E DL8.46.3 @@ -241,6 +258,8 @@ DL8.48.8.2 + G + 8517 AE diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index 6637752..c35407d 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "bfb3aeb7bc32584b64e3a67be5516ee365f2c95908527df4c1eaf491cc8a251d" + "val": "2a6a49cd4519a550e26e9b89488e71891bb461d06a39b1678936ee56a6be2e40" } }, "doc": { @@ -126,11 +126,16 @@ "i": 1, "quantity": "2", "item": { + "key": "goods", "name": "Item Name", "identities": [ { "label": "HS", "code": "88098432" + }, + { + "label": "SAC", + "code": "Service" } ], "description": "Item Description", diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json index 532158c..da72df4 100644 --- a/ubl/testdata/parse/pint/ae/out/standard-invoice.json +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5274a8aa0a6a11c3d1796d2df3372bf4c3d9458babbfb972dd970e04f6bdcab7" + "val": "8ecfd77c9c801b91ac7a8065224d03c08891ab36a77b3a4419b77aff4e493d29" } }, "doc": { @@ -89,6 +89,7 @@ "i": 1, "quantity": "100", "item": { + "key": "goods", "name": "Item Name", "identities": [ { diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 7736dff..5b5736e 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "9049e38006f38c835aa5868ac295abed694f299b1770fb468dd5cbfc34da89a5" + "val": "09f47acb2f05d62c281a97219b2602c8f1791f4aa102b513ad2a0573937dbd36" } }, "doc": { @@ -127,6 +127,7 @@ "i": 1, "quantity": "500", "item": { + "key": "goods", "name": "Item Name", "identities": [ { From 3e995875f7f0d66c0639c5b7bd550a5ec8c6ea09 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:56:43 +0000 Subject: [PATCH 15/73] Add the PINT AE margin scheme category - Map the AE regime's margin-scheme VAT key to the N category, and check categories against the PINT list instead of EN 16931's. - Forbid the margin scheme on discounts and charges (IBR-115-AE, IBR-114-AE), and require it everywhere on margin scheme invoices (IBR-116-AE). - Write N at 5% with no VAT amount, and read it back as the margin-scheme key. Needs the margin-scheme VAT key in the gobl AE regime. --- README.md | 7 +- addon/pint/bill.go | 59 +++++ addon/pint/bill_test.go | 47 ++++ addon/pint/tax_combo.go | 15 +- addon/pint/transaction_type.go | 1 + ubl/ae.go | 52 ++++- ubl/ae_internal_test.go | 29 +++ .../pint/ae/invoice-ae-margin-scheme.json | 185 +++++++++++++++ .../pint/ae/out/invoice-ae-margin-scheme.xml | 129 +++++++++++ ubl/testdata/parse/pint/ae/margin-scheme.xml | 154 +++++++++++++ .../parse/pint/ae/out/margin-scheme.json | 217 ++++++++++++++++++ 11 files changed, 880 insertions(+), 15 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml create mode 100644 ubl/testdata/parse/pint/ae/margin-scheme.xml create mode 100644 ubl/testdata/parse/pint/ae/out/margin-scheme.json diff --git a/README.md b/README.md index 0e8cf54..a7b98b8 100644 --- a/README.md +++ b/README.md @@ -120,13 +120,16 @@ credit note reason as `cac:DiscrepancyResponse`, the billing frequency in item's type of goods or services subject to the reverse charge as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and -identities labelled `SAC` are written as service accounting codes. On import, it reads +identities labelled `SAC` are written as service accounting codes. Lines +with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with +no VAT amount. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption reasons and item goods types back as their extensions, and the item -types and service accounting codes back as item keys and identities. +types and service accounting codes back as item keys and identities, and +the `N` category back as the `margin-scheme` key. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index a15e202..90ea52b 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -375,6 +375,24 @@ func billInvoiceRules() *rules.Set { ), ), )), + rules.Field("discounts", rules.Each( + rules.Assert("54", "discount VAT category cannot be margin scheme (IBR-115-AE)", + is.Not(is.Func("has margin scheme VAT", taxesIn(comboIsMarginScheme))), + ), + )), + rules.Field("charges", rules.Each( + rules.Assert("55", "charge VAT category cannot be margin scheme (IBR-114-AE)", + is.Not(is.Func("has margin scheme VAT", taxesIn(comboIsMarginScheme))), + ), + )), + // With rules 54 and 55, a margin scheme invoice can have no discounts + // or charges, as GOBL requires them to have taxes (BR-32, BR-37). + rules.When( + is.Func("margin scheme", invoiceIsMarginScheme), + rules.Assert("56", "margin scheme invoice must only use the margin scheme VAT key (IBR-116-AE)", + is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), + ), + ), ), ) } @@ -1104,3 +1122,44 @@ func identitiesClassifiedAsHS(val any) bool { } return true } + +// comboIsMarginScheme reports whether a tax combo is VAT under the profit +// margin scheme. +func comboIsMarginScheme(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && c.Category == tax.CategoryVAT && + c.Ext.Get(untdid.ExtKeyTaxCategory) == TaxCategoryMarginScheme +} + +// invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's +// lines, discounts and charges is VAT under the profit margin scheme. +func invoiceTaxesAreMarginScheme(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return false + } + var sets []tax.Set + for _, l := range inv.Lines { + if l != nil { + sets = append(sets, l.Taxes) + } + } + for _, d := range inv.Discounts { + if d != nil { + sets = append(sets, d.Taxes) + } + } + for _, c := range inv.Charges { + if c != nil { + sets = append(sets, c.Taxes) + } + } + for _, set := range sets { + for _, c := range set { + if !comboIsMarginScheme(c) { + return false + } + } + } + return true +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 44a98d1..8a69378 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -1182,3 +1182,50 @@ func TestBillItemTypeRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) }) } + +func TestBillMarginSchemeRulesAE(t *testing.T) { + const ( + faultDiscount = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + faultCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + ) + margin := func(tags ...cbc.Key) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard, tags...) + inv.Lines[0].Taxes = tax.Set{lineCombo(ae.TaxKeyMarginScheme)} + return inv + } + + t.Run("margin scheme lines are N without VAT", func(t *testing.T) { + inv := margin(pint.TagMarginScheme) + assert.Empty(t, aeFaults(t, inv)) + c := inv.Lines[0].Taxes[0] + assert.Equal(t, pint.TaxCategoryMarginScheme, c.Ext.Get(untdid.ExtKeyTaxCategory)) + assert.Nil(t, c.Percent) + assert.True(t, inv.Totals.Tax.IsZero()) + }) + + t.Run("discounts and charges can't be margin scheme (IBR-115-AE, IBR-114-AE)", func(t *testing.T) { + inv := margin() + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(ae.TaxKeyMarginScheme)}}} + inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(ae.TaxKeyMarginScheme)}}} + out := aeFaults(t, inv) + assert.Contains(t, out, faultDiscount) + assert.Contains(t, out, faultCharge) + + inv = aeDocument(bill.InvoiceTypeStandard) + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(tax.KeyStandard)}}} + out = aeFaults(t, inv) + assert.NotContains(t, out, faultDiscount) + }) + + t.Run("margin scheme invoices only use the margin scheme key (IBR-116-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagMarginScheme) + assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + + inv = margin(pint.TagMarginScheme) + inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(tax.KeyStandard)}}} + assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + + assert.NotContains(t, aeFaults(t, margin()), faultOnlyMargin, "N lines don't need the tag") + }) +} diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index fff89b9..d8d0734 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -5,11 +5,18 @@ import ( "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/num" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/rules/is" "github.com/invopop/gobl/tax" ) +// TaxCategoryMarginScheme is the PINT AE VAT category for supplies under the +// profit margin scheme, "Standard rate additional VAT". The official code list +// writes it with a Greek capital Nu (U+039D), but the Schematron tests and +// examples use the Latin N, so we follow them. +const TaxCategoryMarginScheme cbc.Code = "N" + // taxCategoryMap maps GOBL tax keys to the UNTDID 5305 tax category codes that // PINT recognises, mirroring EN 16931's VAT key mapping. var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ @@ -20,6 +27,7 @@ var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ tax.KeyIntraCommunity: en16931.TaxCategoryIntraCommunity, tax.KeyExport: en16931.TaxCategoryExport, tax.KeyOutsideScope: en16931.TaxCategoryOutsideScope, + ae.TaxKeyMarginScheme: TaxCategoryMarginScheme, }) // taxCategoryCodesAUNZ lists the subset of UNTDID 5305 tax category codes @@ -40,6 +48,7 @@ var taxCategoryCodesAE = []cbc.Code{ en16931.TaxCategoryZero, en16931.TaxCategoryOutsideScope, en16931.TaxCategoryReverseCharge, + TaxCategoryMarginScheme, } // normalizeTaxCombo re-maps the UNTDID tax category code from the tax combo's @@ -77,8 +86,12 @@ func taxComboRules() *rules.Set { // TODO: rules 04 and 06 should also apply to AUNZ. rules.When( is.InContext(tax.RegimeIn(regimesAE...)), + // EN 16931 checks VAT category codes against its own list, which has + // no PINT AE margin scheme category (N). Rule 01 checks them against + // the PINT list instead. + rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-02"), rules.Field("ext", - rules.Assert("03", "tax category code must be an AE UNCL5305 code: E, S, Z, O or AE (IBR-139-AE)", + rules.Assert("03", "tax category code must be an AE UNCL5305 code: E, S, Z, O, AE or N (IBR-139-AE)", tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesAE...), ), ), diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index ef367e7..f6b0a74 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -199,6 +199,7 @@ var ( invoiceIsDisclosedAgent = transactionTypeIs(func(t TransactionType) bool { return t.DisclosedAgent }) invoiceIsECommerce = transactionTypeIs(func(t TransactionType) bool { return t.ECommerce }) invoiceIsExport = transactionTypeIs(func(t TransactionType) bool { return t.Export }) + invoiceIsMarginScheme = transactionTypeIs(func(t TransactionType) bool { return t.MarginScheme }) // invoiceIsSummaryDeemedOrMargin reports the flags outside scope documents // and credit notes related to goods and services can't have (IBR-157-AE). invoiceIsSummaryDeemedOrMargin = transactionTypeIs(func(t TransactionType) bool { diff --git a/ubl/ae.go b/ubl/ae.go index a6ee721..5e7cda9 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -7,6 +7,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" @@ -21,17 +22,18 @@ const ( taxCategoryStandard = "S" taxCategoryExempt = "E" taxCategoryReverseCharge = "AE" + taxCategoryMarginScheme = "N" ) // aedTotalDocumentType is the document type code PINT AE gives the additional // document reference that carries the total with VAT in AED (BTAE-20). const aedTotalDocumentType = "aedtotal-incl-vat" -// aeReverseChargeRate is the rate PINT AE expects on reverse charge lines and -// breakdowns. GOBL keeps reverse charge without a percent, as no VAT is -// charged, but the PINT AE examples and the 5% standard rate (IBR-190-AE) -// write 5. -const aeReverseChargeRate = "5" +// aeStandardRate is the rate PINT AE expects on reverse charge and margin +// scheme lines and breakdowns. GOBL keeps both without a percent, as the +// invoice charges no VAT, but the PINT AE examples and the 5% standard rate +// (IBR-190-AE) write 5, and margin scheme lines need a rate (IBR-111-AE). +const aeStandardRate = "5" // taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. const taxSchemeTIN = "TIN" @@ -71,6 +73,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } importAEOutsideScope(in, inv) + importAEMarginScheme(inv) importAETransactionType(in, inv) importAECreditNoteReason(in, inv) importAEBillingFrequency(in, inv) @@ -110,6 +113,30 @@ func importAEOutsideScope(in *goblubl.Invoice, inv *bill.Invoice) { } } +// importAEMarginScheme gives the margin scheme VAT key to the combos gobl.ubl +// imports with the N category and a 5% rate. Without a key, EN 16931 would +// read them as standard rated, which charges VAT the invoice doesn't. +func importAEMarginScheme(inv *bill.Invoice) { + var sets []tax.Set + for _, l := range inv.Lines { + sets = append(sets, l.Taxes) + } + for _, d := range inv.Discounts { + sets = append(sets, d.Taxes) + } + for _, c := range inv.Charges { + sets = append(sets, c.Taxes) + } + for _, set := range sets { + for _, c := range set { + if c.Category == tax.CategoryVAT && c.Ext.Get(untdid.ExtKeyTaxCategory) == pint.TaxCategoryMarginScheme { + c.Key = ae.TaxKeyMarginScheme + c.Percent = nil + } + } + } +} + // exportAEUUID writes the invoice's UUID as cbc:UUID, the unique identifier // number BTAE-07 (IBR-193-AE). func exportAEUUID(out *goblubl.Invoice, inv *bill.Invoice) { @@ -430,8 +457,9 @@ func exportAELine(line *goblubl.InvoiceLine) { // (IBR-194-AE, IBR-104-AE). Despite their names, the official examples write // both in the document currency, not in AED. GOBL keeps no VAT per line, so it // is the line total at the line's rate, rounded to the currency. Exempt lines -// get no VAT amount (IBR-163-AE), and zero rated and reverse charge lines a -// zero one (IBR-165-AE, IBR-162-AE). +// get no VAT amount (IBR-163-AE), and zero rated, reverse charge and margin +// scheme lines a zero one (IBR-165-AE, IBR-162-AE, as the official margin +// scheme example). func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.Code) { if l == nil || l.Total == nil { return @@ -452,7 +480,7 @@ func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.C // aeLineVAT provides the VAT charged on a line, and false for exempt lines, // which must not have one. Only standard rated lines charge VAT: zero rated, -// reverse charge and outside scope lines charge none. +// reverse charge, margin scheme and outside scope lines charge none. func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { zero := num.MakeAmount(0, l.Total.Exp()) if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || line.Item.ClassifiedTaxCategory.ID == nil { @@ -544,8 +572,8 @@ func lineUnitCode(line *goblubl.InvoiceLine) string { // aeRate provides the rate PINT AE expects for a line or breakdown VAT // category. gobl.ubl writes 0 when a combo has no percent, which is right for // A-NZ but not for AE: exempt must have no rate (aligned-ibrp-e-05, -// IBR-121-AE), and reverse charge must have one (aligned-ibrp-ae-05-ae, -// IBR-119-AE). Document allowances and charges keep gobl.ubl's 0, which is +// IBR-121-AE), and reverse charge and margin scheme must have one +// (aligned-ibrp-ae-05-ae, IBR-119-AE, IBR-111-AE). Document allowances and charges keep gobl.ubl's 0, which is // what PINT AE wants there for both (aligned-ibrp-e-06/07, ae-06/07). func aeRate(id *goblubl.IDType, percent *string) *string { if id == nil { @@ -554,8 +582,8 @@ func aeRate(id *goblubl.IDType, percent *string) *string { switch id.Value { case taxCategoryExempt: return nil - case taxCategoryReverseCharge: - rate := aeReverseChargeRate + case taxCategoryReverseCharge, taxCategoryMarginScheme: + rate := aeStandardRate return &rate } return percent diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 9f73525..88ecae5 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -7,6 +7,7 @@ import ( goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/iso" + "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" @@ -93,6 +94,9 @@ func TestAERate(t *testing.T) { rc := aeRate(&goblubl.IDType{Value: "AE"}, zero) require.NotNil(t, rc) assert.Equal(t, "5", *rc, "reverse charge is written at 5") + ms := aeRate(&goblubl.IDType{Value: "N"}, zero) + require.NotNil(t, ms) + assert.Equal(t, "5", *ms, "margin scheme is written at 5") assert.Equal(t, strPtr("5"), aeRate(&goblubl.IDType{Value: "S"}, strPtr("5")), "standard keeps its rate") assert.Nil(t, aeRate(&goblubl.IDType{Value: "O"}, nil), "outside scope keeps no rate") assert.Equal(t, zero, aeRate(nil, zero), "no category, no change") @@ -351,6 +355,31 @@ func TestImportAEPartyIdentities(t *testing.T) { }) } +func TestImportAEMarginScheme(t *testing.T) { + combo := func(category cbc.Code) *tax.Combo { + five := num.MakePercentage(5, 2) + return &tax.Combo{ + Category: tax.CategoryVAT, + Percent: &five, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), + } + } + inv := &bill.Invoice{ + Lines: []*bill.Line{{Taxes: tax.Set{combo("N")}}, {Taxes: tax.Set{combo("S")}}}, + Discounts: []*bill.Discount{{Taxes: tax.Set{combo("N")}}}, + } + importAEMarginScheme(inv) + + ms := inv.Lines[0].Taxes[0] + assert.Equal(t, ae.TaxKeyMarginScheme, ms.Key) + assert.Nil(t, ms.Percent, "margin scheme lines charge no VAT") + assert.Equal(t, ae.TaxKeyMarginScheme, inv.Discounts[0].Taxes[0].Key) + + other := inv.Lines[1].Taxes[0] + assert.Empty(t, other.Key, "other categories are left to EN 16931") + assert.NotNil(t, other.Percent) +} + func TestImportAEOutsideScope(t *testing.T) { importCode := func(invoiceCode, creditNoteCode string) *bill.Invoice { in := new(goblubl.Invoice) diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json new file mode 100644 index 0000000..188fbf5 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -0,0 +1,185 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "b9c84257dc6335edf1313fa23d79eed0d19a0ae5b3967f83f9a00514bc844ad6" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "margin-scheme" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "MARGIN-001", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-transaction-type": "00100000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "key": "goods", + "name": "Second-hand watch", + "identities": [ + { + "label": "HS", + "code": "9102" + } + ], + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1000.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "margin-scheme", + "ext": { + "untdid-tax-category": "N" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml new file mode 100644 index 0000000..78ad67a --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -0,0 +1,129 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00100000 + AE-MARGIN-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 380 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 0.00 + + 1000.00 + 0.00 + + N + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Second-hand watch + + G + 9102 + + + N + 5 + + VAT + + + + + 10.00 + 1 + + false + 0 + 10.00 + + + + 1000.00 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/margin-scheme.xml b/ubl/testdata/parse/pint/ae/margin-scheme.xml new file mode 100644 index 0000000..5123196 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/margin-scheme.xml @@ -0,0 +1,154 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00100000 + AE-001-Marginscheme-TEST + e59f130c-eb13-4476-bc18-2202915f48cf + 2025-02-11 + 2025-02-11 + 380 + Tax invoice + AED + + + 112345678900003 + + Supplier Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address line + + + AE + + + + 112345678900003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Contact Email address + + + + + + 112345679000003 + + Buyer Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address Line + + + AE + + + + 112345679000003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Contact Email address + + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + Instant Payment + + + 0 + false + + 1000 + 0 + + N + 5 + + VAT + + + + + + 1000 + 1000 + 1000 + 1000 + + + 1 + Margin scheme goods + 1 + 1000 + + Item Description + Item Name + + N + 5 + 1000 + + VAT + + + + + 1000 + 1 + + false + 0 + 1000 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json new file mode 100644 index 0000000..cd2ada0 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -0,0 +1,217 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "c7f5e00709da5880cdc4651f00c01804c62238aebcb073a24a39361c8e65cb2d" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "margin-scheme" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001-Marginscheme-TEST", + "issue_date": "2025-02-11", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00100000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "112345678900003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345678900003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "112345679000003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345679000003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "1", + "item": { + "name": "Item Name", + "description": "Item Description", + "list": "1000", + "price": "1000.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ], + "total": "1000.00", + "notes": [ + { + "text": "Margin scheme goods" + } + ] + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-11", + "amount": "1000.00", + "percent": "100%" + } + ], + "notes": "Instant Payment" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "margin-scheme", + "ext": { + "untdid-tax-category": "N" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file From 5caf6f29f3e50beb73308c4558e2b4611d39b558 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:12:02 +0000 Subject: [PATCH 16/73] Add the PINT AE Incoterms Write the delivery identity labelled Incoterms as the delivery terms (BTAE-22), keeping it out of the delivery location ID, and read it back. Needs the delivery terms on deliveries from gobl.ubl#189. --- README.md | 6 +- addon/pint/org_identity.go | 4 ++ ubl/ae.go | 64 +++++++++++++++++++ ubl/ae_internal_test.go | 52 +++++++++++++++ .../pint/ae/invoice-ae-export-summary.json | 10 ++- .../pint/ae/out/invoice-ae-export-summary.xml | 3 + 6 files changed, 135 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a7b98b8..5ddfa07 100644 --- a/README.md +++ b/README.md @@ -122,14 +122,16 @@ item's type of goods or services subject to the reverse charge as its `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and identities labelled `SAC` are written as service accounting codes. Lines with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with -no VAT amount. On import, it reads +no VAT amount, and the delivery identity labelled `Incoterms` is written as +the delivery terms. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and -the `N` category back as the `margin-scheme` key. +the `N` category back as the `margin-scheme` key, and the delivery terms back +as the `Incoterms` delivery identity. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index ab7db5b..85fcfd5 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -79,3 +79,7 @@ func GTINIdentity(ids []*org.Identity) *org.Identity { } return nil } + +// IdentityLabelIncoterms is the label of the delivery identity that holds +// the Incoterms code (BTAE-22), such as "CIF". +const IdentityLabelIncoterms = "Incoterms" diff --git a/ubl/ae.go b/ubl/ae.go index 5e7cda9..8531dde 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -7,6 +7,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -51,6 +52,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) exportAEBillingFrequency(out, inv) + exportAEIncoterms(out, inv) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -77,6 +79,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAETransactionType(in, inv) importAECreditNoteReason(in, inv) importAEBillingFrequency(in, inv) + importAEIncoterms(in, inv) importAELineExemptions(in.InvoiceLines, inv) importAELineExemptions(in.CreditNoteLines, inv) importAELineGoods(in.InvoiceLines, inv) @@ -428,6 +431,67 @@ func importAEBillingFrequency(in *goblubl.Invoice, inv *bill.Invoice) { setAEExt(inv, pint.ExtKeyBillingFrequency, cbc.Code(strings.TrimSpace(in.InvoicePeriod[0].DescriptionCode))) } +// exportAEIncoterms writes the delivery identity labelled "Incoterms" as +// cac:Delivery/cac:DeliveryTerms/cbc:ID (BTAE-22). gobl.ubl writes the first +// delivery identity as the delivery location ID, so the Incoterms one is +// replaced there by the next identity, or removed. +func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { + if inv.Delivery == nil { + return + } + var incoterms *org.Identity + var others []*org.Identity + for _, id := range inv.Delivery.Identities { + if id == nil { + continue + } + if id.Label == pint.IdentityLabelIncoterms && incoterms == nil { + incoterms = id + continue + } + others = append(others, id) + } + if incoterms == nil { + return + } + if len(out.Delivery) == 0 { + out.Delivery = []*goblubl.Delivery{{}} + } + d := out.Delivery[0] + d.DeliveryTerms = &goblubl.DeliveryTerms{ID: incoterms.Code.String()} + if d.DeliveryLocation == nil || d.DeliveryLocation.ID == nil { + return + } + if len(others) == 0 { + d.DeliveryLocation.ID = nil + return + } + id := &goblubl.IDType{Value: others[0].Code.String()} + if s := others[0].Ext.Get(iso.ExtKeySchemeID).String(); s != "" { + id.SchemeID = &s + } + d.DeliveryLocation.ID = id +} + +// importAEIncoterms reads the Incoterms back as a delivery identity labelled +// "Incoterms". +func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { + if len(in.Delivery) == 0 || in.Delivery[0] == nil || in.Delivery[0].DeliveryTerms == nil { + return + } + code := cbc.Code(strings.TrimSpace(in.Delivery[0].DeliveryTerms.ID)) + if code == "" { + return + } + if inv.Delivery == nil { + inv.Delivery = new(bill.DeliveryDetails) + } + inv.Delivery.Identities = append(inv.Delivery.Identities, &org.Identity{ + Label: pint.IdentityLabelIncoterms, + Code: code, + }) +} + // exportAELines completes the UBL lines, which gobl.ubl writes in the same // order as the invoice's lines. func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 88ecae5..5587293 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -742,6 +742,58 @@ func TestAELineItems(t *testing.T) { }) } +func TestAEIncoterms(t *testing.T) { + incoterms := &org.Identity{Label: pint.IdentityLabelIncoterms, Code: "CIF"} + gln := &org.Identity{Code: "5790000436101", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} + withLocation := func(id string) *goblubl.Invoice { + return &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: id}}}}} + } + + t.Run("writes the Incoterms as the delivery terms", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms}}}) + require.Len(t, out.Delivery, 1) + require.NotNil(t, out.Delivery[0].DeliveryTerms) + assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms.ID) + }) + + t.Run("keeps the Incoterms out of the delivery location ID", func(t *testing.T) { + out := withLocation("CIF") + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms, gln}}}) + id := out.Delivery[0].DeliveryLocation.ID + require.NotNil(t, id) + assert.Equal(t, "5790000436101", id.Value) + assert.Equal(t, "0088", *id.SchemeID) + + out = withLocation("CIF") + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms}}}) + assert.Nil(t, out.Delivery[0].DeliveryLocation.ID) + }) + + t.Run("nothing without Incoterms", func(t *testing.T) { + out := withLocation("5790000436101") + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{gln}}}) + assert.Nil(t, out.Delivery[0].DeliveryTerms) + assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) + exportAEIncoterms(out, &bill.Invoice{}) + assert.Nil(t, out.Delivery[0].DeliveryTerms) + }) + + t.Run("reads the Incoterms back", func(t *testing.T) { + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: &goblubl.DeliveryTerms{ID: " CIF "}}}} + inv := new(bill.Invoice) + importAEIncoterms(in, inv) + require.NotNil(t, inv.Delivery) + require.Len(t, inv.Delivery.Identities, 1) + assert.Equal(t, pint.IdentityLabelIncoterms, inv.Delivery.Identities[0].Label) + assert.Equal(t, cbc.Code("CIF"), inv.Delivery.Identities[0].Code) + + inv = new(bill.Invoice) + importAEIncoterms(new(goblubl.Invoice), inv) + assert.Nil(t, inv.Delivery) + }) +} + func TestExportAELineAmounts(t *testing.T) { line := func(category string) *goblubl.InvoiceLine { return &goblubl.InvoiceLine{Item: &goblubl.Item{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 7171098..c5829e7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "16a378b3d56b58f36b3b4dc3cb95719607315b27122fc83a774766dad7dab3f5" + "val": "3427bb173c02dafd94df0157402357448d0a62e64497bc8cd64d5979ba5f332d" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -169,7 +169,13 @@ "country": "GB" } ] - } + }, + "identities": [ + { + "label": "Incoterms", + "code": "CIF" + } + ] }, "totals": { "sum": "1000.00", diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index af68e57..486cd39 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -88,6 +88,9 @@ Buyer Warehouse + + CIF + 30 From d718a055576b867a5d3c754a905d2703b2ddecc3 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:59:22 +0000 Subject: [PATCH 17/73] Import the seller's legal form in the PINT AE parse fixtures gobl.ubl now reads cbc:CompanyLegalForm as the party registration. --- ubl/testdata/parse/pint/ae/out/allowance-exempt.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/deemed-supply.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/margin-scheme.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/reverse-charge.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json | 7 +++++-- ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json | 7 +++++-- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 00b4694..f6b346c 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b4032e917f8d9effdf3aa32eadc30ce30ea826ac049d48f8361675f9ce613fda" + "val": "63ddbbd5567ec8c914b4c49b0e7838005e30412d8c65bbfa2db6387da782f92e" } }, "doc": { @@ -75,7 +75,10 @@ { "num": "+971501234567" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json index 67cb7e0..352059d 100644 --- a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0943e2b9d2e7661f7da67c1932d737eb266483ca6ef8d3c2a46d3ddf6b24d6ce" + "val": "c9263477ad3b2a6c2982e4f11a36ee5e9aa4a3ed5c152147000812b1a2ee2d97" } }, "doc": { @@ -72,7 +72,10 @@ { "num": "+971501234567" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index c35407d..2967828 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2a6a49cd4519a550e26e9b89488e71891bb461d06a39b1678936ee56a6be2e40" + "val": "29e381ec0b2623d8090e20653969638c16ae2b607e9e5f669047cf9d93af4c7c" } }, "doc": { @@ -73,7 +73,10 @@ { "num": "Contact Number" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index cd2ada0..908efe9 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c7f5e00709da5880cdc4651f00c01804c62238aebcb073a24a39361c8e65cb2d" + "val": "0acba08a26a9042df724424835499955e1fb55311ec48169f01ad036cbd6cf72" } }, "doc": { @@ -76,7 +76,10 @@ { "num": "Contact Number" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 7b3c321..b4bed56 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5c83373a893c85d1ea86d5f174d41085dda3746576d927426bb9ff174da71812" + "val": "a71e6bfcbb05d2d451383f7ace53b50e061c70403e51779e3761842d1fb3c811" } }, "doc": { @@ -71,7 +71,10 @@ { "num": "Contact number" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json index 22d93ca..b1133b5 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d8858ddd18559301d6d750bc12ca4ae8b47f13c60c9b9df6cee38fbf98a2cd0c" + "val": "0ef230fc0741ebed67ff7772e31953ffc9f4eac9129d52bd53c9cd2a5aa2c68e" } }, "doc": { @@ -72,7 +72,10 @@ { "num": "+971501234567" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json index c4f18ea..e4ed08f 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "ef828a7a23f309e10f072ccb254218defc1368976eccace823a97aff688cca02" + "val": "134304a3c593cada215679a9393d4cad765d113020eb81f3b25dde2e1203aae5" } }, "doc": { @@ -78,7 +78,10 @@ { "num": "+971501234567" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 5b5736e..82327a5 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "09f47acb2f05d62c281a97219b2602c8f1791f4aa102b513ad2a0573937dbd36" + "val": "40fc24a9e477c33ccc2c5570b1a6d9dfa7dd3a3b770744bf57e05911f0a6630a" } }, "doc": { @@ -74,7 +74,10 @@ { "num": "Contact Number" } - ] + ], + "registration": { + "other": "Merchant" + } }, "customer": { "name": "Buyer Legal Name", From 998b82f453bf38989fe207c32656a76611f01592 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:59:43 +0000 Subject: [PATCH 18/73] Use the ICC Incoterms extensions for the PINT AE delivery terms GOBL now has icc-incoterms-2020 and -2010 extensions on delivery details, and gobl.ubl no longer maps delivery terms to delivery identities. Write the delivery terms from those extensions, and read them back as the 2020 edition, instead of using a delivery identity labelled Incoterms. --- README.md | 6 +-- addon/pint/org_identity.go | 4 -- ubl/ae.go | 50 +++++-------------- ubl/ae_internal_test.go | 45 ++++++++--------- .../pint/ae/invoice-ae-export-summary.json | 11 ++-- 5 files changed, 41 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 5ddfa07..cbf0914 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,8 @@ item's type of goods or services subject to the reverse charge as its `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and identities labelled `SAC` are written as service accounting codes. Lines with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with -no VAT amount, and the delivery identity labelled `Incoterms` is written as -the delivery terms. On import, it reads +no VAT amount, and the delivery's ICC Incoterms (`icc-incoterms-2020` or +`-2010`) are written as the delivery terms. On import, it reads the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and @@ -131,7 +131,7 @@ tags, and the credit note reason, billing frequency, line exemption reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and the `N` category back as the `margin-scheme` key, and the delivery terms back -as the `Incoterms` delivery identity. +as the `icc-incoterms-2020` extension. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 85fcfd5..ab7db5b 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -79,7 +79,3 @@ func GTINIdentity(ids []*org.Identity) *org.Identity { } return nil } - -// IdentityLabelIncoterms is the label of the delivery identity that holds -// the Incoterms code (BTAE-22), such as "CIF". -const IdentityLabelIncoterms = "Incoterms" diff --git a/ubl/ae.go b/ubl/ae.go index 8531dde..46260df 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -7,7 +7,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" - "github.com/invopop/gobl/catalogues/iso" + "github.com/invopop/gobl/catalogues/icc" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -431,50 +431,29 @@ func importAEBillingFrequency(in *goblubl.Invoice, inv *bill.Invoice) { setAEExt(inv, pint.ExtKeyBillingFrequency, cbc.Code(strings.TrimSpace(in.InvoicePeriod[0].DescriptionCode))) } -// exportAEIncoterms writes the delivery identity labelled "Incoterms" as -// cac:Delivery/cac:DeliveryTerms/cbc:ID (BTAE-22). gobl.ubl writes the first -// delivery identity as the delivery location ID, so the Incoterms one is -// replaced there by the next identity, or removed. +// exportAEIncoterms writes the delivery's Incoterms rule code, from the ICC +// Incoterms 2020 or 2010 extension, as cac:Delivery/cac:DeliveryTerms/cbc:ID +// (BTAE-22). func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Delivery == nil { return } - var incoterms *org.Identity - var others []*org.Identity - for _, id := range inv.Delivery.Identities { - if id == nil { - continue - } - if id.Label == pint.IdentityLabelIncoterms && incoterms == nil { - incoterms = id - continue - } - others = append(others, id) + code := inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020) + if code == "" { + code = inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2010) } - if incoterms == nil { + if code == "" { return } if len(out.Delivery) == 0 { out.Delivery = []*goblubl.Delivery{{}} } - d := out.Delivery[0] - d.DeliveryTerms = &goblubl.DeliveryTerms{ID: incoterms.Code.String()} - if d.DeliveryLocation == nil || d.DeliveryLocation.ID == nil { - return - } - if len(others) == 0 { - d.DeliveryLocation.ID = nil - return - } - id := &goblubl.IDType{Value: others[0].Code.String()} - if s := others[0].Ext.Get(iso.ExtKeySchemeID).String(); s != "" { - id.SchemeID = &s - } - d.DeliveryLocation.ID = id + out.Delivery[0].DeliveryTerms = &goblubl.DeliveryTerms{ID: code.String()} } -// importAEIncoterms reads the Incoterms back as a delivery identity labelled -// "Incoterms". +// importAEIncoterms reads the delivery terms back as the ICC Incoterms 2020 +// extension, the current edition, as PINT AE doesn't say which one a code is +// from. func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { if len(in.Delivery) == 0 || in.Delivery[0] == nil || in.Delivery[0].DeliveryTerms == nil { return @@ -486,10 +465,7 @@ func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { if inv.Delivery == nil { inv.Delivery = new(bill.DeliveryDetails) } - inv.Delivery.Identities = append(inv.Delivery.Identities, &org.Identity{ - Label: pint.IdentityLabelIncoterms, - Code: code, - }) + inv.Delivery.Ext = inv.Delivery.Ext.Set(icc.ExtKeyIncoterms2020, code) } // exportAELines completes the UBL lines, which gobl.ubl writes in the same diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 5587293..7e8433b 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -6,6 +6,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/icc" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" @@ -743,50 +744,46 @@ func TestAELineItems(t *testing.T) { } func TestAEIncoterms(t *testing.T) { - incoterms := &org.Identity{Label: pint.IdentityLabelIncoterms, Code: "CIF"} - gln := &org.Identity{Code: "5790000436101", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} - withLocation := func(id string) *goblubl.Invoice { - return &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: id}}}}} + delivery := func(key cbc.Key, code cbc.Code) *bill.Invoice { + return &bill.Invoice{Delivery: &bill.DeliveryDetails{Ext: tax.ExtensionsOf(cbc.CodeMap{key: code})}} } t.Run("writes the Incoterms as the delivery terms", func(t *testing.T) { out := new(goblubl.Invoice) - exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms}}}) + exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) require.Len(t, out.Delivery, 1) require.NotNil(t, out.Delivery[0].DeliveryTerms) assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms.ID) }) - t.Run("keeps the Incoterms out of the delivery location ID", func(t *testing.T) { - out := withLocation("CIF") - exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms, gln}}}) - id := out.Delivery[0].DeliveryLocation.ID - require.NotNil(t, id) - assert.Equal(t, "5790000436101", id.Value) - assert.Equal(t, "0088", *id.SchemeID) + t.Run("also from the 2010 edition", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2010, "DAT")) + assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms.ID) + }) - out = withLocation("CIF") - exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{incoterms}}}) - assert.Nil(t, out.Delivery[0].DeliveryLocation.ID) + t.Run("on the delivery gobl.ubl wrote", func(t *testing.T) { + out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: "5790000436101"}}}}} + exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) + require.Len(t, out.Delivery, 1) + assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms.ID) + assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) }) t.Run("nothing without Incoterms", func(t *testing.T) { - out := withLocation("5790000436101") - exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{Identities: []*org.Identity{gln}}}) - assert.Nil(t, out.Delivery[0].DeliveryTerms) - assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) + out := new(goblubl.Invoice) + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{}}) + assert.Empty(t, out.Delivery) exportAEIncoterms(out, &bill.Invoice{}) - assert.Nil(t, out.Delivery[0].DeliveryTerms) + assert.Empty(t, out.Delivery) }) - t.Run("reads the Incoterms back", func(t *testing.T) { + t.Run("reads the Incoterms back as the 2020 edition", func(t *testing.T) { in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: &goblubl.DeliveryTerms{ID: " CIF "}}}} inv := new(bill.Invoice) importAEIncoterms(in, inv) require.NotNil(t, inv.Delivery) - require.Len(t, inv.Delivery.Identities, 1) - assert.Equal(t, pint.IdentityLabelIncoterms, inv.Delivery.Identities[0].Label) - assert.Equal(t, cbc.Code("CIF"), inv.Delivery.Identities[0].Code) + assert.Equal(t, cbc.Code("CIF"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) inv = new(bill.Invoice) importAEIncoterms(new(goblubl.Invoice), inv) diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index c5829e7..7f2ae26 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3427bb173c02dafd94df0157402357448d0a62e64497bc8cd64d5979ba5f332d" + "val": "5ae6ba316b341cf944951696196580d75e1787daa1f691beb85003953d560203" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -170,12 +170,9 @@ } ] }, - "identities": [ - { - "label": "Incoterms", - "code": "CIF" - } - ] + "ext": { + "icc-incoterms-2020": "CIF" + } }, "totals": { "sum": "1000.00", From 93b82412253ac7077390ddec623498e0d54007bf Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:13:36 +0000 Subject: [PATCH 19/73] Add the usage of the PINT AE extensions - Say where each PINT AE extension applies: the PINT addon, the AE regime, and the object it goes on. - Remove the unused A-NZ and AE regime guard. - Drop a redundant field from the tax point date check. --- addon/pint/bill.go | 2 +- addon/pint/extensions.go | 45 +++++++++++++++++++++++++++++------ addon/pint/extensions_test.go | 26 ++++++++++++++++++++ addon/pint/pint.go | 3 --- 4 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 addon/pint/extensions_test.go diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 90ea52b..892151b 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -655,7 +655,7 @@ func pointDateBeforeIssueDate(val any) bool { if !ok || inv == nil || inv.ValueDate == nil { return true } - return inv.IssueDate.Date.DaysSince(inv.ValueDate.Date) > 0 + return inv.IssueDate.DaysSince(inv.ValueDate.Date) > 0 } // invoiceIsDue reports whether the invoice has an amount due for payment: the diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index c843cae..8e296e1 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -1,9 +1,13 @@ package pint import ( + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/i18n" + "github.com/invopop/gobl/org" "github.com/invopop/gobl/pkg/here" + "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/tax" ) // PINT AE extension keys, for the BTAE fields GOBL has no place for. @@ -36,11 +40,32 @@ const CreditNoteReasonVolumeDiscount cbc.Code = "VD" // in an invoice note (IBR-160-AE). const BillingFrequencyOthers cbc.Code = "OTH" +// Usages of the PINT AE extensions: offered by the PINT addon under the AE +// regime, on the object each one goes on. +var ( + usageAEInvoiceTax = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{bill.ShortSchemaTax}, + } + usageAETaxCombo = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{tax.ShortSchemaCombo}, + } + usageAEItem = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{org.ShortSchemaItem}, + } +) + // extensions are the extensions the PINT addon defines. They are only used // on UAE documents. var extensions = []*cbc.Definition{ { - Key: ExtKeyTransactionType, + Key: ExtKeyTransactionType, + Usage: usageAEInvoiceTax, Name: i18n.String{ i18n.EN: "PINT AE Transaction Type", }, @@ -66,7 +91,8 @@ var extensions = []*cbc.Definition{ Pattern: transactionTypePattern, }, { - Key: ExtKeyBeneficiaryID, + Key: ExtKeyBeneficiaryID, + Usage: usageAEInvoiceTax, Name: i18n.String{ i18n.EN: "PINT AE Beneficiary ID", }, @@ -78,7 +104,8 @@ var extensions = []*cbc.Definition{ }, }, { - Key: ExtKeyPrincipalID, + Key: ExtKeyPrincipalID, + Usage: usageAEInvoiceTax, Name: i18n.String{ i18n.EN: "PINT AE Principal ID", }, @@ -91,7 +118,8 @@ var extensions = []*cbc.Definition{ }, }, { - Key: ExtKeyCreditNoteReason, + Key: ExtKeyCreditNoteReason, + Usage: usageAEInvoiceTax, Name: i18n.String{ i18n.EN: "PINT AE Credit Note Reason", }, @@ -137,7 +165,8 @@ var extensions = []*cbc.Definition{ }, }, { - Key: ExtKeyBillingFrequency, + Key: ExtKeyBillingFrequency, + Usage: usageAEInvoiceTax, Name: i18n.String{ i18n.EN: "PINT AE Frequency of Billing", }, @@ -168,7 +197,8 @@ var extensions = []*cbc.Definition{ }, }, { - Key: ExtKeyExemption, + Key: ExtKeyExemption, + Usage: usageAETaxCombo, Name: i18n.String{ i18n.EN: "PINT AE VAT Exemption Reason", }, @@ -188,7 +218,8 @@ var extensions = []*cbc.Definition{ }, }, { - Key: ExtKeyGoodsType, + Key: ExtKeyGoodsType, + Usage: usageAEItem, Name: i18n.String{ i18n.EN: "PINT AE Type of Goods or Services", }, diff --git a/addon/pint/extensions_test.go b/addon/pint/extensions_test.go new file mode 100644 index 0000000..5123beb --- /dev/null +++ b/addon/pint/extensions_test.go @@ -0,0 +1,26 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestExtensionsUsage(t *testing.T) { + addon := tax.AddonForKey(pint.V1) + require.NotNil(t, addon) + require.NotEmpty(t, addon.Extensions) + for _, ext := range addon.Extensions { + require.NotNil(t, ext.Usage, ext.Key) + assert.Contains(t, ext.Usage.Keys, pint.V1, ext.Key) + assert.Contains(t, ext.Usage.Codes, cbc.Code(ae.CountryCode), ext.Key) + assert.Len(t, ext.Usage.Schemas, 1, ext.Key) + assert.NoError(t, rules.Validate(ext.Usage), ext.Key) + } +} diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 1fe4df9..f8361e1 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -31,9 +31,6 @@ var regimesAUNZ = []l10n.TaxCountryCode{l10n.AU.Tax(), l10n.NZ.Tax()} // regimesAE lists the tax regimes the PINT AE jurisdiction rules apply to. var regimesAE = []l10n.TaxCountryCode{l10n.AE.Tax()} -// regimesAUNZAE lists the tax regimes the PINT A-NZ and PINT AE jurisdictions rules apply to. -var regimesAUNZAE = []l10n.TaxCountryCode{l10n.AU.Tax(), l10n.NZ.Tax(), l10n.AE.Tax()} - func init() { tax.RegisterAddonDef(newV1Addon()) rules.RegisterWithGuard( From e55a3a3dd53b35277dd8e267d79a84d097c66da7 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:50:40 +0000 Subject: [PATCH 20/73] Align the PINT AE rules with the Schematron after review - Check only the first credit transfer for IBR-192-AE, as it is the only one written. - Build the transaction type from the tags only, so removing a tag clears its flag. - Set the scope of UAE identities here instead of in the AE regime, and only when no other identity of the party has that scope. - Drop the IBR-178-AE rule, which EN 16931 already covers. - Follow the tests of IBR-002-AE, IBR-127-AE, IBR-138-AE and IBR-188-AE, which check less than their texts say. - Check IBR-128-AE on the issuer and the line sellers too. - Ignore the EN 16931 VATEX rule on UAE documents: PINT AE only asks for the UAE exemption reason on exempt lines. - Keep the margin scheme category and the addon's tags to UAE documents. - Merge the standard rate above zero rule into the 5% one. Co-Authored-By: Claude Fable 5.2 --- addon/pint/bill.go | 186 +++++++++++++++++++--------- addon/pint/bill_test.go | 124 ++++++++++++++++--- addon/pint/extensions.go | 2 +- addon/pint/org_identity.go | 40 ++++++ addon/pint/org_identity_test.go | 58 +++++++++ addon/pint/pay.go | 20 +-- addon/pint/pay_test.go | 16 +++ addon/pint/pint.go | 7 ++ addon/pint/scenarios.go | 2 +- addon/pint/tax_combo.go | 39 ++++-- addon/pint/tax_combo_test.go | 37 ++++-- addon/pint/transaction_type.go | 16 +-- addon/pint/transaction_type_test.go | 11 +- 13 files changed, 431 insertions(+), 127 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 892151b..df2c435 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -10,7 +10,6 @@ import ( "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" "github.com/invopop/gobl/l10n" - "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" @@ -57,15 +56,16 @@ func billInvoiceRules() *rules.Set { ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), + // EN 16931 wants an EU VATEX code or an exemption note for every E, O + // and AE breakdown (BR-E-10, BR-O-10, BR-AE-10). PINT AE has no such + // rule: it only asks for the UAE exemption reason on exempt lines + // (IBR-167-AE), and no official example has a reason on a breakdown. + rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-08"), rules.Assert("05", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", is.Func("has AED exchange rate", exchangeRateHasAED), ), - rules.Field("exchange_rates", - rules.Each(rules.Field("amount", - rules.Assert("06", "exchange rate must have at most 6 decimals (IBR-002-AE)", - is.Func("has at most 6 decimals", amountHasAtMost6Decimals), - ), - )), + rules.Assert("06", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), rules.When( is.Not(is.Or( @@ -81,7 +81,7 @@ func billInvoiceRules() *rules.Set { documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", rules.Assert("08", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", - is.Func("has tax ID code", partyHasTaxIDCode), + org.PartyHasTaxIDCode(), ), ), ), @@ -152,12 +152,21 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceIsDeemedSupply), )), rules.When( - is.Func("amount is due", invoiceIsDue), - rules.Assert("17", "payment due date is required when an amount is due, except on credit notes and deemed supplies (IBR-127-AE)", + is.Func("amount due is positive", invoiceIsDue), + rules.Assert("17", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Func("has due date", invoiceHasDueDate), ), ), ), + // IBR-128-AE's text names the seller, buyer, tax representative and + // delivery subdivisions (IBT-039, IBT-054, IBT-068, IBT-079), but its + // test never runs on the seller's and buyer's addresses: its context, + // cac:PostalAddress, comes after their address rules (IBR-143-AE, + // IBR-144-AE) in the same pattern, where a node only fires the first + // rule it matches. Rules 19 and 21 follow the text there, as the + // official examples do, so they check more than the test. Rules 22 + // and 23, and line rule 11, follow the test: gobl.ubl also writes the + // issuer and the line sellers with a cac:PostalAddress. rules.Field("supplier", rules.Assert("18", "supplier address must have a street, city and region (IBR-143-AE)", is.Func("first address has street, city and region", partyAddressIsComplete), @@ -180,26 +189,31 @@ func billInvoiceRules() *rules.Set { is.Func("first address region is an emirate", partyAddressHasEmirate), ), ), + rules.Field("issuer", + rules.Assert("23", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + ), ), rules.Field("supplier", rules.When( is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), - rules.Assert("23", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", + rules.Assert("24", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), - rules.Assert("24", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", + rules.Assert("25", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", is.Func("legal identity has a PINT AE type", partyLegalIdentityHasTypeAE), ), ), - rules.Assert("25", "supplier passport must have the issuing country (IBR-012-AE)", + rules.Assert("26", "supplier passport must have the issuing country (IBR-012-AE)", is.Func("passport has country", partyPassportHasCountry), ), - rules.Assert("26", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", + rules.Assert("27", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Func("trade license has authority", partyTradeLicenseHasAuthority), ), - rules.Assert("27", "supplier must have at most one tax scope identity (IBR-178-AE)", - is.Func("at most one tax scope identity", partyHasAtMostOneTaxIdentity), - ), + // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity + // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two + // PartyTaxSchemes with one VAT that it accepts. rules.Field("identities", rules.Each( rules.When( is.Func("tax scope", identityHasTaxScope), @@ -228,6 +242,9 @@ func billInvoiceRules() *rules.Set { rules.Assert("31", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Func("trade license has authority", partyTradeLicenseHasAuthority), ), + // IBR-149-AE's text asks for the buyer legal registration identifier + // (IBT-047), but its test checks the tax registration, + // cac:PartyTaxScheme/cbc:CompanyID. We follow the test. rules.When( is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), rules.Assert("32", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", @@ -252,8 +269,8 @@ func billInvoiceRules() *rules.Set { ), rules.When( is.Func("summary invoice", invoiceIsSummary), - rules.Assert("37", "ordering period is required on summary invoices (IBR-138-AE)", - is.Func("has ordering period", invoiceHasOrderingPeriod), + rules.Assert("37", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), rules.When( @@ -276,6 +293,10 @@ func billInvoiceRules() *rules.Set { is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), + // IBR-152-AE's text says the delivery country should not be AE on + // exports, but its test accepts a delivery address in the UAE, and + // only asks the others for a street, city and region. We follow the + // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), rules.Assert("42", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", @@ -394,6 +415,16 @@ func billInvoiceRules() *rules.Set { ), ), ), + // The tags the addon defines are for UAE documents, but GOBL can't limit + // an addon's tags to a regime. Other documents can only use the ones + // their regime, another addon or GOBL itself defines too, as before the + // addon had tags. + rules.When( + is.Not(is.InContext(tax.RegimeIn(regimesAE...))), + rules.Assert("57", "PINT AE tags can only be used on UAE documents", + is.Func("has no PINT AE tags", invoiceHasNoAETags), + ), + ), ) } @@ -481,12 +512,19 @@ func billLineRules() *rules.Set { // gobl.ubl writes identities with a label and no scheme ID as item // classifications, with the label as their list. FormatAE writes the // SAC ones as service accounting codes instead (IBR-189-AE). + // IBR-188-AE's text asks for HS on every classification, but its + // test passes when any one is HS. rules.Field("identities", - rules.Assert("10", "item classifications must use the HS list (IBR-188-AE)", - is.Func("classifications are HS", identitiesClassifiedAsHS), + rules.Assert("10", "item classifications must include one from the HS list (IBR-188-AE)", + is.Func("classifications include HS", identitiesClassifiedWithHS), ), ), ), + rules.Field("seller", + rules.Assert("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + ), ), ) } @@ -506,6 +544,32 @@ func documentTypeIn(codes ...cbc.Code) func(any) bool { } } +// invoiceHasNoAETags reports whether the invoice has none of the tags only +// the PINT addon defines. A tag its regime, another addon or GOBL itself +// defines with the same key, such as the Spanish "summary", is not one. +func invoiceHasNoAETags(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return true + } + others := bill.DefaultInvoiceTags() + if r := inv.RegimeDef(); r != nil { + others = others.Merge(tax.TagSetForSchema(r.Tags, bill.ShortSchemaInvoice)) + } + for _, a := range inv.AddonDefs() { + if a.Key != V1 { + others = others.Merge(tax.TagSetForSchema(a.Tags, bill.ShortSchemaInvoice)) + } + } + keys := others.Keys() + for _, def := range invoiceTags.List { + if inv.HasTags(def.Key) && !def.Key.In(keys...) { + return false + } + } + return true +} + // partyHasIdentifier reports whether the party can be identified through a tax // identity code or at least one organisation identity. func partyHasIdentifier(val any) bool { @@ -525,12 +589,17 @@ func exchangeRateHasAED(val any) bool { currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) != nil } -// amountHasAtMost6Decimals reports whether an exchange rate amount has at -// most 6 decimals, the limit for cbc:CalculationRate (IBR-002-AE). The rules -// engine passes struct fields as pointers, hence *num.Amount. -func amountHasAtMost6Decimals(val any) bool { - a, ok := val.(*num.Amount) - return ok && a != nil && a.Exp() <= 6 +// exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from +// the invoice currency to AED has at most 6 decimals, the limit for +// cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices +// without it pass: they are in AED, or rule 05 reports them. +func exchangeRateToAEDHasAtMost6Decimals(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil { + return true + } + rate := currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) + return rate == nil || rate.Amount.Exp() <= 6 } // invoiceIsCreditNote reports whether the invoice is a credit note. The EN @@ -549,13 +618,6 @@ func invoiceHasPaymentInstructions(val any) bool { return ok && inv != nil && inv.Payment != nil && inv.Payment.Instructions != nil } -// partyHasTaxIDCode reports whether the party has a tax ID with a code, the -// TRN written as the seller's PartyTaxScheme/CompanyID (IBR-134-AE). -func partyHasTaxIDCode(val any) bool { - p, ok := val.(*org.Party) - return ok && p != nil && p.TaxID != nil && p.TaxID.Code != "" -} - // invoiceHasReverseChargeLine reports whether any line of the invoice has a // VAT combo with the reverse charge key, category AE (IBR-103-AE). func invoiceHasReverseChargeLine(val any) bool { @@ -658,17 +720,18 @@ func pointDateBeforeIssueDate(val any) bool { return inv.IssueDate.DaysSince(inv.ValueDate.Date) > 0 } -// invoiceIsDue reports whether the invoice has an amount due for payment: the -// due total when set, the payable total otherwise. It follows isDue in the -// EN 16931 addon, which is not exported. +// invoiceIsDue reports whether the amount gobl.ubl writes as +// cbc:PayableAmount is greater than zero, as IBR-127-AE tests it: the due +// total when set, the payable total otherwise. func invoiceIsDue(val any) bool { inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { + if !ok || inv == nil || inv.Totals == nil { return false } - return inv.Totals != nil && - ((inv.Totals.Due != nil && !inv.Totals.Due.IsZero()) || - (inv.Totals.Due == nil && !inv.Totals.Payable.IsZero())) + if inv.Totals.Due != nil { + return inv.Totals.Due.IsPositive() + } + return inv.Totals.Payable.IsPositive() } // invoiceHasDueDate reports whether the invoice's payment terms have a due date, @@ -819,14 +882,6 @@ func identityHasTaxScope(val any) bool { return ok && id != nil && id.Scope == org.IdentityScopeTax } -// partyHasAtMostOneTaxIdentity reports whether the party has at most one tax -// scope identity. With the TRN, that makes at most two seller PartyTaxSchemes, -// only one of them VAT (IBR-178-AE). -func partyHasAtMostOneTaxIdentity(val any) bool { - p, ok := val.(*org.Party) - return ok && p != nil && partyTaxIdentityCount(p) <= 1 -} - // partyHasAtMostOneTaxRegistration reports whether the party has at most one // tax registration, counting the tax ID code and the tax scope identities, as // the buyer can only have one PartyTaxScheme/CompanyID (IBR-179-AE). @@ -874,11 +929,17 @@ func invoiceHasExt(key cbc.Key) func(any) bool { } } -// invoiceHasOrderingPeriod reports whether the invoice has an ordering -// period, which gobl.ubl writes as cac:InvoicePeriod (IBR-138-AE). -func invoiceHasOrderingPeriod(val any) bool { +// invoiceHasInvoicePeriod reports whether the invoice has what is written as +// cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's +// text asks for the invoicing period, but its test only checks the element +// is there, so the frequency alone passes. +func invoiceHasInvoicePeriod(val any) bool { inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Ordering != nil && inv.Ordering.Period != nil + if !ok || inv == nil { + return false + } + return (inv.Ordering != nil && inv.Ordering.Period != nil) || + inv.Tax.GetExt(ExtKeyBillingFrequency) != "" } // principalIsNotSupplier reports whether the principal ID differs from the @@ -1104,23 +1165,26 @@ func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { return false } -// identitiesClassifiedAsHS reports whether the identities gobl.ubl writes as -// item classifications, those with a label and no scheme ID, are all HS ones, -// apart from the service accounting codes. -func identitiesClassifiedAsHS(val any) bool { +// identitiesClassifiedWithHS reports whether the identities gobl.ubl writes +// as item classifications, those with a label and no scheme ID, include an HS +// one. Items without classifications pass, and the service accounting codes +// don't count as one. +func identitiesClassifiedWithHS(val any) bool { ids, ok := val.([]*org.Identity) if !ok { return false } + classified := false for _, id := range ids { - if id == nil || id.Label == "" || id.Ext.Has(iso.ExtKeySchemeID) { + if id == nil || id.Label == "" || id.Label == IdentityLabelSAC || id.Ext.Has(iso.ExtKeySchemeID) { continue } - if id.Label != IdentityLabelHS && id.Label != IdentityLabelSAC { - return false + if id.Label == IdentityLabelHS { + return true } + classified = true } - return true + return !classified } // comboIsMarginScheme reports whether a tax combo is VAT under the profit diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 8a69378..ee6e6cf 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -180,6 +180,20 @@ func TestBillInvoiceRulesAE(t *testing.T) { assert.Contains(t, validate(inv), faultDecimals) }) + t.Run("only the rate to AED is checked, as it is the one written (IBR-002-AE)", func(t *testing.T) { + toEUR := ¤cy.ExchangeRate{From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(9212345, 7)} + inv := aeInvoice() + inv.Currency = currency.USD + inv.ExchangeRates = append(usdToAED(num.MakeAmount(3672500, 6)), toEUR) + assert.NotContains(t, validate(inv), faultDecimals) + + inv = aeInvoice() + inv.ExchangeRates = []*currency.ExchangeRate{ + {From: currency.AED, To: currency.EUR, Amount: num.MakeAmount(2512345, 7)}, + } + assert.NotContains(t, validate(inv), faultDecimals) + }) + t.Run("invoice without payment is rejected (IBR-191-AE)", func(t *testing.T) { inv := aeInvoice() inv.Payment = nil @@ -462,6 +476,15 @@ func TestBillDocumentRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultDueDate) }) + t.Run("due date is not required when the amount due is negative (IBR-127-AE)", func(t *testing.T) { + inv := standard() + inv.Payment.Terms = nil + inv.Payment.Advances = []*pay.Record{{Description: "Overpaid", Percent: num.NewPercentage(150, 2)}} + out := aeFaults(t, inv) + require.True(t, inv.Totals.Due.IsNegative()) + assert.NotContains(t, out, faultDueDate) + }) + t.Run("due date is not required on 381, 81 and 261 (IBR-127-AE)", func(t *testing.T) { for name, inv := range map[string]*bill.Invoice{ "381": aeDocument(bill.InvoiceTypeCreditNote), @@ -491,6 +514,8 @@ func TestBillAddressRulesAE(t *testing.T) { faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-11" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -546,6 +571,25 @@ func TestBillAddressRulesAE(t *testing.T) { assert.Contains(t, out, faultTaxRepEmirate) }) + t.Run("issuer and line seller UAE regions must be emirate codes too (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer", Addresses: aeAddress("Dubai")}} + inv.Lines[0].Seller = &org.Party{Name: "Maker", Addresses: aeAddress("Dubai")} + out := aeFaults(t, inv) + assert.Contains(t, out, faultIssuerEmirate) + assert.Contains(t, out, faultSellerEmirate) + + inv = standard() + inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer", Addresses: aeAddress("DXB")}} + inv.Lines[0].Seller = &org.Party{ + Name: "Maker", + Addresses: []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}}, + } + out = aeFaults(t, inv) + assert.NotContains(t, out, faultIssuerEmirate) + assert.NotContains(t, out, faultSellerEmirate) + }) + t.Run("every emirate code is accepted (IBR-128-AE)", func(t *testing.T) { for _, code := range []string{"AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK"} { inv := standard() @@ -582,11 +626,10 @@ func aeIdentityDocument() *bill.Invoice { func TestBillIdentityRulesAE(t *testing.T) { const ( - faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" - faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultSupplierTaxIdentities = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" @@ -655,6 +698,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("only the first legal identity is checked (IBR-173-AE)", func(t *testing.T) { inv := aeIdentityDocument() + inv.Supplier.Identities[0].Scope = org.IdentityScopeLegal inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalType) @@ -695,14 +739,6 @@ func TestBillIdentityRulesAE(t *testing.T) { } }) - t.Run("supplier has at most one tax identity (IBR-178-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}, - &org.Identity{Scope: org.IdentityScopeTax, Type: "TIN", Code: "1234567891"}) - assert.Contains(t, aeFaults(t, inv), faultSupplierTaxIdentities) - }) - t.Run("customer with a UAE endpoint not starting with 1 or 9 needs a tax registration (IBR-149-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = nil @@ -778,8 +814,11 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { t.Run("transaction type must be 8 flags (IBR-154-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) setExt(inv, pint.ExtKeyTransactionType, "0000002") - assert.Contains(t, aeFaults(t, inv), faultTransactionType) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) + require.Error(t, err) + assert.Contains(t, err.Error(), faultTransactionType) }) t.Run("deemed supplies need no payment instructions or due date (IBR-191-AE, IBR-127-AE)", func(t *testing.T) { @@ -803,12 +842,17 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, inv)) }) - t.Run("summary invoice needs the ordering period (IBR-138-AE)", func(t *testing.T) { + t.Run("summary invoice needs the ordering period or billing frequency (IBR-138-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagSummary) assert.Contains(t, aeFaults(t, inv), faultSummaryPeriod) start, end := cal.MakeDate(2026, 10, 1), cal.MakeDate(2026, 10, 31) inv.Ordering = &bill.Ordering{Period: &cal.Period{Start: &start, End: &end}} assert.Empty(t, aeFaults(t, inv)) + + // The billing frequency alone is written as cac:InvoicePeriod too. + inv = aeDocument(bill.InvoiceTypeStandard, pint.TagSummary) + setExt(inv, pint.ExtKeyBillingFrequency, "MTH") + assert.Empty(t, aeFaults(t, inv)) }) t.Run("disclosed agent needs the principal ID (IBR-137-AE)", func(t *testing.T) { @@ -1172,10 +1216,13 @@ func TestBillItemTypeRulesAE(t *testing.T) { assert.NotContains(t, out, faultGoodsServices) }) - t.Run("item classifications must be HS (IBR-188-AE)", func(t *testing.T) { + t.Run("item classifications must include an HS one (IBR-188-AE)", func(t *testing.T) { cpv := &org.Identity{Label: "CPV", Code: "30200000"} - assert.Contains(t, aeFaults(t, item("", hs, cpv)), faultClassification) + assert.Contains(t, aeFaults(t, item("", cpv)), faultClassification) + assert.Contains(t, aeFaults(t, item("", cpv, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, cpv)), faultClassification) assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", sac)), faultClassification) // Identities with a scheme ID aren't classifications. gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} @@ -1229,3 +1276,46 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, margin()), faultOnlyMargin, "N lines don't need the tag") }) } + +func TestBillTagsOutsideAE(t *testing.T) { + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + faults := func(t *testing.T, inv *bill.Invoice) string { + t.Helper() + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(inv.GetRegime())) + if err == nil { + return "" + } + return err.Error() + } + aeTags := []cbc.Key{ + pint.TagOutsideScope, pint.TagFreeTradeZone, pint.TagDeemedSupply, pint.TagMarginScheme, + pint.TagSummary, pint.TagContinuousSupply, pint.TagDisclosedAgent, pint.TagECommerce, tax.TagExport, + } + + t.Run("UAE documents can use every tag", func(t *testing.T) { + inv := scenarioInvoice(l10n.AE.Tax(), bill.InvoiceTypeStandard, aeTags...) + assert.NotContains(t, faults(t, inv), faultTags) + }) + + t.Run("other documents can't use the PINT AE tags", func(t *testing.T) { + for _, tag := range aeTags { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tag) + assert.Contains(t, faults(t, inv), faultTags, tag) + } + }) + + t.Run("other documents keep the tags GOBL and their regime define", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tax.TagSelfBilled) + assert.NotContains(t, faults(t, inv), faultTags) + + // The Spanish regime has its own "summary" tag. + inv = scenarioInvoice(l10n.ES.Tax(), bill.InvoiceTypeStandard, pint.TagSummary) + assert.NotContains(t, faults(t, inv), faultTags) + }) + + t.Run("untagged documents pass", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + assert.NotContains(t, faults(t, inv), faultTags) + }) +} diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 8e296e1..70ec9e4 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -79,7 +79,7 @@ var extensions = []*cbc.Definition{ It is built from the invoice tags with the same names ("free-trade-zone", "deemed-supply", "margin-scheme", "summary", "continuous-supply", "disclosed-agent", "e-commerce" and "export"). - Without any of those tags, a code set directly is kept. + A code set directly is replaced. `), }, Sources: []*cbc.Source{ diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index ab7db5b..b0b7a5d 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -66,6 +66,46 @@ func IdentityKeyAE(typ cbc.Code) cbc.Key { return "" } +// normalizePartyIdentityScopes gives a party's UAE identities the scope +// gobl.ubl needs to write them where PINT AE reads them: tax for the TIN, +// written as a cac:PartyTaxScheme, and legal for the trade licence, Emirates +// ID, passport and Cabinet Decision, written as +// cac:PartyLegalEntity/cbc:CompanyID. Only an identity without a scope gets +// one, and only when no other identity of the party has it, as EN 16931 +// allows one identity per scope (BT-30, BT-47, BT-31, BT-48). +func normalizePartyIdentityScopes(p *org.Party) { + if p == nil { + return + } + taken := make(map[cbc.Key]bool) + for _, id := range p.Identities { + if id != nil { + taken[id.Scope] = true + } + } + for _, id := range p.Identities { + if id == nil || id.Scope != "" { + continue + } + if scope := identityScopeAE(id.Key); scope != "" && !taken[scope] { + id.Scope = scope + taken[scope] = true + } + } +} + +// identityScopeAE returns the scope PINT AE reads an identity key from, or an +// empty key if it has none. +func identityScopeAE(key cbc.Key) cbc.Key { + if key == ae.IdentityKeyTIN { + return org.IdentityScopeTax + } + if IdentityTypeAE(key) != "" { + return org.IdentityScopeLegal + } + return "" +} + // IdentitySchemeGTIN is the ISO 6523 scheme of a GTIN, the item standard // identifier reverse charge lines need (IBR-174-AE). const IdentitySchemeGTIN cbc.Code = "0160" diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index 531bd69..d7aeb53 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -4,9 +4,13 @@ import ( "testing" "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/norm" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" ) @@ -38,3 +42,57 @@ func TestIdentityKeyAE(t *testing.T) { assert.Equal(t, want, pint.IdentityKeyAE(typ), typ) } } + +func TestNormalizePartyIdentityScopes(t *testing.T) { + normalize := func(regime l10n.TaxCountryCode, ids ...*org.Identity) []cbc.Key { + p := &org.Party{Name: "Party", Identities: ids} + norm.Normalize(p, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) + scopes := make([]cbc.Key, len(p.Identities)) + for i, id := range p.Identities { + scopes[i] = id.Scope + } + return scopes + } + tin := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"} } + eid := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"} } + passport := func() *org.Identity { + return &org.Identity{Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"} + } + + t.Run("TIN gets the tax scope and legal registrations the legal scope", func(t *testing.T) { + assert.Equal(t, []cbc.Key{org.IdentityScopeTax, org.IdentityScopeLegal}, + normalize(l10n.AE.Tax(), tin(), passport())) + for _, key := range []cbc.Key{ae.IdentityKeyTradeLicense, ae.IdentityKeyEmiratesID, ae.IdentityKeyCabinetDecision} { + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, + normalize(l10n.AE.Tax(), &org.Identity{Key: key, Code: "784199012345671"}), key) + } + }) + + t.Run("only the first identity of each scope gets it", func(t *testing.T) { + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal, ""}, + normalize(l10n.AE.Tax(), eid(), passport())) + assert.Equal(t, []cbc.Key{org.IdentityScopeTax, ""}, + normalize(l10n.AE.Tax(), tin(), tin())) + }) + + t.Run("a scope another identity already has is not given again", func(t *testing.T) { + legal := &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"} + assert.Equal(t, []cbc.Key{"", org.IdentityScopeLegal}, + normalize(l10n.AE.Tax(), passport(), legal)) + }) + + t.Run("an explicit scope is kept", func(t *testing.T) { + id := eid() + id.Scope = org.IdentityScopeTax + assert.Equal(t, []cbc.Key{org.IdentityScopeTax}, normalize(l10n.AE.Tax(), id)) + }) + + t.Run("other identities get no scope", func(t *testing.T) { + assert.Equal(t, []cbc.Key{""}, + normalize(l10n.AE.Tax(), &org.Identity{Type: "XYZ", Code: "123"})) + }) + + t.Run("only under the AE regime", func(t *testing.T) { + assert.Equal(t, []cbc.Key{"", ""}, normalize(l10n.AU.Tax(), tin(), passport())) + }) +} diff --git a/addon/pint/pay.go b/addon/pint/pay.go index b0417d8..3259582 100644 --- a/addon/pint/pay.go +++ b/addon/pint/pay.go @@ -32,7 +32,7 @@ func payInstructionsRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.When(is.Func("payment means is credit transfer", instructionsMeanCreditTransferAE), - rules.Assert("02", "credit transfer must include an IBAN or account number (IBR-192-AE)", + rules.Assert("02", "first credit transfer must include an IBAN or account number (IBR-192-AE)", is.Func("has a payment account identifier", instructionsHaveAccountID), ), ), @@ -89,19 +89,19 @@ func creditTransferHasAccountID(val any) bool { return ct.IBAN != "" || ct.Number != "" } -// instructionsHaveAccountID reports whether at least one of the instructions' -// credit transfers carries an account identifier (ibt-084), either an IBAN or -// an account number. A missing credit transfer list fails, so one check covers -// both cases of IBR-192-AE. +// instructionsHaveAccountID reports whether the instructions' first credit +// transfer carries an account identifier (ibt-084), either an IBAN or an +// account number. gobl.ubl only writes the first credit transfer as +// cac:PayeeFinancialAccount, so the others can't satisfy IBR-192-AE. A missing +// credit transfer list fails, so one check covers both cases of the rule. func instructionsHaveAccountID(val any) bool { instr, ok := val.(*pay.Instructions) if !ok || instr == nil { return true } - for _, ct := range instr.CreditTransfer { - if ct != nil && (ct.IBAN != "" || ct.Number != "") { - return true - } + if len(instr.CreditTransfer) == 0 { + return false } - return false + ct := instr.CreditTransfer[0] + return ct != nil && (ct.IBAN != "" || ct.Number != "") } diff --git a/addon/pint/pay_test.go b/addon/pint/pay_test.go index 3a7cdc2..8315ec5 100644 --- a/addon/pint/pay_test.go +++ b/addon/pint/pay_test.go @@ -11,6 +11,7 @@ import ( "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func instructionsWithMeansCode(code string) *pay.Instructions { @@ -117,6 +118,16 @@ func TestPayInstructionsRulesAE(t *testing.T) { assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") }) + t.Run("only the first credit transfer counts, as it is the one written (IBR-192-AE)", func(t *testing.T) { + instr := instructionsWithMeansCode("30") + instr.CreditTransfer = []*pay.CreditTransfer{ + {Name: "Emirates NBD"}, + {IBAN: "AE070331234567890123456"}, + } + err := validate(instr) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + }) + t.Run("other payment means are not checked", func(t *testing.T) { for _, code := range []string{"58", "31"} { instr := instructionsWithMeansCode(code) @@ -140,5 +151,10 @@ func TestPayInstructionsRulesAE(t *testing.T) { instr.CreditTransfer = []*pay.CreditTransfer{{BIC: "EBILAEAD"}} err := rules.Validate(instr, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.SG.Tax())) assert.NoError(t, err) + + // A-NZ documents get their own rule for the same case, not the AE one. + err = rules.Validate(instr, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + require.Error(t, err) + assert.NotContains(t, err.Error(), "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") }) } diff --git a/addon/pint/pint.go b/addon/pint/pint.go index f8361e1..d882a99 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -51,6 +51,8 @@ func init() { norm.When( is.InContext(tax.RegimeIn(regimesAE...)), norm.For(normalizeTransactionType), + norm.For(normalizePartyIdentityScopes), + norm.For(normalizeTaxComboAE), ), ) } @@ -85,6 +87,11 @@ func newV1Addon() *tax.AddonDef { UAE trade licences carry their issuing authority in the description, and passports their issuing country. + UAE identities without a scope get the one PINT AE reads them from: + "tax" for the TIN, and "legal" for the first trade licence, Emirates + ID, passport or Cabinet Decision of a party that has no legal + identity yet. + UAE invoices get the PINT AE transaction type from their tags: "free-trade-zone", "deemed-supply", "margin-scheme", "summary", "continuous-supply", "disclosed-agent", "e-commerce" and "export". diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index c65d3d6..2600252 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -39,7 +39,7 @@ var invoiceTags = &tax.TagSet{ i18n.EN: "Outside Scope", }, Desc: i18n.String{ - i18n.EN: "Marks a PINT AE document as out of scope of VAT, the UAE 'commercial invoice'. Invoices are sent with document type 480 and credit notes with 81. Has no effect outside the UAE.", + i18n.EN: "Marks a PINT AE document as out of scope of VAT, the UAE 'commercial invoice'. Invoices are sent with document type 480 and credit notes with 81. Only for UAE documents.", }, }, }, transactionTypeTags...), diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index d8d0734..2b55934 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -18,7 +18,8 @@ import ( const TaxCategoryMarginScheme cbc.Code = "N" // taxCategoryMap maps GOBL tax keys to the UNTDID 5305 tax category codes that -// PINT recognises, mirroring EN 16931's VAT key mapping. +// PINT recognises, mirroring EN 16931's VAT key mapping. The PINT AE margin +// scheme category is not here, as it is only for UAE documents. var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ tax.KeyStandard: en16931.TaxCategoryStandard, tax.KeyZero: en16931.TaxCategoryZero, @@ -27,7 +28,6 @@ var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ tax.KeyIntraCommunity: en16931.TaxCategoryIntraCommunity, tax.KeyExport: en16931.TaxCategoryExport, tax.KeyOutsideScope: en16931.TaxCategoryOutsideScope, - ae.TaxKeyMarginScheme: TaxCategoryMarginScheme, }) // taxCategoryCodesAUNZ lists the subset of UNTDID 5305 tax category codes @@ -62,6 +62,14 @@ func normalizeTaxCombo(tc *tax.Combo) { } } +// normalizeTaxComboAE maps the AE regime's margin scheme key to the PINT AE +// margin scheme category on UAE documents. +func normalizeTaxComboAE(tc *tax.Combo) { + if tc != nil && tc.Key == ae.TaxKeyMarginScheme { + tc.Ext = tc.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) + } +} + func taxComboRules() *rules.Set { return rules.For(new(tax.Combo), // PINT recognises GST (and other non-VAT schemes) as standard, zero or @@ -69,9 +77,14 @@ func taxComboRules() *rules.Set { // to outside scope must not apply here. rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-05"), - rules.Field("ext", - rules.Assert("01", "invoice line tax category code must be a recognised PINT UNTDID 5305 code", - tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryMap.Values()...), + // UAE documents have their own list, with the margin scheme category + // (rule 03). + rules.When( + is.Not(is.InContext(tax.RegimeIn(regimesAE...))), + rules.Field("ext", + rules.Assert("01", "invoice line tax category code must be a recognised PINT UNTDID 5305 code", + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryMap.Values()...), + ), ), ), rules.When( @@ -83,12 +96,13 @@ func taxComboRules() *rules.Set { ), ), - // TODO: rules 04 and 06 should also apply to AUNZ. + // TODO: A-NZ has the same zero rate rule (05), and asks for a standard + // rate above zero (ALIGNED-IBRP-S-05/06/07). rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // EN 16931 checks VAT category codes against its own list, which has - // no PINT AE margin scheme category (N). Rule 01 checks them against - // the PINT list instead. + // no PINT AE margin scheme category (N). Rule 03 checks them against + // the PINT AE list instead. rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-02"), rules.Field("ext", rules.Assert("03", "tax category code must be an AE UNCL5305 code: E, S, Z, O, AE or N (IBR-139-AE)", @@ -99,10 +113,9 @@ func taxComboRules() *rules.Set { rules.When( is.Func("tax combo is standard rated", taxComboIsStandard), rules.Field("percent", - rules.Assert("04", "tax percentage must be a positive number (ALIGNED-IBRP-S-05/06/07)", - num.Positive, - ), - rules.Assert("05", "tax percentage must be 5.00 (IBR-190-AE)", + // 5.00 also covers the rate above zero ALIGNED-IBRP-S-05/06/07 + // ask for. + rules.Assert("04", "tax percentage must be 5.00 (IBR-190-AE, ALIGNED-IBRP-S-05/06/07)", num.Equals(num.MakePercentage(5, 2)), ), ), @@ -111,7 +124,7 @@ func taxComboRules() *rules.Set { rules.When( is.Func("tax combo is zero rated", taxComboIsZero), rules.Field("percent", - rules.Assert("06", "tax percentage must be 0.00 (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", + rules.Assert("05", "tax percentage must be 0.00 (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", num.Equals(num.MakePercentage(0, 2)), ), ), diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index e50c28d..013e2b8 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -10,6 +10,7 @@ import ( "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/norm" "github.com/invopop/gobl/num" + aeregime "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" @@ -61,6 +62,16 @@ func TestTaxComboNormalization(t *testing.T) { norm.Normalize(c, tax.AddonContext(en16931.V2017, pint.V1)) assert.Equal(t, "S", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) }) + + t.Run("margin scheme maps to N only on UAE documents", func(t *testing.T) { + c := &tax.Combo{Category: tax.CategoryVAT, Key: aeregime.TaxKeyMarginScheme} + norm.Normalize(c, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.AE.Tax())) + assert.Equal(t, "N", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) + + c = &tax.Combo{Category: tax.CategoryVAT, Key: aeregime.TaxKeyMarginScheme} + norm.Normalize(c, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.SG.Tax())) + assert.NotEqual(t, "N", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) + }) } func gstCombo(category string) *tax.Combo { @@ -122,6 +133,14 @@ func TestTaxComboRulesAE(t *testing.T) { } assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) + assert.NoError(t, validateIn(vatCombo(aeregime.TaxKeyMarginScheme, "N", nil), ae)) + }) + + t.Run("margin scheme category is rejected outside AE", func(t *testing.T) { + for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { + err := validateIn(vatCombo(cbc.KeyEmpty, "N", nil), regime) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-01", "regime %s", regime) + } }) t.Run("categories outside the AE subset are rejected (IBR-139-AE)", func(t *testing.T) { @@ -135,17 +154,11 @@ func TestTaxComboRulesAE(t *testing.T) { assert.NoError(t, validateIn(vatCombo(cbc.KeyEmpty, "K", nil), l10n.SG.Tax())) }) - t.Run("standard rate must be greater than zero (ALIGNED-IBRP-S-05/06/07)", func(t *testing.T) { - err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(0, 2)), ae) - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-04") - // The Schematron reports both S-05 and IBR-190 for a 0% standard rate. - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") - }) - - t.Run("standard rate must be 5% (IBR-190-AE)", func(t *testing.T) { - err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(10, 2)), ae) - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") - assert.NotContains(t, err.Error(), "GOBL-PEPPOL-PINT-TAX-COMBO-04") + t.Run("standard rate must be 5% (IBR-190-AE, ALIGNED-IBRP-S-05/06/07)", func(t *testing.T) { + for _, rate := range []int64{0, 10} { + err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(rate, 2)), ae) + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-04", "rate %d", rate) + } }) t.Run("5% check compares numbers, not strings", func(t *testing.T) { @@ -154,7 +167,7 @@ func TestTaxComboRulesAE(t *testing.T) { t.Run("zero rate must be 0% (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", func(t *testing.T) { err := validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), ae) - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-06") + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") }) t.Run("rate rules do not apply outside AE", func(t *testing.T) { diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index f6b0a74..3b14b01 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -121,23 +121,19 @@ func invoiceTransactionType(val any) TransactionType { return ParseTransactionType(inv.Tax.GetExt(ExtKeyTransactionType)) } -// normalizeTransactionType sets the transaction type of a UAE invoice. Every -// PINT AE document needs one (IBR-154-AE). When the invoice has any of the -// flag tags, the tags decide the code, so a code from an earlier calculation -// follows the tags when they change. Without tags, a code set directly is -// kept, and "00000000" is set when there is none. +// normalizeTransactionType sets the transaction type of a UAE invoice from its +// flag tags, "00000000" without any. Every PINT AE document needs one +// (IBR-154-AE). The tags are the only source: a code from an earlier +// calculation can't be told apart from one set directly, so keeping it would +// leave the flags of removed tags in place. func normalizeTransactionType(inv *bill.Invoice) { if inv == nil { return } - t := transactionTypeFromTags(inv) - if len(t.Tags()) == 0 && inv.Tax.GetExt(ExtKeyTransactionType) != "" { - return - } if inv.Tax == nil { inv.Tax = new(bill.Tax) } - inv.Tax.Ext = inv.Tax.Ext.Set(ExtKeyTransactionType, t.Code()) + inv.Tax.Ext = inv.Tax.Ext.Set(ExtKeyTransactionType, transactionTypeFromTags(inv).Code()) } // transactionTypeTags are the invoice tags for the transaction type flags. diff --git a/addon/pint/transaction_type_test.go b/addon/pint/transaction_type_test.go index eab5a2b..4fc071f 100644 --- a/addon/pint/transaction_type_test.go +++ b/addon/pint/transaction_type_test.go @@ -59,10 +59,17 @@ func TestNormalizeTransactionType(t *testing.T) { assert.Equal(t, cbc.Code("00010011"), code(inv)) }) - t.Run("a code set directly is kept without tags", func(t *testing.T) { + t.Run("a code set directly is replaced without tags", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00001000"})} - assert.Equal(t, cbc.Code("00001000"), code(inv)) + assert.Equal(t, cbc.Code("00000000"), code(inv)) + }) + + t.Run("removing the last tag clears its flag", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, tax.TagExport) + assert.Equal(t, cbc.Code("00000001"), code(inv)) + inv.Tags.List = nil + assert.Equal(t, cbc.Code("00000000"), code(inv)) }) t.Run("tags replace an earlier code", func(t *testing.T) { From 8c8d3a963b678dbe1cf58100e341f53603049f3f Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 15:51:04 +0000 Subject: [PATCH 21/73] Fix the PINT AE import and price discount, and add self-billing fixtures - Write the zero price discount with the decimals of the price, as gobl.ubl does for a list price, so a re-export gives the same XML. - Import the seller and buyer electronic addresses as endpoints, which the PINT rules need, instead of the inbox gobl.ubl reads them as. - Remove the EU VATEX codes from the fixtures: PINT AE has no reason on the VAT breakdowns. - Add fixtures for a self-billed invoice and credit note, and for an out of scope credit note (81). - Check that the official examples import as valid GOBL documents, listing the ones that don't and why. Co-Authored-By: Claude Fable 5.2 --- README.md | 3 +- ubl/ae.go | 29 ++- ubl/ae_internal_test.go | 45 ++++- .../pint/ae/credit-note-ae-outside-scope.json | 175 +++++++++++++++++ .../pint/ae/credit-note-ae-self-billed.json | 177 +++++++++++++++++ .../convert/pint/ae/invoice-ae-exempt.json | 8 +- .../pint/ae/invoice-ae-outside-scope.json | 4 +- .../invoice-ae-reverse-charge-allowance.json | 6 +- .../pint/ae/invoice-ae-reverse-charge.json | 4 +- .../pint/ae/invoice-ae-self-billed.json | 180 ++++++++++++++++++ .../convert/pint/ae/invoice-ae-usd.json | 6 +- .../ae/out/credit-note-ae-outside-scope.xml | 131 +++++++++++++ .../ae/out/credit-note-ae-self-billed.xml | 133 +++++++++++++ .../ae/out/credit-note-ae-volume-discount.xml | 2 +- .../convert/pint/ae/out/credit-note-ae.xml | 2 +- .../ae/out/invoice-ae-continuous-supply.xml | 2 +- .../pint/ae/out/invoice-ae-deemed-supply.xml | 2 +- .../convert/pint/ae/out/invoice-ae-exempt.xml | 7 +- .../pint/ae/out/invoice-ae-export-summary.xml | 2 +- .../out/invoice-ae-free-trade-zone-agent.xml | 2 +- .../pint/ae/out/invoice-ae-margin-scheme.xml | 2 +- .../pint/ae/out/invoice-ae-outside-scope.xml | 3 +- .../invoice-ae-reverse-charge-allowance.xml | 5 +- .../pint/ae/out/invoice-ae-reverse-charge.xml | 3 +- .../pint/ae/out/invoice-ae-self-billed.xml | 125 ++++++++++++ .../pint/ae/out/invoice-ae-tin-passport.xml | 2 +- .../convert/pint/ae/out/invoice-ae-usd.xml | 10 +- .../convert/pint/ae/out/invoice-ae.xml | 2 +- .../parse/pint/ae/out/allowance-exempt.json | 16 +- .../pint/ae/out/buyer-pas-identifier.json | 16 +- .../parse/pint/ae/out/deemed-supply.json | 16 +- .../parse/pint/ae/out/margin-scheme.json | 16 +- .../parse/pint/ae/out/reverse-charge.json | 16 +- .../pint/ae/out/seller-pas-identifier.json | 16 +- .../pint/ae/out/seller-tin-identifier.json | 16 +- .../parse/pint/ae/out/standard-invoice.json | 16 +- .../pint/ae/out/supply-free-trade-zone.json | 16 +- ubl/ubl_test.go | 31 +++ 38 files changed, 1121 insertions(+), 126 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json create mode 100644 ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json create mode 100644 ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml create mode 100644 ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml diff --git a/README.md b/README.md index cbf0914..e0b46ee 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,8 @@ tags, and the credit note reason, billing frequency, line exemption reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and the `N` category back as the `margin-scheme` key, and the delivery terms back -as the `icc-incoterms-2020` extension. +as the `icc-incoterms-2020` extension, and the seller and buyer electronic +addresses as endpoints. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/ubl/ae.go b/ubl/ae.go index 46260df..3ca676f 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1,6 +1,7 @@ package ubl import ( + "slices" "strings" "github.com/invopop/gobl" @@ -8,6 +9,7 @@ import ( goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/icc" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -88,6 +90,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAELineItems(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) + importAEPartyEndpoint(in.AccountingSupplierParty.Party, inv.Supplier) + importAEPartyEndpoint(in.AccountingCustomerParty.Party, inv.Customer) return nil } @@ -577,7 +581,8 @@ func aeAmount(a num.Amount, cur currency.Code) goblubl.Amount { // (ibt-148) PINT AE requires on every line (IBR-126-AE). GOBL prices are per // unit, so the base quantity is 1 in the line's unit. Without a list price, // gobl.ubl writes no price allowance, so the gross price is the net price with -// a zero discount. The base quantity also lets IBR-147-AE compute the line net +// a zero discount, written with the decimals of the price as gobl.ubl does for +// a list price. The base quantity also lets IBR-147-AE compute the line net // amount. func exportAEPrice(line *goblubl.InvoiceLine) { price := line.Price @@ -589,9 +594,10 @@ func exportAEPrice(line *goblubl.InvoiceLine) { } if price.AllowanceCharge == nil { gross := price.PriceAmount + net, _ := num.AmountFromString(gross.Value) price.AllowanceCharge = &goblubl.AllowanceCharge{ ChargeIndicator: false, - Amount: goblubl.Amount{CurrencyID: price.PriceAmount.CurrencyID, Value: "0"}, + Amount: goblubl.Amount{CurrencyID: gross.CurrencyID, Value: num.AmountZero.MatchPrecision(net).String()}, BaseAmount: &gross, } } @@ -727,6 +733,25 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { } } +// importAEPartyEndpoint reads the party's electronic address, cbc:EndpointID, +// as an endpoint, which the PINT addon requires on the supplier and customer +// (IBR-080, IBR-081). gobl.ubl imports it as an inbox, which the endpoint +// replaces. +func importAEPartyEndpoint(in *goblubl.Party, p *org.Party) { + if in == nil || p == nil || in.EndpointID == nil || in.EndpointID.Value == "" { + return + } + scheme, value := in.EndpointID.SchemeID, in.EndpointID.Value + uri := cbc.URI(iso.ActorIDScheme + "::" + scheme + ":" + value) + if scheme == goblubl.SchemeIDEmail { + uri = cbc.URI("mailto:" + value) + } + p.Inboxes = slices.DeleteFunc(p.Inboxes, func(ib *org.Inbox) bool { + return ib.Email == value || (ib.Scheme.String() == scheme && ib.Code.String() == value) + }) + p.Endpoints = append(p.Endpoints, &org.Endpoint{URI: uri}) +} + // importAELegalIdentity sets the identity's key and, from @schemeAgencyName, // its issuing country or description. func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 7e8433b..941075d 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -58,11 +58,20 @@ func TestExportAEPrice(t *testing.T) { ac := line.Price.AllowanceCharge require.NotNil(t, ac) assert.False(t, ac.ChargeIndicator) - assert.Equal(t, "0", ac.Amount.Value) + assert.Equal(t, "0.00", ac.Amount.Value) require.NotNil(t, ac.BaseAmount) assert.Equal(t, "100.00", ac.BaseAmount.Value) }) + t.Run("writes the zero discount with the decimals of the price", func(t *testing.T) { + line := &goblubl.InvoiceLine{ + InvoicedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, + Price: &goblubl.Price{PriceAmount: aedAmount("10.1234")}, + } + exportAEPrice(line) + assert.Equal(t, "0.0000", line.Price.AllowanceCharge.Amount.Value) + }) + t.Run("uses the credited quantity's unit on credit notes", func(t *testing.T) { line := &goblubl.InvoiceLine{ CreditedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, @@ -356,6 +365,40 @@ func TestImportAEPartyIdentities(t *testing.T) { }) } +func TestImportAEPartyEndpoint(t *testing.T) { + t.Run("the electronic address replaces the inbox gobl.ubl imports", func(t *testing.T) { + in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: "0235", Value: "1357902468"}} + p := &org.Party{Inboxes: []*org.Inbox{ + {Scheme: "0235", Code: "1357902468"}, + {Key: "other", Code: "ABC"}, + }} + importAEPartyEndpoint(in, p) + require.Len(t, p.Endpoints, 1) + assert.Equal(t, cbc.URI("iso6523-actorid-upis::0235:1357902468"), p.Endpoints[0].URI) + require.Len(t, p.Inboxes, 1) + assert.Equal(t, cbc.Code("ABC"), p.Inboxes[0].Code) + }) + + t.Run("an email address is read as a mailto endpoint", func(t *testing.T) { + in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: goblubl.SchemeIDEmail, Value: "billing@example.ae"}} + p := &org.Party{Inboxes: []*org.Inbox{{Email: "billing@example.ae"}}} + importAEPartyEndpoint(in, p) + require.Len(t, p.Endpoints, 1) + assert.Equal(t, cbc.URI("mailto:billing@example.ae"), p.Endpoints[0].URI) + assert.Empty(t, p.Inboxes) + }) + + t.Run("parties without an electronic address are left alone", func(t *testing.T) { + p := &org.Party{} + importAEPartyEndpoint(&goblubl.Party{}, p) + assert.Empty(t, p.Endpoints) + assert.NotPanics(t, func() { + importAEPartyEndpoint(nil, p) + importAEPartyEndpoint(&goblubl.Party{}, nil) + }) + }) +} + func TestImportAEMarginScheme(t *testing.T) { combo := func(category cbc.Code) *tax.Combo { five := num.MakePercentage(5, 2) diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json new file mode 100644 index 0000000..e802ff3 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -0,0 +1,175 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "89307d52648c3f441ba8763726601b4376b46ed40cf72603363beb516d3a1642" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "series": "AE", + "code": "CN-OS-001", + "issue_date": "2025-01-30", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-01-30", + "code": "AE-001" + } + ], + "tax": { + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "81" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json new file mode 100644 index 0000000..ea6e8f1 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -0,0 +1,177 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "916a9b3f20b05bef8377b592fa155e670861b580164ebf69c37439782d682bd8" + }, + "from": "iso6523-actorid-upis::0235:1345678901", + "to": "iso6523-actorid-upis::0235:1357902468" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "self-billed" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "series": "AE", + "code": "SB-CN-001", + "issue_date": "2025-01-30", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-01-30", + "code": "AE-001" + } + ], + "tax": { + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "261" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index 188b931..64e3798 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "03bf9ac5f7d915fc908695404b5e89fbb670cb11e6220c209cbf72d6a7f745df" + "val": "f03d696b4107c8538fde4e3a01a500615a8906a59b9d12836bce1a867edda7cc" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -136,7 +136,6 @@ "cat": "VAT", "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" } @@ -159,7 +158,6 @@ "cat": "VAT", "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-135-1L", "peppol-pint-ae-exemption": "DL8.46.2", "untdid-tax-category": "E" } @@ -178,7 +176,6 @@ "cat": "VAT", "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "untdid-tax-category": "E" } } @@ -251,7 +248,6 @@ { "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" }, @@ -261,7 +257,6 @@ { "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-135-1L", "peppol-pint-ae-exemption": "DL8.46.2", "untdid-tax-category": "E" }, @@ -271,7 +266,6 @@ { "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "untdid-tax-category": "E" }, "base": "-20.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index e85b0d0..635465b 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a64ee8d359ca2961aace3256846f379110e6b7a4e2cbd40a1953e94cc1d009b0" + "val": "50af39bff25a551aa0dd1765cf11219ca6bfe5981b56d5190a7ff98a77eac43d" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -117,7 +117,6 @@ "cat": "VAT", "key": "outside-scope", "ext": { - "cef-vatex": "VATEX-EU-O", "untdid-tax-category": "O" } } @@ -160,7 +159,6 @@ { "key": "outside-scope", "ext": { - "cef-vatex": "VATEX-EU-O", "untdid-tax-category": "O" }, "base": "1000.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index a604217..43532fa 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "894fe7b79f37056933f5da8a3555ae3a12f53507054151dbbdfe9e53b684b33d" + "val": "37e899919569ef46b7819070afb2e807aed37b6a0c27f44451702e3e64510e52" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -125,7 +125,6 @@ "cat": "VAT", "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" } } @@ -143,7 +142,6 @@ "cat": "VAT", "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" } } @@ -160,7 +158,6 @@ "cat": "VAT", "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" } } @@ -204,7 +201,6 @@ { "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" }, "base": "975.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index fd0cccd..c74ae7c 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "6c1fddcee644f42bb3747b650d52fe8f218ac152b70ef7ae26e283d757c12ca9" + "val": "e8901d4b59f3f4f56f757b4fa85aa7f673bc52f499224e254c5d12eae5330fbe" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -130,7 +130,6 @@ "cat": "VAT", "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" } } @@ -173,7 +172,6 @@ { "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" }, "base": "1000.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json new file mode 100644 index 0000000..97a9eea --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -0,0 +1,180 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "b77cb1b493c421a34062302f214919d82ea866a41c55d0c85064133e0a3ba15e" + }, + "from": "iso6523-actorid-upis::0235:1345678901", + "to": "iso6523-actorid-upis::0235:1357902468" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "self-billed" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "SB-001", + "issue_date": "2025-01-30", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "389" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246801003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902468" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902468" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "key": "ae-trade-license", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "name": "Item Name", + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1050.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index 7ace9f0..5241082 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e9ea54853e92a354c970608a21f0cda350f27bd8ece85c00cfdd5ecefb8ff3d4" + "val": "5b1109f376388b2c7dc1a5cb657164ee021253239193916e75b6d84163c441e4" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -190,7 +190,6 @@ "cat": "VAT", "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "peppol-pint-ae-exemption": "DL8.46.3", "untdid-tax-category": "E" } @@ -229,7 +228,6 @@ "cat": "VAT", "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" } } @@ -290,7 +288,6 @@ { "key": "exempt", "ext": { - "cef-vatex": "VATEX-EU-132-1I", "peppol-pint-ae-exemption": "DL8.46.3", "untdid-tax-category": "E" }, @@ -300,7 +297,6 @@ { "key": "reverse-charge", "ext": { - "cef-vatex": "VATEX-EU-AE", "untdid-tax-category": "AE" }, "base": "99.99", diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml new file mode 100644 index 0000000..42a0cdb --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml @@ -0,0 +1,131 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CN-OS-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 81 + AED + + DL8.61.1.E + + + NA + + + + AE-001 + 2025-01-30 + + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 0.00 + + 1000.00 + 0.00 + + O + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + O + + VAT + + + + + 10.00 + 1 + + false + 0.00 + 10.00 + + + + 1000.00 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml new file mode 100644 index 0000000..354b82e --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml @@ -0,0 +1,133 @@ + + + urn:peppol:pint:selfbilling-1@ae-1 + urn:peppol:bis:selfbilling + 00000000 + AE-SB-CN-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 261 + AED + + DL8.61.1.E + + + NA + + + + AE-001 + 2025-01-30 + + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0.00 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml index cd36887..26837e1 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -113,7 +113,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index 6083427..bdc2318 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -119,7 +119,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 11e36f1..95fb017 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -117,7 +117,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml index 3d45f0c..ce21271 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -106,7 +106,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index de16555..9dd5850 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -91,7 +91,6 @@ E 0 - VATEX-EU-132-1I VAT @@ -149,7 +148,7 @@ 1 false - 0 + 0.00 10.00 @@ -180,7 +179,7 @@ 1 false - 0 + 0.00 200.00 @@ -208,7 +207,7 @@ 1 false - 0 + 0.00 300.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index 486cd39..20ef9d9 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -139,7 +139,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index 463f2ed..6b33212 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -125,7 +125,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 78ad67a..3ff037b 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -115,7 +115,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 406405f..a5f89ad 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -78,7 +78,6 @@ 0.00 O - VATEX-EU-O VAT @@ -110,7 +109,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 50fb303..30b363d 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -78,7 +78,6 @@ AE 0 - VATEX-EU-AE VAT @@ -91,7 +90,6 @@ AE 0 - VATEX-EU-AE VAT @@ -105,7 +103,6 @@ AE 5 - VATEX-EU-AE VAT @@ -146,7 +143,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 3a27fc7..2fce460 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -79,7 +79,6 @@ AE 5 - VATEX-EU-AE VAT @@ -120,7 +119,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml new file mode 100644 index 0000000..d0c6698 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -0,0 +1,125 @@ + + + urn:peppol:pint:selfbilling-1@ae-1 + urn:peppol:bis:selfbilling + 00000000 + AE-SB-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 2025-02-06 + 389 + AED + + NA + + + + 1357902468 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246801003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678901 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 30 + + AE070331234567890123456 + Emirates NBD + + + + 50.00 + + 1000.00 + 50.00 + + S + 5 + + VAT + + + + + + 1000.00 + 1000.00 + 1050.00 + 1050.00 + + + 1 + 100 + 1000.00 + + Item Description + Item Name + + S + 5 + + VAT + + + + + 10.00 + 1 + + false + 0.00 + 10.00 + + + + 1050.00 + + 50.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index afff5ce..354d837 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -117,7 +117,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 6df1ac7..d98943e 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -111,7 +111,6 @@ 0.00 E - VATEX-EU-132-1I VAT @@ -123,7 +122,6 @@ AE 5 - VATEX-EU-AE VAT @@ -166,7 +164,7 @@ 1 false - 0 + 0.00 10.00 @@ -201,7 +199,7 @@ 1 false - 0 + 0.00 250.00 @@ -238,7 +236,7 @@ 1 false - 0 + 0.00 120.00 @@ -274,7 +272,7 @@ 1 false - 0 + 0.00 33.33 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 52a6afb..304e68f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -111,7 +111,7 @@ 1 false - 0 + 0.00 10.00 diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index f6b346c..2baabb8 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "63ddbbd5567ec8c914b4c49b0e7838005e30412d8c65bbfa2db6387da782f92e" - } + "val": "38d4dfc2b7ead64cb1486d0cc2bdc72a7d6a5a878772929d8a73de2c64b823e2" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -52,10 +54,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1987654321" + "uri": "iso6523-actorid-upis::0235:1987654321" } ], "addresses": [ @@ -102,10 +103,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1345678901" + "uri": "iso6523-actorid-upis::0235:1345678901" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json index 352059d..d93de66 100644 --- a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c9263477ad3b2a6c2982e4f11a36ee5e9aa4a3ed5c152147000812b1a2ee2d97" - } + "val": "3eb4f96db635fc7e90614ce11c5762d6032f5648e11457b7081b95b719f59bbd" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -49,10 +51,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1987654321" + "uri": "iso6523-actorid-upis::0235:1987654321" } ], "addresses": [ @@ -99,10 +100,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1345678901" + "uri": "iso6523-actorid-upis::0235:1345678901" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index 2967828..18feb1a 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "29e381ec0b2623d8090e20653969638c16ae2b607e9e5f669047cf9d93af4c7c" - } + "val": "a6c349ac19e6ca906f66e03b57f68d8b9cb80add6a1c91729aeb2dff2e458214" + }, + "from": "iso6523-actorid-upis::0235:1246801357", + "to": "iso6523-actorid-upis::0235:1012345678" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -50,10 +52,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1246801357" + "uri": "iso6523-actorid-upis::0235:1246801357" } ], "addresses": [ @@ -99,10 +100,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1012345678" + "uri": "iso6523-actorid-upis::0235:1012345678" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index 908efe9..e4af6f4 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0acba08a26a9042df724424835499955e1fb55311ec48169f01ad036cbd6cf72" - } + "val": "89abd84d782bc7a63a572424071b51d24fc9b6b5633f7ba094e5de0c9fcdc51f" + }, + "from": "iso6523-actorid-upis::0235:112345678900003", + "to": "iso6523-actorid-upis::0235:112345679000003" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -51,10 +53,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "112345678900003" + "uri": "iso6523-actorid-upis::0235:112345678900003" } ], "addresses": [ @@ -103,10 +104,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "112345679000003" + "uri": "iso6523-actorid-upis::0235:112345679000003" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index b4bed56..758bb35 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a71e6bfcbb05d2d451383f7ace53b50e061c70403e51779e3761842d1fb3c811" - } + "val": "c248c13c4043cf95a56e8e93d5be32d9705d731602e8814e009b420169a80daf" + }, + "from": "iso6523-actorid-upis::0235:1278906543", + "to": "iso6523-actorid-upis::0235:1347809543" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -48,10 +50,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1278906543" + "uri": "iso6523-actorid-upis::0235:1278906543" } ], "addresses": [ @@ -97,10 +98,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1347809543" + "uri": "iso6523-actorid-upis::0235:1347809543" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json index b1133b5..fa2e6ae 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0ef230fc0741ebed67ff7772e31953ffc9f4eac9129d52bd53c9cd2a5aa2c68e" - } + "val": "433efe4b5d206d73c0fa7b28963bf65942e6f1b4ac516d17ac151dad1d225941" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -49,10 +51,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1987654321" + "uri": "iso6523-actorid-upis::0235:1987654321" } ], "addresses": [ @@ -99,10 +100,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1345678901" + "uri": "iso6523-actorid-upis::0235:1345678901" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json index e4ed08f..35218ca 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "134304a3c593cada215679a9393d4cad765d113020eb81f3b25dde2e1203aae5" - } + "val": "d08db6f319c19d453ab9d2ff4f2fb66b89a88d011a8e71fcb5d83bbb12eeaf55" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -55,10 +57,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1987654321" + "uri": "iso6523-actorid-upis::0235:1987654321" } ], "addresses": [ @@ -105,10 +106,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1345678901" + "uri": "iso6523-actorid-upis::0235:1345678901" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json index da72df4..0d004d4 100644 --- a/ubl/testdata/parse/pint/ae/out/standard-invoice.json +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "8ecfd77c9c801b91ac7a8065224d03c08891ab36a77b3a4419b77aff4e493d29" - } + "val": "9d5f7e184ece141543a8c205f363b5aafd431716944e0962914e7a3e4dc94d5a" + }, + "from": "iso6523-actorid-upis::0235:1357902468", + "to": "iso6523-actorid-upis::0235:1345678901" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -40,10 +42,9 @@ "description": "Trade License issuing Authority" } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1357902468" + "uri": "iso6523-actorid-upis::0235:1357902468" } ], "addresses": [ @@ -69,10 +70,9 @@ "description": "Trade License issuing Authority" } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1345678901" + "uri": "iso6523-actorid-upis::0235:1345678901" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 82327a5..114f3d8 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,8 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "40fc24a9e477c33ccc2c5570b1a6d9dfa7dd3a3b770744bf57e05911f0a6630a" - } + "val": "a58b34969f6754939e6e5b005be9ebb8c0615aaef8389a281831edebccdb502b" + }, + "from": "iso6523-actorid-upis::0235:1246801357", + "to": "iso6523-actorid-upis::0235:1789012345" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -51,10 +53,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1246801357" + "uri": "iso6523-actorid-upis::0235:1246801357" } ], "addresses": [ @@ -100,10 +101,9 @@ } } ], - "inboxes": [ + "endpoints": [ { - "scheme": "0235", - "code": "1789012345" + "uri": "iso6523-actorid-upis::0235:1789012345" } ], "addresses": [ diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index e87d8c1..7124166 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -1,6 +1,7 @@ package ubl_test import ( + "path/filepath" "testing" "github.com/invopop/gobl.peppol/addon/pint" @@ -140,6 +141,36 @@ func TestDetectAndImportAE(t *testing.T) { assert.Equal(t, l10n.TaxCountryCode("AE"), inv.GetRegime()) } +// invalidImportsAE are the official PINT AE examples that pass the PINT AE +// Schematron but don't import as valid GOBL documents, and why. +var invalidImportsAE = map[string]string{ + "deemed-supply.xml": "placeholder email addresses, and no payment terms, which EN 16931 requires (BR-CO-25)", + "margin-scheme.xml": "placeholder email addresses", + "reverse-charge.xml": "placeholder email addresses", + "supply-free-trade-zone.xml": "placeholder email addresses", +} + +// TestImportAEValid checks that the official PINT AE examples import as valid +// GOBL documents. +func TestImportAEValid(t *testing.T) { + examples, err := filepath.Glob(filepath.Join("testdata", "parse", "pint", "ae", "*.xml")) + require.NoError(t, err) + require.NotEmpty(t, examples) + for _, example := range examples { + name := filepath.Base(example) + t.Run(name, func(t *testing.T) { + env := parseXMLInvoice(t, filepath.Join("pint", "ae", name)) + require.NoError(t, env.Calculate()) + err := env.Validate() + if reason, ok := invalidImportsAE[name]; ok { + assert.Error(t, err, "listed as invalid: %s", reason) + return + } + assert.NoError(t, err) + }) + } +} + // TestExportAE checks that a UAE invoice is exported with the PINT AE // identifiers and detected as PINT AE again. func TestExportAE(t *testing.T) { From 7e047e45fe35a4bbb8277ab350fff74c9b747e73 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:51:45 +0000 Subject: [PATCH 22/73] Read the PINT AE delivery terms from the gobl.ubl slice gobl.ubl now keeps every cac:DeliveryTerms of a delivery, as UBL 2.1 allows. PINT AE has a single Incoterms code (BTAE-22), so write one term and read the first. Co-Authored-By: Claude Opus 5.5 --- ubl/ae.go | 6 +++--- ubl/ae_internal_test.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ubl/ae.go b/ubl/ae.go index 3ca676f..a4b3972 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -452,17 +452,17 @@ func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { if len(out.Delivery) == 0 { out.Delivery = []*goblubl.Delivery{{}} } - out.Delivery[0].DeliveryTerms = &goblubl.DeliveryTerms{ID: code.String()} + out.Delivery[0].DeliveryTerms = []goblubl.DeliveryTerms{{ID: code.String()}} } // importAEIncoterms reads the delivery terms back as the ICC Incoterms 2020 // extension, the current edition, as PINT AE doesn't say which one a code is // from. func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { - if len(in.Delivery) == 0 || in.Delivery[0] == nil || in.Delivery[0].DeliveryTerms == nil { + if len(in.Delivery) == 0 || in.Delivery[0] == nil || len(in.Delivery[0].DeliveryTerms) == 0 { return } - code := cbc.Code(strings.TrimSpace(in.Delivery[0].DeliveryTerms.ID)) + code := cbc.Code(strings.TrimSpace(in.Delivery[0].DeliveryTerms[0].ID)) if code == "" { return } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 941075d..40e6a95 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -795,21 +795,21 @@ func TestAEIncoterms(t *testing.T) { out := new(goblubl.Invoice) exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) require.Len(t, out.Delivery, 1) - require.NotNil(t, out.Delivery[0].DeliveryTerms) - assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms.ID) + require.Len(t, out.Delivery[0].DeliveryTerms, 1) + assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID) }) t.Run("also from the 2010 edition", func(t *testing.T) { out := new(goblubl.Invoice) exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2010, "DAT")) - assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms.ID) + assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms[0].ID) }) t.Run("on the delivery gobl.ubl wrote", func(t *testing.T) { out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: "5790000436101"}}}}} exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) require.Len(t, out.Delivery, 1) - assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms.ID) + assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID) assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) }) @@ -822,7 +822,7 @@ func TestAEIncoterms(t *testing.T) { }) t.Run("reads the Incoterms back as the 2020 edition", func(t *testing.T) { - in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: &goblubl.DeliveryTerms{ID: " CIF "}}}} + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: " CIF "}}}}} inv := new(bill.Invoice) importAEIncoterms(in, inv) require.NotNil(t, inv.Delivery) From f205669a5c5de2a5770d17c5f308c7864469c30c Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:02:45 +0000 Subject: [PATCH 23/73] Fix the PINT AE import and rule gaps found in the final review - Leave importPINT out of FormatAE. It made a tax registration that isn't VAT the tax ID, which in PINT AE is the seller's TIN, so a seller with only a TIN got it as its TRN. gobl.ubl already reads the VAT one as the tax ID. - Read the invoice UUID (BTAE-07) on import. - Set identity scopes on the supplier and customer only, and the tax scope only on the supplier's TIN: PINT AE has no TIN registration for the customer. - Check IBR-128-AE against the country gobl.ubl writes, the tax ID's when there is one, and fail a UAE party without an address, which is written with only its country. - Count only the identities written as classifications for the HS and SAC rules (IBR-184-AE to IBR-186-AE). - Read an Incoterms code only the 2010 edition has as that edition. - Check the exact faults of the official examples that don't import as valid documents. Co-Authored-By: Claude Fable 5.2 --- README.md | 3 +- addon/pint/bill.go | 34 ++++++++++--- addon/pint/bill_test.go | 45 ++++++++++++++++- addon/pint/org_identity.go | 30 +++++++---- addon/pint/org_identity_test.go | 89 ++++++++++++++++++++++++--------- addon/pint/pint.go | 10 ++-- ubl/ae.go | 28 +++++++++-- ubl/ae_internal_test.go | 25 +++++++++ ubl/ubl.go | 5 +- ubl/ubl_test.go | 61 ++++++++++++++++++---- 10 files changed, 266 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index e0b46ee..65f0a84 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,8 @@ identities labelled `SAC` are written as service accounting codes. Lines with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with no VAT amount, and the delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the delivery terms. On import, it reads -the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and +the invoice UUID, the out-of-scope type codes 480 and 81 back as the +`outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption diff --git a/addon/pint/bill.go b/addon/pint/bill.go index df2c435..aa8cddd 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -186,12 +186,12 @@ func billInvoiceRules() *rules.Set { rules.Field("ordering", rules.Field("seller", rules.Assert("22", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), rules.Field("issuer", rules.Assert("23", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), ), @@ -522,7 +522,7 @@ func billLineRules() *rules.Set { ), rules.Field("seller", rules.Assert("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), ), @@ -775,10 +775,28 @@ func partyAddressIsComplete(val any) bool { // partyAddressHasEmirate reports whether the party's first address, when in // the UAE, has an emirate code as its region (IBR-128-AE). Addresses in other -// countries pass. +// countries pass, and so does a party without addresses: it is for the +// supplier and customer, whose addresses EN 16931 requires (BR-8, BR-10). func partyAddressHasEmirate(val any) bool { - a := partyFirstAddress(val) - return a == nil || a.Country != l10n.AE.ISO() || cbc.Code(a.Region).In(emirateCodes...) + return partyFirstAddress(val) == nil || partyPostalAddressHasEmirate(val) +} + +// partyPostalAddressHasEmirate reports whether the cac:PostalAddress gobl.ubl +// writes for the party, when in the UAE, has an emirate code as its region +// (IBR-128-AE). gobl.ubl writes the country of the tax ID over the address's +// own, and writes an address with only that country for a party without +// addresses, which fails the rule. +func partyPostalAddressHasEmirate(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return true + } + a := partyFirstAddress(p) + inAE := a != nil && a.Country == l10n.AE.ISO() + if p.TaxID != nil && p.TaxID.Code != "" { + inAE = p.TaxID.Country.Code() == l10n.AE + } + return !inAE || (a != nil && cbc.Code(a.Region).In(emirateCodes...)) } // partyEndpointID returns the scheme and code of the party's electronic @@ -1156,9 +1174,11 @@ func identitiesHaveLabel(labels ...string) func(any) bool { } } +// identitiesHaveLabelOf reports whether one of the identities gobl.ubl writes +// as item classifications, those with a label and no scheme ID, has the label. func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { for _, id := range ids { - if id != nil && id.Label == label { + if id != nil && id.Label == label && !id.Ext.Has(iso.ExtKeySchemeID) { return true } } diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index ee6e6cf..288cc83 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -600,9 +600,36 @@ func TestBillAddressRulesAE(t *testing.T) { t.Run("foreign address region is not checked (IBR-128-AE)", func(t *testing.T) { inv := standard() + inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} assert.NotContains(t, aeFaults(t, inv), faultCustomerEmirate) }) + + t.Run("the tax ID country counts, as it is the one written (IBR-128-AE)", func(t *testing.T) { + trn := &tax.Identity{Country: "AE", Code: "100000000000203"} + oman := []*org.Address{{Street: "Street 1", Locality: "Muscat", Region: "Muscat", Country: "OM"}} + + inv := standard() + inv.Ordering = &bill.Ordering{ + Seller: &org.Party{Name: "Tax Rep", TaxID: trn, Addresses: oman}, + Issuer: &org.Party{Name: "Issuer", TaxID: trn}, + } + out := aeFaults(t, inv) + assert.Contains(t, out, faultTaxRepEmirate) + assert.Contains(t, out, faultIssuerEmirate, "an address with only the country is written") + + inv = standard() + inv.Lines[0].Seller = &org.Party{ + Name: "Maker", + TaxID: &tax.Identity{Country: "DE", Code: "111111125"}, + Addresses: aeAddress("Dubai"), + } + assert.NotContains(t, aeFaults(t, inv), faultSellerEmirate) + + inv = standard() + inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer"}} + assert.NotContains(t, aeFaults(t, inv), faultIssuerEmirate, "no tax ID and no address") + }) } func uaeEndpoints(code string) []*org.Endpoint { @@ -760,15 +787,25 @@ func TestBillIdentityRulesAE(t *testing.T) { inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}) inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678901"}) assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) }) + t.Run("customer TIN without a scope is a plain identity (IBR-179-AE, IBR-133-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.Identities = append(inv.Customer.Identities, + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + out := aeFaults(t, inv) + assert.Empty(t, inv.Customer.Identities[1].Scope) + assert.NotContains(t, out, faultCustomerTaxCount) + assert.NotContains(t, out, faultCustomerTaxSupplier) + }) + t.Run("customer tax identity needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = nil inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678901"}) assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, @@ -1195,6 +1232,10 @@ func TestBillItemTypeRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) + + // An identity with a scheme ID isn't written as a classification. + withScheme := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) }) t.Run("services need a service accounting code (IBR-185-AE)", func(t *testing.T) { diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index b0b7a5d..5dd999d 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -3,6 +3,7 @@ package pint import ( "regexp" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" @@ -66,14 +67,25 @@ func IdentityKeyAE(typ cbc.Code) cbc.Key { return "" } -// normalizePartyIdentityScopes gives a party's UAE identities the scope -// gobl.ubl needs to write them where PINT AE reads them: tax for the TIN, -// written as a cac:PartyTaxScheme, and legal for the trade licence, Emirates -// ID, passport and Cabinet Decision, written as -// cac:PartyLegalEntity/cbc:CompanyID. Only an identity without a scope gets -// one, and only when no other identity of the party has it, as EN 16931 -// allows one identity per scope (BT-30, BT-47, BT-31, BT-48). -func normalizePartyIdentityScopes(p *org.Party) { +// normalizeIdentityScopes gives the UAE identities of the supplier and +// customer the scope gobl.ubl needs to write them where PINT AE reads them: +// legal for the trade licence, Emirates ID, passport and Cabinet Decision, +// written as cac:PartyLegalEntity/cbc:CompanyID, and tax for the supplier's +// TIN, written as a cac:PartyTaxScheme. PINT AE has no TIN tax registration +// for the customer, whose TIN stays a plain identity. +func normalizeIdentityScopes(inv *bill.Invoice) { + if inv == nil { + return + } + setIdentityScopes(inv.Supplier, org.IdentityScopeLegal, org.IdentityScopeTax) + setIdentityScopes(inv.Customer, org.IdentityScopeLegal) +} + +// setIdentityScopes gives the party's identities without a scope the one +// their key has in PINT AE, when it is one of the given scopes and no other +// identity of the party has it, as EN 16931 allows one identity per scope +// (BT-30, BT-47, BT-31, BT-48). +func setIdentityScopes(p *org.Party, scopes ...cbc.Key) { if p == nil { return } @@ -87,7 +99,7 @@ func normalizePartyIdentityScopes(p *org.Party) { if id == nil || id.Scope != "" { continue } - if scope := identityScopeAE(id.Key); scope != "" && !taken[scope] { + if scope := identityScopeAE(id.Key); scope.In(scopes...) && !taken[scope] { id.Scope = scope taken[scope] = true } diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index d7aeb53..b87cb29 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -5,6 +5,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/addons/eu/en16931" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/norm" @@ -43,56 +44,94 @@ func TestIdentityKeyAE(t *testing.T) { } } -func TestNormalizePartyIdentityScopes(t *testing.T) { - normalize := func(regime l10n.TaxCountryCode, ids ...*org.Identity) []cbc.Key { - p := &org.Party{Name: "Party", Identities: ids} - norm.Normalize(p, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) - scopes := make([]cbc.Key, len(p.Identities)) +func TestNormalizeIdentityScopes(t *testing.T) { + scopes := func(p *org.Party) []cbc.Key { + out := make([]cbc.Key, len(p.Identities)) for i, id := range p.Identities { - scopes[i] = id.Scope + out[i] = id.Scope } - return scopes + return out + } + // normalize returns the scopes the identities get on the supplier and on + // the customer. + normalize := func(regime l10n.TaxCountryCode, ids func() []*org.Identity) (supplier, customer []cbc.Key) { + inv := &bill.Invoice{ + Supplier: &org.Party{Name: "Supplier", Identities: ids()}, + Customer: &org.Party{Name: "Customer", Identities: ids()}, + } + norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) + return scopes(inv.Supplier), scopes(inv.Customer) } tin := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"} } eid := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"} } passport := func() *org.Identity { return &org.Identity{Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"} } + list := func(ids ...func() *org.Identity) func() []*org.Identity { + return func() []*org.Identity { + out := make([]*org.Identity, len(ids)) + for i, id := range ids { + out[i] = id() + } + return out + } + } + + t.Run("legal registrations get the legal scope, and the supplier's TIN the tax scope", func(t *testing.T) { + supplier, customer := normalize(l10n.AE.Tax(), list(tin, passport)) + assert.Equal(t, []cbc.Key{org.IdentityScopeTax, org.IdentityScopeLegal}, supplier) + assert.Equal(t, []cbc.Key{"", org.IdentityScopeLegal}, customer, "PINT AE has no customer TIN registration") - t.Run("TIN gets the tax scope and legal registrations the legal scope", func(t *testing.T) { - assert.Equal(t, []cbc.Key{org.IdentityScopeTax, org.IdentityScopeLegal}, - normalize(l10n.AE.Tax(), tin(), passport())) for _, key := range []cbc.Key{ae.IdentityKeyTradeLicense, ae.IdentityKeyEmiratesID, ae.IdentityKeyCabinetDecision} { - assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, - normalize(l10n.AE.Tax(), &org.Identity{Key: key, Code: "784199012345671"}), key) + id := func() *org.Identity { return &org.Identity{Key: key, Code: "784199012345671"} } + supplier, customer = normalize(l10n.AE.Tax(), list(id)) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, supplier, key) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, customer, key) } }) t.Run("only the first identity of each scope gets it", func(t *testing.T) { - assert.Equal(t, []cbc.Key{org.IdentityScopeLegal, ""}, - normalize(l10n.AE.Tax(), eid(), passport())) - assert.Equal(t, []cbc.Key{org.IdentityScopeTax, ""}, - normalize(l10n.AE.Tax(), tin(), tin())) + supplier, customer := normalize(l10n.AE.Tax(), list(eid, passport)) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal, ""}, supplier) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal, ""}, customer) + supplier, _ = normalize(l10n.AE.Tax(), list(tin, tin)) + assert.Equal(t, []cbc.Key{org.IdentityScopeTax, ""}, supplier) }) t.Run("a scope another identity already has is not given again", func(t *testing.T) { - legal := &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"} - assert.Equal(t, []cbc.Key{"", org.IdentityScopeLegal}, - normalize(l10n.AE.Tax(), passport(), legal)) + legal := func() *org.Identity { return &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"} } + supplier, _ := normalize(l10n.AE.Tax(), list(passport, legal)) + assert.Equal(t, []cbc.Key{"", org.IdentityScopeLegal}, supplier) }) t.Run("an explicit scope is kept", func(t *testing.T) { - id := eid() - id.Scope = org.IdentityScopeTax - assert.Equal(t, []cbc.Key{org.IdentityScopeTax}, normalize(l10n.AE.Tax(), id)) + id := func() *org.Identity { + id := eid() + id.Scope = org.IdentityScopeTax + return id + } + supplier, _ := normalize(l10n.AE.Tax(), list(id)) + assert.Equal(t, []cbc.Key{org.IdentityScopeTax}, supplier) }) t.Run("other identities get no scope", func(t *testing.T) { - assert.Equal(t, []cbc.Key{""}, - normalize(l10n.AE.Tax(), &org.Identity{Type: "XYZ", Code: "123"})) + other := func() *org.Identity { return &org.Identity{Type: "XYZ", Code: "123"} } + supplier, _ := normalize(l10n.AE.Tax(), list(other)) + assert.Equal(t, []cbc.Key{""}, supplier) + }) + + t.Run("other parties are left alone", func(t *testing.T) { + inv := &bill.Invoice{ + Supplier: &org.Party{Name: "Supplier"}, + Ordering: &bill.Ordering{Seller: &org.Party{Name: "Tax Rep", Identities: []*org.Identity{eid()}}}, + } + norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.AE.Tax())) + assert.Empty(t, inv.Ordering.Seller.Identities[0].Scope) }) t.Run("only under the AE regime", func(t *testing.T) { - assert.Equal(t, []cbc.Key{"", ""}, normalize(l10n.AU.Tax(), tin(), passport())) + supplier, customer := normalize(l10n.AU.Tax(), list(tin, passport)) + assert.Equal(t, []cbc.Key{"", ""}, supplier) + assert.Equal(t, []cbc.Key{"", ""}, customer) }) } diff --git a/addon/pint/pint.go b/addon/pint/pint.go index d882a99..41d4e80 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -51,7 +51,7 @@ func init() { norm.When( is.InContext(tax.RegimeIn(regimesAE...)), norm.For(normalizeTransactionType), - norm.For(normalizePartyIdentityScopes), + norm.For(normalizeIdentityScopes), norm.For(normalizeTaxComboAE), ), ) @@ -87,10 +87,10 @@ func newV1Addon() *tax.AddonDef { UAE trade licences carry their issuing authority in the description, and passports their issuing country. - UAE identities without a scope get the one PINT AE reads them from: - "tax" for the TIN, and "legal" for the first trade licence, Emirates - ID, passport or Cabinet Decision of a party that has no legal - identity yet. + The supplier's and customer's UAE identities without a scope get the + one PINT AE reads them from: "legal" for the first trade licence, + Emirates ID, passport or Cabinet Decision of a party that has no legal + identity yet, and "tax" for the supplier's TIN. UAE invoices get the PINT AE transaction type from their tags: "free-trade-zone", "deemed-supply", "margin-scheme", "summary", diff --git a/ubl/ae.go b/ubl/ae.go index a4b3972..15339ae 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -18,6 +18,7 @@ import ( "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" + "github.com/invopop/gobl/uuid" ) // UNTDID 5305 VAT category codes the AE format writes rates and amounts for. @@ -41,9 +42,7 @@ const aeStandardRate = "5" // taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. const taxSchemeTIN = "TIN" -// exportAE applies the Peppol PINT AE rules to an exported invoice. Each step -// only uses data GOBL already has; the AE amounts and the BTAE extensions are -// added by later steps. +// exportAE applies the Peppol PINT AE rules to an exported invoice. func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error { out, ok := doc.(*goblubl.Invoice) inv, ok2 := env.Extract().(*bill.Invoice) @@ -76,6 +75,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error if !ok || !ok2 { return nil } + importAEUUID(in, inv) importAEOutsideScope(in, inv) importAEMarginScheme(inv) importAETransactionType(in, inv) @@ -166,6 +166,14 @@ func exportAETransactionType(out *goblubl.Invoice, inv *bill.Invoice) { } } +// importAEUUID reads the invoice's UUID back from cbc:UUID (BTAE-07). A value +// that is not a UUID is left out. +func importAEUUID(in *goblubl.Invoice, inv *bill.Invoice) { + if id, err := uuid.Parse(strings.TrimSpace(in.UUID)); err == nil { + inv.UUID = id + } +} + // identifiedParty returns a party with only a cac:PartyIdentification. func identifiedParty(id cbc.Code) *goblubl.Party { return &goblubl.Party{PartyIdentification: []goblubl.Identification{ @@ -457,7 +465,7 @@ func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { // importAEIncoterms reads the delivery terms back as the ICC Incoterms 2020 // extension, the current edition, as PINT AE doesn't say which one a code is -// from. +// from. A code only the 2010 edition has is read as that one. func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { if len(in.Delivery) == 0 || in.Delivery[0] == nil || len(in.Delivery[0].DeliveryTerms) == 0 { return @@ -469,7 +477,17 @@ func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { if inv.Delivery == nil { inv.Delivery = new(bill.DeliveryDetails) } - inv.Delivery.Ext = inv.Delivery.Ext.Set(icc.ExtKeyIncoterms2020, code) + key := icc.ExtKeyIncoterms2020 + if !extensionHasCode(key, code) && extensionHasCode(icc.ExtKeyIncoterms2010, code) { + key = icc.ExtKeyIncoterms2010 + } + inv.Delivery.Ext = inv.Delivery.Ext.Set(key, code) +} + +// extensionHasCode reports whether the extension lists the code. +func extensionHasCode(key cbc.Key, code cbc.Code) bool { + def := tax.ExtensionForKey(key) + return def != nil && def.HasCode(code) } // exportAELines completes the UBL lines, which gobl.ubl writes in the same diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 40e6a95..d3f2bd8 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -46,6 +46,18 @@ func TestExportAEUUID(t *testing.T) { assert.Equal(t, "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", out.UUID) } +func TestImportAEUUID(t *testing.T) { + inv := new(bill.Invoice) + importAEUUID(&goblubl.Invoice{UUID: " 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 "}, inv) + assert.Equal(t, "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", inv.UUID.String()) + + for _, bad := range []string{"", "not-a-uuid"} { + inv = new(bill.Invoice) + importAEUUID(&goblubl.Invoice{UUID: bad}, inv) + assert.True(t, inv.UUID.IsZero(), bad) + } +} + func TestExportAEPrice(t *testing.T) { t.Run("adds the base quantity and a zero discount on the net price", func(t *testing.T) { line := &goblubl.InvoiceLine{ @@ -828,6 +840,19 @@ func TestAEIncoterms(t *testing.T) { require.NotNil(t, inv.Delivery) assert.Equal(t, cbc.Code("CIF"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) + // DAT is only in the 2010 edition. + in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: "DAT"}}}}} + inv = new(bill.Invoice) + importAEIncoterms(in, inv) + assert.Equal(t, cbc.Code("DAT"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2010)) + assert.Empty(t, inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) + + // A code in neither edition is kept under the current one. + in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: "XYZ"}}}}} + inv = new(bill.Invoice) + importAEIncoterms(in, inv) + assert.Equal(t, cbc.Code("XYZ"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) + inv = new(bill.Invoice) importAEIncoterms(new(goblubl.Invoice), inv) assert.Nil(t, inv.Delivery) diff --git a/ubl/ubl.go b/ubl/ubl.go index e5de867..c702bc1 100644 --- a/ubl/ubl.go +++ b/ubl/ubl.go @@ -158,7 +158,10 @@ var FormatAE = goblubl.Format{ SpecificationAESelfBilling, }, ExportFuncs: []goblubl.ExportFunc{exportAE}, - ImportFuncs: []goblubl.ImportFunc{importPINT, importAE}, + // importPINT is left out: it makes a tax registration that isn't VAT the + // tax ID, which is right for GST, but in PINT AE that one is the seller's + // TIN. gobl.ubl already reads the VAT one as the tax ID. + ImportFuncs: []goblubl.ImportFunc{importAE}, Match: matchCustomization("urn:peppol:pint:billing-1@ae-1", "urn:peppol:pint:selfbilling-1@ae-1"), } diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 7124166..325373d 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -2,6 +2,7 @@ package ubl_test import ( "path/filepath" + "regexp" "testing" "github.com/invopop/gobl.peppol/addon/pint" @@ -11,6 +12,8 @@ import ( "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/convert" "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -142,14 +145,19 @@ func TestDetectAndImportAE(t *testing.T) { } // invalidImportsAE are the official PINT AE examples that pass the PINT AE -// Schematron but don't import as valid GOBL documents, and why. -var invalidImportsAE = map[string]string{ - "deemed-supply.xml": "placeholder email addresses, and no payment terms, which EN 16931 requires (BR-CO-25)", - "margin-scheme.xml": "placeholder email addresses", - "reverse-charge.xml": "placeholder email addresses", - "supply-free-trade-zone.xml": "placeholder email addresses", +// Schematron but don't import as valid GOBL documents, with the faults they +// give: placeholder email addresses, and, on the deemed supply, no payment +// terms, which EN 16931 requires (BR-CO-25). +var invalidImportsAE = map[string][]string{ + "deemed-supply.xml": {"GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-ORG-EMAIL-02"}, + "supply-free-trade-zone.xml": {"GOBL-ORG-EMAIL-02"}, } +// faultCodePattern matches the fault codes in a validation error. +var faultCodePattern = regexp.MustCompile(`\[(GOBL-[A-Z0-9-]+)\]`) + // TestImportAEValid checks that the official PINT AE examples import as valid // GOBL documents. func TestImportAEValid(t *testing.T) { @@ -162,15 +170,50 @@ func TestImportAEValid(t *testing.T) { env := parseXMLInvoice(t, filepath.Join("pint", "ae", name)) require.NoError(t, env.Calculate()) err := env.Validate() - if reason, ok := invalidImportsAE[name]; ok { - assert.Error(t, err, "listed as invalid: %s", reason) + want, ok := invalidImportsAE[name] + if !ok { + assert.NoError(t, err) return } - assert.NoError(t, err) + require.Error(t, err) + var got []string + for _, m := range faultCodePattern.FindAllStringSubmatch(err.Error(), -1) { + got = append(got, m[1]) + } + assert.ElementsMatch(t, want, got) }) } } +// TestImportAESellerTIN checks that a seller with a TIN and no TRN, as out of +// scope documents allow, keeps the TIN as a tax registration when imported, +// instead of getting it as its tax ID. +func TestImportAESellerTIN(t *testing.T) { + env := loadTestEnvelope(t, "pint/ae/invoice-ae-outside-scope.json") + inv, ok := env.Extract().(*bill.Invoice) + require.True(t, ok) + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} + inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Key: ae.IdentityKeyTIN, Code: "1357902468"}) + require.NoError(t, env.Calculate()) + require.NoError(t, env.Validate()) + + doc, err := ubl.ExportInvoice(env, ubl.WithFormat(peppolubl.FormatAE)) + require.NoError(t, err) + out, err := ubl.Import(doc) + require.NoError(t, err) + supplier := out.Extract().(*bill.Invoice).Supplier + assert.Nil(t, supplier.TaxID) + var tin *org.Identity + for _, id := range supplier.Identities { + if id.Key == ae.IdentityKeyTIN { + tin = id + } + } + require.NotNil(t, tin) + assert.Equal(t, org.IdentityScopeTax, tin.Scope) + assert.Equal(t, cbc.Code("1357902468"), tin.Code) +} + // TestExportAE checks that a UAE invoice is exported with the PINT AE // identifiers and detected as PINT AE again. func TestExportAE(t *testing.T) { From 57fb47a2e45a58c1ab4fd18dfde93ccabb6eb3e4 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:19:52 +0000 Subject: [PATCH 24/73] Use UAE tax numbers with a valid check digit in the PINT AE fixtures The AE regime now checks the check digit of the TIN, also in the first 10 digits of a TRN. Give the fixtures, the example and the tests TRNs and TINs that pass it. The official PINT AE examples use made-up numbers, so none of them imports as a valid GOBL document any more. The import test now checks the exact faults each one gives, so any other fault is still caught. Co-Authored-By: Claude Fable 5.2 --- addon/pint/bill_test.go | 42 +++++++++--------- addon/pint/org_identity.go | 7 +-- addon/pint/org_identity_test.go | 2 +- addon/pint/pay_test.go | 2 +- addon/pint/tax_identity.go | 5 ++- addon/pint/tax_identity_test.go | 4 +- examples/invoice-ae.yaml | 8 ++-- examples/out/invoice-ae.json | 18 ++++---- ubl/ae_internal_test.go | 38 ++++++++-------- .../pint/ae/credit-note-ae-outside-scope.json | 18 ++++---- .../pint/ae/credit-note-ae-self-billed.json | 18 ++++---- .../ae/credit-note-ae-volume-discount.json | 18 ++++---- .../convert/pint/ae/credit-note-ae.json | 18 ++++---- .../pint/ae/invoice-ae-continuous-supply.json | 18 ++++---- .../pint/ae/invoice-ae-deemed-supply.json | 18 ++++---- .../convert/pint/ae/invoice-ae-exempt.json | 18 ++++---- .../pint/ae/invoice-ae-export-summary.json | 18 ++++---- .../ae/invoice-ae-free-trade-zone-agent.json | 18 ++++---- .../pint/ae/invoice-ae-margin-scheme.json | 18 ++++---- .../pint/ae/invoice-ae-outside-scope.json | 18 ++++---- .../invoice-ae-reverse-charge-allowance.json | 18 ++++---- .../pint/ae/invoice-ae-reverse-charge.json | 18 ++++---- .../pint/ae/invoice-ae-self-billed.json | 18 ++++---- .../pint/ae/invoice-ae-tin-passport.json | 20 ++++----- .../convert/pint/ae/invoice-ae-usd.json | 18 ++++---- ubl/testdata/convert/pint/ae/invoice-ae.json | 18 ++++---- .../ae/out/credit-note-ae-outside-scope.xml | 8 ++-- .../ae/out/credit-note-ae-self-billed.xml | 8 ++-- .../ae/out/credit-note-ae-volume-discount.xml | 8 ++-- .../convert/pint/ae/out/credit-note-ae.xml | 8 ++-- .../ae/out/invoice-ae-continuous-supply.xml | 8 ++-- .../pint/ae/out/invoice-ae-deemed-supply.xml | 8 ++-- .../convert/pint/ae/out/invoice-ae-exempt.xml | 8 ++-- .../pint/ae/out/invoice-ae-export-summary.xml | 8 ++-- .../out/invoice-ae-free-trade-zone-agent.xml | 8 ++-- .../pint/ae/out/invoice-ae-margin-scheme.xml | 8 ++-- .../pint/ae/out/invoice-ae-outside-scope.xml | 8 ++-- .../invoice-ae-reverse-charge-allowance.xml | 8 ++-- .../pint/ae/out/invoice-ae-reverse-charge.xml | 8 ++-- .../pint/ae/out/invoice-ae-self-billed.xml | 8 ++-- .../pint/ae/out/invoice-ae-tin-passport.xml | 10 ++--- .../convert/pint/ae/out/invoice-ae-usd.xml | 8 ++-- .../convert/pint/ae/out/invoice-ae.xml | 8 ++-- ubl/ubl_test.go | 44 ++++++++++--------- 44 files changed, 310 insertions(+), 306 deletions(-) diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 288cc83..40cdac9 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -236,14 +236,14 @@ func aeDocument(typ cbc.Key, tags ...cbc.Key) *bill.Invoice { inv := scenarioInvoice(l10n.AE.Tax(), typ, tags...) inv.Supplier = &org.Party{ Name: "Seller LLC", - TaxID: &tax.Identity{Country: "AE", Code: "100000000000003"}, - Endpoints: validEndpoints("100000000000003"), + TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, + Endpoints: validEndpoints("100000001600003"), Addresses: aeAddress("DXB"), } inv.Customer = &org.Party{ Name: "Buyer LLC", - TaxID: &tax.Identity{Country: "AE", Code: "100000000000103"}, - Endpoints: validEndpoints("100000000000103"), + TaxID: &tax.Identity{Country: "AE", Code: "100000002400003"}, + Endpoints: validEndpoints("100000002400003"), Addresses: aeAddress("AUH"), } inv.Lines[0].Item.Description = "Consulting services" @@ -359,7 +359,7 @@ func TestBillDocumentRulesAE(t *testing.T) { inv := standard() inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} inv.Customer.TaxID = nil - inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000000000103"}} + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000002400003"}} assert.NotContains(t, aeFaults(t, inv), faultReverseCharge) }) @@ -378,7 +378,7 @@ func TestBillDocumentRulesAE(t *testing.T) { t.Run("a tax scope identity is not a legal identity (IBR-136-AE)", func(t *testing.T) { inv := outsideScope() - inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000000000103"}} + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "100000002400003"}} assert.Contains(t, aeFaults(t, inv), faultBuyerLegalID) }) @@ -606,7 +606,7 @@ func TestBillAddressRulesAE(t *testing.T) { }) t.Run("the tax ID country counts, as it is the one written (IBR-128-AE)", func(t *testing.T) { - trn := &tax.Identity{Country: "AE", Code: "100000000000203"} + trn := &tax.Identity{Country: "AE", Code: "100000003200003"} oman := []*org.Address{{Street: "Street 1", Locality: "Muscat", Region: "Muscat", Country: "OM"}} inv := standard() @@ -644,9 +644,9 @@ func tradeLicense(code string) *org.Identity { // endpoints and trade licences, the case the legal registration rules apply to. func aeIdentityDocument() *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) - inv.Supplier.Endpoints = uaeEndpoints("1357902468") + inv.Supplier.Endpoints = uaeEndpoints("1357902467") inv.Supplier.Identities = []*org.Identity{tradeLicense("112345678900003")} - inv.Customer.Endpoints = uaeEndpoints("1345678901") + inv.Customer.Endpoints = uaeEndpoints("1345678906") inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} return inv } @@ -679,7 +679,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("supplier without a UAE endpoint needs no legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil - inv.Supplier.Endpoints = validEndpoints("1357902468") + inv.Supplier.Endpoints = validEndpoints("1357902467") assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalRequired) }) @@ -687,7 +687,7 @@ func TestBillIdentityRulesAE(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil inv.Supplier.Endpoints = nil - inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1357902468"}} + inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1357902467"}} assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) }) @@ -702,9 +702,9 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { inv := aeIdentityDocument() - inv.Supplier.Endpoints = validEndpoints("1357902468") + inv.Supplier.Endpoints = validEndpoints("1357902467") inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} - inv.Customer.Endpoints = validEndpoints("1345678901") + inv.Customer.Endpoints = validEndpoints("1345678906") inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} out := aeFaults(t, inv) assert.NotContains(t, out, faultSupplierLegalType) @@ -752,7 +752,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("supplier TIN is accepted, before or after the legal identity (IBR-148-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append([]*org.Identity{ - {Key: ae.IdentityKeyTIN, Code: "1234567890"}, + {Key: ae.IdentityKeyTIN, Code: "1234567897"}, }, inv.Supplier.Identities...) assert.Empty(t, aeFaults(t, inv)) }) @@ -774,7 +774,7 @@ func TestBillIdentityRulesAE(t *testing.T) { }) t.Run("customer with a UAE endpoint starting with 1 or 9 needs no tax registration (IBR-149-AE)", func(t *testing.T) { - for _, code := range []string{"1345678901", "9345678901"} { + for _, code := range []string{"1345678906", "9345678901"} { inv := aeIdentityDocument() inv.Customer.TaxID = nil inv.Customer.Endpoints = uaeEndpoints(code) @@ -785,16 +785,16 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("customer has at most one tax registration (IBR-179-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}) + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"}) inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678901"}) + &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) }) t.Run("customer TIN without a scope is a plain identity (IBR-179-AE, IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678901"}) + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678906"}) out := aeFaults(t, inv) assert.Empty(t, inv.Customer.Identities[1].Scope) assert.NotContains(t, out, faultCustomerTaxCount) @@ -805,11 +805,11 @@ func TestBillIdentityRulesAE(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = nil inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678901"}) + &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"}) + &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"}) assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) }) } @@ -961,7 +961,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { inv = aeDocument(bill.InvoiceTypeStandard) inv.Customer.TaxID = nil - inv.Customer.Endpoints = uaeEndpoints("1345678901") + inv.Customer.Endpoints = uaeEndpoints("1345678906") assert.NotContains(t, aeFaults(t, inv), faultCustomerIdentifier) }) } diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 5dd999d..1ef1232 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -11,9 +11,10 @@ import ( ) // tinRegexp matches a UAE TIN as PINT AE expects it: 10 digits starting with -// 1 (IBR-148-AE). The AE regime only checks the 10 digits; the leading 1 is -// PINT AE's. UAE Peppol endpoints (0235) are TINs too, so it also tells -// whether an endpoint is one (IBR-135-AE). +// 1 (IBR-148-AE). The AE regime checks the identities with the TIN key, check +// digit included; this one covers any tax scope identity, as the Schematron +// tests the value written. UAE Peppol endpoints (0235) are TINs too, so it +// also tells whether an endpoint is one (IBR-135-AE). var tinRegexp = regexp.MustCompile(`^1\d{9}$`) // PINT AE legal registration identifier types, written as @schemeAgencyID on diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index b87cb29..1866bda 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -62,7 +62,7 @@ func TestNormalizeIdentityScopes(t *testing.T) { norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) return scopes(inv.Supplier), scopes(inv.Customer) } - tin := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567890"} } + tin := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"} } eid := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"} } passport := func() *org.Identity { return &org.Identity{Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"} diff --git a/addon/pint/pay_test.go b/addon/pint/pay_test.go index 8315ec5..63f07f6 100644 --- a/addon/pint/pay_test.go +++ b/addon/pint/pay_test.go @@ -102,7 +102,7 @@ func TestPayInstructionsRulesAE(t *testing.T) { t.Run("credit transfer with account number is accepted", func(t *testing.T) { instr := instructionsWithMeansCode("30") - instr.CreditTransfer = []*pay.CreditTransfer{{Number: "1234567890"}} + instr.CreditTransfer = []*pay.CreditTransfer{{Number: "1234567897"}} assert.NoError(t, validate(instr)) }) diff --git a/addon/pint/tax_identity.go b/addon/pint/tax_identity.go index 19f5edf..98f8447 100644 --- a/addon/pint/tax_identity.go +++ b/addon/pint/tax_identity.go @@ -7,8 +7,9 @@ import ( ) // taxIdentityRules enforces the UAE TRN format on every UAE tax identity of a -// UAE document (IBR-132-AE). The AE regime only checks for 15 digits; PINT AE -// also requires a leading 1 and a trailing 03. +// UAE document (IBR-132-AE). The AE regime checks the 15 digits and the +// TIN they start with; PINT AE also requires the trailing 03 of a VAT +// registration. func taxIdentityRules() *rules.Set { return rules.For(new(tax.Identity), rules.When( diff --git a/addon/pint/tax_identity_test.go b/addon/pint/tax_identity_test.go index 9c64573..52f5051 100644 --- a/addon/pint/tax_identity_test.go +++ b/addon/pint/tax_identity_test.go @@ -19,13 +19,13 @@ func TestTaxIdentityRulesAE(t *testing.T) { validate := func(id *tax.Identity) error { return validateIn(id, l10n.AE.Tax()) } t.Run("valid TRN is accepted (IBR-132-AE)", func(t *testing.T) { - assert.NoError(t, validate(&tax.Identity{Country: "AE", Code: "100000000000003"})) + assert.NoError(t, validate(&tax.Identity{Country: "AE", Code: "100000001600003"})) }) t.Run("malformed TRNs are rejected (IBR-132-AE)", func(t *testing.T) { for name, code := range map[string]cbc.Code{ "does not start with 1": "200000000000003", - "does not end with 03": "100000000000004", + "does not end with 03": "100000001600004", "too short": "10000000000003", "too long": "1000000000000003", } { diff --git a/examples/invoice-ae.yaml b/examples/invoice-ae.yaml index ac03e21..d97df6e 100644 --- a/examples/invoice-ae.yaml +++ b/examples/invoice-ae.yaml @@ -12,7 +12,7 @@ supplier: name: "Supplier Legal Name" tax_id: country: "AE" - code: "135790246801003" + code: "135790246700003" identities: - key: "ae-trade-license" code: "112345678900003" @@ -20,7 +20,7 @@ supplier: inboxes: - key: "peppol" scheme: "0235" - code: "1357902468" + code: "1357902467" addresses: - street: "Sheikh Zayed Road" locality: "Dubai" @@ -31,7 +31,7 @@ customer: name: "Buyer Legal Name" tax_id: country: "AE" - code: "134567890123003" + code: "134567890600003" identities: - key: "ae-trade-license" code: "112345679000001" @@ -39,7 +39,7 @@ customer: inboxes: - key: "peppol" scheme: "0235" - code: "1345678901" + code: "1345678906" addresses: - street: "Corniche Road" locality: "Abu Dhabi" diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index 4e76f41..6b64451 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,10 +4,10 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "5c0282d9bba5f8cdea7c7ed8c1c954e0ed1b54ce34af37afdcd51ca3ee2aa1af" + "val": "8e2e608f4836428a77673ed749093fd1a8d8dde2604d7e7b6c66dc14f9688e20" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,7 +32,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -44,14 +44,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -67,7 +67,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -79,14 +79,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index d3f2bd8..1eebe1b 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -179,9 +179,9 @@ func TestExportAEPartyTaxID(t *testing.T) { } t.Run("writes a UAE TRN without its prefix", func(t *testing.T) { - out := party("AE100000000000003") - exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000000000003"}) - assert.Equal(t, "100000000000003", out.PartyTaxScheme[0].CompanyID.Value) + out := party("AE100000001600003") + exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000001600003"}) + assert.Equal(t, "100000001600003", out.PartyTaxScheme[0].CompanyID.Value) }) t.Run("keeps the prefix of other countries' VAT numbers", func(t *testing.T) { @@ -191,15 +191,15 @@ func TestExportAEPartyTaxID(t *testing.T) { }) t.Run("leaves other tax registrations alone", func(t *testing.T) { - out := party("1234567890") - exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000000000003"}) - assert.Equal(t, "1234567890", out.PartyTaxScheme[0].CompanyID.Value) + out := party("1234567897") + exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000001600003"}) + assert.Equal(t, "1234567897", out.PartyTaxScheme[0].CompanyID.Value) }) t.Run("parties without a tax ID are skipped", func(t *testing.T) { - out := party("AE100000000000003") + out := party("AE100000001600003") exportAEPartyTaxID(out, nil) - assert.Equal(t, "AE100000000000003", out.PartyTaxScheme[0].CompanyID.Value) + assert.Equal(t, "AE100000001600003", out.PartyTaxScheme[0].CompanyID.Value) }) } @@ -262,7 +262,7 @@ func TestExportAEPartyIdentities(t *testing.T) { t.Run("the first legal identity is described, after a tax one", func(t *testing.T) { cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ - {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567890"}, + {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, legal(ae.IdentityKeyEmiratesID, "784199012345671"), legal(ae.IdentityKeyCabinetDecision, "CD-1"), }}).PartyLegalEntity.CompanyID @@ -273,20 +273,20 @@ func TestExportAEPartyIdentities(t *testing.T) { t.Run("TIN is written under the TIN scheme, next to the VAT TRN", func(t *testing.T) { out := export(&org.Party{ Name: "Seller", - TaxID: &tax.Identity{Country: "AE", Code: "100000000000003"}, + TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, Identities: []*org.Identity{ - {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567890"}, + {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, }, }) require.Len(t, out.PartyTaxScheme, 2) assert.Equal(t, "VAT", out.PartyTaxScheme[0].TaxScheme.ID.Value) - assert.Equal(t, "1234567890", out.PartyTaxScheme[1].CompanyID.Value) + assert.Equal(t, "1234567897", out.PartyTaxScheme[1].CompanyID.Value) assert.Equal(t, "TIN", out.PartyTaxScheme[1].TaxScheme.ID.Value) }) t.Run("other tax identities keep the scheme gobl.ubl gives them", func(t *testing.T) { out := export(&org.Party{Name: "Seller", Identities: []*org.Identity{ - {Scope: org.IdentityScopeTax, Code: "1234567890"}, + {Scope: org.IdentityScopeTax, Code: "1234567897"}, }}) require.Len(t, out.PartyTaxScheme, 1) assert.Equal(t, goblubl.TaxSchemeTaxRegistration, out.PartyTaxScheme[0].TaxScheme.ID.Value) @@ -357,13 +357,13 @@ func TestImportAEPartyIdentities(t *testing.T) { t.Run("supplier non-VAT tax registration is the TIN", func(t *testing.T) { in := companyID("TL", "Authority") in.PartyTaxScheme = []goblubl.PartyTaxScheme{ - {CompanyID: &goblubl.IDType{Value: "198765432102003"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}}, - {CompanyID: &goblubl.IDType{Value: "1234567890"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "TIN"}}}, + {CompanyID: &goblubl.IDType{Value: "198765432200003"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}}, + {CompanyID: &goblubl.IDType{Value: "1234567897"}, TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "TIN"}}}, } p := imported(in, true) require.Len(t, p.Identities, 2) assert.Equal(t, ae.IdentityKeyTIN, p.Identities[1].Key) - assert.Equal(t, cbc.Code("1234567890"), p.Identities[1].Code) + assert.Equal(t, cbc.Code("1234567897"), p.Identities[1].Code) p = imported(in, false) assert.Empty(t, p.Identities[1].Key, "only the seller has a TIN") @@ -379,14 +379,14 @@ func TestImportAEPartyIdentities(t *testing.T) { func TestImportAEPartyEndpoint(t *testing.T) { t.Run("the electronic address replaces the inbox gobl.ubl imports", func(t *testing.T) { - in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: "0235", Value: "1357902468"}} + in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: "0235", Value: "1357902467"}} p := &org.Party{Inboxes: []*org.Inbox{ - {Scheme: "0235", Code: "1357902468"}, + {Scheme: "0235", Code: "1357902467"}, {Key: "other", Code: "ABC"}, }} importAEPartyEndpoint(in, p) require.Len(t, p.Endpoints, 1) - assert.Equal(t, cbc.URI("iso6523-actorid-upis::0235:1357902468"), p.Endpoints[0].URI) + assert.Equal(t, cbc.URI("iso6523-actorid-upis::0235:1357902467"), p.Endpoints[0].URI) require.Len(t, p.Inboxes, 1) assert.Equal(t, cbc.Code("ABC"), p.Inboxes[0].Code) }) diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json index e802ff3..8268742 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "89307d52648c3f441ba8763726601b4376b46ed40cf72603363beb516d3a1642" + "val": "0430fc09e17a0375b6d51ab9ed1cd0fafcc3a147e65ce1a627a83382c0f313ee" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -42,7 +42,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -54,14 +54,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -77,7 +77,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -89,14 +89,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json index ea6e8f1..94f2985 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "916a9b3f20b05bef8377b592fa155e670861b580164ebf69c37439782d682bd8" + "val": "44c2f0324debee9394a59a34f38820cb782cb1c7fc9b9584a87860c0fa0d1b0f" }, - "from": "iso6523-actorid-upis::0235:1345678901", - "to": "iso6523-actorid-upis::0235:1357902468" + "from": "iso6523-actorid-upis::0235:1345678906", + "to": "iso6523-actorid-upis::0235:1357902467" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -42,7 +42,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -54,14 +54,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -77,7 +77,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -89,14 +89,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json index 4928100..40b84e8 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e7a15773211970c27660a0838c8448a9b57d9ddd60c4b8716a28edf8b1ef98b5" + "val": "d904436614ce611d74de4293b505a5411f021204365db500830da42963ca0ac3" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -33,7 +33,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -45,14 +45,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -68,7 +68,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -80,14 +80,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index 2daa16b..35c9e90 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "24fcff53f09d9db79f270edf12997196e22b4419a9bc1eee1c632c9eee26e40d" + "val": "02e5744a95abc0d768d070667650449ce065dc5b55474fbf23ecb4ca60d934cf" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -39,7 +39,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -51,14 +51,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -74,7 +74,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -86,14 +86,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index e784376..8e8660c 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "8fd1920993fcd36db4c3c18a41ce7cb7cc07d01d356285c856a13ef122d6530b" + "val": "d1f5ceba24a3a97adb52868ea22abd7a7e15a8c1717c256a090c8286dfa5969a" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -36,7 +36,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -48,14 +48,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -71,7 +71,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -83,14 +83,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index 3129065..0fa8ea4 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5d4feec1d19e01d05cc517a85153126b227febba43b6435293f53a06f8bf03a4" + "val": "36c8b6d1a0ea7e24dc80ade02c6b33cf353fabcb3e53b22e723caad0cf1649c0" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -35,7 +35,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -47,14 +47,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -70,7 +70,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -82,14 +82,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index 64e3798..4b05ce7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f03d696b4107c8538fde4e3a01a500615a8906a59b9d12836bce1a867edda7cc" + "val": "21da47d3bd98121a46a6a42b424444233a611d2ec5080b9bb9d800296a5d1d5a" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,7 +32,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -44,14 +44,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -67,7 +67,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -79,14 +79,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 7f2ae26..51e1919 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5ae6ba316b341cf944951696196580d75e1787daa1f691beb85003953d560203" + "val": "b3ff7190be2217a9c49b073f312a3f21cbb804e7c1f5fb09098b65e377ae3aea" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -37,7 +37,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -49,14 +49,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -72,7 +72,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -84,14 +84,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json index a0f5300..3cc1650 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "02c76b4d4da6715d30ae2d9bf51cb81ae6967bf14fa7ad244c5e5417787194ed" + "val": "805083f45161fae4dd82ae7dd3cd2a7ef354ab577e2a307ea9ac2bd03f83cd97" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -38,7 +38,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -50,14 +50,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -73,7 +73,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -85,14 +85,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index 188fbf5..bce13ca 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b9c84257dc6335edf1313fa23d79eed0d19a0ae5b3967f83f9a00514bc844ad6" + "val": "7605d1a6c5331f72342308110ff47d34f0ad2546441711a5c1bcfb98818e4d7e" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -35,7 +35,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -47,14 +47,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -70,7 +70,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -82,14 +82,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index 635465b..485f291 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "50af39bff25a551aa0dd1765cf11219ca6bfe5981b56d5190a7ff98a77eac43d" + "val": "b7eed4cad0cf2a784963db7cdc213203c80dbae3f6ee04de339ea9cbdd5569c3" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -35,7 +35,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -47,14 +47,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -70,7 +70,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -82,14 +82,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 43532fa..4b0be54 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "37e899919569ef46b7819070afb2e807aed37b6a0c27f44451702e3e64510e52" + "val": "48631c6053724f64aa1eee791fd04aa790ab4d6f6b144b24696d5a06ff9e3a69" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,7 +32,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -44,14 +44,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -67,7 +67,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -79,14 +79,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index c74ae7c..da1a2f2 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e8901d4b59f3f4f56f757b4fa85aa7f673bc52f499224e254c5d12eae5330fbe" + "val": "0110b236aa10a9cd2f9e5a5d0fe29e24035444978f1034d002c847018755e9d9" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,7 +32,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -44,14 +44,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -67,7 +67,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -79,14 +79,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json index 97a9eea..a86b3b5 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b77cb1b493c421a34062302f214919d82ea866a41c55d0c85064133e0a3ba15e" + "val": "5c35f1643870efa7a89cdb79677b025848da34c4e90d0f5fe7928360ac551739" }, - "from": "iso6523-actorid-upis::0235:1345678901", - "to": "iso6523-actorid-upis::0235:1357902468" + "from": "iso6523-actorid-upis::0235:1345678906", + "to": "iso6523-actorid-upis::0235:1357902467" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -35,7 +35,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -47,14 +47,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -70,7 +70,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -82,14 +82,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index 3aa8222..8d586dc 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f66432e26e2db15630aa470cee82076c3ea5055e70c43c9e9f6c56b853a46009" + "val": "d2f0b707ea1f49f909469171b4b98ea1fc4fc8588efa982bc8d54498318d20f3" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,13 +32,13 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { "scope": "tax", "key": "ae-tin", - "code": "1234567890" + "code": "1234567897" }, { "scope": "legal", @@ -49,14 +49,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -72,7 +72,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -84,14 +84,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index 5241082..e0db0fe 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5b1109f376388b2c7dc1a5cb657164ee021253239193916e75b6d84163c441e4" + "val": "9ebf5cec76ecacd58e1d8b6f8d83665231778ae99c07bd784ca16d9bed045d82" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -39,7 +39,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -51,14 +51,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -74,7 +74,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -86,14 +86,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 9ace1e7..abf8a71 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5c0282d9bba5f8cdea7c7ed8c1c954e0ed1b54ce34af37afdcd51ca3ee2aa1af" + "val": "8e2e608f4836428a77673ed749093fd1a8d8dde2604d7e7b6c66dc14f9688e20" }, - "from": "iso6523-actorid-upis::0235:1357902468", - "to": "iso6523-actorid-upis::0235:1345678901" + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -32,7 +32,7 @@ "name": "Supplier Legal Name", "tax_id": { "country": "AE", - "code": "135790246801003" + "code": "135790246700003" }, "identities": [ { @@ -44,14 +44,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1357902468" + "uri": "iso6523-actorid-upis::0235:1357902467" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1357902468" + "code": "1357902467" } ], "addresses": [ @@ -67,7 +67,7 @@ "name": "Buyer Legal Name", "tax_id": { "country": "AE", - "code": "134567890123003" + "code": "134567890600003" }, "identities": [ { @@ -79,14 +79,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678901" + "uri": "iso6523-actorid-upis::0235:1345678906" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678901" + "code": "1345678906" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml index 42a0cdb..64e7362 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml @@ -22,7 +22,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -35,7 +35,7 @@ - 135790246801003 + 135790246700003 VAT @@ -48,7 +48,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -61,7 +61,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml index 354b82e..eb3b9be 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml @@ -22,7 +22,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -35,7 +35,7 @@ - 135790246801003 + 135790246700003 VAT @@ -48,7 +48,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -61,7 +61,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml index 26837e1..973f1c0 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -16,7 +16,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -29,7 +29,7 @@ - 135790246801003 + 135790246700003 VAT @@ -42,7 +42,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -55,7 +55,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index bdc2318..e192bda 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -22,7 +22,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -35,7 +35,7 @@ - 135790246801003 + 135790246700003 VAT @@ -48,7 +48,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -61,7 +61,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 95fb017..555a189 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -20,7 +20,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -33,7 +33,7 @@ - 135790246801003 + 135790246700003 VAT @@ -46,7 +46,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -59,7 +59,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml index ce21271..5c25d69 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -13,7 +13,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -26,7 +26,7 @@ - 135790246801003 + 135790246700003 VAT @@ -39,7 +39,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -52,7 +52,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index 9dd5850..997d6fa 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index 20ef9d9..b895765 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -18,7 +18,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -31,7 +31,7 @@ - 135790246801003 + 135790246700003 VAT @@ -44,7 +44,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -57,7 +57,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index 6b33212..1a71000 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 3ff037b..7d7c930 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index a5f89ad..5824303 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 30b363d..8ef9592 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 2fce460..87b7d8b 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml index d0c6698..4a3273a 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index 354d837..d49676f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,13 +27,13 @@ - 135790246801003 + 135790246700003 VAT - 1234567890 + 1234567897 TIN @@ -46,7 +46,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -59,7 +59,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index d98943e..8baea1a 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -20,7 +20,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -33,7 +33,7 @@ - 135790246801003 + 135790246700003 VAT @@ -46,7 +46,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -59,7 +59,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 304e68f..d3ac622 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -14,7 +14,7 @@ - 1357902468 + 1357902467 Supplier Legal Name @@ -27,7 +27,7 @@ - 135790246801003 + 135790246700003 VAT @@ -40,7 +40,7 @@ - 1345678901 + 1345678906 Buyer Legal Name @@ -53,7 +53,7 @@ - 134567890123003 + 134567890600003 VAT diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 325373d..f6e9181 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -144,43 +144,45 @@ func TestDetectAndImportAE(t *testing.T) { assert.Equal(t, l10n.TaxCountryCode("AE"), inv.GetRegime()) } -// invalidImportsAE are the official PINT AE examples that pass the PINT AE -// Schematron but don't import as valid GOBL documents, with the faults they -// give: placeholder email addresses, and, on the deemed supply, no payment -// terms, which EN 16931 requires (BR-CO-25). -var invalidImportsAE = map[string][]string{ - "deemed-supply.xml": {"GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, - "margin-scheme.xml": {"GOBL-ORG-EMAIL-02"}, - "reverse-charge.xml": {"GOBL-ORG-EMAIL-02"}, - "supply-free-trade-zone.xml": {"GOBL-ORG-EMAIL-02"}, +// importFaultsAE are the faults the official PINT AE examples give once +// imported. They pass the PINT AE Schematron, but their data is made up: the +// TRNs and TINs fail the check digit the Federal Tax Authority defines, some +// email addresses are placeholders, and the deemed supply has no payment +// terms, which EN 16931 requires (BR-CO-25). Any other fault is a defect in +// the import. +var importFaultsAE = map[string][]string{ + "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-01"}, + "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-01"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, + "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-01"}, + "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-01", "GOBL-AE-TAX-IDENTITY-01"}, + "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-01"}, + "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, } // faultCodePattern matches the fault codes in a validation error. var faultCodePattern = regexp.MustCompile(`\[(GOBL-[A-Z0-9-]+)\]`) -// TestImportAEValid checks that the official PINT AE examples import as valid -// GOBL documents. -func TestImportAEValid(t *testing.T) { +// TestImportAEFaults checks that the official PINT AE examples import with +// no faults beyond the ones their made-up data gives. +func TestImportAEFaults(t *testing.T) { examples, err := filepath.Glob(filepath.Join("testdata", "parse", "pint", "ae", "*.xml")) require.NoError(t, err) - require.NotEmpty(t, examples) + require.Len(t, examples, len(importFaultsAE)) for _, example := range examples { name := filepath.Base(example) t.Run(name, func(t *testing.T) { env := parseXMLInvoice(t, filepath.Join("pint", "ae", name)) require.NoError(t, env.Calculate()) err := env.Validate() - want, ok := invalidImportsAE[name] - if !ok { - assert.NoError(t, err) - return - } require.Error(t, err) var got []string for _, m := range faultCodePattern.FindAllStringSubmatch(err.Error(), -1) { got = append(got, m[1]) } - assert.ElementsMatch(t, want, got) + assert.ElementsMatch(t, importFaultsAE[name], got) }) } } @@ -193,7 +195,7 @@ func TestImportAESellerTIN(t *testing.T) { inv, ok := env.Extract().(*bill.Invoice) require.True(t, ok) inv.Supplier.TaxID = &tax.Identity{Country: "AE"} - inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Key: ae.IdentityKeyTIN, Code: "1357902468"}) + inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Key: ae.IdentityKeyTIN, Code: "1357902467"}) require.NoError(t, env.Calculate()) require.NoError(t, env.Validate()) @@ -211,7 +213,7 @@ func TestImportAESellerTIN(t *testing.T) { } require.NotNil(t, tin) assert.Equal(t, org.IdentityScopeTax, tin.Scope) - assert.Equal(t, cbc.Code("1357902468"), tin.Code) + assert.Equal(t, cbc.Code("1357902467"), tin.Code) } // TestExportAE checks that a UAE invoice is exported with the PINT AE From 47e06f0a90cc5aa2420066a9e957ddd3980c5ddd Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:34:23 +0000 Subject: [PATCH 25/73] Pin gobl and gobl.ubl to the PINT AE dependency PRs Until invopop/gobl#1033 and invopop/gobl.ubl#189 are released, build against their head commits so the tests can run. Co-Authored-By: Claude Fable 5.2 --- go.mod | 4 ++-- go.sum | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index fb48070..bafff28 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.0 + github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.0 + github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 3d333d4..014ab98 100644 --- a/go.sum +++ b/go.sum @@ -16,34 +16,24 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM= github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= -github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= -github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-jose/go-jose/v4 v4.1.6 h1:sNRkftxFJxwsILiQukqp5z83QBSmntVwmgRY7AqBDO4= github.com/go-jose/go-jose/v4 v4.1.6/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.510.0 h1:zA9b3ZD0H1tIWM/dPdeWUEo9VGqLFQ28S8paZIINDMY= -github.com/invopop/gobl v0.510.0/go.mod h1:HmiEdQreTSQYyNbhs81VKTmI7BAJKYC/6enh9RDwnE0= -github.com/invopop/gobl v0.512.0 h1:qcZ4WvbgUqp8UFjjQ80VPHhdPAZzjexnBaKEJmcml3o= -github.com/invopop/gobl v0.512.0/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= -github.com/invopop/gobl.cii v0.75.1-0.20261019131130-638784aa8ee4 h1:T2T9gBYE6jXhrCRkVepi++pmOXWuQ3FaHlHuR2Uoixc= -github.com/invopop/gobl.cii v0.75.1-0.20261019131130-638784aa8ee4/go.mod h1:V9rp7WVREOHESleTO825BuslioeIzbEzZCN0GXicLsQ= +github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c h1:qbKm7vBSVax4ug8ye+MTr1FXWtw1Vr5xgqEZwZeA4cY= +github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.94.1-0.20261019110252-77b5d5cd53af h1:ZDZCMvnfSqVOPPlwG/FEai8IEOELSrQOmGyp6U8WARY= -github.com/invopop/gobl.ubl v0.94.1-0.20261019110252-77b5d5cd53af/go.mod h1:LYnmg9fH0W8fZXK6LqzYQt3pzQYZonm2gkn4Slt1mtY= -github.com/invopop/gobl.ubl v0.101.0 h1:/+zCZIvpX84p9dkXVfaOvdz8u9t+TjOgduSzRiNezzA= -github.com/invopop/gobl.ubl v0.101.0/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a h1:hqRURd3RsrOZV/BXBUuLGFbR1s/5fBrCH4F20h59u+4= +github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= github.com/invopop/phorm v0.1.5/go.mod h1:7GJMH9RwreocY9NX36ZnhmMcS/qE/NY4+Ro+YFdFHR8= github.com/invopop/validation v0.8.0 h1:e5hXHGnONHImgJdonIpNbctg1hlWy1ncaHoVIQ0JWuw= github.com/invopop/validation v0.8.0/go.mod h1:nLLeXYPGwUNfdCdJo7/q3yaHO62LSx/3ri7JvgKR9vg= -github.com/invopop/xmlctx v0.13.0 h1:ZNRMC0O/A5h8InoLVSA7tIjjrhJn/NDBYfByBUpSb+g= -github.com/invopop/xmlctx v0.13.0/go.mod h1:xZ3Bdf0jq2GcjN6QNroUa+l37kyXDXmDEEKiBj9NAl0= github.com/invopop/xmlctx v0.14.0 h1:s2nfna7gylrBfS93iYqCF0d/imwTIsivtxwwvdLEWGE= github.com/invopop/xmlctx v0.14.0/go.mod h1:xZ3Bdf0jq2GcjN6QNroUa+l37kyXDXmDEEKiBj9NAl0= github.com/invopop/xmldsig v0.14.0 h1:ROwf32DZtX2EekrrOSjLLiY0s2kPEcqHZculITlZfAw= From b268e2e85bfbc0ad99a19fb65daf65bdca62fcb6 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:03:47 +0000 Subject: [PATCH 26/73] Refactor the PINT AE rules after review Use GOBL's own validators and drill down to the field a rule checks with rules.Field, where the rule depends on a single field. Split the payment rule into payment details and instructions. Split the rules and helpers by GOBL package: the line rules go to bill_line.go, the party helpers to org_party.go, and the item, identity and tax combo helpers next to their types. The document level discount and charge rules get their own sets, as in the EN 16931 addon. Group the invoice rules with one block per condition: the rules that always apply to the supplier and the customer first, then one block per document type and per transaction type flag. They are numbered 01 to 54 in file order, so most invoice fault codes change. Co-Authored-By: Claude Fable 5.2 --- addon/pint/bill.go | 1096 ++++++++++---------------------- addon/pint/bill_line.go | 126 ++++ addon/pint/bill_line_test.go | 154 +++++ addon/pint/bill_test.go | 262 ++------ addon/pint/org_identity.go | 23 + addon/pint/org_item.go | 59 ++ addon/pint/org_party.go | 220 +++++++ addon/pint/pint.go | 2 + addon/pint/tax_combo.go | 31 + addon/pint/transaction_type.go | 4 - ubl/ae.go | 2 +- 11 files changed, 1009 insertions(+), 970 deletions(-) create mode 100644 addon/pint/bill_line.go create mode 100644 addon/pint/bill_line_test.go create mode 100644 addon/pint/org_party.go diff --git a/addon/pint/bill.go b/addon/pint/bill.go index aa8cddd..d75f858 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -1,11 +1,8 @@ package pint import ( - "strings" - "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" - "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -17,29 +14,11 @@ import ( "github.com/invopop/gobl/tax" ) -// taxCategoryCodesOutsideScope are the VAT category codes allowed on 480 and -// 81 documents: exempt (E), zero rated (Z) and not subject to VAT (O) -// (IBR-122-AE). -var taxCategoryCodesOutsideScope = []cbc.Code{ - en16931.TaxCategoryExempt, - en16931.TaxCategoryZero, - en16931.TaxCategoryOutsideScope, -} - -// emirateCodes are the country subdivision codes PINT AE accepts for UAE -// addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. -var emirateCodes = []cbc.Code{ - "AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK", -} - -// endpointSchemeUAE is the Peppol participant identifier scheme for UAE -// endpoints, which the PINT AE legal registration rules depend on. -const endpointSchemeUAE cbc.Code = "0235" - // billInvoiceRules enforces the PINT invoice rules shared by every // jurisdiction, and the PINT AE rules on UAE documents. func billInvoiceRules() *rules.Set { return rules.For(new(bill.Invoice), + // Supplier rules.Field("supplier", rules.Assert("01", "invoice supplier must have a tax ID or identity (IBR-CO-26)", is.Func("has identifier", partyHasIdentifier), @@ -48,6 +27,7 @@ func billInvoiceRules() *rules.Set { rules.Assert("02", "invoice supplier electronic address is required (IBR-081)", is.Present), ), ), + // Customer rules.Field("customer", rules.Assert("03", "invoice customer is required (IBR-007)", is.Present), rules.Field("endpoints", @@ -61,235 +41,349 @@ func billInvoiceRules() *rules.Set { // rule: it only asks for the UAE exemption reason on exempt lines // (IBR-167-AE), and no official example has a reason on a breakdown. rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-08"), - rules.Assert("05", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", - is.Func("has AED exchange rate", exchangeRateHasAED), + + // AE supplier + // + // IBR-128-AE's text names the seller, buyer, tax representative and + // delivery subdivisions (IBT-039, IBT-054, IBT-068, IBT-079), but its + // test never runs on the seller's and buyer's addresses: its context, + // cac:PostalAddress, comes after their address rules (IBR-143-AE, + // IBR-144-AE) in the same pattern, where a node only fires the first + // rule it matches. Rules 06 and 13 follow the text there, as the + // official examples do, so they check more than the test. Rules 20 + // and 21, and line rule 11, follow the test: gobl.ubl also writes the + // issuer and the line sellers with a cac:PostalAddress. + rules.Field("supplier", + rules.Assert("05", "supplier address must have a street, city and region (IBR-143-AE)", + is.Func("first address has street, city and region", partyAddressIsComplete), + ), + rules.Assert("06", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + rules.When( + is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), + rules.Assert("07", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", + is.Func("has legal identity", partyHasLegalIdentity), + ), + rules.Field("identities", rules.Each( + rules.When( + is.Func("legal scope", identityHasLegalScope), + rules.Assert("08", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", + org.IdentityKeyIn(identityKeysAE...), + ), + ), + )), + ), + rules.Field("identities", rules.Each( + rules.When( + org.IdentityKeyIn(org.IdentityKeyPassport), + rules.Field("country", + rules.Assert("09", "supplier passport must have the issuing country (IBR-012-AE)", is.Present), + ), + ), + rules.When( + org.IdentityKeyIn(ae.IdentityKeyTradeLicense), + rules.Field("description", + rules.Assert("10", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Present), + ), + ), + // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity + // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two + // PartyTaxSchemes with one VAT that it accepts. + rules.When( + is.Func("tax scope", identityHasTaxScope), + rules.Field("code", + rules.Assert("11", "supplier tax scope identity must be a TIN of 10 digits starting with 1 (IBR-148-AE)", + is.MatchesRegexp(tinRegexp), + ), + ), + ), + )), ), - rules.Assert("06", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + + // AE customer + rules.Field("customer", + rules.Assert("12", "customer address must have a street, city and region (IBR-144-AE)", + is.Func("first address has street, city and region", partyAddressIsComplete), + ), + rules.Assert("13", "customer region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyAddressHasEmirate), + ), + // IBR-183-AE's test also accepts CL, which only its rule text's + // "Commercial/Trade license" explains. FormatAE reads CL as a + // trade licence on import, but GOBL writes TL, which is valid for + // both seller and buyer. + rules.When( + is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), + rules.Field("identities", rules.Each( + rules.When( + is.Func("legal scope", identityHasLegalScope), + rules.Assert("14", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", + org.IdentityKeyIn(identityKeysAE...), + ), + ), + )), + ), + rules.Field("identities", rules.Each( + rules.When( + org.IdentityKeyIn(org.IdentityKeyPassport), + rules.Field("country", + rules.Assert("15", "customer passport must have the issuing country (IBR-010-AE)", is.Present), + ), + ), + rules.When( + org.IdentityKeyIn(ae.IdentityKeyTradeLicense), + rules.Field("description", + rules.Assert("16", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Present), + ), + ), + )), + // IBR-149-AE's text asks for the buyer legal registration identifier + // (IBT-047), but its test checks the tax registration, + // cac:PartyTaxScheme/cbc:CompanyID. We follow the test. + rules.When( + is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), + rules.Assert("17", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", + is.Func("has tax registration", partyHasTaxRegistration), + ), + ), + rules.Assert("18", "customer must have at most one tax registration (IBR-179-AE)", + is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), + ), + ), + rules.Assert("19", "customer tax scope identities require a supplier TIN (IBR-133-AE)", + is.Func("customer tax scope identities with supplier TIN", customerTaxIdentitiesHaveSupplierTIN), + ), + + // AE tax representative and issuer + rules.Field("ordering", + rules.Field("seller", + rules.Assert("20", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), + ), + ), + rules.Field("issuer", + rules.Assert("21", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), + ), + ), + ), + + // AE currency + rules.Assert("22", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + currency.CanConvertTo(currency.AED), + ), + rules.Assert("23", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), + + // AE VAT point date + rules.Assert("24", "VAT point date must be before the invoice issue date (IBR-141-AE)", + is.Func("VAT point date before issue date", pointDateBeforeIssueDate), + ), + + // AE payment rules.When( is.Not(is.Or( - is.Func("credit note", invoiceIsCreditNote), + bill.InvoiceTypeIn(bill.InvoiceTypeCreditNote), is.Func("deemed supply", invoiceIsDeemedSupply), )), - rules.Assert("07", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", - is.Func("has payment instructions", invoiceHasPaymentInstructions), + rules.Field("payment", + rules.Assert("25", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + is.Present, + ), + rules.Field("instructions", + rules.Assert("26", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + is.Present, + ), + ), ), ), + // Self-billed credit notes (261) are exempt too. The rule text only + // names 381 and 81, but the Schematron test also exempts 261, and we + // follow the test. rules.When( - is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", - documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), - rules.Field("supplier", - rules.Assert("08", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", - org.PartyHasTaxIDCode(), + is.Not(is.Or( + is.Func("document type is 381, 81 or 261", + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote)), + is.Func("deemed supply", invoiceIsDeemedSupply), + )), + rules.When( + is.Func("amount due is positive", invoiceIsDue), + rules.Assert("27", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + is.Func("has due date", invoiceHasDueDate), ), ), ), + + // AE document types: all but outside scope (480, 81) rules.When( - is.Func("has reverse charge lines", invoiceHasReverseChargeLine), - rules.Field("customer", - rules.Assert("09", "customer tax registration is required with reverse charge (IBR-103-AE)", - is.Func("has tax registration", partyHasTaxRegistration), + is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), + rules.Field("supplier", + rules.Assert("28", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + org.PartyHasTaxIDCode(), ), ), ), + + // AE document types: outside scope (480, 81) rules.When( is.Func("document type is invoice outside scope or credit note related to goods and services", - documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - rules.Assert("10", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("29", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), ), rules.Field("lines", rules.Each( rules.Field("taxes", rules.Each( - rules.Assert("11", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + rules.When( + is.Func("VAT", comboIsVAT), + rules.Field("ext", + rules.Assert("30", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), + ), + ), ), )), )), rules.Field("discounts", rules.Each( rules.Field("taxes", rules.Each( - rules.Assert("12", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + rules.When( + is.Func("VAT", comboIsVAT), + rules.Field("ext", + rules.Assert("31", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), + ), + ), ), )), )), rules.Field("charges", rules.Each( rules.Field("taxes", rules.Each( - rules.Assert("13", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - is.Func("is E, O or Z", comboCategoryIn(taxCategoryCodesOutsideScope...)), + rules.When( + is.Func("VAT", comboIsVAT), + rules.Field("ext", + rules.Assert("32", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), + ), + ), ), )), )), + rules.Assert("33", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), + ), ), + + // AE document types: commercial invoice and credit note (380, 381) rules.When( is.Func("document type is 380 or 381", - documentTypeIn(docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("14", "at least one line combo must be something other than E or O (IBR-151-AE)", + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), + rules.Assert("34", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), + + // AE document types: credit notes (381, 81) + // + // IBR-158-AE only names 381, but IBR-055-AE's test fails 81 credit + // notes without a reason too, whether or not they have a preceding + // invoice, so both need one. rules.When( is.Func("document type is credit note or credit note related to goods and services", - documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices)), + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("15", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("35", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), - ), - rules.Assert("16", "VAT point date must be before the invoice issue date (IBR-141-AE)", - is.Func("VAT point date before issue date", pointDateBeforeIssueDate), - ), - // Self-billed credit notes (261) are exempt too. The rule text only - // names 381 and 81, but the Schematron test also exempts 261, and we - // follow the test. - rules.When( - is.Not(is.Or( - is.Func("document type is 381, 81 or 261", - documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote)), - is.Func("deemed supply", invoiceIsDeemedSupply), - )), - rules.When( - is.Func("amount due is positive", invoiceIsDue), - rules.Assert("17", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", - is.Func("has due date", invoiceHasDueDate), - ), - ), - ), - // IBR-128-AE's text names the seller, buyer, tax representative and - // delivery subdivisions (IBT-039, IBT-054, IBT-068, IBT-079), but its - // test never runs on the seller's and buyer's addresses: its context, - // cac:PostalAddress, comes after their address rules (IBR-143-AE, - // IBR-144-AE) in the same pattern, where a node only fires the first - // rule it matches. Rules 19 and 21 follow the text there, as the - // official examples do, so they check more than the test. Rules 22 - // and 23, and line rule 11, follow the test: gobl.ubl also writes the - // issuer and the line sellers with a cac:PostalAddress. - rules.Field("supplier", - rules.Assert("18", "supplier address must have a street, city and region (IBR-143-AE)", - is.Func("first address has street, city and region", partyAddressIsComplete), - ), - rules.Assert("19", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), - ), - ), - rules.Field("customer", - rules.Assert("20", "customer address must have a street, city and region (IBR-144-AE)", - is.Func("first address has street, city and region", partyAddressIsComplete), - ), - rules.Assert("21", "customer region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), - ), - ), - rules.Field("ordering", - rules.Field("seller", - rules.Assert("22", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), - ), - ), - rules.Field("issuer", - rules.Assert("23", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), + rules.Field("tax", + rules.Field("ext", + rules.Assert("36", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + tax.ExtensionsRequire(ExtKeyCreditNoteReason), + ), ), ), - ), - rules.Field("supplier", rules.When( - is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), - rules.Assert("24", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", - is.Func("has legal identity", partyHasLegalIdentity), - ), - rules.Assert("25", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", - is.Func("legal identity has a PINT AE type", partyLegalIdentityHasTypeAE), + // A credit note without a reason is reported by the rule above. + is.Not(is.Func("credit note reason is missing or volume discount", + invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), + rules.Field("preceding", + rules.Assert("37", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + is.Present, + ), ), ), - rules.Assert("26", "supplier passport must have the issuing country (IBR-012-AE)", - is.Func("passport has country", partyPassportHasCountry), - ), - rules.Assert("27", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", - is.Func("trade license has authority", partyTradeLicenseHasAuthority), - ), - // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity - // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two - // PartyTaxSchemes with one VAT that it accepts. - rules.Field("identities", rules.Each( - rules.When( - is.Func("tax scope", identityHasTaxScope), - rules.Field("code", - rules.Assert("28", "supplier tax scope identity must be a TIN of 10 digits starting with 1 (IBR-148-AE)", - is.MatchesRegexp(tinRegexp), - ), + rules.When( + is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), + rules.Field("preceding", + rules.Assert("38", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + is.Not(is.Present), ), ), - )), + ), ), - rules.Field("customer", - // IBR-183-AE's test also accepts CL, which only its rule text's - // "Commercial/Trade license" explains. FormatAE reads CL as a - // trade licence on import, but GOBL writes TL, which is valid for - // both seller and buyer. - rules.When( - is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), - rules.Assert("29", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", - is.Func("legal identity has a PINT AE type", partyLegalIdentityHasTypeAE), + + // AE transaction type + rules.Field("tax", + rules.Field("ext", + rules.Assert("39", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + tax.ExtensionsRequire(ExtKeyTransactionType), + tax.ExtensionHasValidCode(ExtKeyTransactionType), ), ), - rules.Assert("30", "customer passport must have the issuing country (IBR-010-AE)", - is.Func("passport has country", partyPassportHasCountry), - ), - rules.Assert("31", "customer trade license must have the issuing authority in the description (IBR-101-AE)", - is.Func("trade license has authority", partyTradeLicenseHasAuthority), - ), - // IBR-149-AE's text asks for the buyer legal registration identifier - // (IBT-047), but its test checks the tax registration, - // cac:PartyTaxScheme/cbc:CompanyID. We follow the test. - rules.When( - is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), - rules.Assert("32", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", - is.Func("has tax registration", partyHasTaxRegistration), + ), + rules.When( + is.Func("free trade zone", invoiceIsFreeTradeZone), + rules.Field("tax", + rules.Field("ext", + rules.Assert("40", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + tax.ExtensionsRequire(ExtKeyBeneficiaryID), + ), ), ), - rules.Assert("33", "customer must have at most one tax registration (IBR-179-AE)", - is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), - ), - ), - rules.Assert("34", "customer tax scope identities require a supplier TIN (IBR-133-AE)", - is.Func("customer tax scope identities with supplier TIN", customerTaxIdentitiesHaveSupplierTIN), - ), - rules.Assert("35", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", - is.Func("has a valid transaction type", invoiceHasTransactionType), ), + // With the discount and charge rules 02, a margin scheme invoice can + // have no discounts or charges, as GOBL requires them to have taxes + // (BR-32, BR-37). rules.When( - is.Func("free trade zone", invoiceIsFreeTradeZone), - rules.Assert("36", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", - is.Func("has beneficiary ID", invoiceHasExt(ExtKeyBeneficiaryID)), + is.Func("margin scheme", invoiceIsMarginScheme), + rules.Assert("41", "margin scheme invoice must only use the margin scheme VAT key (IBR-116-AE)", + is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( is.Func("summary invoice", invoiceIsSummary), - rules.Assert("37", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + rules.Assert("42", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), rules.When( is.Func("disclosed agent billing", invoiceIsDisclosedAgent), - rules.Assert("38", "principal ID is required on disclosed agent billing (IBR-137-AE)", - is.Func("has principal ID", invoiceHasExt(ExtKeyPrincipalID)), + rules.Field("tax", + rules.Field("ext", + rules.Assert("43", "principal ID is required on disclosed agent billing (IBR-137-AE)", + tax.ExtensionsRequire(ExtKeyPrincipalID), + ), + ), ), - rules.Assert("39", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", + rules.Assert("44", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", is.Func("principal ID is not the supplier tax ID", principalIsNotSupplier), ), rules.Field("supplier", - rules.Assert("40", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", + rules.Assert("45", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), ), rules.When( is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("41", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + rules.Assert("46", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), @@ -299,60 +393,39 @@ func billInvoiceRules() *rules.Set { // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), - rules.Assert("42", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + rules.Assert("47", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), ), ), - rules.When( - is.Func("document type is invoice outside scope or credit note related to goods and services", - documentTypeIn(docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), - rules.Assert("43", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", - is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), - ), - ), rules.When( is.Not(is.Func("export", invoiceIsExport)), rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("44", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("48", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), ), ), ), ), - // IBR-158-AE only names 381, but IBR-055-AE's test fails 81 credit - // notes without a reason too, whether or not they have a preceding - // invoice, so both need one. + + // AE reverse charge rules.When( - is.Func("document type is credit note or credit note related to goods and services", - documentTypeIn(docTypeCreditNote, docTypeCreditNoteGoodsServices)), - rules.Assert("45", "credit note reason is required (IBR-158-AE, IBR-055-AE)", - is.Func("has credit note reason", invoiceHasExt(ExtKeyCreditNoteReason)), - ), - rules.When( - is.Func("credit note reason is not volume discount", creditNoteReasonIsNotVolumeDiscount), - rules.Field("preceding", - rules.Assert("46", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", - is.Present, - ), - ), - ), - rules.When( - is.Func("credit note reason is volume discount", creditNoteReasonIs(CreditNoteReasonVolumeDiscount)), - rules.Field("preceding", - rules.Assert("47", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", - is.Not(is.Present), - ), + is.Func("has reverse charge lines", invoiceHasReverseChargeLine), + rules.Field("customer", + rules.Assert("49", "customer tax registration is required with reverse charge (IBR-103-AE)", + is.Func("has tax registration", partyHasTaxRegistration), ), ), ), + + // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("48", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("50", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("49", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("51", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), ), @@ -360,187 +433,105 @@ func billInvoiceRules() *rules.Set { // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, // and IBR-005-AE only accepts frequencies there. rules.Field("point", - rules.Assert("50", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("52", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", is.Not(is.Present), ), ), ), rules.When( - is.Func("billing frequency is Others", billingFrequencyIs(BillingFrequencyOthers)), + is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), rules.Field("notes", - rules.Assert("51", "a note is required with the billing frequency Others (IBR-160-AE)", + rules.Assert("53", "a note is required with the billing frequency Others (IBR-160-AE)", is.Present, ), ), ), - // IBR-168-AE and IBR-169-AE name the exemption reason code (IBT-196, - // IBT-198), but their tests check the allowance or charge reason code, - // cbc:AllowanceChargeReasonCode. We follow the tests. - rules.Field("discounts", rules.Each( - rules.When( - is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), - rules.Field("ext", - rules.Assert("52", "exempt discount needs an allowance reason code (IBR-168-AE)", - tax.ExtensionsRequire(untdid.ExtKeyAllowance), - ), - ), - ), - )), - rules.Field("charges", rules.Each( - rules.When( - is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), - rules.Field("ext", - rules.Assert("53", "exempt charge needs a charge reason code (IBR-169-AE)", - tax.ExtensionsRequire(untdid.ExtKeyCharge), - ), - ), - ), - )), - rules.Field("discounts", rules.Each( - rules.Assert("54", "discount VAT category cannot be margin scheme (IBR-115-AE)", - is.Not(is.Func("has margin scheme VAT", taxesIn(comboIsMarginScheme))), - ), - )), - rules.Field("charges", rules.Each( - rules.Assert("55", "charge VAT category cannot be margin scheme (IBR-114-AE)", - is.Not(is.Func("has margin scheme VAT", taxesIn(comboIsMarginScheme))), - ), - )), - // With rules 54 and 55, a margin scheme invoice can have no discounts - // or charges, as GOBL requires them to have taxes (BR-32, BR-37). - rules.When( - is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("56", "margin scheme invoice must only use the margin scheme VAT key (IBR-116-AE)", - is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), - ), - ), ), + + // Tags + // // The tags the addon defines are for UAE documents, but GOBL can't limit // an addon's tags to a regime. Other documents can only use the ones // their regime, another addon or GOBL itself defines too, as before the // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("57", "PINT AE tags can only be used on UAE documents", + rules.Assert("54", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), ) } -// billLineRules enforces the PINT AE line rules on UAE documents. -func billLineRules() *rules.Set { - return rules.For(new(bill.Line), - // TODO: IBR-145-AE matches ALIGNED-IBRP-050/059-AUNZ (GST). Extend to - // A-NZ after discussing it with colleagues. +// billDiscountRules enforces the PINT AE document level discount rules on UAE +// documents. +func billDiscountRules() *rules.Set { + return rules.For(new(bill.Discount), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - rules.Field("taxes", - rules.Assert("01", "line must have a VAT tax combo (IBR-145-AE)", - is.Func("has VAT combo", taxesHaveVAT), - ), - ), - rules.Field("item", - rules.Field("description", - rules.Assert("02", "item description is required (IBR-125-AE)", is.Present), + // IBR-168-AE names the exemption reason code, but its test checks the + // allowance reason code, cbc:AllowanceChargeReasonCode. We follow the + // test. + rules.When( + is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), + rules.Field("ext", + rules.Assert("01", "exempt discount needs an allowance reason code (IBR-168-AE)", + tax.ExtensionsRequire(untdid.ExtKeyAllowance), + ), ), ), rules.Field("taxes", rules.Each( rules.When( - is.Func("exempt VAT", comboIsExemptVAT), + is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("03", "exempt line needs a UAE VAT exemption reason (IBR-167-AE)", - tax.ExtensionsRequire(ExtKeyExemption), + rules.Assert("02", "discount VAT category cannot be margin scheme (IBR-115-AE)", + tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), ), ), ), )), + ), + ) +} + +// billChargeRules enforces the PINT AE document level charge rules on UAE +// documents. +func billChargeRules() *rules.Set { + return rules.For(new(bill.Charge), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + // IBR-169-AE names the exemption reason code, but its test checks the + // charge reason code, cbc:AllowanceChargeReasonCode. We follow the + // test. rules.When( - is.Func("reverse charge VAT", lineHasReverseChargeVAT), - rules.Field("item", - rules.Field("ext", - rules.Assert("04", "reverse charge line item needs the type of goods or services (IBR-166-AE)", - tax.ExtensionsRequire(ExtKeyGoodsType), - ), - ), - ), - ), - // The IBR-006-AE test checks every goods type, not only those of - // reverse charge lines as its text says. - rules.Field("item", + is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), rules.Field("ext", - rules.Assert("05", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", - tax.ExtensionHasValidCode(ExtKeyGoodsType), - ), - ), - ), - rules.When( - is.Func("reverse charge VAT", lineHasReverseChargeVAT), - rules.Field("item", - rules.Field("identities", - rules.Assert("06", "reverse charge line item needs a GTIN identity, scheme 0160 (IBR-174-AE)", - is.Func("has GTIN", identitiesHaveGTIN), - ), + rules.Assert("01", "exempt charge needs a charge reason code (IBR-169-AE)", + tax.ExtensionsRequire(untdid.ExtKeyCharge), ), ), ), - rules.Field("item", - rules.When( - is.Func("goods", itemKeyIs(org.ItemKeyGoods)), - rules.Field("identities", - rules.Assert("07", "goods item needs an HS item classification (IBR-184-AE)", - is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), - ), - ), - ), - rules.When( - is.Func("services", itemKeyIs(org.ItemKeyServices)), - rules.Field("identities", - rules.Assert("08", "services item needs a service accounting code (IBR-185-AE)", - is.Func("has SAC", identitiesHaveLabel(IdentityLabelSAC)), - ), - ), - ), + rules.Field("taxes", rules.Each( rules.When( - is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), - rules.Field("identities", - rules.Assert("09", "goods and services item needs an HS item classification and a service accounting code (IBR-186-AE)", - is.Func("has HS and SAC", identitiesHaveLabel(IdentityLabelHS, IdentityLabelSAC)), + is.Func("VAT", comboIsVAT), + rules.Field("ext", + rules.Assert("02", "charge VAT category cannot be margin scheme (IBR-114-AE)", + tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), ), ), ), - // gobl.ubl writes identities with a label and no scheme ID as item - // classifications, with the label as their list. FormatAE writes the - // SAC ones as service accounting codes instead (IBR-189-AE). - // IBR-188-AE's text asks for HS on every classification, but its - // test passes when any one is HS. - rules.Field("identities", - rules.Assert("10", "item classifications must include one from the HS list (IBR-188-AE)", - is.Func("classifications include HS", identitiesClassifiedWithHS), - ), - ), - ), - rules.Field("seller", - rules.Assert("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), - ), - ), + )), ), ) } -// documentType returns the UNTDID 1001 document type code (ibt-003) that the -// scenarios set on the invoice, or an empty code if none is set. -func documentType(inv *bill.Invoice) cbc.Code { - return inv.Tax.GetExt(untdid.ExtKeyDocumentType) -} - -// documentTypeIn returns a predicate that reports whether the invoice's -// document type is one of the given codes. -func documentTypeIn(codes ...cbc.Code) func(any) bool { +// invoiceExtIn returns a predicate that reports whether the invoice's tax +// extension for the key is one of the codes. A missing extension is the empty +// code. +func invoiceExtIn(key cbc.Key, codes ...cbc.Code) func(any) bool { return func(val any) bool { inv, ok := val.(*bill.Invoice) - return ok && inv != nil && documentType(inv).In(codes...) + return ok && inv != nil && inv.Tax.GetExt(key).In(codes...) } } @@ -570,29 +561,10 @@ func invoiceHasNoAETags(val any) bool { return true } -// partyHasIdentifier reports whether the party can be identified through a tax -// identity code or at least one organisation identity. -func partyHasIdentifier(val any) bool { - p, ok := val.(*org.Party) - return ok && p != nil && ((p.TaxID != nil && p.TaxID.Code != "") || len(p.Identities) > 0) -} - -// exchangeRateHasAED reports whether an invoice not in AED has an exchange -// rate from its currency to AED, the rate written as cbc:CalculationRate in the -// tax exchange rate (IBR-159-AE). AED invoices need no rate. -func exchangeRateHasAED(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return true - } - return inv.Currency == currency.AED || - currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) != nil -} - // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 05 reports them. +// without it pass: they are in AED, or rule 22 reports them. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -602,88 +574,21 @@ func exchangeRateToAEDHasAtMost6Decimals(val any) bool { return rate == nil || rate.Amount.Exp() <= 6 } -// invoiceIsCreditNote reports whether the invoice is a credit note. The EN -// 16931 scenarios map this type to the document type codes 381, and 261 when -// self-billed, the codes IBR-191-AE exempts. -func invoiceIsCreditNote(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Type == bill.InvoiceTypeCreditNote -} - -// invoiceHasPaymentInstructions reports whether the invoice has payment -// instructions. It is checked on the invoice rather than with nested fields, -// because the rules engine skips the fields of a nil payment. -func invoiceHasPaymentInstructions(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Payment != nil && inv.Payment.Instructions != nil -} - // invoiceHasReverseChargeLine reports whether any line of the invoice has a -// VAT combo with the reverse charge key, category AE (IBR-103-AE). +// VAT combo with the reverse charge category AE, the code IBR-103-AE tests. func invoiceHasReverseChargeLine(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { return false } for _, l := range inv.Lines { - if l == nil { - continue - } - if c := l.Taxes.Get(tax.CategoryVAT); c != nil && c.Key == tax.KeyReverseCharge { + if lineHasReverseChargeVAT(l) { return true } } return false } -// partyHasTaxRegistration reports whether the party has a tax registration: -// a tax ID code or an identity with the tax scope. IBR-103-AE accepts any -// buyer PartyTaxScheme/CompanyID, and gobl.ubl writes either one there. -func partyHasTaxRegistration(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - if p.TaxID != nil && p.TaxID.Code != "" { - return true - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeTax { - return true - } - } - return false -} - -// partyHasLegalIdentity reports whether the party has an identity with the -// legal scope. gobl.ubl writes the first one as -// PartyLegalEntity/CompanyID, the buyer legal registration identifier -// IBR-136-AE requires on 480 and 81. -func partyHasLegalIdentity(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeLegal { - return true - } - } - return false -} - -// comboCategoryIn returns a predicate that reports whether a VAT combo's -// UNTDID 5305 category code is one of the given codes. Combos of other taxes -// pass, and any value that is not a combo fails, so a misplaced rule cannot -// pass silently. -func comboCategoryIn(codes ...cbc.Code) func(any) bool { - return func(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && - (c.Category != tax.CategoryVAT || c.Ext.Get(untdid.ExtKeyTaxCategory).In(codes...)) - } -} - // invoiceHasLineComboOtherThanEorO reports whether at least one line has a VAT // combo whose category is neither exempt (E) nor not subject to VAT (O) // (IBR-151-AE). Combos of other taxes are ignored, as they carry no VAT @@ -753,168 +658,6 @@ func invoiceHasDueDate(val any) bool { return false } -// partyFirstAddress returns the party's first address, the only one gobl.ubl -// writes as cac:PostalAddress, or nil if there is none. -func partyFirstAddress(val any) *org.Address { - p, ok := val.(*org.Party) - if !ok || p == nil || len(p.Addresses) == 0 { - return nil - } - return p.Addresses[0] -} - -// partyAddressIsComplete reports whether the party's first address has a -// street, city and region, written as cbc:StreetName, cbc:CityName and -// cbc:CountrySubentity (IBR-143-AE, IBR-144-AE). A party without an address -// passes: EN 16931 already requires supplier and customer addresses (BR-8, -// BR-10). -func partyAddressIsComplete(val any) bool { - a := partyFirstAddress(val) - return a == nil || (a.Street != "" && a.Locality != "" && a.Region != "") -} - -// partyAddressHasEmirate reports whether the party's first address, when in -// the UAE, has an emirate code as its region (IBR-128-AE). Addresses in other -// countries pass, and so does a party without addresses: it is for the -// supplier and customer, whose addresses EN 16931 requires (BR-8, BR-10). -func partyAddressHasEmirate(val any) bool { - return partyFirstAddress(val) == nil || partyPostalAddressHasEmirate(val) -} - -// partyPostalAddressHasEmirate reports whether the cac:PostalAddress gobl.ubl -// writes for the party, when in the UAE, has an emirate code as its region -// (IBR-128-AE). gobl.ubl writes the country of the tax ID over the address's -// own, and writes an address with only that country for a party without -// addresses, which fails the rule. -func partyPostalAddressHasEmirate(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return true - } - a := partyFirstAddress(p) - inAE := a != nil && a.Country == l10n.AE.ISO() - if p.TaxID != nil && p.TaxID.Code != "" { - inAE = p.TaxID.Country.Code() == l10n.AE - } - return !inAE || (a != nil && cbc.Code(a.Region).In(emirateCodes...)) -} - -// partyEndpointID returns the scheme and code of the party's electronic -// address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 -// endpoint, or else the first inbox with a scheme. -func partyEndpointID(p *org.Party) (cbc.Code, string) { - if e := p.Endpoint(iso.ActorIDScheme); e != nil { - // An ISO 6523 URI reads "iso6523-actorid-upis:::". - scheme, code, ok := strings.Cut(strings.TrimPrefix(e.URI.Opaque(), ":"), ":") - if ok && scheme != "" && code != "" { - return cbc.Code(scheme), code - } - } - for _, ib := range p.Inboxes { - if ib != nil && ib.Email == "" && ib.Scheme != "" { - return ib.Scheme, ib.Code.String() - } - } - return "", "" -} - -// partyHasUAEEndpoint reports whether the party's electronic address uses the -// UAE Peppol scheme 0235, the condition of the legal registration rules. -func partyHasUAEEndpoint(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - scheme, _ := partyEndpointID(p) - return scheme == endpointSchemeUAE -} - -// partyHasUAEEndpointNotStartingWith1or9 reports whether the party's -// electronic address uses the UAE Peppol scheme 0235 with a code that doesn't -// start with 1 or 9 (IBR-149-AE). -func partyHasUAEEndpointNotStartingWith1or9(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - scheme, code := partyEndpointID(p) - return scheme == endpointSchemeUAE && !strings.HasPrefix(code, "1") && !strings.HasPrefix(code, "9") -} - -// partyFirstLegalIdentity returns the party's first identity with the legal -// scope, the one gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID, or nil -// if there is none. -func partyFirstLegalIdentity(val any) *org.Identity { - p, ok := val.(*org.Party) - if !ok || p == nil { - return nil - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeLegal { - return id - } - } - return nil -} - -// partyLegalIdentityHasTypeAE reports whether the party's legal identity has -// a PINT AE legal registration identifier type: trade licence, Emirates ID, -// passport or Cabinet Decision. A party without a legal identity passes. -func partyLegalIdentityHasTypeAE(val any) bool { - id := partyFirstLegalIdentity(val) - return id == nil || IdentityTypeAE(id.Key) != "" -} - -// partyPassportHasCountry reports whether the party's legal identity, when a -// passport, has the issuing country, written as @schemeAgencyName (BTAE-18, -// BTAE-19). GOBL already checks the country is an ISO 3166-1 code -// (IBR-011-AE, IBR-013-AE). -func partyPassportHasCountry(val any) bool { - id := partyFirstLegalIdentity(val) - return id == nil || id.Key != org.IdentityKeyPassport || id.Country != "" -} - -// partyTradeLicenseHasAuthority reports whether the party's legal identity, -// when a trade licence, has the issuing authority in its description, written -// as @schemeAgencyName (BTAE-11, BTAE-12). -func partyTradeLicenseHasAuthority(val any) bool { - id := partyFirstLegalIdentity(val) - return id == nil || id.Key != ae.IdentityKeyTradeLicense || id.Description != "" -} - -// partyTaxIdentityCount returns how many of the party's identities have the -// tax scope. gobl.ubl writes each one as a cac:PartyTaxScheme. -func partyTaxIdentityCount(p *org.Party) int { - n := 0 - for _, id := range p.Identities { - if identityHasTaxScope(id) { - n++ - } - } - return n -} - -// identityHasTaxScope reports whether an identity has the tax scope. -func identityHasTaxScope(val any) bool { - id, ok := val.(*org.Identity) - return ok && id != nil && id.Scope == org.IdentityScopeTax -} - -// partyHasAtMostOneTaxRegistration reports whether the party has at most one -// tax registration, counting the tax ID code and the tax scope identities, as -// the buyer can only have one PartyTaxScheme/CompanyID (IBR-179-AE). -func partyHasAtMostOneTaxRegistration(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - n := partyTaxIdentityCount(p) - if p.TaxID != nil && p.TaxID.Code != "" { - n++ - } - return n <= 1 -} - // customerTaxIdentitiesHaveSupplierTIN reports whether the supplier has a tax // scope identity, the TIN (IBT-032), whenever the customer has one. gobl.ubl // writes a customer tax scope identity under a tax scheme other than VAT, @@ -930,23 +673,6 @@ func customerTaxIdentitiesHaveSupplierTIN(val any) bool { return inv.Supplier != nil && partyTaxIdentityCount(inv.Supplier) > 0 } -// invoiceHasTransactionType reports whether the invoice has a transaction -// type of 8 flags of 0 or 1, written as cbc:ProfileExecutionID (IBR-154-AE). -// GOBL doesn't check an extension's pattern on its own. -func invoiceHasTransactionType(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && transactionTypeRegexp.MatchString(inv.Tax.GetExt(ExtKeyTransactionType).String()) -} - -// invoiceHasExt returns a predicate that reports whether the invoice's tax -// extensions have a value for the key. -func invoiceHasExt(key cbc.Key) func(any) bool { - return func(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Tax.GetExt(key) != "" - } -} - // invoiceHasInvoicePeriod reports whether the invoice has what is written as // cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's // text asks for the invoicing period, but its test only checks the element @@ -963,7 +689,7 @@ func invoiceHasInvoicePeriod(val any) bool { // principalIsNotSupplier reports whether the principal ID differs from the // supplier's tax registrations, the cbc:CompanyID values of its // PartyTaxSchemes (IBR-176-AE). A missing principal ID or supplier tax -// registration passes, as rules 38 and 40 report those. +// registration passes, as rules 43 and 45 report those. func principalIsNotSupplier(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -1025,78 +751,6 @@ func invoiceDeliveryAddressIsAEOrComplete(val any) bool { return a != nil && (a.Country == l10n.AE.ISO() || (a.Street != "" && a.Locality != "" && a.Region != "")) } -// partyHasUAEEndpointNotTIN reports whether the party's electronic address -// uses the UAE Peppol scheme 0235 with a code that is not a TIN, 1XXXXXXXXX -// (IBR-135-AE). -func partyHasUAEEndpointNotTIN(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - scheme, code := partyEndpointID(p) - return scheme == endpointSchemeUAE && !tinRegexp.MatchString(code) -} - -// partyHasIdentificationOrTaxRegistration reports whether the party has an -// identity gobl.ubl writes as cac:PartyIdentification (any identity that is -// neither a tax registration nor the first legal one) or a tax registration -// (IBR-135-AE). -func partyHasIdentificationOrTaxRegistration(val any) bool { - if partyHasTaxRegistration(val) { - return true - } - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - legal := partyFirstLegalIdentity(p) - for _, id := range p.Identities { - if id != nil && id != legal && id.Scope != org.IdentityScopeTax { - return true - } - } - return false -} - -// creditNoteReasonIsNotVolumeDiscount reports whether the invoice has a -// credit note reason other than volume discount, the reasons that need a -// preceding invoice (IBR-055-AE). Invoices without a reason fail, as rule 45 -// reports them. -func creditNoteReasonIsNotVolumeDiscount(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return false - } - reason := inv.Tax.GetExt(ExtKeyCreditNoteReason) - return reason != "" && reason != CreditNoteReasonVolumeDiscount -} - -// creditNoteReasonIs returns a predicate that reports whether the invoice's -// credit note reason is the given code. -func creditNoteReasonIs(code cbc.Code) func(any) bool { - return func(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Tax.GetExt(ExtKeyCreditNoteReason) == code - } -} - -// billingFrequencyIs returns a predicate that reports whether the invoice's -// billing frequency is the given code. -func billingFrequencyIs(code cbc.Code) func(any) bool { - return func(val any) bool { - inv, ok := val.(*bill.Invoice) - return ok && inv != nil && inv.Tax.GetExt(ExtKeyBillingFrequency) == code - } -} - -// comboIsExemptVAT reports whether a tax combo is VAT with the exempt -// category code E. -func comboIsExemptVAT(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && c.Category == tax.CategoryVAT && - c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryExempt -} - // taxesIn returns a predicate that reports whether a discount or charge has // a tax combo that check accepts. func taxesIn(check func(any) bool) func(any) bool { @@ -1121,100 +775,6 @@ func taxesIn(check func(any) bool) func(any) bool { } } -// taxesHaveVAT reports whether a line's taxes include a VAT combo (IBR-145-AE). -// It fails on any other value, so a type mismatch can't pass silently. -func taxesHaveVAT(val any) bool { - set, ok := val.(tax.Set) - return ok && set.Get(tax.CategoryVAT) != nil -} - -// lineHasReverseChargeVAT reports whether a line's VAT combo is reverse -// charge. -func lineHasReverseChargeVAT(val any) bool { - l, ok := val.(*bill.Line) - if !ok || l == nil { - return false - } - c := l.Taxes.Get(tax.CategoryVAT) - return c != nil && c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryReverseCharge -} - -// identitiesHaveGTIN reports whether an item has an identity with the GTIN -// scheme, 0160, the one gobl.ubl writes as the standard item identifier. -func identitiesHaveGTIN(val any) bool { - ids, ok := val.([]*org.Identity) - if !ok { - return false - } - return GTINIdentity(ids) != nil -} - -// itemKeyIs returns a predicate that reports whether an item has the key. -func itemKeyIs(key cbc.Key) func(any) bool { - return func(val any) bool { - it, ok := val.(*org.Item) - return ok && it != nil && it.Key == key - } -} - -// identitiesHaveLabel returns a predicate that reports whether an item has -// identities with all the labels. -func identitiesHaveLabel(labels ...string) func(any) bool { - return func(val any) bool { - ids, ok := val.([]*org.Identity) - if !ok { - return false - } - for _, label := range labels { - if !identitiesHaveLabelOf(ids, label) { - return false - } - } - return true - } -} - -// identitiesHaveLabelOf reports whether one of the identities gobl.ubl writes -// as item classifications, those with a label and no scheme ID, has the label. -func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { - for _, id := range ids { - if id != nil && id.Label == label && !id.Ext.Has(iso.ExtKeySchemeID) { - return true - } - } - return false -} - -// identitiesClassifiedWithHS reports whether the identities gobl.ubl writes -// as item classifications, those with a label and no scheme ID, include an HS -// one. Items without classifications pass, and the service accounting codes -// don't count as one. -func identitiesClassifiedWithHS(val any) bool { - ids, ok := val.([]*org.Identity) - if !ok { - return false - } - classified := false - for _, id := range ids { - if id == nil || id.Label == "" || id.Label == IdentityLabelSAC || id.Ext.Has(iso.ExtKeySchemeID) { - continue - } - if id.Label == IdentityLabelHS { - return true - } - classified = true - } - return !classified -} - -// comboIsMarginScheme reports whether a tax combo is VAT under the profit -// margin scheme. -func comboIsMarginScheme(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && c.Category == tax.CategoryVAT && - c.Ext.Get(untdid.ExtKeyTaxCategory) == TaxCategoryMarginScheme -} - // invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's // lines, discounts and charges is VAT under the profit margin scheme. func invoiceTaxesAreMarginScheme(val any) bool { diff --git a/addon/pint/bill_line.go b/addon/pint/bill_line.go new file mode 100644 index 0000000..40311e8 --- /dev/null +++ b/addon/pint/bill_line.go @@ -0,0 +1,126 @@ +package pint + +import ( + "github.com/invopop/gobl/addons/eu/en16931" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" + "github.com/invopop/gobl/catalogues/untdid" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" +) + +// billLineRules enforces the PINT AE line rules on UAE documents. +func billLineRules() *rules.Set { + return rules.For(new(bill.Line), + // TODO: IBR-145-AE matches ALIGNED-IBRP-050/059-AUNZ (GST). Extend to + // A-NZ after discussing it with colleagues. + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.Field("taxes", + rules.Assert("01", "line must have a VAT tax combo (IBR-145-AE)", + tax.SetHasCategory(tax.CategoryVAT), + ), + ), + rules.Field("item", + rules.Field("description", + rules.Assert("02", "item description is required (IBR-125-AE)", is.Present), + ), + ), + rules.Field("taxes", rules.Each( + rules.When( + is.Func("exempt VAT", comboIsExemptVAT), + rules.Field("ext", + rules.Assert("03", "exempt line needs a UAE VAT exemption reason (IBR-167-AE)", + tax.ExtensionsRequire(ExtKeyExemption), + ), + ), + ), + )), + rules.When( + is.Func("reverse charge VAT", lineHasReverseChargeVAT), + rules.Field("item", + rules.Field("ext", + rules.Assert("04", "reverse charge line item needs the type of goods or services (IBR-166-AE)", + tax.ExtensionsRequire(ExtKeyGoodsType), + ), + ), + ), + ), + // The IBR-006-AE test checks every goods type, not only those of + // reverse charge lines as its text says. + rules.Field("item", + rules.Field("ext", + rules.Assert("05", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", + tax.ExtensionHasValidCode(ExtKeyGoodsType), + ), + ), + ), + rules.When( + is.Func("reverse charge VAT", lineHasReverseChargeVAT), + rules.Field("item", + rules.Field("identities", + rules.Assert("06", "reverse charge line item needs a GTIN identity, scheme 0160 (IBR-174-AE)", + org.IdentitiesExtensionIn(iso.ExtKeySchemeID, IdentitySchemeGTIN), + ), + ), + ), + ), + rules.Field("item", + rules.When( + is.Func("goods", itemKeyIs(org.ItemKeyGoods)), + rules.Field("identities", + rules.Assert("07", "goods item needs an HS item classification (IBR-184-AE)", + is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), + ), + ), + ), + rules.When( + is.Func("services", itemKeyIs(org.ItemKeyServices)), + rules.Field("identities", + rules.Assert("08", "services item needs a service accounting code (IBR-185-AE)", + is.Func("has SAC", identitiesHaveLabel(IdentityLabelSAC)), + ), + ), + ), + rules.When( + is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), + rules.Field("identities", + rules.Assert("09", "goods and services item needs an HS item classification and a service accounting code (IBR-186-AE)", + is.Func("has HS and SAC", identitiesHaveLabel(IdentityLabelHS, IdentityLabelSAC)), + ), + ), + ), + // gobl.ubl writes identities with a label and no scheme ID as item + // classifications, with the label as their list. FormatAE writes the + // SAC ones as service accounting codes instead (IBR-189-AE). + // IBR-188-AE's text asks for HS on every classification, but its + // test passes when any one is HS. + rules.Field("identities", + rules.Assert("10", "item classifications must include one from the HS list (IBR-188-AE)", + is.Func("classifications include HS", identitiesClassifiedWithHS), + ), + ), + ), + rules.Field("seller", + rules.Assert("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), + ), + ), + ), + ) +} + +// lineHasReverseChargeVAT reports whether a line's VAT combo has the reverse +// charge category AE, the code gobl.ubl writes as the line's +// cac:ClassifiedTaxCategory/cbc:ID and IBR-103-AE, IBR-166-AE and IBR-174-AE +// test. +func lineHasReverseChargeVAT(val any) bool { + l, ok := val.(*bill.Line) + if !ok || l == nil { + return false + } + c := l.Taxes.Get(tax.CategoryVAT) + return c != nil && c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryReverseCharge +} diff --git a/addon/pint/bill_line_test.go b/addon/pint/bill_line_test.go new file mode 100644 index 0000000..e03c7a1 --- /dev/null +++ b/addon/pint/bill_line_test.go @@ -0,0 +1,154 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestBillLineRulesAE(t *testing.T) { + const ( + faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" + faultLineDescription = "GOBL-PEPPOL-PINT-BILL-LINE-02" + ) + + t.Run("line without a VAT combo is rejected (IBR-145-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = nil + out := aeFaults(t, inv) + assert.Contains(t, out, faultLineVAT) + assert.Contains(t, out, "$.lines[0].taxes") + }) + + t.Run("item description is required (IBR-125-AE)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Description = "" + out := aeFaults(t, inv) + assert.Contains(t, out, faultLineDescription) + assert.Contains(t, out, "$.lines[0].item.description") + }) + + t.Run("line rules do not apply outside AE", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + if err != nil { + assert.NotContains(t, err.Error(), faultLineDescription) + } + }) +} + +func TestBillGoodsTypeRulesAE(t *testing.T) { + const ( + faultGoodsType = "GOBL-PEPPOL-PINT-BILL-LINE-04" + faultGoodsTypeValue = "GOBL-PEPPOL-PINT-BILL-LINE-05" + faultGTIN = "GOBL-PEPPOL-PINT-BILL-LINE-06" + ) + gtin := func(scheme cbc.Code) []*org.Identity { + return []*org.Identity{{Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})}} + } + reverseCharge := func(goodsType cbc.Code, ids []*org.Identity) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} + inv.Lines[0].Item.Identities = ids + if goodsType != "" { + inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: goodsType}) + } + return inv + } + + t.Run("reverse charge item needs the goods type (IBR-166-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("", gtin("0160"))), faultGoodsType) + out := aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0160"))) + assert.NotContains(t, out, faultGoodsType) + assert.NotContains(t, out, faultGoodsTypeValue) + assert.NotContains(t, out, faultGTIN) + }) + + t.Run("goods type must be from the AE list on any line (IBR-006-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.9", gtin("0160"))), faultGoodsTypeValue) + + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: "OTHER"}) + assert.Contains(t, aeFaults(t, inv), faultGoodsTypeValue) + }) + + t.Run("reverse charge item needs a GTIN (IBR-174-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", nil)), faultGTIN) + assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0088"))), faultGTIN) + }) + + t.Run("other lines need neither", func(t *testing.T) { + out := aeFaults(t, aeDocument(bill.InvoiceTypeStandard)) + assert.NotContains(t, out, faultGoodsType) + assert.NotContains(t, out, faultGTIN) + }) +} + +func TestBillItemTypeRulesAE(t *testing.T) { + const ( + faultGoodsHS = "GOBL-PEPPOL-PINT-BILL-LINE-07" + faultServicesSAC = "GOBL-PEPPOL-PINT-BILL-LINE-08" + faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-09" + faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-10" + ) + hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} + sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} + item := func(key cbc.Key, ids ...*org.Identity) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Key = key + inv.Lines[0].Item.Identities = ids + return inv + } + + t.Run("goods need an HS classification (IBR-184-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) + assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) + + // An identity with a scheme ID isn't written as a classification. + withScheme := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) + }) + + t.Run("services need a service accounting code (IBR-185-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(org.ItemKeyServices)), faultServicesSAC) + assert.Contains(t, aeFaults(t, item(org.ItemKeyServices, hs)), faultServicesSAC) + assert.NotContains(t, aeFaults(t, item(org.ItemKeyServices, sac)), faultServicesSAC) + }) + + t.Run("goods and services need both (IBR-186-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) + assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs, sac)), faultGoodsServices) + }) + + t.Run("no item type needs neither", func(t *testing.T) { + out := aeFaults(t, item("")) + assert.NotContains(t, out, faultGoodsHS) + assert.NotContains(t, out, faultServicesSAC) + assert.NotContains(t, out, faultGoodsServices) + }) + + t.Run("item classifications must include an HS one (IBR-188-AE)", func(t *testing.T) { + cpv := &org.Identity{Label: "CPV", Code: "30200000"} + assert.Contains(t, aeFaults(t, item("", cpv)), faultClassification) + assert.Contains(t, aeFaults(t, item("", cpv, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, cpv)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", sac)), faultClassification) + + // Identities with a scheme ID aren't classifications. + gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} + assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) + }) +} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 40cdac9..c814e59 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -6,7 +6,6 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cal" - "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -116,9 +115,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -136,6 +136,7 @@ func TestBillInvoiceRulesAE(t *testing.T) { assert.NotContains(t, out, faultRate) assert.NotContains(t, out, faultDecimals) assert.NotContains(t, out, faultPayment) + assert.NotContains(t, out, faultInstructions) }) t.Run("AED invoice needs no exchange rate (IBR-159-AE)", func(t *testing.T) { @@ -203,7 +204,9 @@ func TestBillInvoiceRulesAE(t *testing.T) { t.Run("invoice with payment but no instructions is rejected (IBR-191-AE)", func(t *testing.T) { inv := aeInvoice() inv.Payment = &bill.PaymentDetails{} - assert.Contains(t, validate(inv), faultPayment) + out := validate(inv) + assert.NotContains(t, out, faultPayment) + assert.Contains(t, out, faultInstructions) }) t.Run("credit note without payment is accepted (IBR-191-AE)", func(t *testing.T) { @@ -305,16 +308,16 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -509,12 +512,12 @@ func TestBillDocumentRulesAE(t *testing.T) { func TestBillAddressRulesAE(t *testing.T) { const ( - faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" - faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" - faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" - faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" - faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" + faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" + faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" + faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" + faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-11" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -653,17 +656,17 @@ func aeIdentityDocument() *bill.Invoice { func TestBillIdentityRulesAE(t *testing.T) { const ( - faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultCustomerTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" + faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" + faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" + faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" + faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultCustomerTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" ) t.Run("trade licences with authorities pass", func(t *testing.T) { @@ -723,12 +726,15 @@ func TestBillIdentityRulesAE(t *testing.T) { } }) - t.Run("only the first legal identity is checked (IBR-173-AE)", func(t *testing.T) { + t.Run("every legal identity is checked (IBR-173-AE)", func(t *testing.T) { + // EN 16931 already rejects a second legal identity. inv := aeIdentityDocument() inv.Supplier.Identities[0].Scope = org.IdentityScopeLegal inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) - assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalType) + out := aeFaults(t, inv) + assert.Contains(t, out, "GOBL-EU-EN16931-ORG-PARTY-02") + assert.Contains(t, out, faultSupplierLegalType) }) t.Run("passport needs the issuing country (IBR-012-AE, IBR-010-AE)", func(t *testing.T) { @@ -816,18 +822,18 @@ func TestBillIdentityRulesAE(t *testing.T) { func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -968,10 +974,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1032,9 +1038,9 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" ) withFrequency := func(code cbc.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1076,8 +1082,8 @@ func TestBillBillingFrequencyRulesAE(t *testing.T) { func TestBillExemptionRulesAE(t *testing.T) { const ( faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultDiscountReason = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" - faultChargeReason = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultDiscountReason = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" + faultChargeReason = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" ) exempt := func(code cbc.Code) *tax.Combo { c := lineCombo(tax.KeyExempt) @@ -1133,149 +1139,11 @@ func TestBillExemptionRulesAE(t *testing.T) { }) } -func TestBillLineRulesAE(t *testing.T) { - const ( - faultLineVAT = "GOBL-PEPPOL-PINT-BILL-LINE-01" - faultLineDescription = "GOBL-PEPPOL-PINT-BILL-LINE-02" - ) - - t.Run("line without a VAT combo is rejected (IBR-145-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Taxes = nil - out := aeFaults(t, inv) - assert.Contains(t, out, faultLineVAT) - assert.Contains(t, out, "$.lines[0].taxes") - }) - - t.Run("item description is required (IBR-125-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Item.Description = "" - out := aeFaults(t, inv) - assert.Contains(t, out, faultLineDescription) - assert.Contains(t, out, "$.lines[0].item.description") - }) - - t.Run("line rules do not apply outside AE", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) - require.NoError(t, inv.Calculate()) - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) - if err != nil { - assert.NotContains(t, err.Error(), faultLineDescription) - } - }) -} - -func TestBillGoodsTypeRulesAE(t *testing.T) { - const ( - faultGoodsType = "GOBL-PEPPOL-PINT-BILL-LINE-04" - faultGoodsTypeValue = "GOBL-PEPPOL-PINT-BILL-LINE-05" - faultGTIN = "GOBL-PEPPOL-PINT-BILL-LINE-06" - ) - gtin := func(scheme cbc.Code) []*org.Identity { - return []*org.Identity{{Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})}} - } - reverseCharge := func(goodsType cbc.Code, ids []*org.Identity) *bill.Invoice { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyReverseCharge)} - inv.Lines[0].Item.Identities = ids - if goodsType != "" { - inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: goodsType}) - } - return inv - } - - t.Run("reverse charge item needs the goods type (IBR-166-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, reverseCharge("", gtin("0160"))), faultGoodsType) - out := aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0160"))) - assert.NotContains(t, out, faultGoodsType) - assert.NotContains(t, out, faultGoodsTypeValue) - assert.NotContains(t, out, faultGTIN) - }) - - t.Run("goods type must be from the AE list on any line (IBR-006-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.9", gtin("0160"))), faultGoodsTypeValue) - - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Item.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: "OTHER"}) - assert.Contains(t, aeFaults(t, inv), faultGoodsTypeValue) - }) - - t.Run("reverse charge item needs a GTIN (IBR-174-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", nil)), faultGTIN) - assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0088"))), faultGTIN) - }) - - t.Run("other lines need neither", func(t *testing.T) { - out := aeFaults(t, aeDocument(bill.InvoiceTypeStandard)) - assert.NotContains(t, out, faultGoodsType) - assert.NotContains(t, out, faultGTIN) - }) -} - -func TestBillItemTypeRulesAE(t *testing.T) { - const ( - faultGoodsHS = "GOBL-PEPPOL-PINT-BILL-LINE-07" - faultServicesSAC = "GOBL-PEPPOL-PINT-BILL-LINE-08" - faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-09" - faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-10" - ) - hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} - sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} - item := func(key cbc.Key, ids ...*org.Identity) *bill.Invoice { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Item.Key = key - inv.Lines[0].Item.Identities = ids - return inv - } - - t.Run("goods need an HS classification (IBR-184-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) - assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) - - // An identity with a scheme ID isn't written as a classification. - withScheme := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) - }) - - t.Run("services need a service accounting code (IBR-185-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(org.ItemKeyServices)), faultServicesSAC) - assert.Contains(t, aeFaults(t, item(org.ItemKeyServices, hs)), faultServicesSAC) - assert.NotContains(t, aeFaults(t, item(org.ItemKeyServices, sac)), faultServicesSAC) - }) - - t.Run("goods and services need both (IBR-186-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) - assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) - assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs, sac)), faultGoodsServices) - }) - - t.Run("no item type needs neither", func(t *testing.T) { - out := aeFaults(t, item("")) - assert.NotContains(t, out, faultGoodsHS) - assert.NotContains(t, out, faultServicesSAC) - assert.NotContains(t, out, faultGoodsServices) - }) - - t.Run("item classifications must include an HS one (IBR-188-AE)", func(t *testing.T) { - cpv := &org.Identity{Label: "CPV", Code: "30200000"} - assert.Contains(t, aeFaults(t, item("", cpv)), faultClassification) - assert.Contains(t, aeFaults(t, item("", cpv, sac)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", hs, cpv)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", sac)), faultClassification) - - // Identities with a scheme ID aren't classifications. - gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} - assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) - }) -} - func TestBillMarginSchemeRulesAE(t *testing.T) { const ( - faultDiscount = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" - faultCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" + faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1319,7 +1187,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 1ef1232..331f2bb 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -36,6 +36,15 @@ const ( identityTypeCommercialLicense cbc.Code = "CL" ) +// identityKeysAE are the identity keys of the PINT AE legal registration +// identifier types. +var identityKeysAE = []cbc.Key{ + ae.IdentityKeyTradeLicense, + ae.IdentityKeyEmiratesID, + org.IdentityKeyPassport, + ae.IdentityKeyCabinetDecision, +} + // IdentityTypeAE returns the PINT AE legal registration identifier type for an // identity key, or an empty code if the key has none. func IdentityTypeAE(key cbc.Key) cbc.Code { @@ -132,3 +141,17 @@ func GTINIdentity(ids []*org.Identity) *org.Identity { } return nil } + +// identityHasLegalScope reports whether an identity has the legal scope. +// EN 16931 allows one per party (GOBL-EU-EN16931-ORG-PARTY-02), the one +// gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID. +func identityHasLegalScope(val any) bool { + id, ok := val.(*org.Identity) + return ok && id != nil && id.Scope == org.IdentityScopeLegal +} + +// identityHasTaxScope reports whether an identity has the tax scope. +func identityHasTaxScope(val any) bool { + id, ok := val.(*org.Identity) + return ok && id != nil && id.Scope == org.IdentityScopeTax +} diff --git a/addon/pint/org_item.go b/addon/pint/org_item.go index 9eb5850..79d9807 100644 --- a/addon/pint/org_item.go +++ b/addon/pint/org_item.go @@ -1,6 +1,7 @@ package pint import ( + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" ) @@ -52,3 +53,61 @@ func ItemKeyAE(typ cbc.Code) cbc.Key { } return "" } + +// itemKeyIs returns a predicate that reports whether an item has the key. +func itemKeyIs(key cbc.Key) func(any) bool { + return func(val any) bool { + it, ok := val.(*org.Item) + return ok && it != nil && it.Key == key + } +} + +// identitiesHaveLabel returns a predicate that reports whether an item has +// identities with all the labels. +func identitiesHaveLabel(labels ...string) func(any) bool { + return func(val any) bool { + ids, ok := val.([]*org.Identity) + if !ok { + return false + } + for _, label := range labels { + if !identitiesHaveLabelOf(ids, label) { + return false + } + } + return true + } +} + +// identitiesHaveLabelOf reports whether one of the identities gobl.ubl writes +// as item classifications, those with a label and no scheme ID, has the label. +func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { + for _, id := range ids { + if id != nil && id.Label == label && !id.Ext.Has(iso.ExtKeySchemeID) { + return true + } + } + return false +} + +// identitiesClassifiedWithHS reports whether the identities gobl.ubl writes +// as item classifications, those with a label and no scheme ID, include an HS +// one. Items without classifications pass, and the service accounting codes +// don't count as one. +func identitiesClassifiedWithHS(val any) bool { + ids, ok := val.([]*org.Identity) + if !ok { + return false + } + classified := false + for _, id := range ids { + if id == nil || id.Label == "" || id.Label == IdentityLabelSAC || id.Ext.Has(iso.ExtKeySchemeID) { + continue + } + if id.Label == IdentityLabelHS { + return true + } + classified = true + } + return !classified +} diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go new file mode 100644 index 0000000..7aeb680 --- /dev/null +++ b/addon/pint/org_party.go @@ -0,0 +1,220 @@ +package pint + +import ( + "strings" + + "github.com/invopop/gobl/catalogues/iso" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/org" +) + +// emirateCodes are the country subdivision codes PINT AE accepts for UAE +// addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. +var emirateCodes = []cbc.Code{ + "AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK", +} + +// endpointSchemeUAE is the Peppol participant identifier scheme for UAE +// endpoints, which the PINT AE legal registration rules depend on. +const endpointSchemeUAE cbc.Code = "0235" + +// partyHasIdentifier reports whether the party can be identified through a tax +// identity code or at least one organisation identity. +func partyHasIdentifier(val any) bool { + p, ok := val.(*org.Party) + return ok && p != nil && ((p.TaxID != nil && p.TaxID.Code != "") || len(p.Identities) > 0) +} + +// partyHasTaxRegistration reports whether the party has a tax registration: +// a tax ID code or an identity with the tax scope. IBR-103-AE accepts any +// buyer PartyTaxScheme/CompanyID, and gobl.ubl writes either one there. +func partyHasTaxRegistration(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + if p.TaxID != nil && p.TaxID.Code != "" { + return true + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeTax { + return true + } + } + return false +} + +// partyHasLegalIdentity reports whether the party has an identity with the +// legal scope. gobl.ubl writes the first one as +// PartyLegalEntity/CompanyID, the buyer legal registration identifier +// IBR-136-AE requires on 480 and 81. +func partyHasLegalIdentity(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeLegal { + return true + } + } + return false +} + +// partyFirstAddress returns the party's first address, the only one gobl.ubl +// writes as cac:PostalAddress, or nil if there is none. +func partyFirstAddress(val any) *org.Address { + p, ok := val.(*org.Party) + if !ok || p == nil || len(p.Addresses) == 0 { + return nil + } + return p.Addresses[0] +} + +// partyAddressIsComplete reports whether the party's first address has a +// street, city and region, written as cbc:StreetName, cbc:CityName and +// cbc:CountrySubentity (IBR-143-AE, IBR-144-AE). A party without an address +// passes: EN 16931 already requires supplier and customer addresses (BR-8, +// BR-10). +func partyAddressIsComplete(val any) bool { + a := partyFirstAddress(val) + return a == nil || (a.Street != "" && a.Locality != "" && a.Region != "") +} + +// partyAddressHasEmirate reports whether the party's first address, when in +// the UAE, has an emirate code as its region (IBR-128-AE). Addresses in other +// countries pass, and so does a party without addresses: it is for the +// supplier and customer, whose addresses EN 16931 requires (BR-8, BR-10). +func partyAddressHasEmirate(val any) bool { + return partyFirstAddress(val) == nil || partyPostalAddressHasEmirate(val) +} + +// partyPostalAddressHasEmirate reports whether the cac:PostalAddress gobl.ubl +// writes for the party, when in the UAE, has an emirate code as its region +// (IBR-128-AE). gobl.ubl writes the country of the tax ID over the address's +// own, and writes an address with only that country for a party without +// addresses, which fails the rule. +func partyPostalAddressHasEmirate(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return true + } + a := partyFirstAddress(p) + inAE := a != nil && a.Country == l10n.AE.ISO() + if p.TaxID != nil && p.TaxID.Code != "" { + inAE = p.TaxID.Country.Code() == l10n.AE + } + return !inAE || (a != nil && cbc.Code(a.Region).In(emirateCodes...)) +} + +// partyEndpointID returns the scheme and code of the party's electronic +// address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 +// endpoint, or else the first inbox with a scheme. +func partyEndpointID(p *org.Party) (cbc.Code, string) { + if e := p.Endpoint(iso.ActorIDScheme); e != nil { + // An ISO 6523 URI reads "iso6523-actorid-upis:::". + scheme, code, ok := strings.Cut(strings.TrimPrefix(e.URI.Opaque(), ":"), ":") + if ok && scheme != "" && code != "" { + return cbc.Code(scheme), code + } + } + for _, ib := range p.Inboxes { + if ib != nil && ib.Email == "" && ib.Scheme != "" { + return ib.Scheme, ib.Code.String() + } + } + return "", "" +} + +// partyHasUAEEndpointWith returns a predicate that reports whether the party's +// electronic address uses the UAE Peppol scheme 0235 with a code that match +// accepts. +func partyHasUAEEndpointWith(match func(code string) bool) func(any) bool { + return func(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + scheme, code := partyEndpointID(p) + return scheme == endpointSchemeUAE && match(code) + } +} + +var ( + // partyHasUAEEndpoint is the condition of the legal registration rules. + partyHasUAEEndpoint = partyHasUAEEndpointWith(func(string) bool { return true }) + // partyHasUAEEndpointNotStartingWith1or9 is the condition of IBR-149-AE. + partyHasUAEEndpointNotStartingWith1or9 = partyHasUAEEndpointWith(func(code string) bool { + return !strings.HasPrefix(code, "1") && !strings.HasPrefix(code, "9") + }) + // partyHasUAEEndpointNotTIN is the condition of IBR-135-AE: a code that + // is not a TIN, 1XXXXXXXXX. + partyHasUAEEndpointNotTIN = partyHasUAEEndpointWith(func(code string) bool { + return !tinRegexp.MatchString(code) + }) +) + +// partyFirstLegalIdentity returns the party's first identity with the legal +// scope, the one gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID, or nil +// if there is none. +func partyFirstLegalIdentity(val any) *org.Identity { + p, ok := val.(*org.Party) + if !ok || p == nil { + return nil + } + for _, id := range p.Identities { + if id != nil && id.Scope == org.IdentityScopeLegal { + return id + } + } + return nil +} + +// partyTaxIdentityCount returns how many of the party's identities have the +// tax scope. gobl.ubl writes each one as a cac:PartyTaxScheme. +func partyTaxIdentityCount(p *org.Party) int { + n := 0 + for _, id := range p.Identities { + if identityHasTaxScope(id) { + n++ + } + } + return n +} + +// partyHasAtMostOneTaxRegistration reports whether the party has at most one +// tax registration, counting the tax ID code and the tax scope identities, as +// the buyer can only have one PartyTaxScheme/CompanyID (IBR-179-AE). +func partyHasAtMostOneTaxRegistration(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + n := partyTaxIdentityCount(p) + if p.TaxID != nil && p.TaxID.Code != "" { + n++ + } + return n <= 1 +} + +// partyHasIdentificationOrTaxRegistration reports whether the party has an +// identity gobl.ubl writes as cac:PartyIdentification (any identity that is +// neither a tax registration nor the first legal one) or a tax registration +// (IBR-135-AE). +func partyHasIdentificationOrTaxRegistration(val any) bool { + if partyHasTaxRegistration(val) { + return true + } + p, ok := val.(*org.Party) + if !ok || p == nil { + return false + } + legal := partyFirstLegalIdentity(p) + for _, id := range p.Identities { + if id != nil && id != legal && id.Scope != org.IdentityScopeTax { + return true + } + } + return false +} diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 41d4e80..46f3697 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -38,6 +38,8 @@ func init() { rules.GOBL.Add(Namespace), is.InContext(tax.AddonIn(V1)), billInvoiceRules(), + billDiscountRules(), + billChargeRules(), billLineRules(), taxComboRules(), taxCategoryTotalRules(), diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 2b55934..24548ec 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -142,3 +142,34 @@ func taxComboIsZero(val any) bool { tc, ok := val.(*tax.Combo) return ok && tc != nil && tc.Key == tax.KeyZero } + +// taxCategoryCodesOutsideScope are the VAT category codes allowed on 480 and +// 81 documents: exempt (E), zero rated (Z) and not subject to VAT (O) +// (IBR-122-AE). +var taxCategoryCodesOutsideScope = []cbc.Code{ + en16931.TaxCategoryExempt, + en16931.TaxCategoryZero, + en16931.TaxCategoryOutsideScope, +} + +// comboIsVAT reports whether a tax combo is VAT. +func comboIsVAT(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && c.Category == tax.CategoryVAT +} + +// comboIsExemptVAT reports whether a tax combo is VAT with the exempt +// category code E. +func comboIsExemptVAT(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && c.Category == tax.CategoryVAT && + c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryExempt +} + +// comboIsMarginScheme reports whether a tax combo is VAT under the profit +// margin scheme. +func comboIsMarginScheme(val any) bool { + c, ok := val.(*tax.Combo) + return ok && c != nil && c.Category == tax.CategoryVAT && + c.Ext.Get(untdid.ExtKeyTaxCategory) == TaxCategoryMarginScheme +} diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index 3b14b01..85063a6 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -1,8 +1,6 @@ package pint import ( - "regexp" - "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/i18n" @@ -35,8 +33,6 @@ const ( // 0 or 1 (IBR-154-AE). const transactionTypePattern = `^[01]{8}$` -var transactionTypeRegexp = regexp.MustCompile(transactionTypePattern) - // TransactionType is a parsed PINT AE invoice transaction type (BTAE-02). type TransactionType struct { FreeTradeZone bool diff --git a/ubl/ae.go b/ubl/ae.go index 15339ae..78162fb 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -564,7 +564,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-05) with at most 6 decimals (-06). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-22) with at most 6 decimals (-23). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return From 19d3ce1b8b7802a070de4a29ee63b69486ec1d87 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:08:26 +0000 Subject: [PATCH 27/73] Use the AE regime's identity types The AE regime defines the TIN, trade licence, Emirates ID and Cabinet Decision as identity types instead of keys, and splits the TIN and TRN check digit into its own fault code. Read and write the identity types, and expect the check digit codes on the official examples. Needs gobl with the identity types: bump the gobl pin in go.mod before pushing. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 8 +- addon/pint/bill_test.go | 14 ++-- addon/pint/org_identity.go | 84 +++++++++---------- addon/pint/org_identity_test.go | 57 +++++++------ examples/invoice-ae.yaml | 4 +- examples/out/invoice-ae.json | 6 +- ubl/ae.go | 29 ++++--- ubl/ae_internal_test.go | 47 ++++++----- .../pint/ae/credit-note-ae-outside-scope.json | 6 +- .../pint/ae/credit-note-ae-self-billed.json | 6 +- .../ae/credit-note-ae-volume-discount.json | 6 +- .../convert/pint/ae/credit-note-ae.json | 6 +- .../pint/ae/invoice-ae-continuous-supply.json | 6 +- .../pint/ae/invoice-ae-deemed-supply.json | 6 +- .../convert/pint/ae/invoice-ae-exempt.json | 6 +- .../pint/ae/invoice-ae-export-summary.json | 6 +- .../ae/invoice-ae-free-trade-zone-agent.json | 6 +- .../pint/ae/invoice-ae-margin-scheme.json | 6 +- .../pint/ae/invoice-ae-outside-scope.json | 6 +- .../invoice-ae-reverse-charge-allowance.json | 6 +- .../pint/ae/invoice-ae-reverse-charge.json | 6 +- .../pint/ae/invoice-ae-self-billed.json | 6 +- .../pint/ae/invoice-ae-tin-passport.json | 6 +- .../convert/pint/ae/invoice-ae-usd.json | 6 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 6 +- .../convert/pint/aunz/invoice-au.json | 2 +- .../convert/pint/aunz/invoice-nz.json | 2 +- ubl/testdata/convert/pint/invoice-au.json | 2 +- .../parse/pint/ae/out/allowance-exempt.json | 6 +- .../pint/ae/out/buyer-pas-identifier.json | 4 +- .../parse/pint/ae/out/deemed-supply.json | 6 +- .../parse/pint/ae/out/margin-scheme.json | 6 +- .../parse/pint/ae/out/reverse-charge.json | 6 +- .../pint/ae/out/seller-pas-identifier.json | 4 +- .../pint/ae/out/seller-tin-identifier.json | 8 +- .../parse/pint/ae/out/standard-invoice.json | 6 +- .../pint/ae/out/supply-free-trade-zone.json | 6 +- ubl/ubl_test.go | 22 ++--- 38 files changed, 215 insertions(+), 216 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index d75f858..a228ab2 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -69,7 +69,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("legal scope", identityHasLegalScope), rules.Assert("08", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", - org.IdentityKeyIn(identityKeysAE...), + is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), )), @@ -82,7 +82,7 @@ func billInvoiceRules() *rules.Set { ), ), rules.When( - org.IdentityKeyIn(ae.IdentityKeyTradeLicense), + org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", rules.Assert("10", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Present), ), @@ -119,7 +119,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("legal scope", identityHasLegalScope), rules.Assert("14", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", - org.IdentityKeyIn(identityKeysAE...), + is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), )), @@ -132,7 +132,7 @@ func billInvoiceRules() *rules.Set { ), ), rules.When( - org.IdentityKeyIn(ae.IdentityKeyTradeLicense), + org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", rules.Assert("16", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Present), ), diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index c814e59..826abf6 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -640,7 +640,7 @@ func uaeEndpoints(code string) []*org.Endpoint { } func tradeLicense(code string) *org.Identity { - return &org.Identity{Key: ae.IdentityKeyTradeLicense, Code: cbc.Code(code), Description: "Dubai Economy and Tourism"} + return &org.Identity{Type: ae.IdentityTypeTradeLicense, Code: cbc.Code(code), Description: "Dubai Economy and Tourism"} } // aeIdentityDocument returns a valid UAE invoice whose parties have UAE Peppol @@ -716,9 +716,9 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("each PINT AE type is accepted (IBR-173-AE, IBR-183-AE)", func(t *testing.T) { for _, id := range []*org.Identity{ - {Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"}, + {Type: ae.IdentityTypeEmiratesID, Code: "784199012345671"}, {Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"}, - {Key: ae.IdentityKeyCabinetDecision, Code: "CD-12-2020"}, + {Type: ae.IdentityTypeCabinetDecision, Code: "CD-12-2020"}, } { inv := aeIdentityDocument() inv.Supplier.Identities = []*org.Identity{id} @@ -758,7 +758,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("supplier TIN is accepted, before or after the legal identity (IBR-148-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append([]*org.Identity{ - {Key: ae.IdentityKeyTIN, Code: "1234567897"}, + {Type: ae.IdentityTypeTIN, Code: "1234567897"}, }, inv.Supplier.Identities...) assert.Empty(t, aeFaults(t, inv)) }) @@ -791,7 +791,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("customer has at most one tax registration (IBR-179-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"}) + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) inv.Customer.Identities = append(inv.Customer.Identities, &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) @@ -800,7 +800,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("customer TIN without a scope is a plain identity (IBR-179-AE, IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1345678906"}) + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1345678906"}) out := aeFaults(t, inv) assert.Empty(t, inv.Customer.Identities[1].Scope) assert.NotContains(t, out, faultCustomerTaxCount) @@ -815,7 +815,7 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"}) + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) }) } diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 331f2bb..0a38c67 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -11,24 +11,19 @@ import ( ) // tinRegexp matches a UAE TIN as PINT AE expects it: 10 digits starting with -// 1 (IBR-148-AE). The AE regime checks the identities with the TIN key, check +// 1 (IBR-148-AE). The AE regime checks the identities of the TIN type, check // digit included; this one covers any tax scope identity, as the Schematron // tests the value written. UAE Peppol endpoints (0235) are TINs too, so it // also tells whether an endpoint is one (IBR-135-AE). var tinRegexp = regexp.MustCompile(`^1\d{9}$`) // PINT AE legal registration identifier types, written as @schemeAgencyID on -// the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The Ministry of -// Finance lists the same four types of commercial registration number. +// the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The trade licence +// (TL), Emirates ID (EID) and Cabinet Decision (CD) are the AE regime's +// identity types of the same codes; the passport is GOBL's passport key. const ( - // IdentityTypeTradeLicense is a commercial or trade licence. - IdentityTypeTradeLicense cbc.Code = "TL" - // IdentityTypeEmiratesID is an Emirates ID. - IdentityTypeEmiratesID cbc.Code = "EID" // IdentityTypePassport is a passport. IdentityTypePassport cbc.Code = "PAS" - // IdentityTypeCabinetDecision is a Cabinet Decision. - IdentityTypeCabinetDecision cbc.Code = "CD" // identityTypeCommercialLicense is only accepted by IBR-183-AE's test, for // the buyer. No other source lists it; its rule text names // "Commercial/Trade license", so it is read as a trade licence and never @@ -36,45 +31,42 @@ const ( identityTypeCommercialLicense cbc.Code = "CL" ) -// identityKeysAE are the identity keys of the PINT AE legal registration -// identifier types. -var identityKeysAE = []cbc.Key{ - ae.IdentityKeyTradeLicense, - ae.IdentityKeyEmiratesID, - org.IdentityKeyPassport, - ae.IdentityKeyCabinetDecision, +// identityTypesAE are the AE regime's identity types that are PINT AE legal +// registration identifier types. +var identityTypesAE = []cbc.Code{ + ae.IdentityTypeTradeLicense, + ae.IdentityTypeEmiratesID, + ae.IdentityTypeCabinetDecision, } -// IdentityTypeAE returns the PINT AE legal registration identifier type for an -// identity key, or an empty code if the key has none. -func IdentityTypeAE(key cbc.Key) cbc.Code { - switch key { - case ae.IdentityKeyTradeLicense: - return IdentityTypeTradeLicense - case ae.IdentityKeyEmiratesID: - return IdentityTypeEmiratesID - case org.IdentityKeyPassport: +// IdentityTypeAE returns the PINT AE legal registration identifier type of an +// identity, or an empty code if it has none. +func IdentityTypeAE(id *org.Identity) cbc.Code { + switch { + case id == nil: + return "" + case id.Key == org.IdentityKeyPassport: return IdentityTypePassport - case ae.IdentityKeyCabinetDecision: - return IdentityTypeCabinetDecision + case id.Type.In(identityTypesAE...): + return id.Type } return "" } -// IdentityKeyAE returns the identity key for a PINT AE legal registration -// identifier type, or an empty key if the type is unknown. -func IdentityKeyAE(typ cbc.Code) cbc.Key { - switch typ { - case IdentityTypeTradeLicense, identityTypeCommercialLicense: - return ae.IdentityKeyTradeLicense - case IdentityTypeEmiratesID: - return ae.IdentityKeyEmiratesID - case IdentityTypePassport: - return org.IdentityKeyPassport - case IdentityTypeCabinetDecision: - return ae.IdentityKeyCabinetDecision +// SetIdentityTypeAE sets the identity's key or type from a PINT AE legal +// registration identifier type, and reports whether the type is known. +func SetIdentityTypeAE(id *org.Identity, typ cbc.Code) bool { + switch { + case typ == IdentityTypePassport: + id.Key = org.IdentityKeyPassport + case typ == identityTypeCommercialLicense: + id.Type = ae.IdentityTypeTradeLicense + case typ.In(identityTypesAE...): + id.Type = typ + default: + return false } - return "" + return true } // normalizeIdentityScopes gives the UAE identities of the supplier and @@ -92,7 +84,7 @@ func normalizeIdentityScopes(inv *bill.Invoice) { } // setIdentityScopes gives the party's identities without a scope the one -// their key has in PINT AE, when it is one of the given scopes and no other +// they have in PINT AE, when it is one of the given scopes and no other // identity of the party has it, as EN 16931 allows one identity per scope // (BT-30, BT-47, BT-31, BT-48). func setIdentityScopes(p *org.Party, scopes ...cbc.Key) { @@ -109,20 +101,20 @@ func setIdentityScopes(p *org.Party, scopes ...cbc.Key) { if id == nil || id.Scope != "" { continue } - if scope := identityScopeAE(id.Key); scope.In(scopes...) && !taken[scope] { + if scope := identityScopeAE(id); scope.In(scopes...) && !taken[scope] { id.Scope = scope taken[scope] = true } } } -// identityScopeAE returns the scope PINT AE reads an identity key from, or an +// identityScopeAE returns the scope PINT AE reads an identity from, or an // empty key if it has none. -func identityScopeAE(key cbc.Key) cbc.Key { - if key == ae.IdentityKeyTIN { +func identityScopeAE(id *org.Identity) cbc.Key { + if id.Type == ae.IdentityTypeTIN { return org.IdentityScopeTax } - if IdentityTypeAE(key) != "" { + if IdentityTypeAE(id) != "" { return org.IdentityScopeLegal } return "" diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index 1866bda..12b87a0 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -16,31 +16,38 @@ import ( ) func TestIdentityTypeAE(t *testing.T) { - tests := map[cbc.Key]cbc.Code{ - ae.IdentityKeyTradeLicense: pint.IdentityTypeTradeLicense, - ae.IdentityKeyEmiratesID: pint.IdentityTypeEmiratesID, - org.IdentityKeyPassport: pint.IdentityTypePassport, - ae.IdentityKeyCabinetDecision: pint.IdentityTypeCabinetDecision, - ae.IdentityKeyTIN: "", - cbc.KeyEmpty: "", + tests := []struct { + id *org.Identity + want cbc.Code + }{ + {&org.Identity{Type: ae.IdentityTypeTradeLicense}, "TL"}, + {&org.Identity{Type: ae.IdentityTypeEmiratesID}, "EID"}, + {&org.Identity{Key: org.IdentityKeyPassport}, pint.IdentityTypePassport}, + {&org.Identity{Type: ae.IdentityTypeCabinetDecision}, "CD"}, + {&org.Identity{Type: ae.IdentityTypeTIN}, ""}, + {&org.Identity{}, ""}, + {nil, ""}, } - for key, want := range tests { - assert.Equal(t, want, pint.IdentityTypeAE(key), key) + for _, tt := range tests { + assert.Equal(t, tt.want, pint.IdentityTypeAE(tt.id), tt.id) } } -func TestIdentityKeyAE(t *testing.T) { - tests := map[cbc.Code]cbc.Key{ - "TL": ae.IdentityKeyTradeLicense, - "CL": ae.IdentityKeyTradeLicense, - "EID": ae.IdentityKeyEmiratesID, - "PAS": org.IdentityKeyPassport, - "CD": ae.IdentityKeyCabinetDecision, - "XYZ": "", - "": "", +func TestSetIdentityTypeAE(t *testing.T) { + tests := map[cbc.Code]org.Identity{ + "TL": {Type: ae.IdentityTypeTradeLicense}, + "CL": {Type: ae.IdentityTypeTradeLicense}, + "EID": {Type: ae.IdentityTypeEmiratesID}, + "PAS": {Key: org.IdentityKeyPassport}, + "CD": {Type: ae.IdentityTypeCabinetDecision}, + "XYZ": {}, + "": {}, } for typ, want := range tests { - assert.Equal(t, want, pint.IdentityKeyAE(typ), typ) + id := new(org.Identity) + known := want.Key != "" || want.Type != "" + assert.Equal(t, known, pint.SetIdentityTypeAE(id, typ), typ) + assert.Equal(t, want, *id, typ) } } @@ -62,8 +69,8 @@ func TestNormalizeIdentityScopes(t *testing.T) { norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) return scopes(inv.Supplier), scopes(inv.Customer) } - tin := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyTIN, Code: "1234567897"} } - eid := func() *org.Identity { return &org.Identity{Key: ae.IdentityKeyEmiratesID, Code: "784199012345671"} } + tin := func() *org.Identity { return &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"} } + eid := func() *org.Identity { return &org.Identity{Type: ae.IdentityTypeEmiratesID, Code: "784199012345671"} } passport := func() *org.Identity { return &org.Identity{Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"} } @@ -82,11 +89,11 @@ func TestNormalizeIdentityScopes(t *testing.T) { assert.Equal(t, []cbc.Key{org.IdentityScopeTax, org.IdentityScopeLegal}, supplier) assert.Equal(t, []cbc.Key{"", org.IdentityScopeLegal}, customer, "PINT AE has no customer TIN registration") - for _, key := range []cbc.Key{ae.IdentityKeyTradeLicense, ae.IdentityKeyEmiratesID, ae.IdentityKeyCabinetDecision} { - id := func() *org.Identity { return &org.Identity{Key: key, Code: "784199012345671"} } + for _, typ := range []cbc.Code{ae.IdentityTypeTradeLicense, ae.IdentityTypeEmiratesID, ae.IdentityTypeCabinetDecision} { + id := func() *org.Identity { return &org.Identity{Type: typ, Code: "784199012345671"} } supplier, customer = normalize(l10n.AE.Tax(), list(id)) - assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, supplier, key) - assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, customer, key) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, supplier, typ) + assert.Equal(t, []cbc.Key{org.IdentityScopeLegal}, customer, typ) } }) diff --git a/examples/invoice-ae.yaml b/examples/invoice-ae.yaml index d97df6e..6e2a958 100644 --- a/examples/invoice-ae.yaml +++ b/examples/invoice-ae.yaml @@ -14,7 +14,7 @@ supplier: country: "AE" code: "135790246700003" identities: - - key: "ae-trade-license" + - type: "TL" code: "112345678900003" description: "Trade License issuing Authority" inboxes: @@ -33,7 +33,7 @@ customer: country: "AE" code: "134567890600003" identities: - - key: "ae-trade-license" + - type: "TL" code: "112345679000001" description: "Trade License issuing Authority" inboxes: diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index 6b64451..ee9f961 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "8e2e608f4836428a77673ed749093fd1a8d8dde2604d7e7b6c66dc14f9688e20" + "val": "0b91eaea84879790f911f34a1b0114903a0385b08cb3ab3c4246ad1013199467" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -72,7 +72,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/ae.go b/ubl/ae.go index 78162fb..2154c58 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -702,7 +702,7 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { if id == nil { return } - typ := pint.IdentityTypeAE(id.Key) + typ := pint.IdentityTypeAE(id) if typ == "" { return } @@ -715,7 +715,7 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { name := id.Country.String() cid.SchemeAgencyName = &name } - case pint.IdentityTypeTradeLicense: + case ae.IdentityTypeTradeLicense: if id.Description != "" { name := id.Description cid.SchemeAgencyName = &name @@ -724,9 +724,10 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { } // importAEPartyIdentities reads back what exportAEPartyIdentities writes: -// the legal identity's key from @schemeAgencyID, with @schemeAgencyName as -// the passport's country or the trade licence's description, and, for the -// supplier, the TIN key on the tax registration that is not VAT, as PINT AE +// the legal identity's key or type from @schemeAgencyID, with +// @schemeAgencyName as the passport's country or the trade licence's +// description, and, for the supplier, the TIN type on the tax registration +// that is not VAT, as PINT AE // defines IBT-032 as the seller TIN. func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { if in == nil || p == nil { @@ -745,7 +746,7 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { if supplier { for _, id := range p.Identities { if id != nil && id.Scope == org.IdentityScopeTax && id.Key == "" && id.Type == "" { - id.Key = ae.IdentityKeyTIN + id.Type = ae.IdentityTypeTIN } } } @@ -770,22 +771,20 @@ func importAEPartyEndpoint(in *goblubl.Party, p *org.Party) { p.Endpoints = append(p.Endpoints, &org.Endpoint{URI: uri}) } -// importAELegalIdentity sets the identity's key and, from @schemeAgencyName, -// its issuing country or description. +// importAELegalIdentity sets the identity's key or type and, from +// @schemeAgencyName, its issuing country or description. func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { - key := pint.IdentityKeyAE(cbc.Code(strings.TrimSpace(*cid.SchemeAgencyID))) - if key == "" { + if !pint.SetIdentityTypeAE(id, cbc.Code(strings.TrimSpace(*cid.SchemeAgencyID))) { return } - id.Key = key if cid.SchemeAgencyName == nil { return } name := strings.TrimSpace(*cid.SchemeAgencyName) - switch key { - case org.IdentityKeyPassport: + switch { + case id.Key == org.IdentityKeyPassport: id.Country = l10n.ISOCountryCode(name) - case ae.IdentityKeyTradeLicense: + case id.Type == ae.IdentityTypeTradeLicense: id.Description = name } } @@ -802,7 +801,7 @@ func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { // It is not the TIN of UNCL 1153, which is a transport instruction number. func exportAETINScheme(out *goblubl.Party, p *org.Party) { for _, id := range p.Identities { - if id == nil || id.Key != ae.IdentityKeyTIN || id.Scope != org.IdentityScopeTax { + if id == nil || id.Type != ae.IdentityTypeTIN || id.Scope != org.IdentityScopeTax { continue } for i := range out.PartyTaxScheme { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 1eebe1b..43d533a 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -211,12 +211,15 @@ func TestExportAEPartyIdentities(t *testing.T) { exportAEPartyIdentities(out, p) return out } - legal := func(key cbc.Key, code string) *org.Identity { - return &org.Identity{Key: key, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} + legal := func(typ cbc.Code, code string) *org.Identity { + return &org.Identity{Type: typ, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} + } + passport := func(code string) *org.Identity { + return &org.Identity{Key: org.IdentityKeyPassport, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} } t.Run("trade licence gets TL and its authority", func(t *testing.T) { - id := legal(ae.IdentityKeyTradeLicense, "112345678900003") + id := legal(ae.IdentityTypeTradeLicense, "112345678900003") id.Description = "Trade License issuing Authority" cid := export(&org.Party{Name: "Seller", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID assert.Equal(t, "112345678900003", cid.Value) @@ -225,7 +228,7 @@ func TestExportAEPartyIdentities(t *testing.T) { }) t.Run("passport gets PAS and its issuing country", func(t *testing.T) { - id := legal(org.IdentityKeyPassport, "P1234567890") + id := passport("P1234567890") id.Country = "IN" cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID assert.Equal(t, "PAS", *cid.SchemeAgencyID) @@ -233,20 +236,17 @@ func TestExportAEPartyIdentities(t *testing.T) { }) t.Run("Emirates ID and Cabinet Decision get their type only", func(t *testing.T) { - for key, typ := range map[cbc.Key]string{ - ae.IdentityKeyEmiratesID: "EID", - ae.IdentityKeyCabinetDecision: "CD", - } { - id := legal(key, "784199012345671") + for _, typ := range []cbc.Code{ae.IdentityTypeEmiratesID, ae.IdentityTypeCabinetDecision} { + id := legal(typ, "784199012345671") id.Description = "not an authority" cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID - assert.Equal(t, typ, *cid.SchemeAgencyID, key) - assert.Nil(t, cid.SchemeAgencyName, key) + assert.Equal(t, typ.String(), *cid.SchemeAgencyID, typ) + assert.Nil(t, cid.SchemeAgencyName, typ) } }) t.Run("passport ignores the description", func(t *testing.T) { - id := legal(org.IdentityKeyPassport, "P1234567890") + id := passport("P1234567890") id.Description = "not a country" cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID assert.Nil(t, cid.SchemeAgencyName) @@ -262,9 +262,9 @@ func TestExportAEPartyIdentities(t *testing.T) { t.Run("the first legal identity is described, after a tax one", func(t *testing.T) { cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ - {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, - legal(ae.IdentityKeyEmiratesID, "784199012345671"), - legal(ae.IdentityKeyCabinetDecision, "CD-1"), + {Type: ae.IdentityTypeTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, + legal(ae.IdentityTypeEmiratesID, "784199012345671"), + legal(ae.IdentityTypeCabinetDecision, "CD-1"), }}).PartyLegalEntity.CompanyID assert.Equal(t, "784199012345671", cid.Value) assert.Equal(t, "EID", *cid.SchemeAgencyID) @@ -275,7 +275,7 @@ func TestExportAEPartyIdentities(t *testing.T) { Name: "Seller", TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, Identities: []*org.Identity{ - {Key: ae.IdentityKeyTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, + {Type: ae.IdentityTypeTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, }, }) require.Len(t, out.PartyTaxScheme, 2) @@ -321,13 +321,13 @@ func TestImportAEPartyIdentities(t *testing.T) { t.Run("trade licence with its authority", func(t *testing.T) { id := imported(companyID("TL", "Trade License issuing Authority"), false).Identities[0] - assert.Equal(t, ae.IdentityKeyTradeLicense, id.Key) + assert.Equal(t, ae.IdentityTypeTradeLicense, id.Type) assert.Equal(t, "Trade License issuing Authority", id.Description) }) t.Run("CL is read as a trade licence", func(t *testing.T) { id := imported(companyID("CL", "Dubai Economy and Tourism"), false).Identities[0] - assert.Equal(t, ae.IdentityKeyTradeLicense, id.Key) + assert.Equal(t, ae.IdentityTypeTradeLicense, id.Type) assert.Equal(t, "Dubai Economy and Tourism", id.Description) }) @@ -339,9 +339,9 @@ func TestImportAEPartyIdentities(t *testing.T) { }) t.Run("Emirates ID and Cabinet Decision, without an authority", func(t *testing.T) { - for typ, key := range map[string]cbc.Key{"EID": ae.IdentityKeyEmiratesID, "CD": ae.IdentityKeyCabinetDecision} { - id := imported(companyID(typ, "Some Authority"), false).Identities[0] - assert.Equal(t, key, id.Key, typ) + for _, typ := range []cbc.Code{ae.IdentityTypeEmiratesID, ae.IdentityTypeCabinetDecision} { + id := imported(companyID(typ.String(), "Some Authority"), false).Identities[0] + assert.Equal(t, typ, id.Type, typ) assert.Empty(t, id.Description, typ) } }) @@ -350,6 +350,7 @@ func TestImportAEPartyIdentities(t *testing.T) { for _, typ := range []string{"XYZ", ""} { id := imported(companyID(typ, "Some Authority"), false).Identities[0] assert.Empty(t, id.Key, typ) + assert.Empty(t, id.Type, typ) assert.Empty(t, id.Description, typ) } }) @@ -362,11 +363,11 @@ func TestImportAEPartyIdentities(t *testing.T) { } p := imported(in, true) require.Len(t, p.Identities, 2) - assert.Equal(t, ae.IdentityKeyTIN, p.Identities[1].Key) + assert.Equal(t, ae.IdentityTypeTIN, p.Identities[1].Type) assert.Equal(t, cbc.Code("1234567897"), p.Identities[1].Code) p = imported(in, false) - assert.Empty(t, p.Identities[1].Key, "only the seller has a TIN") + assert.Empty(t, p.Identities[1].Type, "only the seller has a TIN") }) t.Run("nil parties are skipped", func(t *testing.T) { diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json index 8268742..3e8638b 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0430fc09e17a0375b6d51ab9ed1cd0fafcc3a147e65ce1a627a83382c0f313ee" + "val": "baa8ed80869a93e121817a8640f164d23d16ee174f89822632db7bb7234a9e02" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -47,7 +47,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -82,7 +82,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json index 94f2985..2e9c212 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "44c2f0324debee9394a59a34f38820cb782cb1c7fc9b9584a87860c0fa0d1b0f" + "val": "842faf54e5939bac0c57b4212d090d8bcd242cb65db4ef0f7cc11f2f7fdc2747" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -47,7 +47,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -82,7 +82,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json index 40b84e8..4c29827 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d904436614ce611d74de4293b505a5411f021204365db500830da42963ca0ac3" + "val": "52d4086677c93bf74c9c94617add823e6f5e780a8d92bf7fb14cd1809f0bfc95" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -38,7 +38,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -73,7 +73,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index 35c9e90..24fa077 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "02e5744a95abc0d768d070667650449ce065dc5b55474fbf23ecb4ca60d934cf" + "val": "2e11036fa7fc2bc6b0682805970c47d21831ef47e83328bee0db86cd992bb6cd" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -44,7 +44,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -79,7 +79,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index 8e8660c..c2b91c7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d1f5ceba24a3a97adb52868ea22abd7a7e15a8c1717c256a090c8286dfa5969a" + "val": "985eee20b45f61cfe7c415ed98a4c3b24a49e2903fe66b07d8d8c528a4d821a5" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -41,7 +41,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -76,7 +76,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index 0fa8ea4..bfeefa1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "36c8b6d1a0ea7e24dc80ade02c6b33cf353fabcb3e53b22e723caad0cf1649c0" + "val": "18c6f843194b5be40eff98de27a2043d1206ead85d68b9e1cf608a33c4dab19e" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -40,7 +40,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -75,7 +75,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index 4b05ce7..af89414 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "21da47d3bd98121a46a6a42b424444233a611d2ec5080b9bb9d800296a5d1d5a" + "val": "23e53f589a01745b5f143024c155aab5cfffe3d7dde315db14d9e2010d087f8f" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -72,7 +72,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 51e1919..b69b44c 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b3ff7190be2217a9c49b073f312a3f21cbb804e7c1f5fb09098b65e377ae3aea" + "val": "c1db9b2b5408c9cd5003607a40aa9064f8646d1b93142c3160a5b377f2d200e4" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -42,7 +42,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -77,7 +77,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json index 3cc1650..052498f 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "805083f45161fae4dd82ae7dd3cd2a7ef354ab577e2a307ea9ac2bd03f83cd97" + "val": "016c7342a30b6b87221f503da670459250853149de967a0d2a0e39798a3083f7" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -43,7 +43,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -78,7 +78,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index bce13ca..df7bd39 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7605d1a6c5331f72342308110ff47d34f0ad2546441711a5c1bcfb98818e4d7e" + "val": "bd5de76ffd6980841addc3244bb18245dc98014e422d067060c067ab9b400b5f" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -40,7 +40,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -75,7 +75,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index 485f291..c527aea 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b7eed4cad0cf2a784963db7cdc213203c80dbae3f6ee04de339ea9cbdd5569c3" + "val": "4674931caa19d438c9cb6e57b0f2c774256c9c37cf05b4c037a07443d3a823d0" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -40,7 +40,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -75,7 +75,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 4b0be54..0803ac2 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "48631c6053724f64aa1eee791fd04aa790ab4d6f6b144b24696d5a06ff9e3a69" + "val": "43164b973a340e425d2aa18319d664b1d9a76e7bc70738716dd76e7d8cb4ef03" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -72,7 +72,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index da1a2f2..28403de 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0110b236aa10a9cd2f9e5a5d0fe29e24035444978f1034d002c847018755e9d9" + "val": "af1671d0b7c35d2a5b4ed4da78904b8880c18cd5ed43bd6a1f02e7270d5d5309" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -72,7 +72,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json index a86b3b5..b27d5df 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5c35f1643870efa7a89cdb79677b025848da34c4e90d0f5fe7928360ac551739" + "val": "e0d90f542504f5df1381f56b0cfc8971014f3cdfe9db441f28c5bc32d4fcbf0e" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -40,7 +40,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -75,7 +75,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index 8d586dc..04790a1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d2f0b707ea1f49f909469171b4b98ea1fc4fc8588efa982bc8d54498318d20f3" + "val": "459f5560212a0ba47252606e4ed8a9d1fc7a12161388dd6f33e54797d2cbd8f2" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,12 +37,12 @@ "identities": [ { "scope": "tax", - "key": "ae-tin", + "type": "TIN", "code": "1234567897" }, { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index e0db0fe..ae8defc 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "9ebf5cec76ecacd58e1d8b6f8d83665231778ae99c07bd784ca16d9bed045d82" + "val": "7cfd4d6b98f5f8ea0aa7f2ca217d9da989ccc452cb2a1e36da5f8951b1736c48" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -44,7 +44,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -79,7 +79,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index abf8a71..4ee0a50 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "8e2e608f4836428a77673ed749093fd1a8d8dde2604d7e7b6c66dc14f9688e20" + "val": "0b91eaea84879790f911f34a1b0114903a0385b08cb3ab3c4246ad1013199467" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -72,7 +72,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/convert/pint/aunz/invoice-au.json b/ubl/testdata/convert/pint/aunz/invoice-au.json index c99114a..fd59888 100644 --- a/ubl/testdata/convert/pint/aunz/invoice-au.json +++ b/ubl/testdata/convert/pint/aunz/invoice-au.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "194e284ed37ed32678488c78bd7ebd357b52c60ca0b40c15fd9073435a0bcf39" + "val": "87536bed12a6f38cce3d9b4e846708961b72521406fa1666a20f9ea0aa6f6cbb" }, "from": "iso6523-actorid-upis::0151:51824753556", "to": "iso6523-actorid-upis::0151:53004085616" diff --git a/ubl/testdata/convert/pint/aunz/invoice-nz.json b/ubl/testdata/convert/pint/aunz/invoice-nz.json index e97b79c..0e90cad 100644 --- a/ubl/testdata/convert/pint/aunz/invoice-nz.json +++ b/ubl/testdata/convert/pint/aunz/invoice-nz.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "fcd446f74e87c36c29d6d4cd78a307fa62611c47df4b6430cadf4d28ca0893aa" + "val": "582b20df43826dc1267062417ecafa76335fffaf780c051f73a9e36ff0d7d83f" }, "from": "iso6523-actorid-upis::0088:9429044000004", "to": "iso6523-actorid-upis::0088:9429044000011" diff --git a/ubl/testdata/convert/pint/invoice-au.json b/ubl/testdata/convert/pint/invoice-au.json index c99114a..fd59888 100644 --- a/ubl/testdata/convert/pint/invoice-au.json +++ b/ubl/testdata/convert/pint/invoice-au.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "194e284ed37ed32678488c78bd7ebd357b52c60ca0b40c15fd9073435a0bcf39" + "val": "87536bed12a6f38cce3d9b4e846708961b72521406fa1666a20f9ea0aa6f6cbb" }, "from": "iso6523-actorid-upis::0151:51824753556", "to": "iso6523-actorid-upis::0151:53004085616" diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 2baabb8..1b52a46 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "38d4dfc2b7ead64cb1486d0cc2bdc72a7d6a5a878772929d8a73de2c64b823e2" + "val": "26edb1ca821be6f0f2cf40f00364b25743dabf864152a5af661ac818842ace4c" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -42,7 +42,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -91,7 +91,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json index d93de66..b466148 100644 --- a/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/buyer-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3eb4f96db635fc7e90614ce11c5762d6032f5648e11457b7081b95b719f59bbd" + "val": "dab84aedaed8ae421f79f91695890c143c9c19578014afab6f26b9302c555c6f" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -39,7 +39,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index 18feb1a..0148988 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a6c349ac19e6ca906f66e03b57f68d8b9cb80add6a1c91729aeb2dff2e458214" + "val": "9e57d5483072fed836f83f859561c7773d1af56c36fffdc23f09d500c4664726" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:1012345678" @@ -40,7 +40,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -88,7 +88,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index e4af6f4..d87acb2 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "89abd84d782bc7a63a572424071b51d24fc9b6b5633f7ba094e5de0c9fcdc51f" + "val": "2c687f4fb4aa859cb11f90134e1b82c7d771a05edf109d1e90dfbd8ac7405002" }, "from": "iso6523-actorid-upis::0235:112345678900003", "to": "iso6523-actorid-upis::0235:112345679000003" @@ -41,7 +41,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -92,7 +92,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 758bb35..f675d1d 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c248c13c4043cf95a56e8e93d5be32d9705d731602e8814e009b420169a80daf" + "val": "07fe54e846c66905b22ad743cdc69254c0e8b99c3e3321c9b9648d9d4109dad1" }, "from": "iso6523-actorid-upis::0235:1278906543", "to": "iso6523-actorid-upis::0235:1347809543" @@ -38,7 +38,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -86,7 +86,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json index fa2e6ae..1269057 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-pas-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "433efe4b5d206d73c0fa7b28963bf65942e6f1b4ac516d17ac151dad1d225941" + "val": "46960c77e2031f9a2031e885104bcf25fc199d8433c5aa2bbedb19b0aeeb27ad" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -88,7 +88,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json index 35218ca..216c37b 100644 --- a/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json +++ b/ubl/testdata/parse/pint/ae/out/seller-tin-identifier.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d08db6f319c19d453ab9d2ff4f2fb66b89a88d011a8e71fcb5d83bbb12eeaf55" + "val": "11e41f9b8d13f1efe06178451e5781f311bd8ea52bc48a4ccffd9732349487b2" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -39,14 +39,14 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" }, { "scope": "tax", "country": "AE", - "key": "ae-tin", + "type": "TIN", "code": "1234567890" } ], @@ -94,7 +94,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-invoice.json index 0d004d4..40ecda1 100644 --- a/ubl/testdata/parse/pint/ae/out/standard-invoice.json +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "9d5f7e184ece141543a8c205f363b5aafd431716944e0962914e7a3e4dc94d5a" + "val": "339ee2694f6001ca9b11e68c2242403bbdceefadaa21d7e44aaa930413b6e488" }, "from": "iso6523-actorid-upis::0235:1357902468", "to": "iso6523-actorid-upis::0235:1345678901" @@ -37,7 +37,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -65,7 +65,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 114f3d8..2239177 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a58b34969f6754939e6e5b005be9ebb8c0615aaef8389a281831edebccdb502b" + "val": "5a6f8c9c4e0e231e1a56bcabfce971c936a555443c4d345b7f7470c46cdbed06" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:1789012345" @@ -41,7 +41,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" } @@ -89,7 +89,7 @@ "identities": [ { "scope": "legal", - "key": "ae-trade-license", + "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" } diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index f6e9181..9e953e1 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -151,15 +151,15 @@ func TestDetectAndImportAE(t *testing.T) { // terms, which EN 16931 requires (BR-CO-25). Any other fault is a defect in // the import. var importFaultsAE = map[string][]string{ - "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-01"}, - "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-01"}, - "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, - "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, - "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, - "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-01"}, - "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-01", "GOBL-AE-TAX-IDENTITY-01"}, - "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-01"}, - "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-01", "GOBL-ORG-EMAIL-02"}, + "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, } // faultCodePattern matches the fault codes in a validation error. @@ -195,7 +195,7 @@ func TestImportAESellerTIN(t *testing.T) { inv, ok := env.Extract().(*bill.Invoice) require.True(t, ok) inv.Supplier.TaxID = &tax.Identity{Country: "AE"} - inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Key: ae.IdentityKeyTIN, Code: "1357902467"}) + inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1357902467"}) require.NoError(t, env.Calculate()) require.NoError(t, env.Validate()) @@ -207,7 +207,7 @@ func TestImportAESellerTIN(t *testing.T) { assert.Nil(t, supplier.TaxID) var tin *org.Identity for _, id := range supplier.Identities { - if id.Key == ae.IdentityKeyTIN { + if id.Type == ae.IdentityTypeTIN { tin = id } } From c36bf190e2c8a9928a61702531924af0b0157552 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:49:31 +0000 Subject: [PATCH 28/73] Add the PINT AE extensions for the fields GOBL has no place for PINT AE fields with no home in GOBL get their own extensions, offered under the AE regime on the object each one belongs to: - customs reference number (BTAE-21), on the invoice tax - contract value (BTAE-05), on the contract reference - batch number (BTAE-24), on the item - scheme version of an item classification or service accounting code (IBT-158-2, BTAE-17-2), on the item identity - purchase order and despatch advice references of a line (IBT-183, IBT-184), on the line - scheme of the remittance reference (IBT-083-1), on the payment instructions Co-Authored-By: Claude Opus 5.5 --- addon/pint/extensions.go | 131 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 70ec9e4..865a0ce 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -5,6 +5,7 @@ import ( "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/i18n" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pay" "github.com/invopop/gobl/pkg/here" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" @@ -30,6 +31,26 @@ const ( // ExtKeyGoodsType is the type of goods or services subject to the reverse // charge mechanism, on the item (BTAE-09). ExtKeyGoodsType cbc.Key = "peppol-pint-ae-goods-type" + // ExtKeyCustomsReference is the customs reference number of an export or + // import (BTAE-21). + ExtKeyCustomsReference cbc.Key = "peppol-pint-ae-customs-reference" + // ExtKeyBatchNumber is the production batch or lot the items come from, + // on the item (BTAE-24). + ExtKeyBatchNumber cbc.Key = "peppol-pint-ae-batch-number" + // ExtKeySchemeVersion is the version of the scheme an item identity's code + // is from, such as an HS or SAC code (IBT-158-2, BTAE-17-2). + ExtKeySchemeVersion cbc.Key = "peppol-pint-ae-scheme-version" + // ExtKeyContractValue is the value of a contract, on its reference + // (BTAE-05). + ExtKeyContractValue cbc.Key = "peppol-pint-ae-contract-value" + // ExtKeyPurchaseOrder is the purchase order a line belongs to (IBT-183). + ExtKeyPurchaseOrder cbc.Key = "peppol-pint-ae-purchase-order" + // ExtKeyDespatchAdvice is the despatch advice a line was sent with + // (IBT-184). + ExtKeyDespatchAdvice cbc.Key = "peppol-pint-ae-despatch-advice" + // ExtKeyRemittanceScheme is the scheme of the payment instructions' + // remittance reference, such as "ABA" (IBT-083-1). + ExtKeyRemittanceScheme cbc.Key = "peppol-pint-ae-remittance-scheme" ) // CreditNoteReasonVolumeDiscount is the credit note reason for a volume @@ -58,6 +79,26 @@ var ( Codes: []cbc.Code{ae.CountryCode}, Schemas: []string{org.ShortSchemaItem}, } + usageAEIdentity = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{org.ShortSchemaIdentity}, + } + usageAEDocumentRef = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{org.ShortSchemaDocumentRef}, + } + usageAELine = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{bill.ShortSchemaLine}, + } + usageAEInstructions = &cbc.Usage{ + Keys: []cbc.Key{V1}, + Codes: []cbc.Code{ae.CountryCode}, + Schemas: []string{pay.ShortSchemaInstructions}, + } ) // extensions are the extensions the PINT addon defines. They are only used @@ -244,4 +285,94 @@ var extensions = []*cbc.Definition{ {Code: "DL8.48.3.3", Name: i18n.String{i18n.EN: "Pure hydrocarbons"}}, }, }, + { + Key: ExtKeyCustomsReference, + Usage: usageAEInvoiceTax, + Name: i18n.String{ + i18n.EN: "PINT AE Customs Reference Number", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Customs reference number of an export or import transaction + (BTAE-21). + `), + }, + }, + { + Key: ExtKeyBatchNumber, + Usage: usageAEItem, + Name: i18n.String{ + i18n.EN: "PINT AE Batch Number", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Production batch or lot the items come from (BTAE-24). + `), + }, + }, + { + Key: ExtKeySchemeVersion, + Usage: usageAEIdentity, + Name: i18n.String{ + i18n.EN: "PINT AE Scheme Version", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Version of the scheme the code of an item identity is from, for the + item classifications and service accounting codes of an item + (IBT-158-2, BTAE-17-2). + `), + }, + }, + { + Key: ExtKeyContractValue, + Usage: usageAEDocumentRef, + Name: i18n.String{ + i18n.EN: "PINT AE Contract Value", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Value of a contract, on its reference in the invoice's ordering + details, such as "AED 200000" (BTAE-05). + `), + }, + }, + { + Key: ExtKeyPurchaseOrder, + Usage: usageAELine, + Name: i18n.String{ + i18n.EN: "PINT AE Line Purchase Order Reference", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Identifier of the purchase order a line belongs to, issued by the + buyer (IBT-183). The line's "order" is the line of that order. + `), + }, + }, + { + Key: ExtKeyDespatchAdvice, + Usage: usageAELine, + Name: i18n.String{ + i18n.EN: "PINT AE Line Despatch Advice Reference", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Identifier of the despatch advice a line was sent with (IBT-184). + `), + }, + }, + { + Key: ExtKeyRemittanceScheme, + Usage: usageAEInstructions, + Name: i18n.String{ + i18n.EN: "PINT AE Remittance Reference Scheme", + }, + Desc: i18n.String{ + i18n.EN: here.Doc(` + Scheme of the payment instructions' reference, the remittance + information, such as "ABA" (IBT-083-1). + `), + }, + }, } From e8269bf9544ff87655faa00249874843b93c6408 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:49:32 +0000 Subject: [PATCH 29/73] Write and read the remaining PINT AE fields The AE format now writes the PINT AE fields gobl.ubl leaves out, and reads them back: - issue time, and the customs reference as cac:StatementDocumentReference - each contract's value as its cbc:DocumentDescription - the IBAN scheme of the payee account, the address of its branch, and the scheme of the remittance reference - the first due date's amount and date as the payment terms, which refer to the payment instructions by the ID 1 - cbc:TaxIncludedIndicator as false - the UAE VAT exemption reason of exempt discounts and charges, and the tax note of a line's VAT category as its exemption reason text - each item's batch number as its lot, and the scheme versions of its classifications and service accounting codes - each line's purchase order and despatch advice, with NA as the line of either when there is none The payment means ID, the tax included indicator and the payment terms are constants or come from gobl.ubl's own import, so there is nothing more to read back. Two BIS parse outputs gain the third address line gobl.ubl now imports. Co-Authored-By: Claude Opus 5.5 --- README.md | 23 +- ubl/ae.go | 469 +++++++++++++++++- ubl/ae_internal_test.go | 414 +++++++++++++++- .../convert/pint/ae/invoice-ae-exempt.json | 25 +- .../pint/ae/invoice-ae-export-summary.json | 8 +- .../convert/pint/ae/invoice-ae-usd.json | 12 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 35 +- .../ae/out/credit-note-ae-outside-scope.xml | 3 +- .../ae/out/credit-note-ae-self-billed.xml | 3 +- .../ae/out/credit-note-ae-volume-discount.xml | 3 +- .../convert/pint/ae/out/credit-note-ae.xml | 3 +- .../ae/out/invoice-ae-continuous-supply.xml | 9 +- .../pint/ae/out/invoice-ae-deemed-supply.xml | 1 + .../convert/pint/ae/out/invoice-ae-exempt.xml | 14 +- .../pint/ae/out/invoice-ae-export-summary.xml | 17 +- .../out/invoice-ae-free-trade-zone-agent.xml | 9 +- .../pint/ae/out/invoice-ae-margin-scheme.xml | 9 +- .../pint/ae/out/invoice-ae-outside-scope.xml | 9 +- .../invoice-ae-reverse-charge-allowance.xml | 9 +- .../pint/ae/out/invoice-ae-reverse-charge.xml | 9 +- .../pint/ae/out/invoice-ae-self-billed.xml | 9 +- .../pint/ae/out/invoice-ae-tin-passport.xml | 9 +- .../convert/pint/ae/out/invoice-ae-usd.xml | 13 +- .../convert/pint/ae/out/invoice-ae.xml | 47 +- .../parse/bis/out/Allowance-example.json | 3 +- .../parse/bis/out/Vat-category-S.json | 3 +- .../parse/pint/ae/out/deemed-supply.json | 7 +- .../parse/pint/ae/out/margin-scheme.json | 4 +- .../parse/pint/ae/out/reverse-charge.json | 7 +- .../pint/ae/out/supply-free-trade-zone.json | 7 +- 30 files changed, 1124 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 65f0a84..1498fec 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,23 @@ item's type of goods or services subject to the reverse charge as its identities labelled `SAC` are written as service accounting codes. Lines with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with no VAT amount, and the delivery's ICC Incoterms (`icc-incoterms-2020` or -`-2010`) are written as the delivery terms. On import, it reads +`-2010`) are written as the delivery terms. + +It also writes the PINT fields gobl.ubl leaves out: the issue time; the +customs reference number (`peppol-pint-ae-customs-reference`) as +`cac:StatementDocumentReference`; each contract's value +(`peppol-pint-ae-contract-value`); the `IBAN` scheme of the payee account +and the address of its branch; the scheme of the remittance reference +(`peppol-pint-ae-remittance-scheme`); the first due date's amount and date +as the payment terms, which refer to the payment instructions by the ID `1`; +each line's purchase order (`peppol-pint-ae-purchase-order`) and despatch +advice (`peppol-pint-ae-despatch-advice`), with `NA` as the line of either +when there is none; `cbc:TaxIncludedIndicator` as `false`; +the UAE VAT exemption reason of exempt discounts and charges; the tax note +of a line's VAT category as its exemption reason text; each item's batch +number (`peppol-pint-ae-batch-number`) as its lot; and the scheme version +(`peppol-pint-ae-scheme-version`) of the item's classification and service +accounting codes. On import, it reads the invoice UUID, the out-of-scope type codes 480 and 81 back as the `outside-scope` tag, and the identity types, authorities, passport countries and seller TIN back as @@ -133,7 +149,10 @@ reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and the `N` category back as the `margin-scheme` key, and the delivery terms back as the `icc-incoterms-2020` extension, and the seller and buyer electronic -addresses as endpoints. +addresses as endpoints, and the customs reference, discount and charge +exemption reasons, line exemption reason texts, batch numbers, scheme +versions, contract values, remittance reference schemes and line purchase +orders and despatch advices back as their extensions and tax notes. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/ubl/ae.go b/ubl/ae.go index 2154c58..035f641 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -16,6 +16,7 @@ import ( "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pay" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" "github.com/invopop/gobl/uuid" @@ -42,6 +43,15 @@ const aeStandardRate = "5" // taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. const taxSchemeTIN = "TIN" +// accountSchemeIBAN is the scheme PINT AE gives the ID of an IBAN account +// (IBT-084-1), as the official examples do. +const accountSchemeIBAN = "IBAN" + +// aePaymentMeansID identifies the invoice's payment instructions (IBT-178), so +// that its payment terms can refer to them (IBT-187). GOBL has a single set of +// instructions, so it needs no ID of its own. +const aePaymentMeansID = "1" + // exportAE applies the Peppol PINT AE rules to an exported invoice. func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error { out, ok := doc.(*goblubl.Invoice) @@ -50,10 +60,15 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error return nil } exportAEUUID(out, inv) + exportAEIssueTime(out, inv) exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) exportAEBillingFrequency(out, inv) exportAEIncoterms(out, inv) + exportAECustomsReference(out, inv) + exportAEContractValue(out, inv) + exportAEPayment(out, inv) + exportAEChargeExemptions(out, inv) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -82,12 +97,18 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAECreditNoteReason(in, inv) importAEBillingFrequency(in, inv) importAEIncoterms(in, inv) + importAECustomsReference(in, inv) + importAEContractValue(in, inv) + importAERemittanceScheme(in, inv) + importAEChargeExemptions(in, inv) importAELineExemptions(in.InvoiceLines, inv) importAELineExemptions(in.CreditNoteLines, inv) importAELineGoods(in.InvoiceLines, inv) importAELineGoods(in.CreditNoteLines, inv) importAELineItems(in.InvoiceLines, inv) importAELineItems(in.CreditNoteLines, inv) + importAELineReferences(in.InvoiceLines, inv) + importAELineReferences(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) importAEPartyEndpoint(in.AccountingSupplierParty.Party, inv.Supplier) @@ -174,6 +195,241 @@ func importAEUUID(in *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAEIssueTime writes the invoice's issue time as cbc:IssueTime +// (IBT-168), which gobl.ubl reads but doesn't write. +func exportAEIssueTime(out *goblubl.Invoice, inv *bill.Invoice) { + if inv.IssueTime != nil { + out.IssueTime = inv.IssueTime.String() + } +} + +// exportAECustomsReference writes the customs reference number as +// cac:StatementDocumentReference/cbc:ID (BTAE-21). +func exportAECustomsReference(out *goblubl.Invoice, inv *bill.Invoice) { + if ref := inv.Tax.GetExt(pint.ExtKeyCustomsReference); ref != "" { + out.StatementDocumentReference = []goblubl.Reference{ + {ID: goblubl.IDType{Value: ref.String()}}, + } + } +} + +// importAECustomsReference reads the first customs reference number back. +func importAECustomsReference(in *goblubl.Invoice, inv *bill.Invoice) { + for _, r := range in.StatementDocumentReference { + if ref := cbc.Code(strings.TrimSpace(r.ID.Value)); ref != "" { + setAEExt(inv, pint.ExtKeyCustomsReference, ref) + return + } + } +} + +// exportAEContractValue writes the value of each contract as +// cac:ContractDocumentReference/cbc:DocumentDescription (BTAE-05), on the +// references gobl.ubl writes in the same order as the invoice's contracts. +func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { + if inv.Ordering == nil || len(inv.Ordering.Contracts) != len(out.ContractDocumentReference) { + return + } + for i, c := range inv.Ordering.Contracts { + if c == nil { + continue + } + if v := c.Ext.Get(pint.ExtKeyContractValue); v != "" { + out.ContractDocumentReference[i].DocumentDescription = v.String() + } + } +} + +// importAEContractValue reads the value of each contract back, which gobl.ubl +// imports as the description of the contract. +func importAEContractValue(in *goblubl.Invoice, inv *bill.Invoice) { + if inv.Ordering == nil || len(inv.Ordering.Contracts) != len(in.ContractDocumentReference) { + return + } + for i, r := range in.ContractDocumentReference { + c := inv.Ordering.Contracts[i] + if v := cbc.Code(strings.TrimSpace(r.DocumentDescription)); c != nil && v != "" { + c.Ext = c.Ext.Set(pint.ExtKeyContractValue, v) + c.Description = "" + } + } +} + +// exportAEPayment completes the payment instructions gobl.ubl writes, which +// are the invoice's only ones, and the payment terms that go with them. +func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { + if len(out.PaymentMeans) == 0 || inv.Payment == nil { + return + } + pm := &out.PaymentMeans[0] + if instr := inv.Payment.Instructions; instr != nil { + if scheme := instr.Ext.Get(pint.ExtKeyRemittanceScheme).String(); scheme != "" && pm.PaymentID != nil { + pm.PaymentID.SchemeID = &scheme + } + if len(instr.CreditTransfer) > 0 { + exportAECreditTransfer(pm.PayeeFinancialAccount, instr.CreditTransfer[0]) + } + } + exportAEPaymentTerms(out, pm, inv) +} + +// importAERemittanceScheme reads the scheme of the remittance reference back +// (IBT-083-1). +func importAERemittanceScheme(in *goblubl.Invoice, inv *bill.Invoice) { + if len(in.PaymentMeans) == 0 || inv.Payment == nil || inv.Payment.Instructions == nil { + return + } + id := in.PaymentMeans[0].PaymentID + if id == nil || id.SchemeID == nil { + return + } + if scheme := cbc.Code(strings.TrimSpace(*id.SchemeID)); scheme != "" { + instr := inv.Payment.Instructions + instr.Ext = instr.Ext.Set(pint.ExtKeyRemittanceScheme, scheme) + } +} + +// exportAECreditTransfer writes the IBAN scheme of the payee account +// (IBT-084-1) and the address of its branch (IBT-169 to IBT-175). +// gobl.ubl already reads the address back. +func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfer) { + if acc == nil || ct == nil { + return + } + if acc.ID != nil && ct.IBAN != "" && acc.ID.Value == ct.IBAN.String() { + scheme := accountSchemeIBAN + acc.ID.SchemeID = &scheme + } + if addr := aeAddress(ct.Branch); addr != nil { + if acc.FinancialInstitutionBranch == nil { + acc.FinancialInstitutionBranch = new(goblubl.Branch) + } + acc.FinancialInstitutionBranch.Address = addr + } +} + +// aeAddress provides the UBL address of a GOBL one, with the lines gobl.ubl +// writes for a party's address. +func aeAddress(a *org.Address) *goblubl.PostalAddress { + if a == nil { + return nil + } + addr := new(goblubl.PostalAddress) + set := func(field **string, v string) { + if v != "" { + *field = &v + } + } + set(&addr.StreetName, a.LineOne()) + set(&addr.AdditionalStreetName, a.LineTwo()) + if l := a.LineThree(); l != "" { + addr.AddressLine = []goblubl.AddressLine{{Line: l}} + } + set(&addr.CityName, a.Locality) + set(&addr.PostalZone, a.Code.String()) + set(&addr.CountrySubentity, a.Region) + if a.Country != "" { + addr.Country = &goblubl.Country{IdentificationCode: a.Country.String()} + } + return addr +} + +// exportAEPaymentTerms writes the amount of the first due date and its date +// as the amount and installment due date of the payment terms (IBT-176, +// IBT-177), which refer to the payment instructions by their ID (IBT-187, +// IBT-178). gobl.ubl writes a single cac:PaymentTerms, so later due dates are +// left out, as they are from cbc:DueDate. A due date in another currency has +// no amount to write, as every amount is in the invoice's (IBR-126). +func exportAEPaymentTerms(out *goblubl.Invoice, pm *goblubl.PaymentMeans, inv *bill.Invoice) { + terms := inv.Payment.Terms + if terms == nil || len(terms.DueDates) == 0 { + return + } + dd := terms.DueDates[0] + def := inv.Currency.Def() + if dd == nil || dd.Date == nil || dd.Amount == nil || def == nil || + (dd.Currency != "" && dd.Currency != inv.Currency) { + return + } + if out.PaymentTerms == nil { + out.PaymentTerms = new(goblubl.PaymentTerms) + } + id := aePaymentMeansID + pm.ID = &id + amount := aeAmount(def.Rescale(*dd.Amount), inv.Currency) + out.PaymentTerms.PaymentMeansID = id + out.PaymentTerms.Amount = &amount + out.PaymentTerms.InstallmentDueDate = dd.Date.String() +} + +// aeChargeTaxes provides the taxes of the invoice's charges and discounts, in +// the order gobl.ubl writes their cac:AllowanceCharge. +func aeChargeTaxes(inv *bill.Invoice) []tax.Set { + sets := make([]tax.Set, 0, len(inv.Charges)+len(inv.Discounts)) + for _, c := range inv.Charges { + sets = append(sets, c.Taxes) + } + for _, d := range inv.Discounts { + sets = append(sets, d.Taxes) + } + return sets +} + +// exportAEChargeExemptions writes the UAE VAT exemption reason of the exempt +// charges and discounts as their cac:TaxCategory/cbc:TaxExemptionReasonCode +// (IBT-196, IBT-198). +func exportAEChargeExemptions(out *goblubl.Invoice, inv *bill.Invoice) { + sets := aeChargeTaxes(inv) + if len(sets) != len(out.AllowanceCharge) { + return + } + for i, set := range sets { + cats := out.AllowanceCharge[i].TaxCategory + if len(cats) != len(set) { + continue + } + for j, c := range set { + if code := c.Ext.Get(pint.ExtKeyExemption); code != "" && c.Category == tax.CategoryVAT { + v := code.String() + cats[j].TaxExemptionReasonCode = &v + } + } + } +} + +// importAEChargeExemptions reads the exemption reasons of the charges and +// discounts back onto their VAT combos. gobl.ubl imports the charges and the +// discounts apart, each in the order of the document. +func importAEChargeExemptions(in *goblubl.Invoice, inv *bill.Invoice) { + if len(in.AllowanceCharge) != len(inv.Charges)+len(inv.Discounts) { + return + } + var charges, discounts int + for _, ac := range in.AllowanceCharge { + var set tax.Set + if ac.ChargeIndicator { + set = inv.Charges[charges].Taxes + charges++ + } else { + set = inv.Discounts[discounts].Taxes + discounts++ + } + c := set.Get(tax.CategoryVAT) + if c == nil { + continue + } + for _, cat := range ac.TaxCategory { + if cat == nil || cat.TaxExemptionReasonCode == nil { + continue + } + if code := cbc.Code(strings.TrimSpace(*cat.TaxExemptionReasonCode)); code != "" { + c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + break + } + } + } +} + // identifiedParty returns a party with only a cac:PartyIdentification. func identifiedParty(id cbc.Code) *goblubl.Party { return &goblubl.Party{PartyIdentification: []goblubl.Identification{ @@ -253,8 +509,10 @@ func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { // exportAELineExemption writes the UAE VAT exemption reason of an exempt line // as its cac:ClassifiedTaxCategory/cbc:TaxExemptionReasonCode (IBT-186, -// IBR-167-AE). -func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line) { +// IBR-167-AE), and the text of the invoice's tax note for the line's VAT +// category as its cbc:TaxExemptionReason (IBT-185), the same note gobl.ubl +// writes on the category's VAT breakdown. Standard rated lines have no reason. +func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line, tx *bill.Tax) { if l == nil || line.Item == nil || line.Item.ClassifiedTaxCategory == nil { return } @@ -262,27 +520,65 @@ func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line) { if c == nil { return } + ctc := line.Item.ClassifiedTaxCategory if code := c.Ext.Get(pint.ExtKeyExemption); code != "" { v := code.String() - line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &v + ctc.TaxExemptionReasonCode = &v } + if tx == nil || c.Ext.Get(untdid.ExtKeyTaxCategory) == taxCategoryStandard { + return + } + if note := aeTaxNote(tx.Notes, c); note != nil { + ctc.TaxExemptionReason = ¬e.Text + } +} + +// aeTaxNote finds the tax note for a combo's category, the way gobl.ubl does +// for the VAT breakdowns: by tax category and UNTDID 5305 category code. +func aeTaxNote(notes []*tax.Note, c *tax.Combo) *tax.Note { + code := c.Ext.Get(untdid.ExtKeyTaxCategory) + if code == "" { + return nil + } + for _, n := range notes { + if n != nil && n.Category == c.Category && n.Ext.Get(untdid.ExtKeyTaxCategory) == code { + return n + } + } + return nil } // importAELineExemptions reads the line exemption reasons back onto the VAT -// combos of the invoice's lines, which gobl.ubl imports in the same order. +// combos of the invoice's lines, which gobl.ubl imports in the same order. A +// reason text becomes the tax note of the line's VAT category, unless the VAT +// breakdown already gave it one. func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return } for i, line := range lines { - if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || - line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode == nil { + c := inv.Lines[i].Taxes.Get(tax.CategoryVAT) + if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || c == nil { continue } - code := cbc.Code(strings.TrimSpace(*line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode)) - if c := inv.Lines[i].Taxes.Get(tax.CategoryVAT); c != nil && code != "" { - c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + ctc := line.Item.ClassifiedTaxCategory + if ctc.TaxExemptionReasonCode != nil { + if code := cbc.Code(strings.TrimSpace(*ctc.TaxExemptionReasonCode)); code != "" { + c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + } + } + if ctc.TaxExemptionReason == nil || strings.TrimSpace(*ctc.TaxExemptionReason) == "" { + continue } + code := c.Ext.Get(untdid.ExtKeyTaxCategory) + if code == "" || (inv.Tax != nil && aeTaxNote(inv.Tax.Notes, c) != nil) { + continue + } + inv.Tax = inv.Tax.MergeNotes(&tax.Note{ + Category: c.Category, + Text: strings.TrimSpace(*ctc.TaxExemptionReason), + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: code}), + }) } } @@ -354,15 +650,120 @@ func exportAELineItemType(line *goblubl.InvoiceLine, l *bill.Line) { } } -// importAELineGoods reads the type of goods or services back onto the items -// of the invoice's lines, which gobl.ubl imports in the same order. gobl.ubl -// already reads the GTIN as an identity. +// exportAELineSchemeVersions writes the scheme version of the item's +// identities that have one: as @listVersionID on their item classification +// code (IBT-158-2), or as @schemeVersionID on their additional item +// identification (BTAE-17-2), which is where the service accounting codes are +// by now. +func exportAELineSchemeVersions(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil || l.Item == nil || line.Item == nil { + return + } + for _, id := range l.Item.Identities { + if id == nil || id.Label == "" || id.Ext.Get(pint.ExtKeySchemeVersion) == "" { + continue + } + version := id.Ext.Get(pint.ExtKeySchemeVersion).String() + if line.Item.CommodityClassification != nil { + for _, cc := range *line.Item.CommodityClassification { + if c := cc.ItemClassificationCode; c != nil && c.ListID != nil && *c.ListID == id.Label && c.Value == id.Code.String() { + c.ListVersionID = &version + } + } + } + for _, ai := range line.Item.AdditionalItemIdentification { + if ai.ID != nil && ai.ID.SchemeID != nil && *ai.ID.SchemeID == id.Label && ai.ID.Value == id.Code.String() { + ai.ID.SchemeVersionID = &version + } + } + } +} + +// exportAELineBatch writes the item's batch number as its +// cac:ItemInstance/cac:LotIdentification/cbc:LotNumberID (BTAE-24). +func exportAELineBatch(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil || l.Item == nil || line.Item == nil { + return + } + if batch := l.Item.Ext.Get(pint.ExtKeyBatchNumber); batch != "" { + line.Item.ItemInstance = []goblubl.ItemInstance{ + {LotIdentification: &goblubl.LotIdentification{LotNumberID: batch.String()}}, + } + } +} + +// aeNoLineID stands for the line of an order or despatch advice when only +// the document is known, as UBL needs a line ID in a line reference. +const aeNoLineID = "NA" + +// exportAELineReferences writes the purchase order of a line as +// cac:OrderLineReference/cac:OrderReference/cbc:ID (IBT-183), next to the +// order line gobl.ubl writes, and its despatch advice as +// cac:DespatchLineReference/cac:DocumentReference/cbc:ID (IBT-184). +func exportAELineReferences(line *goblubl.InvoiceLine, l *bill.Line) { + if l == nil { + return + } + if po := l.Ext.Get(pint.ExtKeyPurchaseOrder); po != "" { + if line.OrderLineReference == nil { + line.OrderLineReference = &goblubl.OrderLineReference{LineID: aeNoLineID} + } + line.OrderLineReference.OrderReference = &goblubl.OrderReference{ID: po.String()} + } + if da := l.Ext.Get(pint.ExtKeyDespatchAdvice); da != "" { + line.DespatchLineReference = &goblubl.LineReference{ + LineID: aeNoLineID, + DocumentReference: &goblubl.Reference{ID: goblubl.IDType{Value: da.String()}}, + } + } +} + +// importAELineReferences reads the purchase order and despatch advice of each +// line back, on the lines gobl.ubl imports in the same order. An order line +// that only stands in for a missing one is dropped. +func importAELineReferences(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + if len(lines) != len(inv.Lines) { + return + } + for i, line := range lines { + l := inv.Lines[i] + if ref := line.OrderLineReference; ref != nil && ref.OrderReference != nil { + if po := cbc.Code(strings.TrimSpace(ref.OrderReference.ID)); po != "" { + l.Ext = l.Ext.Set(pint.ExtKeyPurchaseOrder, po) + if l.Order == aeNoLineID { + l.Order = "" + } + } + } + if ref := line.DespatchLineReference; ref != nil && ref.DocumentReference != nil { + if da := cbc.Code(strings.TrimSpace(ref.DocumentReference.ID.Value)); da != "" { + l.Ext = l.Ext.Set(pint.ExtKeyDespatchAdvice, da) + } + } + } +} + +// importAELineGoods reads the type of goods or services and the batch number +// back onto the items of the invoice's lines, which gobl.ubl imports in the +// same order. gobl.ubl already reads the GTIN as an identity. func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return } for i, line := range lines { - if line.Item == nil || line.Item.CommodityClassification == nil || inv.Lines[i].Item == nil { + if line.Item == nil || inv.Lines[i].Item == nil { + continue + } + for _, ii := range line.Item.ItemInstance { + if ii.LotIdentification == nil { + continue + } + if batch := cbc.Code(strings.TrimSpace(ii.LotIdentification.LotNumberID)); batch != "" { + inv.Lines[i].Item.Ext = inv.Lines[i].Item.Ext.Set(pint.ExtKeyBatchNumber, batch) + break + } + } + if line.Item.CommodityClassification == nil { continue } for _, cc := range *line.Item.CommodityClassification { @@ -377,9 +778,10 @@ func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// importAELineItems reads back what exportAELineSAC and exportAELineItemType -// write: the service accounting codes as identities with their scheme as -// label, and the item type as the item's key. +// importAELineItems reads back what exportAELineSAC, exportAELineItemType and +// exportAELineSchemeVersions write: the service accounting codes as +// identities with their scheme as label, the item type as the item's key, and +// the scheme versions on the identities of their codes. func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return @@ -397,11 +799,23 @@ func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if ai.ID.SchemeID != nil { id.Label = strings.TrimSpace(*ai.ID.SchemeID) } + setAESchemeVersion(id, ai.ID.SchemeVersionID) it.Identities = append(it.Identities, id) } if line.Item.CommodityClassification == nil { continue } + for _, cc := range *line.Item.CommodityClassification { + c := cc.ItemClassificationCode + if c == nil || c.ListID == nil { + continue + } + for _, id := range it.Identities { + if id != nil && id.Label == strings.TrimSpace(*c.ListID) && id.Code.String() == c.Value { + setAESchemeVersion(id, c.ListVersionID) + } + } + } for _, cc := range *line.Item.CommodityClassification { if cc.CommodityCode == nil { continue @@ -414,6 +828,15 @@ func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } +// setAESchemeVersion sets the scheme version of an item identity, when there +// is one. +func setAESchemeVersion(id *org.Identity, version *string) { + if version == nil || strings.TrimSpace(*version) == "" { + return + } + id.Ext = id.Ext.Set(pint.ExtKeySchemeVersion, cbc.Code(strings.TrimSpace(*version))) +} + // exportAEBillingFrequency writes the billing frequency as // cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl // writes from the ordering period, or on its own: IBR-CO-19 accepts a period @@ -497,10 +920,13 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { exportAELine(&lines[i]) if len(lines) == len(inv.Lines) { exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) - exportAELineExemption(&lines[i], inv.Lines[i]) + exportAELineExemption(&lines[i], inv.Lines[i], inv.Tax) exportAELineSAC(&lines[i]) exportAELineGoods(&lines[i], inv.Lines[i]) exportAELineItemType(&lines[i], inv.Lines[i]) + exportAELineSchemeVersions(&lines[i], inv.Lines[i]) + exportAELineBatch(&lines[i], inv.Lines[i]) + exportAELineReferences(&lines[i], inv.Lines[i]) } } } @@ -815,13 +1241,20 @@ func exportAETINScheme(out *goblubl.Party, p *org.Party) { } // exportAETaxTotal fixes the rates of the VAT breakdowns, and merges the ones -// left with the same category and rate. +// left with the same category and rate. The total with breakdowns, which is +// the one in the document currency, also says its prices don't include VAT +// (IBT-200). func exportAETaxTotal(tt *goblubl.TaxTotal) { for i := range tt.TaxSubtotal { c := &tt.TaxSubtotal[i].TaxCategory c.Percent = aeRate(c.ID, c.Percent) } tt.TaxSubtotal = mergeAETaxSubtotals(tt.TaxSubtotal) + if len(tt.TaxSubtotal) > 0 { + // gobl.ubl takes the taxes out of prices that include them. + included := false + tt.TaxIncludedIndicator = &included + } } // mergeAETaxSubtotals merges the VAT breakdowns with the same category and diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 43d533a..e93f1a7 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -6,6 +6,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cal" "github.com/invopop/gobl/catalogues/icc" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" @@ -14,6 +15,7 @@ import ( "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pay" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" "github.com/invopop/gobl/uuid" @@ -168,6 +170,13 @@ func TestExportAETaxTotal(t *testing.T) { require.Len(t, tt.TaxSubtotal, 2) assert.Equal(t, strPtr("5"), tt.TaxSubtotal[0].TaxCategory.Percent) assert.Nil(t, tt.TaxSubtotal[1].TaxCategory.Percent) + require.NotNil(t, tt.TaxIncludedIndicator) + assert.False(t, *tt.TaxIncludedIndicator) + + // The VAT total in AED has no breakdowns, and no indicator. + aed := &goblubl.TaxTotal{TaxAmount: aedAmount("5.00")} + exportAETaxTotal(aed) + assert.Nil(t, aed.TaxIncludedIndicator) } func TestExportAEPartyTaxID(t *testing.T) { @@ -626,16 +635,16 @@ func TestAELineExemption(t *testing.T) { t.Run("writes the exemption reason on the line", func(t *testing.T) { line := ublLine() - exportAELineExemption(&line, goblLine("DL8.46.2")) + exportAELineExemption(&line, goblLine("DL8.46.2"), nil) require.NotNil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) assert.Equal(t, "DL8.46.2", *line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) }) t.Run("nothing without a reason", func(t *testing.T) { line := ublLine() - exportAELineExemption(&line, goblLine("")) + exportAELineExemption(&line, goblLine(""), nil) assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) - exportAELineExemption(&line, nil) + exportAELineExemption(&line, nil, nil) assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) }) @@ -958,3 +967,402 @@ func TestExportAEExchangeRate(t *testing.T) { assert.Empty(t, out.AdditionalDocumentReference) }) } + +func TestExportAEIssueTime(t *testing.T) { + out := new(goblubl.Invoice) + exportAEIssueTime(out, &bill.Invoice{}) + assert.Empty(t, out.IssueTime) + + exportAEIssueTime(out, &bill.Invoice{IssueTime: cal.NewTime(17, 31, 0)}) + assert.Equal(t, "17:31:00", out.IssueTime) +} + +func TestAECustomsReference(t *testing.T) { + t.Run("writes the customs reference as the statement reference", func(t *testing.T) { + inv := &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyCustomsReference: "EXP010101234"})}} + out := new(goblubl.Invoice) + exportAECustomsReference(out, inv) + require.Len(t, out.StatementDocumentReference, 1) + assert.Equal(t, "EXP010101234", out.StatementDocumentReference[0].ID.Value) + }) + + t.Run("nothing without one", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAECustomsReference(out, &bill.Invoice{}) + assert.Empty(t, out.StatementDocumentReference) + }) + + t.Run("reads the first one back", func(t *testing.T) { + in := &goblubl.Invoice{StatementDocumentReference: []goblubl.Reference{ + {ID: goblubl.IDType{Value: " "}}, + {ID: goblubl.IDType{Value: " EXP010101234 "}}, + {ID: goblubl.IDType{Value: "EXP2"}}, + }} + inv := new(bill.Invoice) + importAECustomsReference(in, inv) + assert.Equal(t, cbc.Code("EXP010101234"), inv.Tax.GetExt(pint.ExtKeyCustomsReference)) + }) +} + +func TestExportAEContractValue(t *testing.T) { + inv := &bill.Invoice{Ordering: &bill.Ordering{Contracts: []*org.DocumentRef{ + {Code: "CT-1", Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyContractValue: "AED 200000"})}, + {Code: "CT-2", Description: "Framework agreement"}, + }}} + + t.Run("writes the value of each contract", func(t *testing.T) { + out := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{ + {ID: goblubl.IDType{Value: "CT-1"}}, + {ID: goblubl.IDType{Value: "CT-2"}}, + }} + exportAEContractValue(out, inv) + assert.Equal(t, "AED 200000", out.ContractDocumentReference[0].DocumentDescription) + assert.Empty(t, out.ContractDocumentReference[1].DocumentDescription) + }) + + t.Run("references that don't match are skipped", func(t *testing.T) { + out := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{{ID: goblubl.IDType{Value: "CT-1"}}}} + exportAEContractValue(out, inv) + assert.Empty(t, out.ContractDocumentReference[0].DocumentDescription) + exportAEContractValue(out, &bill.Invoice{}) + assert.Empty(t, out.ContractDocumentReference[0].DocumentDescription) + }) + + t.Run("reads it back from the description gobl.ubl imports", func(t *testing.T) { + in := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{ + {ID: goblubl.IDType{Value: "CT-1"}, DocumentDescription: " AED 200000 "}, + {ID: goblubl.IDType{Value: "CT-2"}}, + }} + got := &bill.Invoice{Ordering: &bill.Ordering{Contracts: []*org.DocumentRef{ + {Code: "CT-1", Description: "AED 200000"}, + {Code: "CT-2"}, + }}} + importAEContractValue(in, got) + assert.Equal(t, cbc.Code("AED 200000"), got.Ordering.Contracts[0].Ext.Get(pint.ExtKeyContractValue)) + assert.Empty(t, got.Ordering.Contracts[0].Description) + assert.True(t, got.Ordering.Contracts[1].Ext.IsZero()) + }) +} + +func TestExportAEPayment(t *testing.T) { + iban := cbc.Code("AE070331234567890123456") + ublInvoice := func() *goblubl.Invoice { + return &goblubl.Invoice{PaymentMeans: []goblubl.PaymentMeans{{ + PayeeFinancialAccount: &goblubl.FinancialAccount{ID: &goblubl.IDType{Value: iban.String()}}, + }}} + } + goblInvoice := func(ct *pay.CreditTransfer, dd *pay.DueDate) *bill.Invoice { + inv := &bill.Invoice{Currency: currency.AED, Payment: &bill.PaymentDetails{ + Instructions: &pay.Instructions{CreditTransfer: []*pay.CreditTransfer{ct}}, + }} + if dd != nil { + inv.Payment.Terms = &pay.Terms{DueDates: []*pay.DueDate{dd}} + } + return inv + } + amount := num.MakeAmount(105000, 2) + dueDate := func() *pay.DueDate { + return &pay.DueDate{Date: cal.NewDate(2025, 2, 6), Amount: &amount} + } + + t.Run("writes the IBAN scheme and the branch address", func(t *testing.T) { + out := ublInvoice() + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{ + IBAN: iban, + Branch: &org.Address{Street: "Baniyas Road", StreetExtra: "Deira", StreetThird: "Main Branch", Locality: "Dubai", Region: "DXB", Code: "777", Country: "AE"}, + }, nil)) + acc := out.PaymentMeans[0].PayeeFinancialAccount + assert.Equal(t, "IBAN", *acc.ID.SchemeID) + addr := acc.FinancialInstitutionBranch.Address + require.NotNil(t, addr) + assert.Equal(t, "Baniyas Road", *addr.StreetName) + assert.Equal(t, "Deira", *addr.AdditionalStreetName) + require.Len(t, addr.AddressLine, 1) + assert.Equal(t, "Main Branch", addr.AddressLine[0].Line) + assert.Equal(t, "Dubai", *addr.CityName) + assert.Equal(t, "DXB", *addr.CountrySubentity) + assert.Equal(t, "777", *addr.PostalZone) + assert.Equal(t, "AE", addr.Country.IdentificationCode) + assert.Nil(t, out.PaymentMeans[0].ID, "no terms to refer to the instructions") + assert.Nil(t, out.PaymentTerms) + }) + + t.Run("an account number has no scheme, and no branch no address", func(t *testing.T) { + out := ublInvoice() + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{Number: iban}, nil)) + acc := out.PaymentMeans[0].PayeeFinancialAccount + assert.Nil(t, acc.ID.SchemeID) + assert.Nil(t, acc.FinancialInstitutionBranch) + }) + + t.Run("writes the first due date as the terms of the instructions", func(t *testing.T) { + out := ublInvoice() + out.PaymentTerms = &goblubl.PaymentTerms{Note: "Net 15 days"} + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dueDate())) + assert.Equal(t, "1", *out.PaymentMeans[0].ID) + assert.Equal(t, "1", out.PaymentTerms.PaymentMeansID) + assert.Equal(t, "Net 15 days", out.PaymentTerms.Note) + assert.Equal(t, aedAmount("1050.00"), *out.PaymentTerms.Amount) + assert.Equal(t, "2025-02-06", out.PaymentTerms.InstallmentDueDate) + }) + + t.Run("no terms for a due date in another currency", func(t *testing.T) { + out := ublInvoice() + dd := dueDate() + dd.Currency = currency.USD + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dd)) + assert.Nil(t, out.PaymentTerms) + assert.Nil(t, out.PaymentMeans[0].ID) + }) + + t.Run("nothing without payment instructions", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dueDate())) + assert.Nil(t, out.PaymentTerms) + }) + + t.Run("writes the scheme of the remittance reference and reads it back", func(t *testing.T) { + out := ublInvoice() + out.PaymentMeans[0].PaymentID = &goblubl.IDType{Value: "REM-1"} + inv := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) + inv.Payment.Instructions.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyRemittanceScheme: "ABA"}) + exportAEPayment(out, inv) + assert.Equal(t, "ABA", *out.PaymentMeans[0].PaymentID.SchemeID) + + got := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) + importAERemittanceScheme(out, got) + assert.Equal(t, cbc.Code("ABA"), got.Payment.Instructions.Ext.Get(pint.ExtKeyRemittanceScheme)) + }) + + t.Run("no scheme without one on the reference", func(t *testing.T) { + out := ublInvoice() + out.PaymentMeans[0].PaymentID = &goblubl.IDType{Value: "REM-1"} + got := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) + exportAEPayment(out, got) + assert.Nil(t, out.PaymentMeans[0].PaymentID.SchemeID) + importAERemittanceScheme(out, got) + assert.True(t, got.Payment.Instructions.Ext.IsZero()) + }) +} + +func TestAELineReferences(t *testing.T) { + ext := tax.ExtensionsOf(cbc.CodeMap{ + pint.ExtKeyPurchaseOrder: "PO-1", + pint.ExtKeyDespatchAdvice: "DA-1", + }) + + t.Run("writes the purchase order next to the order line", func(t *testing.T) { + line := goblubl.InvoiceLine{OrderLineReference: &goblubl.OrderLineReference{LineID: "3"}} + exportAELineReferences(&line, &bill.Line{Order: "3", Ext: ext}) + assert.Equal(t, "3", line.OrderLineReference.LineID) + assert.Equal(t, "PO-1", line.OrderLineReference.OrderReference.ID) + assert.Equal(t, "NA", line.DespatchLineReference.LineID) + assert.Equal(t, "DA-1", line.DespatchLineReference.DocumentReference.ID.Value) + }) + + t.Run("without an order line, NA stands for it and is dropped on import", func(t *testing.T) { + line := goblubl.InvoiceLine{} + exportAELineReferences(&line, &bill.Line{Ext: ext}) + assert.Equal(t, "NA", line.OrderLineReference.LineID) + + inv := &bill.Invoice{Lines: []*bill.Line{{Order: "NA"}}} + importAELineReferences([]goblubl.InvoiceLine{line}, inv) + assert.Empty(t, inv.Lines[0].Order) + assert.Equal(t, cbc.Code("PO-1"), inv.Lines[0].Ext.Get(pint.ExtKeyPurchaseOrder)) + assert.Equal(t, cbc.Code("DA-1"), inv.Lines[0].Ext.Get(pint.ExtKeyDespatchAdvice)) + }) + + t.Run("nothing without the extensions", func(t *testing.T) { + line := goblubl.InvoiceLine{OrderLineReference: &goblubl.OrderLineReference{LineID: "3"}} + exportAELineReferences(&line, &bill.Line{Order: "3"}) + assert.Nil(t, line.OrderLineReference.OrderReference) + assert.Nil(t, line.DespatchLineReference) + + inv := &bill.Invoice{Lines: []*bill.Line{{Order: "3"}}} + importAELineReferences([]goblubl.InvoiceLine{line}, inv) + assert.Equal(t, cbc.Code("3"), inv.Lines[0].Order) + assert.True(t, inv.Lines[0].Ext.IsZero()) + }) +} + +func TestAEChargeExemptions(t *testing.T) { + combo := func(code cbc.Code) tax.Set { + c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} + if code != "" { + c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + } + return tax.Set{c} + } + category := func(code *string) []*goblubl.TaxCategory { + return []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: "E"}, TaxExemptionReasonCode: code}} + } + + t.Run("writes the reasons of the charges, then the discounts", func(t *testing.T) { + inv := &bill.Invoice{ + Charges: []*bill.Charge{{Taxes: combo("DL8.46.3")}}, + Discounts: []*bill.Discount{{Taxes: combo("")}, {Taxes: combo("DL8.46.1")}}, + } + out := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ + {ChargeIndicator: true, TaxCategory: category(nil)}, + {TaxCategory: category(nil)}, + {TaxCategory: category(nil)}, + }} + exportAEChargeExemptions(out, inv) + assert.Equal(t, "DL8.46.3", *out.AllowanceCharge[0].TaxCategory[0].TaxExemptionReasonCode) + assert.Nil(t, out.AllowanceCharge[1].TaxCategory[0].TaxExemptionReasonCode) + assert.Equal(t, "DL8.46.1", *out.AllowanceCharge[2].TaxCategory[0].TaxExemptionReasonCode) + }) + + t.Run("reads them back in the order of the document", func(t *testing.T) { + in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ + {TaxCategory: category(strPtr(" DL8.46.1 "))}, + {ChargeIndicator: true, TaxCategory: category(strPtr("DL8.46.3"))}, + {TaxCategory: category(nil)}, + }} + inv := &bill.Invoice{ + Charges: []*bill.Charge{{Taxes: combo("")}}, + Discounts: []*bill.Discount{{Taxes: combo("")}, {Taxes: combo("")}}, + } + importAEChargeExemptions(in, inv) + assert.Equal(t, cbc.Code("DL8.46.3"), inv.Charges[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Empty(t, inv.Discounts[1].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + }) + + t.Run("charges that don't match are skipped", func(t *testing.T) { + inv := &bill.Invoice{Discounts: []*bill.Discount{{Taxes: combo("DL8.46.1")}}} + out := new(goblubl.Invoice) + exportAEChargeExemptions(out, inv) + in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ + {TaxCategory: category(strPtr("DL8.46.2"))}, + {TaxCategory: category(strPtr("DL8.46.2"))}, + }} + importAEChargeExemptions(in, inv) + assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + }) +} + +func TestAELineExemptionReason(t *testing.T) { + ublLine := func(category string, reason *string) goblubl.InvoiceLine { + return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ + ID: &goblubl.IDType{Value: category}, TaxExemptionReason: reason, + }}} + } + goblLine := func(category cbc.Code) *bill.Line { + return &bill.Line{Taxes: tax.Set{{ + Category: tax.CategoryVAT, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), + }}} + } + note := func(category cbc.Code, text string) *tax.Note { + return &tax.Note{ + Category: tax.CategoryVAT, + Text: text, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), + } + } + + t.Run("writes the tax note of the line's category", func(t *testing.T) { + tx := &bill.Tax{Notes: []*tax.Note{note("O", "Out of scope"), note("E", "Exempt supply")}} + line := ublLine("E", nil) + exportAELineExemption(&line, goblLine("E"), tx) + require.NotNil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) + assert.Equal(t, "Exempt supply", *line.Item.ClassifiedTaxCategory.TaxExemptionReason) + }) + + t.Run("nothing on standard rated lines or without a note", func(t *testing.T) { + tx := &bill.Tax{Notes: []*tax.Note{note("S", "Standard"), note("O", "Out of scope")}} + line := ublLine("S", nil) + exportAELineExemption(&line, goblLine("S"), tx) + assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) + line = ublLine("E", nil) + exportAELineExemption(&line, goblLine("E"), tx) + assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) + }) + + t.Run("reads the text back as a tax note, once per category", func(t *testing.T) { + inv := &bill.Invoice{Lines: []*bill.Line{goblLine("E"), goblLine("E"), goblLine("O")}} + importAELineExemptions([]goblubl.InvoiceLine{ + ublLine("E", strPtr(" Exempt supply ")), + ublLine("E", strPtr("Another text")), + ublLine("O", strPtr(" ")), + }, inv) + require.Len(t, inv.Tax.Notes, 1) + assert.Equal(t, "Exempt supply", inv.Tax.Notes[0].Text) + assert.Equal(t, cbc.Code("E"), inv.Tax.Notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + }) +} + +func TestAELineSchemeVersions(t *testing.T) { + version := func(v cbc.Code) tax.Extensions { + return tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeySchemeVersion: v}) + } + hs, sac := pint.IdentityLabelHS, pint.IdentityLabelSAC + + t.Run("writes the versions of the classification and the service accounting code", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{ + CommodityClassification: &[]goblubl.CommodityClassification{ + {ItemClassificationCode: &goblubl.IDType{ListID: &hs, Value: "8471"}}, + {ItemClassificationCode: &goblubl.IDType{ListID: &hs, Value: "8472"}}, + }, + AdditionalItemIdentification: []goblubl.ItemIdentification{ + {ID: &goblubl.IDType{SchemeID: &sac, Value: "998713"}}, + }, + }} + exportAELineSchemeVersions(&line, &bill.Line{Item: &org.Item{Identities: []*org.Identity{ + {Label: hs, Code: "8471", Ext: version("2022")}, + {Label: hs, Code: "8472"}, + {Label: sac, Code: "998713", Ext: version("1.0")}, + }}}) + ccs := *line.Item.CommodityClassification + assert.Equal(t, "2022", *ccs[0].ItemClassificationCode.ListVersionID) + assert.Nil(t, ccs[1].ItemClassificationCode.ListVersionID) + assert.Equal(t, "1.0", *line.Item.AdditionalItemIdentification[0].ID.SchemeVersionID) + }) + + t.Run("reads them back onto the identities", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{ + CommodityClassification: &[]goblubl.CommodityClassification{ + {ItemClassificationCode: &goblubl.IDType{ListID: &hs, ListVersionID: strPtr("2022"), Value: "8471"}}, + }, + AdditionalItemIdentification: []goblubl.ItemIdentification{ + {ID: &goblubl.IDType{SchemeID: &sac, SchemeVersionID: strPtr("1.0"), Value: "998713"}}, + }, + }} + inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{Identities: []*org.Identity{ + {Label: hs, Code: "8471"}, + }}}}} + importAELineItems([]goblubl.InvoiceLine{line}, inv) + ids := inv.Lines[0].Item.Identities + require.Len(t, ids, 2) + assert.Equal(t, cbc.Code("2022"), ids[0].Ext.Get(pint.ExtKeySchemeVersion)) + assert.Equal(t, cbc.Code("1.0"), ids[1].Ext.Get(pint.ExtKeySchemeVersion)) + }) +} + +func TestAELineBatch(t *testing.T) { + t.Run("writes the batch number as the lot of the item", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{}} + exportAELineBatch(&line, &bill.Line{Item: &org.Item{ + Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBatchNumber: "Lot 1"}), + }}) + require.Len(t, line.Item.ItemInstance, 1) + assert.Equal(t, "Lot 1", line.Item.ItemInstance[0].LotIdentification.LotNumberID) + }) + + t.Run("nothing without one", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{}} + exportAELineBatch(&line, &bill.Line{Item: &org.Item{}}) + assert.Empty(t, line.Item.ItemInstance) + }) + + t.Run("reads it back onto the item", func(t *testing.T) { + line := goblubl.InvoiceLine{Item: &goblubl.Item{ItemInstance: []goblubl.ItemInstance{ + {}, + {LotIdentification: &goblubl.LotIdentification{LotNumberID: " Lot 1 "}}, + }}} + inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}}} + importAELineGoods([]goblubl.InvoiceLine{line}, inv) + assert.Equal(t, cbc.Code("Lot 1"), inv.Lines[0].Item.Ext.Get(pint.ExtKeyBatchNumber)) + }) +} diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index af89414..df5a9d5 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "23e53f589a01745b5f143024c155aab5cfffe3d7dde315db14d9e2010d087f8f" + "val": "f0ababc9a1fd7c623843f86a3080c78e604f19ac09e7f897f635bd4200537aa7" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,7 +26,17 @@ "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" - } + }, + "notes": [ + { + "cat": "VAT", + "key": "exempt", + "text": "Exempt supplies under Article 46 of the VAT Decree-Law", + "ext": { + "untdid-tax-category": "E" + } + } + ] }, "supplier": { "name": "Supplier Legal Name", @@ -176,6 +186,7 @@ "cat": "VAT", "key": "exempt", "ext": { + "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" } } @@ -251,7 +262,7 @@ "peppol-pint-ae-exemption": "DL8.46.1", "untdid-tax-category": "E" }, - "base": "200.00", + "base": "180.00", "amount": "0.00" }, { @@ -262,14 +273,6 @@ }, "base": "300.00", "amount": "0.00" - }, - { - "key": "exempt", - "ext": { - "untdid-tax-category": "E" - }, - "base": "-20.00", - "amount": "0.00" } ], "amount": "51.50" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index b69b44c..84f2b71 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c1db9b2b5408c9cd5003607a40aa9064f8646d1b93142c3160a5b377f2d200e4" + "val": "30dccb1572e21e3ffb318e67dc6b88365d2d44b95c63016891ade597d552d792" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -29,6 +29,7 @@ "currency": "AED", "tax": { "ext": { + "peppol-pint-ae-customs-reference": "EXP010101234", "peppol-pint-ae-transaction-type": "00010011", "untdid-document-type": "380" } @@ -111,7 +112,10 @@ "name": "Item Name", "description": "Item Description", "price": "10.00", - "unit": "one" + "unit": "one", + "ext": { + "peppol-pint-ae-batch-number": "Lot 1" + } }, "sum": "1000.00", "taxes": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index ae8defc..ba291ee 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7cfd4d6b98f5f8ea0aa7f2ca217d9da989ccc452cb2a1e36da5f8951b1736c48" + "val": "cb58009cd95794150a1bcab16d35d9dd80f36424eef9a5db32c0dc57ad876d89" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -115,11 +115,17 @@ "identities": [ { "label": "HS", - "code": "8471" + "code": "8471", + "ext": { + "peppol-pint-ae-scheme-version": "1.0" + } }, { "label": "SAC", - "code": "998713" + "code": "998713", + "ext": { + "peppol-pint-ae-scheme-version": "1.0" + } } ], "description": "Item Description", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 4ee0a50..3ff2ca1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "0b91eaea84879790f911f34a1b0114903a0385b08cb3ab3c4246ad1013199467" + "val": "4f32717773093a08859eef8d28e6943ae35954b73442128d36133ab3c82b0f93" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -21,6 +21,7 @@ "series": "AE", "code": "001", "issue_date": "2025-01-30", + "issue_time": "17:31:00", "currency": "AED", "tax": { "ext": { @@ -57,6 +58,8 @@ "addresses": [ { "street": "Sheikh Zayed Road", + "street_extra": "Trade Centre", + "street_third": "Tower 2, Office 1405", "locality": "Dubai", "region": "DXB", "country": "AE" @@ -102,6 +105,7 @@ { "i": 1, "quantity": "100", + "cost": "CS-024", "item": { "name": "Item Name", "description": "Item Description", @@ -119,9 +123,23 @@ } } ], - "total": "1000.00" + "total": "1000.00", + "ext": { + "peppol-pint-ae-despatch-advice": "DA-2025-031", + "peppol-pint-ae-purchase-order": "PO-2025-118" + } } ], + "ordering": { + "contracts": [ + { + "code": "CT-2025-014", + "ext": { + "peppol-pint-ae-contract-value": "AED 200000" + } + } + ] + }, "payment": { "terms": { "key": "due-date", @@ -135,13 +153,24 @@ }, "instructions": { "key": "credit-transfer", + "ref": "INV-REM-0042", "credit_transfer": [ { "iban": "AE070331234567890123456", - "name": "Emirates NBD" + "bic": "EBILAEAD", + "name": "Emirates NBD", + "branch": { + "street": "Baniyas Road", + "street_extra": "Deira", + "street_third": "Main Branch", + "locality": "Dubai", + "code": "777", + "country": "AE" + } } ], "ext": { + "peppol-pint-ae-remittance-scheme": "ABA", "untdid-payment-means": "30" } } diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml index 64e7362..10f9a6f 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml @@ -75,12 +75,13 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD 0.00 + false 1000.00 0.00 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml index eb3b9be..d48993d 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml @@ -75,12 +75,13 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml index 973f1c0..f7d41c6 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -69,12 +69,13 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index e192bda..75fa8d0 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -75,12 +75,13 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 555a189..9d89ab6 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -71,14 +71,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1050.00 + 2025-02-06 + 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml index 5c25d69..2a2507e 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -68,6 +68,7 @@ 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index 997d6fa..af76299 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -65,12 +65,18 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1561.50 + 2025-02-06 + true Delivery @@ -91,6 +97,8 @@ E 0 + DL8.46.1 + Exempt supplies under Article 46 of the VAT Decree-Law VAT @@ -98,6 +106,7 @@ 51.50 + false 1030.00 51.50 @@ -114,6 +123,7 @@ 0.00 E + Exempt supplies under Article 46 of the VAT Decree-Law VAT @@ -169,6 +179,7 @@ E DL8.46.1 + Exempt supplies under Article 46 of the VAT Decree-Law VAT @@ -197,6 +208,7 @@ E DL8.46.2 + Exempt supplies under Article 46 of the VAT Decree-Law VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index b895765..a176df8 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -16,6 +16,9 @@ NA + + EXP010101234 + 1357902467 @@ -93,14 +96,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1000.00 + 2025-02-06 + 0.00 + false 1000.00 0.00 @@ -133,6 +143,11 @@ VAT + + + Lot 1 + + 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index 1a71000..ed82e06 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -79,14 +79,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1050.00 + 2025-02-06 + 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 7d7c930..d2357ed 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -65,14 +65,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1000.00 + 2025-02-06 + 0.00 + false 1000.00 0.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 5824303..23aaaa4 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -65,14 +65,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1000.00 + 2025-02-06 + 0.00 + false 1000.00 0.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 8ef9592..f042f6e 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -65,12 +65,18 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 975.00 + 2025-02-06 + true Handling @@ -97,6 +103,7 @@ 0.00 + false 975.00 0.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 87b7d8b..acec5aa 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -65,14 +65,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1000.00 + 2025-02-06 + 0.00 + false 1000.00 0.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml index 4a3273a..d9c1010 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -65,14 +65,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1050.00 + 2025-02-06 + 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index d49676f..26cb177 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -71,14 +71,21 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1050.00 + 2025-02-06 + 50.00 + false 1000.00 50.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 8baea1a..586dafe 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -71,12 +71,18 @@ + 1 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + 1 + 1769.99 + 2025-02-06 + USD AED @@ -84,6 +90,7 @@ 50.00 + false 1000.00 50.00 @@ -145,11 +152,11 @@ Item Description Item Name - 998713 + 998713 B - 8471 + 8471 S diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index d3ac622..d849216 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -6,12 +6,17 @@ AE-001 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 2025-01-30 + 17:31:00 2025-02-06 380 AED NA + + CT-2025-014 + AED 200000 + 1357902467 @@ -20,8 +25,12 @@ Sheikh Zayed Road + Trade Centre Dubai DXB + + Tower 2, Office 1405 + AE @@ -65,14 +74,37 @@ + 1 30 + INV-REM-0042 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD + + EBILAEAD + + Baniyas Road + Deira + Dubai + 777 + + Main Branch + + + AE + + + + + 1 + 1050.00 + 2025-02-06 + 50.00 + false 1000.00 50.00 @@ -95,6 +127,19 @@ 1 100 1000.00 + CS-024 + + NA + + PO-2025-118 + + + + NA + + DA-2025-031 + + Item Description Item Name diff --git a/ubl/testdata/parse/bis/out/Allowance-example.json b/ubl/testdata/parse/bis/out/Allowance-example.json index 10c60ea..2e675c4 100644 --- a/ubl/testdata/parse/bis/out/Allowance-example.json +++ b/ubl/testdata/parse/bis/out/Allowance-example.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2ac7756b37527bdb78d4162d8299a74c4a3f5139ef22446415cab69975670eb6" + "val": "5ecdc65beee6ae2bfab266e14e5a17eb7b6f2230ec9fa774d641b63b057e26f1" } }, "doc": { @@ -417,6 +417,7 @@ { "street": "Delivery street 2", "street_extra": "Building 56", + "street_third": "Gate 15", "locality": "Stockholm", "region": "Södermalm", "code": "21234", diff --git a/ubl/testdata/parse/bis/out/Vat-category-S.json b/ubl/testdata/parse/bis/out/Vat-category-S.json index cf44327..9a3844e 100644 --- a/ubl/testdata/parse/bis/out/Vat-category-S.json +++ b/ubl/testdata/parse/bis/out/Vat-category-S.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "dbaf58495e23c1d5e9d59cc877518b5428c3eacb9600aa11f71d3ea10c1dfc74" + "val": "f1af5ad8508725dbb280bb4b5d4b4528830786117f5d41b5e2f2c4a4cfad74c0" } }, "doc": { @@ -325,6 +325,7 @@ { "street": "Delivery street 2", "street_extra": "Building 56", + "street_third": "Gate 15", "locality": "Stockholm", "region": "Södermalm", "code": "21234", diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index 0148988..abe452c 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "9e57d5483072fed836f83f859561c7773d1af56c36fffdc23f09d500c4664726" + "val": "750a5aeb7b61cdb0e7684cce2c9bb5d964c883a235ef611e4987e4d46801f061" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:1012345678" @@ -134,7 +134,10 @@ "identities": [ { "label": "HS", - "code": "88098432" + "code": "88098432", + "ext": { + "peppol-pint-ae-scheme-version": "1.0" + } }, { "label": "SAC", diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index d87acb2..b047df3 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2c687f4fb4aa859cb11f90134e1b82c7d771a05edf109d1e90dfbd8ac7405002" + "val": "4ccaf2567c4378cb75d067ea0e75eeb335b5f8ecd0daa5d2ab6e97ff5cba8efc" }, "from": "iso6523-actorid-upis::0235:112345678900003", "to": "iso6523-actorid-upis::0235:112345679000003" @@ -62,6 +62,7 @@ { "street": "Street Name", "street_extra": "Additional Street Name", + "street_third": "Additional Address line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", @@ -113,6 +114,7 @@ { "street": "Street Name", "street_extra": "Additional Street Name", + "street_third": "Additional Address Line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index f675d1d..414c9b6 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "07fe54e846c66905b22ad743cdc69254c0e8b99c3e3321c9b9648d9d4109dad1" + "val": "d5bd0299239dc50f49c03c6be1025562f72afecf17f41023bbdfb198d3c2b1ec" }, "from": "iso6523-actorid-upis::0235:1278906543", "to": "iso6523-actorid-upis::0235:1347809543" @@ -137,7 +137,10 @@ }, { "label": "HS", - "code": "88098432324" + "code": "88098432324", + "ext": { + "peppol-pint-ae-scheme-version": "1.0" + } } ], "description": "Item Description", diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 2239177..8861caa 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5a6f8c9c4e0e231e1a56bcabfce971c936a555443c4d345b7f7470c46cdbed06" + "val": "806a60879d8335f8fbd46177ba7c24efcdc17b2bcbedea28c9ffdd94ea28677d" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:1789012345" @@ -135,7 +135,10 @@ "identities": [ { "label": "HS", - "code": "112233" + "code": "112233", + "ext": { + "peppol-pint-ae-scheme-version": "1.0" + } } ], "description": "Item Description", From 08b568ae38bb132e2c884e1182a4e983cad0c06a Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:31:12 +0000 Subject: [PATCH 30/73] Cover the fields PINT AE shares with EN 16931 in a fixture The AE fixtures left out the VAT point date, allowance and charge base amounts and percentages on the document and lines, the tax representative, the payee, and the delivery location and date, which PINT AE rules check (IBR-124-AE, IBR-131-AE, IBR-142-AE and others) or the AE export changes, as the tax representative's TRN. The new e-commerce invoice has them all, with the third address line of the buyer, the tax representative and the delivery address. Co-Authored-By: Claude Opus 5.5 --- .../pint/ae/invoice-ae-shared-fields.json | 318 ++++++++++++++++++ .../pint/ae/out/invoice-ae-shared-fields.xml | 280 +++++++++++++++ 2 files changed, 598 insertions(+) create mode 100644 ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json create mode 100644 ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json new file mode 100644 index 0000000..ca74a50 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -0,0 +1,318 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "9e26744bf9188c49cc2d4b584ba703e5f24e0d50f0aab605e34e05e6c4419983" + }, + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "e-commerce" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "series": "AE", + "code": "SF-001", + "issue_date": "2025-01-30", + "issue_time": "17:31:00", + "value_date": "2025-01-28", + "currency": "AED", + "tax": { + "ext": { + "peppol-pint-ae-transaction-type": "00000010", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246700003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902467" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902467" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "street_extra": "Trade Centre", + "street_third": "Tower 2, Office 1405", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890600003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678906" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678906" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "street_extra": "Al Bateen", + "street_third": "Building 7, Floor 3", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Office Chair", + "description": "Ergonomic office chair", + "price": "200.00", + "unit": "one" + }, + "sum": "2000.00", + "discounts": [ + { + "reason": "Loyalty discount", + "percent": "10%", + "amount": "200.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Assembly", + "percent": "5%", + "amount": "100.00", + "ext": { + "untdid-charge": "ABL" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1900.00" + }, + { + "i": 2, + "quantity": "4", + "item": { + "name": "Desk Lamp", + "description": "LED desk lamp", + "price": "50.00", + "unit": "one" + }, + "sum": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "200.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Early order discount", + "base": "2100.00", + "percent": "2%", + "amount": "42.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Handling", + "base": "2100.00", + "percent": "1%", + "amount": "21.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "ABL" + } + } + ], + "ordering": { + "seller": { + "name": "Tax Representative LLC", + "tax_id": { + "country": "AE", + "code": "124681357800003" + }, + "addresses": [ + { + "street": "Al Maktoum Road", + "street_extra": "Deira", + "street_third": "Office 210", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + } + }, + "payment": { + "payee": { + "name": "Payee Collections LLC", + "identities": [ + { + "scope": "legal", + "code": "112345679100002" + } + ] + }, + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-28", + "amount": "2182.95", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Payee Collections LLC" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "delivery": { + "receiver": { + "name": "Buyer Warehouse", + "addresses": [ + { + "street": "Industrial Area 4", + "street_extra": "Musaffah", + "street_third": "Gate 3", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "date": "2025-01-27" + }, + "totals": { + "sum": "2100.00", + "discount": "42.00", + "charge": "21.00", + "total": "2079.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "2079.00", + "percent": "5%", + "amount": "103.95" + } + ], + "amount": "103.95" + } + ], + "sum": "103.95" + }, + "tax": "103.95", + "total_with_tax": "2182.95", + "payable": "2182.95" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml new file mode 100644 index 0000000..61e0382 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -0,0 +1,280 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000010 + AE-SF-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-01-30 + 17:31:00 + 2025-02-28 + 380 + 2025-01-28 + AED + + NA + + + + 1357902467 + + Supplier Legal Name + + + Sheikh Zayed Road + Trade Centre + Dubai + DXB + + Tower 2, Office 1405 + + + AE + + + + 135790246700003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678906 + + Buyer Legal Name + + + Corniche Road + Al Bateen + Abu Dhabi + AUH + + Building 7, Floor 3 + + + AE + + + + 134567890600003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + + Payee Collections LLC + + + 112345679100002 + + + + + Tax Representative LLC + + + Al Maktoum Road + Deira + Dubai + DXB + + Office 210 + + + AE + + + + 124681357800003 + + VAT + + + + Tax Representative LLC + + + + 2025-01-27 + + + Industrial Area 4 + Musaffah + Abu Dhabi + AUH + + Gate 3 + + + AE + + + + + + Buyer Warehouse + + + Buyer Warehouse + + + + + 1 + 30 + + AE070331234567890123456 + Payee Collections LLC + + + + 1 + 2182.95 + 2025-02-28 + + + true + ABL + Handling + 1 + 21.00 + 2100.00 + + S + 5 + + VAT + + + + + false + 95 + Early order discount + 2 + 42.00 + 2100.00 + + S + 5 + + VAT + + + + + 103.95 + false + + 2079.00 + 103.95 + + S + 5 + + VAT + + + + + + 2100.00 + 2079.00 + 2182.95 + 42.00 + 21.00 + 2182.95 + + + 1 + 10 + 1900.00 + + true + ABL + Assembly + 5 + 100.00 + 2000.00 + + + false + 95 + Loyalty discount + 10 + 200.00 + 2000.00 + + + Ergonomic office chair + Office Chair + + S + 5 + + VAT + + + + + 200.00 + 1 + + false + 0.00 + 200.00 + + + + 1995.00 + + 95.00 + + + + + 2 + 4 + 200.00 + + LED desk lamp + Desk Lamp + + S + 5 + + VAT + + + + + 50.00 + 1 + + false + 0.00 + 50.00 + + + + 210.00 + + 10.00 + + + + \ No newline at end of file From 6a20e3ac7a044b16b34c862a6fc4fb7bbe80d40d Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:26:44 +0000 Subject: [PATCH 31/73] Pin gobl and gobl.ubl to the latest PINT AE dependency PRs gobl#1033 now has the AE identity types and street_third, and gobl.ubl#189 the remaining UBL 2.1 elements PINT uses and the third address line. Move both pins back to releases once those PRs are merged and released. Co-Authored-By: Claude Opus 5.5 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index bafff28..e0f326a 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c + github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a + github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 014ab98..83aa1f2 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c h1:qbKm7vBSVax4ug8ye+MTr1FXWtw1Vr5xgqEZwZeA4cY= -github.com/invopop/gobl v0.512.1-0.20261112191836-3cb493151c2c/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f h1:Exyp3CihjuBUfIMoFrQ1mkS0pzyctY/WBkXYngXklhs= +github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a h1:hqRURd3RsrOZV/BXBUuLGFbR1s/5fBrCH4F20h59u+4= -github.com/invopop/gobl.ubl v0.101.1-0.20261112165045-06d037d9e05a/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0 h1:FpoPCrhTR24Q8A/hytulvLuNzqj2puULSIHXmct1ABU= +github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0/go.mod h1:Tags5dHiwT56Rd+GJAZpl3dbFQFP1VqKAhJFhvSjPFc= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From 37ff625a7466da6a366ac7cfefc9d64d6cc5a1ec Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:50:23 +0000 Subject: [PATCH 32/73] Pin gobl and gobl.ubl to the restacked PINT AE dependency PRs The generic changes moved to their own PRs, gobl#1039 (street_third) and gobl.ubl#192 (line accounting reference and third address line), with gobl#1033 and gobl.ubl#189 stacked on them. Pin the tips of the stacks, which have everything this PR needs. Co-Authored-By: Claude Opus 5.5 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e0f326a..a2c2f9e 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f + github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97 github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0 + github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 83aa1f2..9cc9f67 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f h1:Exyp3CihjuBUfIMoFrQ1mkS0pzyctY/WBkXYngXklhs= -github.com/invopop/gobl v0.512.1-0.20261116161619-77ca482df08f/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97 h1:bLcRxjeewZPe+s7aGvwDPcvYyUuB3/p4Y9h7t/RID1E= +github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0 h1:FpoPCrhTR24Q8A/hytulvLuNzqj2puULSIHXmct1ABU= -github.com/invopop/gobl.ubl v0.101.1-0.20261116162512-0a66b7d763d0/go.mod h1:Tags5dHiwT56Rd+GJAZpl3dbFQFP1VqKAhJFhvSjPFc= +github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409 h1:30/QNaUOF0torj4y4qwHp6QvziFjqULo6QhLWQFhekY= +github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From ffbf486c029178b6733f739a4d1a62fa76ad8831 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:10:15 +0000 Subject: [PATCH 33/73] Pin gobl and gobl.ubl to the Copilot review fixes gobl#1033 now rejects TINs whose business identifier is all zeros and leaves informative charges out of BR-37, and gobl.ubl#189 keeps a payee account that only has a branch address. Co-Authored-By: Claude Opus 5.5 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index a2c2f9e..63e5f49 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97 + github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409 + github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 9cc9f67..f28b581 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97 h1:bLcRxjeewZPe+s7aGvwDPcvYyUuB3/p4Y9h7t/RID1E= -github.com/invopop/gobl v0.512.1-0.20261116163947-711d4de67e97/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 h1:X2GKnrdzIRsC0qU8zCHw+X8lbsQhFoXmHRlgewlZYIc= +github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409 h1:30/QNaUOF0torj4y4qwHp6QvziFjqULo6QhLWQFhekY= -github.com/invopop/gobl.ubl v0.101.1-0.20261116164458-86041da87409/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= +github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e h1:IQT4w69ofUw/Rtg5dthTgZhUu8VppF35q2cGj3Ayf34= +github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From 9a0ae656356d8aca6b1deb47416ff8ae97c88068 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:47:34 +0000 Subject: [PATCH 34/73] Merge AE VAT breakdowns whose rates differ only in how they are written FormatAE merged breakdowns of the same category and rate, but compared the rates as text, so a Z breakdown at "0" and another at "0.0" stayed apart and broke ALIGNED-IBRP-Z-01. Compare the rates by value. Co-Authored-By: Claude Opus 5.5 --- ubl/ae.go | 17 ++++++++++++++++- ubl/ae_internal_test.go | 9 +++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ubl/ae.go b/ubl/ae.go index 035f641..c83b4ef 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1289,7 +1289,7 @@ func mergeAETaxSubtotals(subtotals []goblubl.TaxSubtotal) []goblubl.TaxSubtotal func indexAETaxSubtotal(list []goblubl.TaxSubtotal, c goblubl.TaxCategory) int { for i, st := range list { if sameID(st.TaxCategory.ID, c.ID) && - sameString(st.TaxCategory.Percent, c.Percent) && + samePercent(st.TaxCategory.Percent, c.Percent) && sameScheme(st.TaxCategory.TaxScheme, c.TaxScheme) { return i } @@ -1304,6 +1304,21 @@ func sameID(a, b *goblubl.IDType) bool { return a.Value == b.Value } +// samePercent compares two rates by value, so that "0" and "0.0" are the +// same rate and their breakdowns are merged (ALIGNED-IBRP-Z-01 and the other +// one-breakdown-per-category rules). +func samePercent(a, b *string) bool { + if a == nil || b == nil { + return a == b + } + x, errA := num.AmountFromString(*a) + y, errB := num.AmountFromString(*b) + if errA != nil || errB != nil { + return *a == *b + } + return x.Equals(y) +} + func sameString(a, b *string) bool { if a == nil || b == nil { return a == b diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index e93f1a7..d36d33d 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -159,6 +159,15 @@ func TestMergeAETaxSubtotals(t *testing.T) { out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{standard, zero}) assert.Len(t, out, 2) }) + + t.Run("merges rates written differently (ALIGNED-IBRP-Z-01)", func(t *testing.T) { + zero := func(base, pc string) goblubl.TaxSubtotal { + return goblubl.TaxSubtotal{TaxableAmount: aedAmount(base), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("Z", strPtr(pc))} + } + out := mergeAETaxSubtotals([]goblubl.TaxSubtotal{zero("10.00", "0"), zero("20.00", "0.0")}) + require.Len(t, out, 1) + assert.Equal(t, "30.00", out[0].TaxableAmount.Value) + }) } func TestExportAETaxTotal(t *testing.T) { From fbab21f7f32f4e1b042ae158368c858b3b126cdb Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:58:53 +0000 Subject: [PATCH 35/73] Require a supplier TIN for a customer tax ID that isn't under VAT IBR-133-AE only allows tax schemes other than VAT when the seller has a TIN. A customer tax ID from a regime with another scheme, such as GST in Australia, Singapore or India, is written under that scheme, so it now needs a supplier TIN too, as customer tax scope identities already did (rule 19). The official exports example sends such a buyer's number as its electronic address and legal identifier instead. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 30 ++++++++++++++++++++++-------- addon/pint/bill_test.go | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index a228ab2..fa50747 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -151,8 +151,8 @@ func billInvoiceRules() *rules.Set { is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), ), ), - rules.Assert("19", "customer tax scope identities require a supplier TIN (IBR-133-AE)", - is.Func("customer tax scope identities with supplier TIN", customerTaxIdentitiesHaveSupplierTIN), + rules.Assert("19", "customer tax registrations other than VAT require a supplier TIN (IBR-133-AE)", + is.Func("customer non-VAT tax registrations with supplier TIN", customerNonVATTaxRegistrationsHaveSupplierTIN), ), // AE tax representative and issuer @@ -658,21 +658,35 @@ func invoiceHasDueDate(val any) bool { return false } -// customerTaxIdentitiesHaveSupplierTIN reports whether the supplier has a tax -// scope identity, the TIN (IBT-032), whenever the customer has one. gobl.ubl -// writes a customer tax scope identity under a tax scheme other than VAT, -// which PINT AE only allows when the seller has a TIN (IBR-133-AE). -func customerTaxIdentitiesHaveSupplierTIN(val any) bool { +// customerNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier +// has a tax scope identity, the TIN (IBT-032), whenever the customer has a tax +// registration that gobl.ubl writes under a tax scheme other than VAT: a tax +// scope identity, or a tax ID from a regime with another scheme, such as GST +// in Australia. PINT AE only allows those when the seller has a TIN +// (IBR-133-AE). The official exports example sends a foreign buyer's tax +// number as its electronic address and legal identifier instead. +func customerNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { return false } - if inv.Customer == nil || partyTaxIdentityCount(inv.Customer) == 0 { + c := inv.Customer + if c == nil || (partyTaxIdentityCount(c) == 0 && !partyTaxIDIsNotVAT(c)) { return true } return inv.Supplier != nil && partyTaxIdentityCount(inv.Supplier) > 0 } +// partyTaxIDIsNotVAT reports whether the party has a tax ID code whose scheme +// is not VAT. gobl.ubl writes a tax ID without a scheme under VAT. +func partyTaxIDIsNotVAT(p *org.Party) bool { + if p.TaxID == nil || p.TaxID.Code == "" { + return false + } + scheme := p.TaxID.GetScheme() + return scheme != "" && scheme != tax.CategoryVAT +} + // invoiceHasInvoicePeriod reports whether the invoice has what is written as // cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's // text asks for the invoicing period, but its test only checks the element diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 826abf6..95e36df 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -818,6 +818,24 @@ func TestBillIdentityRulesAE(t *testing.T) { &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) }) + + t.Run("customer tax ID under GST needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + // The scheme is set here as these tests don't register the AU regime, + // which gives AU tax IDs the GST scheme. + inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} + assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) + assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + }) + + t.Run("customer tax ID under VAT needs no supplier TIN", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} + assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + }) } func TestBillTransactionTypeRulesAE(t *testing.T) { From 7992b92b47be29603282c4b802a455637eccd52d Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:58:53 +0000 Subject: [PATCH 36/73] Use currency rounding on UAE invoices PINT sends each line amount rounded to the currency, and each VAT breakdown must equal the sum of its lines (ALIGNED-IBRP-S-08 and the other breakdown rules). With GOBL's default precise rule the breakdown is the sum of the unrounded lines: 12 lines of 0.3335 x 10.00 are sent as 3.34 each, 40.08 in all, against a 40.02 breakdown. The PINT addon now gives UAE invoices without a rounding rule the currency one. The AE fixtures gain the rule; no amount changes. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 17 +++++++++ addon/pint/bill_test.go | 38 +++++++++++++++++++ addon/pint/pint.go | 1 + examples/out/invoice-ae.json | 3 +- .../pint/ae/credit-note-ae-outside-scope.json | 3 +- .../pint/ae/credit-note-ae-self-billed.json | 3 +- .../ae/credit-note-ae-volume-discount.json | 3 +- .../convert/pint/ae/credit-note-ae.json | 3 +- .../pint/ae/invoice-ae-continuous-supply.json | 3 +- .../pint/ae/invoice-ae-deemed-supply.json | 3 +- .../convert/pint/ae/invoice-ae-exempt.json | 3 +- .../pint/ae/invoice-ae-export-summary.json | 3 +- .../ae/invoice-ae-free-trade-zone-agent.json | 3 +- .../pint/ae/invoice-ae-margin-scheme.json | 3 +- .../pint/ae/invoice-ae-outside-scope.json | 3 +- .../invoice-ae-reverse-charge-allowance.json | 3 +- .../pint/ae/invoice-ae-reverse-charge.json | 3 +- .../pint/ae/invoice-ae-self-billed.json | 3 +- .../pint/ae/invoice-ae-shared-fields.json | 3 +- .../pint/ae/invoice-ae-tin-passport.json | 3 +- .../convert/pint/ae/invoice-ae-usd.json | 3 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 3 +- 22 files changed, 94 insertions(+), 19 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index fa50747..b2e1a83 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -687,6 +687,23 @@ func partyTaxIDIsNotVAT(p *org.Party) bool { return scheme != "" && scheme != tax.CategoryVAT } +// normalizeRounding gives UAE invoices without a rounding rule the currency +// one. PINT sends each line amount rounded to the currency, and each VAT +// breakdown must equal the sum of its lines (ALIGNED-IBRP-S-08 and the other +// breakdown rules). With the default precise rule, the breakdown is the sum +// of the unrounded lines, which can differ by a few cents. +func normalizeRounding(inv *bill.Invoice) { + if inv == nil { + return + } + if inv.Tax == nil { + inv.Tax = new(bill.Tax) + } + if inv.Tax.Rounding == "" { + inv.Tax.Rounding = tax.RoundingRuleCurrency + } +} + // invoiceHasInvoicePeriod reports whether the invoice has what is written as // cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's // text asks for the invoicing period, but its test only checks the element diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 95e36df..82c33e7 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -838,6 +838,44 @@ func TestBillIdentityRulesAE(t *testing.T) { }) } +func TestNormalizeRounding(t *testing.T) { + t.Run("AE invoices get the currency rule", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + assert.Equal(t, tax.RoundingRuleCurrency, inv.Tax.Rounding) + }) + + t.Run("a rule set on the invoice is kept", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Tax = &bill.Tax{Rounding: tax.RoundingRulePrecise} + require.NoError(t, inv.Calculate()) + assert.Equal(t, tax.RoundingRulePrecise, inv.Tax.Rounding) + }) + + t.Run("lines and VAT breakdown add up", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard) + line := inv.Lines[0] + line.Quantity = num.MakeAmount(3335, 4) + line.Item.Price = num.NewAmount(1000, 2) + inv.Lines = nil + for i := 0; i < 12; i++ { + l := *line + inv.Lines = append(inv.Lines, &l) + } + require.NoError(t, inv.Calculate()) + assert.Equal(t, "40.08", inv.Totals.Sum.String()) + assert.Equal(t, "40.08", inv.Totals.Taxes.Categories[0].Rates[0].Base.String()) + }) + + t.Run("other regimes keep the default", func(t *testing.T) { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + require.NoError(t, inv.Calculate()) + if inv.Tax != nil { + assert.Empty(t, inv.Tax.Rounding) + } + }) +} + func TestBillTransactionTypeRulesAE(t *testing.T) { const ( faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 46f3697..d3839ca 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -53,6 +53,7 @@ func init() { norm.When( is.InContext(tax.RegimeIn(regimesAE...)), norm.For(normalizeTransactionType), + norm.For(normalizeRounding), norm.For(normalizeIdentityScopes), norm.For(normalizeTaxComboAE), ), diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index ee9f961..efdc6f3 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "0b91eaea84879790f911f34a1b0114903a0385b08cb3ab3c4246ad1013199467" + "val": "cb23ddfc55e8643654f9c6adc73a72b65ab885128bec511bd3de620b4f0af22a" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json index 3e8638b..8d8125e 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "baa8ed80869a93e121817a8640f164d23d16ee174f89822632db7bb7234a9e02" + "val": "3a431eac1384de1fea831158c59bca26dc40761b586b27b5bb1943cbf169859a" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -32,6 +32,7 @@ } ], "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json index 2e9c212..170f9de 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "842faf54e5939bac0c57b4212d090d8bcd242cb65db4ef0f7cc11f2f7fdc2747" + "val": "f5eec2c2922021f63a877e11dfdf1735d639118e099c0691b52d4b18978cbfe2" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -32,6 +32,7 @@ } ], "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json index 4c29827..56f79f2 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "52d4086677c93bf74c9c94617add823e6f5e780a8d92bf7fb14cd1809f0bfc95" + "val": "dd609e84e97665d69c7ae82639d359f36460682972e78d17aba5e4d926c96b25" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "VD", "peppol-pint-ae-transaction-type": "00000000", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index 24fa077..a14b08f 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2e11036fa7fc2bc6b0682805970c47d21831ef47e83328bee0db86cd992bb6cd" + "val": "c5e60d8847b7be4c53b9295b201d1a1c7bb4fbb8711f566ae14e06ba8d3ea298" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -29,6 +29,7 @@ } ], "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index c2b91c7..5dc17a2 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "985eee20b45f61cfe7c415ed98a4c3b24a49e2903fe66b07d8d8c528a4d821a5" + "val": "abb82a8714a0db36b7d0a8d6e7b2888d12391bb43d40ad2bf99d9913ae148a79" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,6 +26,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-billing-frequency": "OTH", "peppol-pint-ae-transaction-type": "00001000", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index bfeefa1..aa5e449 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "18c6f843194b5be40eff98de27a2043d1206ead85d68b9e1cf608a33c4dab19e" + "val": "fe39c4389ff3c50db52fc45ac4444a44a8ff0642f9d32fdb3799c01b76d1bb5a" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,6 +26,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "01000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index df5a9d5..dad3af5 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f0ababc9a1fd7c623843f86a3080c78e604f19ac09e7f897f635bd4200537aa7" + "val": "18bc57c6da55d0b030eb734989fdc6832eb18582db33a67a9374f76734fe7300" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 84f2b71..8fab8b6 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "30dccb1572e21e3ffb318e67dc6b88365d2d44b95c63016891ade597d552d792" + "val": "aebc8acc4f386c67a51b974e8f5cc0f0c1abd4e056255c72c2f221f57dfec748" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -28,6 +28,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-customs-reference": "EXP010101234", "peppol-pint-ae-transaction-type": "00010011", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json index 052498f..c02fc91 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "016c7342a30b6b87221f503da670459250853149de967a0d2a0e39798a3083f7" + "val": "71e2dfa98d40f6c76e25623b60de2e97612c8ef4efbf76a39bd765d98ec1d34c" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -27,6 +27,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-beneficiary-id": "189098765401003", "peppol-pint-ae-principal-id": "155667745601003", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index df7bd39..2cbb3bf 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "bd5de76ffd6980841addc3244bb18245dc98014e422d067060c067ab9b400b5f" + "val": "f13e3cb01d05f1866639b7b62f6a99125529f38856cb3527108749e3928be43b" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,6 +26,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00100000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index c527aea..dee0094 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4674931caa19d438c9cb6e57b0f2c774256c9c37cf05b4c037a07443d3a823d0" + "val": "b0e8d5cf4ad8f98b0612581b762e5eb87ff0e399c8e0e4b1118eaed6651174b8" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,6 +26,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "480" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 0803ac2..fff42c6 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "43164b973a340e425d2aa18319d664b1d9a76e7bc70738716dd76e7d8cb4ef03" + "val": "b85ca28bacdafd0b5e34f9f5462ade76d1b685cd6ac09ed060012a3e154c7f8e" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 28403de..8aa2bff 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "af1671d0b7c35d2a5b4ed4da78904b8880c18cd5ed43bd6a1f02e7270d5d5309" + "val": "815e6543badbe3ca4c442dfe0c9601e41d65dc83eccfe4fbb5c5cb8c69059e14" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json index b27d5df..aad0ce1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e0d90f542504f5df1381f56b0cfc8971014f3cdfe9db441f28c5bc32d4fcbf0e" + "val": "e8d615b6e0d5515c1af87ab6ea363577379e21176423242106d2d7a72303ac24" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -26,6 +26,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "389" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index ca74a50..bbbda68 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "9e26744bf9188c49cc2d4b584ba703e5f24e0d50f0aab605e34e05e6c4419983" + "val": "14c06bfb428554fe2b384e85f4d9eba22850ae9cd5cfc8e334830caf3ede3a2e" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -28,6 +28,7 @@ "value_date": "2025-01-28", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000010", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index 04790a1..569e1c9 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "459f5560212a0ba47252606e4ed8a9d1fc7a12161388dd6f33e54797d2cbd8f2" + "val": "2b7e494e361bc3474671b5556c44fe4530a97eaefeba8d773c2b52caa1c40cea" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,6 +23,7 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index ba291ee..3cc5b1b 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "cb58009cd95794150a1bcab16d35d9dd80f36424eef9a5db32c0dc57ad876d89" + "val": "d60f1147f35580e51db8bfced20d1426f497ec2b8220512578741804484f9730" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -30,6 +30,7 @@ } ], "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 3ff2ca1..0f50859 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4f32717773093a08859eef8d28e6943ae35954b73442128d36133ab3c82b0f93" + "val": "139a5d40d4f5ff439072a65bbabc517e0c70b7e83020ab63c2a3ba4197ddb8c7" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -24,6 +24,7 @@ "issue_time": "17:31:00", "currency": "AED", "tax": { + "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" From 00c518f4f5a13ed70c9f8201ad475781f72ecef8 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:41:21 +0000 Subject: [PATCH 37/73] Write the Incoterms scheme on the AE delivery terms The syntax binding requires @schemeID on cac:DeliveryTerms/cbc:ID (BTAE-22), and the official examples write schemeID="Incoterms". Pin gobl.ubl to the commit that lets the delivery terms ID hold it. Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- ubl/ae.go | 13 ++++++++++--- ubl/ae_internal_test.go | 15 +++++++++------ .../pint/ae/out/invoice-ae-export-summary.xml | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 63e5f49..1b23bf3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 require ( github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e + github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index f28b581..bee913f 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 h1:X2GKnrdzIRsC0q github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e h1:IQT4w69ofUw/Rtg5dthTgZhUu8VppF35q2cGj3Ayf34= -github.com/invopop/gobl.ubl v0.101.1-0.20261116170757-9838ba00853e/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= +github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= +github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= diff --git a/ubl/ae.go b/ubl/ae.go index c83b4ef..efa7e43 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -47,6 +47,10 @@ const taxSchemeTIN = "TIN" // (IBT-084-1), as the official examples do. const accountSchemeIBAN = "IBAN" +// deliveryTermsSchemeIncoterms is the scheme of the Incoterms code (BTAE-22), +// which the syntax binding requires and the official examples write. +const deliveryTermsSchemeIncoterms = "Incoterms" + // aePaymentMeansID identifies the invoice's payment instructions (IBT-178), so // that its payment terms can refer to them (IBT-187). GOBL has a single set of // instructions, so it needs no ID of its own. @@ -868,7 +872,7 @@ func importAEBillingFrequency(in *goblubl.Invoice, inv *bill.Invoice) { // exportAEIncoterms writes the delivery's Incoterms rule code, from the ICC // Incoterms 2020 or 2010 extension, as cac:Delivery/cac:DeliveryTerms/cbc:ID -// (BTAE-22). +// (BTAE-22) under the Incoterms scheme. func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Delivery == nil { return @@ -883,7 +887,10 @@ func exportAEIncoterms(out *goblubl.Invoice, inv *bill.Invoice) { if len(out.Delivery) == 0 { out.Delivery = []*goblubl.Delivery{{}} } - out.Delivery[0].DeliveryTerms = []goblubl.DeliveryTerms{{ID: code.String()}} + scheme := deliveryTermsSchemeIncoterms + out.Delivery[0].DeliveryTerms = []goblubl.DeliveryTerms{ + {ID: goblubl.IDType{SchemeID: &scheme, Value: code.String()}}, + } } // importAEIncoterms reads the delivery terms back as the ICC Incoterms 2020 @@ -893,7 +900,7 @@ func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { if len(in.Delivery) == 0 || in.Delivery[0] == nil || len(in.Delivery[0].DeliveryTerms) == 0 { return } - code := cbc.Code(strings.TrimSpace(in.Delivery[0].DeliveryTerms[0].ID)) + code := cbc.Code(strings.TrimSpace(in.Delivery[0].DeliveryTerms[0].ID.Value)) if code == "" { return } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index d36d33d..194a6dc 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -827,20 +827,23 @@ func TestAEIncoterms(t *testing.T) { exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) require.Len(t, out.Delivery, 1) require.Len(t, out.Delivery[0].DeliveryTerms, 1) - assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID) + id := out.Delivery[0].DeliveryTerms[0].ID + assert.Equal(t, "CIF", id.Value) + require.NotNil(t, id.SchemeID) + assert.Equal(t, "Incoterms", *id.SchemeID) }) t.Run("also from the 2010 edition", func(t *testing.T) { out := new(goblubl.Invoice) exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2010, "DAT")) - assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms[0].ID) + assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms[0].ID.Value) }) t.Run("on the delivery gobl.ubl wrote", func(t *testing.T) { out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: "5790000436101"}}}}} exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) require.Len(t, out.Delivery, 1) - assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID) + assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID.Value) assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) }) @@ -853,21 +856,21 @@ func TestAEIncoterms(t *testing.T) { }) t.Run("reads the Incoterms back as the 2020 edition", func(t *testing.T) { - in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: " CIF "}}}}} + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: goblubl.IDType{Value: " CIF "}}}}}} inv := new(bill.Invoice) importAEIncoterms(in, inv) require.NotNil(t, inv.Delivery) assert.Equal(t, cbc.Code("CIF"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) // DAT is only in the 2010 edition. - in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: "DAT"}}}}} + in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: goblubl.IDType{Value: "DAT"}}}}}} inv = new(bill.Invoice) importAEIncoterms(in, inv) assert.Equal(t, cbc.Code("DAT"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2010)) assert.Empty(t, inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) // A code in neither edition is kept under the current one. - in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: "XYZ"}}}}} + in = &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: goblubl.IDType{Value: "XYZ"}}}}}} inv = new(bill.Invoice) importAEIncoterms(in, inv) assert.Equal(t, cbc.Code("XYZ"), inv.Delivery.Ext.Get(icc.ExtKeyIncoterms2020)) diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index a176df8..f727652 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -92,7 +92,7 @@ - CIF + CIF From ae425e86f829a62b71ba7efe6d402de97c7a1f82 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:16:36 +0000 Subject: [PATCH 38/73] Map the AE margin scheme from the regime tag and exempt lines The ae regime drops its margin-scheme VAT key for a margin-scheme tag with exempt lines. With the tag, exempt lines get the N category, and the regime's statement note gets N so it goes out as the N breakdown's exemption reason. Imports read N back as exempt with the tag. Adds a margin scheme credit note to the convert and parse fixtures. Co-Authored-By: Claude Opus 5.5 --- README.md | 25 +- addon/pint/bill.go | 2 +- addon/pint/bill_test.go | 104 ++++++-- addon/pint/pint.go | 11 +- addon/pint/tax_combo.go | 43 +++- addon/pint/tax_combo_test.go | 60 ++++- addon/pint/transaction_type.go | 9 +- go.mod | 2 +- go.sum | 4 +- ubl/ae.go | 15 +- ubl/ae_internal_test.go | 9 +- .../pint/ae/credit-note-ae-margin-scheme.json | 204 +++++++++++++++ .../pint/ae/invoice-ae-margin-scheme.json | 18 +- .../ae/out/credit-note-ae-margin-scheme.xml | 147 +++++++++++ .../pint/ae/out/invoice-ae-margin-scheme.xml | 2 + .../pint/ae/margin-scheme-credit-note.xml | 162 ++++++++++++ .../ae/out/margin-scheme-credit-note.json | 232 ++++++++++++++++++ .../parse/pint/ae/out/margin-scheme.json | 18 +- ubl/ubl_test.go | 22 +- 19 files changed, 1018 insertions(+), 71 deletions(-) create mode 100644 ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json create mode 100644 ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml create mode 100644 ubl/testdata/parse/pint/ae/margin-scheme-credit-note.xml create mode 100644 ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json diff --git a/README.md b/README.md index 1498fec..19ad0e0 100644 --- a/README.md +++ b/README.md @@ -120,10 +120,24 @@ credit note reason as `cac:DiscrepancyResponse`, the billing frequency in item's type of goods or services subject to the reverse charge as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and -identities labelled `SAC` are written as service accounting codes. Lines -with the AE regime's `margin-scheme` VAT key get the `N` category at 5%, with -no VAT amount, and the delivery's ICC Incoterms (`icc-incoterms-2020` or -`-2010`) are written as the delivery terms. +identities labelled `SAC` are written as service accounting codes. The +delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the +delivery terms. + +**Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's +`margin-scheme` tag, with the `exempt` VAT key on every line: + +- Issue one invoice per margin scheme sale, with no other VAT treatments and + no document-level discounts or charges (IBR-116-AE). +- The lines go out in the `N` category at 5%, with no VAT amount. +- The statement that VAT is charged under the scheme, which the regime's + scenario adds as a VAT note, goes out as the VAT exemption reason text of + the `N` breakdown and lines. +- The margin VAT is reported in the VAT return, not on the invoice. + +Without the tag, `exempt` lines are a normal exempt supply (`E`). Anyone +reading GOBL data must identify margin scheme lines by the tag together with +the `exempt` key, never by the key alone. It also writes the PINT fields gobl.ubl leaves out: the issue time; the customs reference number (`peppol-pint-ae-customs-reference`) as @@ -147,7 +161,8 @@ identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and -the `N` category back as the `margin-scheme` key, and the delivery terms back +the `N` category back as the `exempt` key with the `margin-scheme` tag, and +the delivery terms back as the `icc-incoterms-2020` extension, and the seller and buyer electronic addresses as endpoints, and the customs reference, discount and charge exemption reasons, line exemption reason texts, batch numbers, scheme diff --git a/addon/pint/bill.go b/addon/pint/bill.go index b2e1a83..36edee6 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -353,7 +353,7 @@ func billInvoiceRules() *rules.Set { // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("41", "margin scheme invoice must only use the margin scheme VAT key (IBR-116-AE)", + rules.Assert("41", "margin scheme invoice must only have exempt lines, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 82c33e7..be904b1 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -1197,48 +1197,115 @@ func TestBillExemptionRulesAE(t *testing.T) { func TestBillMarginSchemeRulesAE(t *testing.T) { const ( - faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" - faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" + faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" + faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) - inv.Lines[0].Taxes = tax.Set{lineCombo(ae.TaxKeyMarginScheme)} + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyExempt)} return inv } + statements := func(inv *bill.Invoice) []*tax.Note { + var notes []*tax.Note + for _, n := range inv.Tax.Notes { + if n.Key == pint.TagMarginScheme { + notes = append(notes, n) + } + } + return notes + } + marginCombo := func() *tax.Combo { + return &tax.Combo{ + Category: tax.CategoryVAT, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: pint.TaxCategoryMarginScheme}), + } + } - t.Run("margin scheme lines are N without VAT", func(t *testing.T) { + t.Run("exempt lines are N without VAT", func(t *testing.T) { inv := margin(pint.TagMarginScheme) assert.Empty(t, aeFaults(t, inv)) c := inv.Lines[0].Taxes[0] assert.Equal(t, pint.TaxCategoryMarginScheme, c.Ext.Get(untdid.ExtKeyTaxCategory)) assert.Nil(t, c.Percent) assert.True(t, inv.Totals.Tax.IsZero()) + assert.Equal(t, inv.Totals.Sum.String(), inv.Totals.Payable.String()) + assert.Equal(t, cbc.Code("00100000"), inv.Tax.GetExt(pint.ExtKeyTransactionType)) }) - t.Run("discounts and charges can't be margin scheme (IBR-115-AE, IBR-114-AE)", func(t *testing.T) { + t.Run("adds one statement linked to N", func(t *testing.T) { + inv := margin(pint.TagMarginScheme) + require.NoError(t, inv.Calculate()) + notes := statements(inv) + require.Len(t, notes, 1) + assert.Equal(t, pint.TaxCategoryMarginScheme, notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + + require.NoError(t, inv.Calculate()) + assert.Len(t, statements(inv), 1) + }) + + t.Run("an imported statement isn't added again", func(t *testing.T) { + inv := margin(pint.TagMarginScheme) + inv.Tax = &bill.Tax{Notes: []*tax.Note{{ + Category: tax.CategoryVAT, + Text: "VAT charged under the Profit Margin Scheme", + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: pint.TaxCategoryMarginScheme}), + }}} + require.NoError(t, inv.Calculate()) + notes := statements(inv) + require.Len(t, notes, 1) + assert.Len(t, inv.Tax.Notes, 1) + }) + + t.Run("exempt lines without the tag stay E", func(t *testing.T) { inv := margin() - inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(ae.TaxKeyMarginScheme)}}} - inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(ae.TaxKeyMarginScheme)}}} - out := aeFaults(t, inv) - assert.Contains(t, out, faultDiscount) - assert.Contains(t, out, faultCharge) + assert.Contains(t, aeFaults(t, inv), faultLineExemption) + assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + assert.Empty(t, statements(inv)) + }) - inv = aeDocument(bill.InvoiceTypeStandard) + t.Run("removing the tag maps the lines back to E", func(t *testing.T) { + inv := margin(pint.TagMarginScheme) + require.NoError(t, inv.Calculate()) + inv.Tags = tax.Tags{} + require.NoError(t, inv.Calculate()) + assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + }) + + t.Run("discounts and charges can't be margin scheme (IBR-115-AE, IBR-114-AE)", func(t *testing.T) { + // The normalizers only give N to lines, so only a category set + // directly gets here. + ctx := []rules.WithContext{tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())} + d := &bill.Discount{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{marginCombo()}} + assert.ErrorContains(t, rules.Validate(d, ctx...), faultDiscount) + c := &bill.Charge{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{marginCombo()}} + assert.ErrorContains(t, rules.Validate(c, ctx...), faultCharge) + + inv := aeDocument(bill.InvoiceTypeStandard) inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(tax.KeyStandard)}}} - out = aeFaults(t, inv) + out := aeFaults(t, inv) assert.NotContains(t, out, faultDiscount) }) - t.Run("margin scheme invoices only use the margin scheme key (IBR-116-AE)", func(t *testing.T) { + t.Run("margin scheme invoices only have exempt lines (IBR-116-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagMarginScheme) assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) inv = margin(pint.TagMarginScheme) - inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(tax.KeyStandard)}}} + inv.Lines = append(inv.Lines, &bill.Line{ + Quantity: num.MakeAmount(1, 0), + Item: &org.Item{Name: "Watch strap", Description: "Leather strap", Price: num.NewAmount(1000, 2)}, + Taxes: tax.Set{standardVAT()}, + }) assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) - assert.NotContains(t, aeFaults(t, margin()), faultOnlyMargin, "N lines don't need the tag") + for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyStandard} { + inv = margin(pint.TagMarginScheme) + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(key)}}} + inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(key)}}} + assert.Contains(t, aeFaults(t, inv), faultOnlyMargin, key) + } }) } @@ -1266,6 +1333,11 @@ func TestBillTagsOutsideAE(t *testing.T) { t.Run("other documents can't use the PINT AE tags", func(t *testing.T) { for _, tag := range aeTags { inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tag) + if tag == pint.TagMarginScheme { + // The UAE regime defines it, so GOBL rejects it first. + assert.ErrorContains(t, inv.Calculate(), "'margin-scheme' undefined") + continue + } assert.Contains(t, faults(t, inv), faultTags, tag) } }) diff --git a/addon/pint/pint.go b/addon/pint/pint.go index d3839ca..297d034 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -55,7 +55,8 @@ func init() { norm.For(normalizeTransactionType), norm.For(normalizeRounding), norm.For(normalizeIdentityScopes), - norm.For(normalizeTaxComboAE), + norm.For(normalizeMarginSchemeAE), + norm.For(normalizeMarginSchemeNoteAE), ), ) } @@ -98,6 +99,14 @@ func newV1Addon() *tax.AddonDef { UAE invoices get the PINT AE transaction type from their tags: "free-trade-zone", "deemed-supply", "margin-scheme", "summary", "continuous-supply", "disclosed-agent", "e-commerce" and "export". + + A UAE supply under the profit margin scheme takes the regime's + "margin-scheme" tag, with the "exempt" VAT key on every line. Issue + one invoice per sale, with no other VAT treatments and no + document-level discounts or charges. The lines get the PINT AE + category "N", written at 5% with no VAT amount, and the regime's + statement goes out as the VAT exemption reason of the "N" breakdown. + The margin VAT is reported in the VAT return. `), }, Sources: []*cbc.Source{ diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 24548ec..94a4ae9 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -2,10 +2,10 @@ package pint import ( "github.com/invopop/gobl/addons/eu/en16931" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/num" - "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/rules/is" "github.com/invopop/gobl/tax" @@ -62,11 +62,42 @@ func normalizeTaxCombo(tc *tax.Combo) { } } -// normalizeTaxComboAE maps the AE regime's margin scheme key to the PINT AE -// margin scheme category on UAE documents. -func normalizeTaxComboAE(tc *tax.Combo) { - if tc != nil && tc.Key == ae.TaxKeyMarginScheme { - tc.Ext = tc.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) +// normalizeMarginSchemeAE gives the PINT AE margin scheme category to the +// exempt VAT lines of a UAE margin scheme invoice. The line combos already have +// E from their key, as norm reaches them before the invoice, and get it back +// once the tag is removed. Discounts and charges are left alone, so the +// discount and charge rules 02 and rule 41 reject them (IBR-114-AE, +// IBR-115-AE, IBR-116-AE). +func normalizeMarginSchemeAE(inv *bill.Invoice) { + if inv == nil || !inv.HasTags(TagMarginScheme) { + return + } + for _, l := range inv.Lines { + if l == nil { + continue + } + for _, c := range l.Taxes { + if c != nil && c.Category == tax.CategoryVAT && c.Key == tax.KeyExempt { + c.Ext = c.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) + } + } + } +} + +// normalizeMarginSchemeNoteAE links the regime's margin scheme statement to +// the margin scheme category, so it goes out as the reason on the N VAT +// breakdown. It is a note normalizer because the scenario adds the note after +// the invoice is normalized. The reverse mapping gives the key back to an +// imported statement, so the scenario doesn't add a second one. +func normalizeMarginSchemeNoteAE(n *tax.Note) { + if n == nil || n.Category != tax.CategoryVAT { + return + } + if n.Key.IsEmpty() && n.Ext.Get(untdid.ExtKeyTaxCategory) == TaxCategoryMarginScheme { + n.Key = TagMarginScheme + } + if n.Key == TagMarginScheme { + n.Ext = n.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) } } diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index 013e2b8..ce32d05 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -5,12 +5,12 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/addons/eu/en16931" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/norm" "github.com/invopop/gobl/num" - aeregime "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" @@ -63,14 +63,56 @@ func TestTaxComboNormalization(t *testing.T) { assert.Equal(t, "S", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) }) - t.Run("margin scheme maps to N only on UAE documents", func(t *testing.T) { - c := &tax.Combo{Category: tax.CategoryVAT, Key: aeregime.TaxKeyMarginScheme} - norm.Normalize(c, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.AE.Tax())) - assert.Equal(t, "N", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) + t.Run("exempt lines map to N only on UAE margin scheme invoices", func(t *testing.T) { + normalized := func(regime l10n.TaxCountryCode) *bill.Invoice { + inv := &bill.Invoice{ + Tags: tax.WithTags(pint.TagMarginScheme), + Lines: []*bill.Line{{Taxes: tax.Set{{Category: tax.CategoryVAT, Key: tax.KeyExempt}}}}, + Tax: &bill.Tax{Notes: []*tax.Note{{ + Category: tax.CategoryVAT, + Key: pint.TagMarginScheme, + Text: "VAT charged under the Profit Margin Scheme", + }}}, + } + norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) + return inv + } + + inv := normalized(l10n.AE.Tax()) + assert.Equal(t, "N", inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory).String()) + assert.Equal(t, "N", inv.Tax.Notes[0].Ext.Get(untdid.ExtKeyTaxCategory).String()) + + inv = normalized(l10n.SG.Tax()) + assert.Equal(t, "E", inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory).String()) + assert.Empty(t, inv.Tax.Notes[0].Ext) + }) +} + +func TestMarginSchemeNoteNormalizationAE(t *testing.T) { + normalize := func(n *tax.Note) { + norm.Normalize(n, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.AE.Tax())) + } + + t.Run("the statement gets the N category", func(t *testing.T) { + n := &tax.Note{Category: tax.CategoryVAT, Key: pint.TagMarginScheme, Text: "VAT charged under the Profit Margin Scheme"} + normalize(n) + assert.Equal(t, "N", n.Ext.Get(untdid.ExtKeyTaxCategory).String()) + }) + + t.Run("an N note without a key gets the margin scheme key", func(t *testing.T) { + n := &tax.Note{ + Category: tax.CategoryVAT, + Text: "VAT charged under the Profit Margin Scheme", + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: "N"}), + } + normalize(n) + assert.Equal(t, pint.TagMarginScheme, n.Key) + }) - c = &tax.Combo{Category: tax.CategoryVAT, Key: aeregime.TaxKeyMarginScheme} - norm.Normalize(c, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.SG.Tax())) - assert.NotEqual(t, "N", c.Ext.Get(untdid.ExtKeyTaxCategory).String()) + t.Run("other notes are left alone", func(t *testing.T) { + n := &tax.Note{Category: tax.CategoryVAT, Key: tax.KeyReverseCharge, Text: "Reverse Charge"} + normalize(n) + assert.Equal(t, "AE", n.Ext.Get(untdid.ExtKeyTaxCategory).String()) }) } @@ -133,7 +175,7 @@ func TestTaxComboRulesAE(t *testing.T) { } assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) - assert.NoError(t, validateIn(vatCombo(aeregime.TaxKeyMarginScheme, "N", nil), ae)) + assert.NoError(t, validateIn(vatCombo(tax.KeyExempt, "N", nil), ae)) }) t.Run("margin scheme category is rejected outside AE", func(t *testing.T) { diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index 85063a6..0809f8a 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -4,6 +4,7 @@ import ( "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/i18n" + "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" ) @@ -16,7 +17,8 @@ const ( // consideration. TagDeemedSupply cbc.Key = "deemed-supply" // TagMarginScheme marks a supply of goods under the profit margin scheme. - TagMarginScheme cbc.Key = "margin-scheme" + // The UAE regime defines it, with the statement the invoice must carry. + TagMarginScheme = ae.TagMarginScheme // TagSummary marks a summary invoice: more than one supply to the same // person in the same calendar month. TagSummary cbc.Key = "summary" @@ -144,11 +146,6 @@ var transactionTypeTags = []*cbc.Definition{ Name: i18n.String{i18n.EN: "Deemed Supply"}, Desc: i18n.String{i18n.EN: "PINT AE: supply of goods or services without consideration."}, }, - { - Key: TagMarginScheme, - Name: i18n.String{i18n.EN: "Profit Margin Scheme"}, - Desc: i18n.String{i18n.EN: "PINT AE: supply of goods under the profit margin scheme."}, - }, { Key: TagSummary, Name: i18n.String{i18n.EN: "Summary Invoice"}, diff --git a/go.mod b/go.mod index 1b23bf3..ac761de 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 + github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5 github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index bee913f..53b6898 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7 h1:X2GKnrdzIRsC0qU8zCHw+X8lbsQhFoXmHRlgewlZYIc= -github.com/invopop/gobl v0.512.1-0.20261116170644-71ee2d6037a7/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5 h1:GDhOQmvQSgRBSoLEKvjiwUYrvyucAEuBFYq/EuzF6Eg= +github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= diff --git a/ubl/ae.go b/ubl/ae.go index efa7e43..e95a929 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -145,9 +145,11 @@ func importAEOutsideScope(in *goblubl.Invoice, inv *bill.Invoice) { } } -// importAEMarginScheme gives the margin scheme VAT key to the combos gobl.ubl -// imports with the N category and a 5% rate. Without a key, EN 16931 would -// read them as standard rated, which charges VAT the invoice doesn't. +// importAEMarginScheme reads the combos gobl.ubl imports with the N category +// and a 5% rate as exempt, with the margin-scheme tag, the way a user writes a +// margin scheme supply. Without a key, EN 16931 would read them as standard +// rated, which charges VAT the invoice doesn't. The tag normally comes from +// the transaction type, but keeps N on the lines when the flag is missing. func importAEMarginScheme(inv *bill.Invoice) { var sets []tax.Set for _, l := range inv.Lines { @@ -159,14 +161,19 @@ func importAEMarginScheme(inv *bill.Invoice) { for _, c := range inv.Charges { sets = append(sets, c.Taxes) } + found := false for _, set := range sets { for _, c := range set { if c.Category == tax.CategoryVAT && c.Ext.Get(untdid.ExtKeyTaxCategory) == pint.TaxCategoryMarginScheme { - c.Key = ae.TaxKeyMarginScheme + c.Key = tax.KeyExempt c.Percent = nil + found = true } } } + if found && !inv.HasTags(pint.TagMarginScheme) { + inv.Tags.List = append(inv.Tags.List, pint.TagMarginScheme) + } } // exportAEUUID writes the invoice's UUID as cbc:UUID, the unique identifier diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 194a6dc..6905273 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -446,13 +446,18 @@ func TestImportAEMarginScheme(t *testing.T) { importAEMarginScheme(inv) ms := inv.Lines[0].Taxes[0] - assert.Equal(t, ae.TaxKeyMarginScheme, ms.Key) + assert.Equal(t, tax.KeyExempt, ms.Key) assert.Nil(t, ms.Percent, "margin scheme lines charge no VAT") - assert.Equal(t, ae.TaxKeyMarginScheme, inv.Discounts[0].Taxes[0].Key) + assert.Equal(t, tax.KeyExempt, inv.Discounts[0].Taxes[0].Key) + assert.True(t, inv.HasTags(pint.TagMarginScheme), "the tag keeps N on the lines") other := inv.Lines[1].Taxes[0] assert.Empty(t, other.Key, "other categories are left to EN 16931") assert.NotNil(t, other.Percent) + + inv = &bill.Invoice{Lines: []*bill.Line{{Taxes: tax.Set{combo("S")}}}} + importAEMarginScheme(inv) + assert.False(t, inv.HasTags(pint.TagMarginScheme)) } func TestImportAEOutsideScope(t *testing.T) { diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json new file mode 100644 index 0000000..b35253a --- /dev/null +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json @@ -0,0 +1,204 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "2d2e574d3be6d3b5dde197b4a960a887e4b37dee64b63e562e338afa3d090c1d" + }, + "from": "iso6523-actorid-upis::0235:1357902467", + "to": "iso6523-actorid-upis::0235:1345678906" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "margin-scheme" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "series": "AE", + "code": "MARGIN-CN-001", + "issue_date": "2025-02-10", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-01-30", + "series": "AE", + "code": "MARGIN-001" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-transaction-type": "00100000", + "untdid-document-type": "381" + }, + "notes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "text": "VAT charged under the Profit Margin Scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ] + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "135790246700003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1357902467" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1357902467" + } + ], + "addresses": [ + { + "street": "Sheikh Zayed Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ] + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890600003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678906" + } + ], + "inboxes": [ + { + "key": "peppol", + "scheme": "0235", + "code": "1345678906" + } + ], + "addresses": [ + { + "street": "Corniche Road", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "item": { + "key": "goods", + "name": "Second-hand watch", + "identities": [ + { + "label": "HS", + "code": "9102" + } + ], + "description": "Item Description", + "price": "10.00", + "unit": "one" + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "untdid-tax-category": "N" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "key": "due-date", + "due_dates": [ + { + "date": "2025-02-06", + "amount": "1000.00", + "percent": "100%" + } + ] + }, + "instructions": { + "key": "credit-transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "name": "Emirates NBD" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "exempt", + "ext": { + "untdid-tax-category": "N" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index 2cbb3bf..fad80ba 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f13e3cb01d05f1866639b7b62f6a99125529f38856cb3527108749e3928be43b" + "val": "96de7b44eeaa9558c2f4d286a5eb9b7f6bbaf7cc6fb5c8bec4c41c36b67a8409" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -30,7 +30,17 @@ "ext": { "peppol-pint-ae-transaction-type": "00100000", "untdid-document-type": "380" - } + }, + "notes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "text": "VAT charged under the Profit Margin Scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ] }, "supplier": { "name": "Supplier Legal Name", @@ -123,7 +133,7 @@ "taxes": [ { "cat": "VAT", - "key": "margin-scheme", + "key": "exempt", "ext": { "untdid-tax-category": "N" } @@ -165,7 +175,7 @@ "code": "VAT", "rates": [ { - "key": "margin-scheme", + "key": "exempt", "ext": { "untdid-tax-category": "N" }, diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml new file mode 100644 index 0000000..e8cfd65 --- /dev/null +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml @@ -0,0 +1,147 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00100000 + AE-MARGIN-CN-001 + 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 + 2025-02-10 + 381 + AED + + DL8.61.1.E + + + NA + + + + AE-MARGIN-001 + 2025-01-30 + + + + + 1357902467 + + Supplier Legal Name + + + Sheikh Zayed Road + Dubai + DXB + + AE + + + + 135790246700003 + + VAT + + + + Supplier Legal Name + 112345678900003 + + + + + + 1345678906 + + Buyer Legal Name + + + Corniche Road + Abu Dhabi + AUH + + AE + + + + 134567890600003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + + + 1 + 30 + 2025-02-06 + + AE070331234567890123456 + Emirates NBD + + + + 1 + 1000.00 + 2025-02-06 + + + 0.00 + false + + 1000.00 + 0.00 + + N + 5 + VAT charged under the Profit Margin Scheme + + VAT + + + + + + 1000.00 + 1000.00 + 1000.00 + 1000.00 + + + 1 + 100 + 1000.00 + + Item Description + Second-hand watch + + G + 9102 + + + N + 5 + VAT charged under the Profit Margin Scheme + + VAT + + + + + 10.00 + 1 + + false + 0.00 + 10.00 + + + + 1000.00 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index d2357ed..3b4f9e2 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -86,6 +86,7 @@ N 5 + VAT charged under the Profit Margin Scheme VAT @@ -112,6 +113,7 @@ N 5 + VAT charged under the Profit Margin Scheme VAT diff --git a/ubl/testdata/parse/pint/ae/margin-scheme-credit-note.xml b/ubl/testdata/parse/pint/ae/margin-scheme-credit-note.xml new file mode 100644 index 0000000..93ed02b --- /dev/null +++ b/ubl/testdata/parse/pint/ae/margin-scheme-credit-note.xml @@ -0,0 +1,162 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00100000 + AE-001-Marginscheme-CN-TEST + e59f130c-eb13-4476-bc18-2202915f48d0 + 2025-02-11 + 381 + Tax invoice + AED + + DL8.61.1.E + + + + AE-001-Marginscheme-TEST + 2025-02-11 + + + + + 112345678900003 + + Supplier Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address line + + + AE + + + + 112345678900003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Contact Email address + + + + + + 112345679000003 + + Buyer Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address Line + + + AE + + + + 112345679000003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Contact Email address + + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + Instant Payment + + + 0 + false + + 1000 + 0 + + N + 5 + + VAT + + + + + + 1000 + 1000 + 1000 + 1000 + + + 1 + Margin scheme goods + 1 + 1000 + + Item Description + Item Name + + N + 5 + 1000 + + VAT + + + + + 1000 + 1 + + false + 0 + 1000 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json b/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json new file mode 100644 index 0000000..25c3814 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json @@ -0,0 +1,232 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "5d2210e055c6541dcab01ada5fa1f3e9b586c91711e514b39894d524d1f477a6" + }, + "from": "iso6523-actorid-upis::0235:112345678900003", + "to": "iso6523-actorid-upis::0235:112345679000003" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "margin-scheme" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "code": "AE-001-Marginscheme-CN-TEST", + "issue_date": "2025-02-11", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-02-11", + "code": "AE-001-Marginscheme-TEST" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-transaction-type": "00100000", + "untdid-document-type": "381" + }, + "notes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "text": "VAT charged under the Profit Margin Scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ] + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "112345678900003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345678900003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "street_third": "Additional Address line", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "112345679000003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345679000003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "street_third": "Additional Address Line", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "1", + "item": { + "name": "Item Name", + "description": "Item Description", + "list": "1000", + "price": "1000.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "untdid-tax-category": "N" + } + } + ], + "total": "1000.00", + "notes": [ + { + "text": "Margin scheme goods" + } + ] + } + ], + "payment": { + "terms": { + "notes": "Instant Payment" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "exempt", + "ext": { + "untdid-tax-category": "N" + }, + "base": "1000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1000.00", + "payable": "1000.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index b047df3..070fed2 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4ccaf2567c4378cb75d067ea0e75eeb335b5f8ecd0daa5d2ab6e97ff5cba8efc" + "val": "c26c3f64b0a1bd3704a2504990810aeea8a10a0cedbc352f4fe33d5c83a5fc4c" }, "from": "iso6523-actorid-upis::0235:112345678900003", "to": "iso6523-actorid-upis::0235:112345679000003" @@ -29,7 +29,17 @@ "ext": { "peppol-pint-ae-transaction-type": "00100000", "untdid-document-type": "380" - } + }, + "notes": [ + { + "cat": "VAT", + "key": "margin-scheme", + "text": "VAT charged under the Profit Margin Scheme", + "ext": { + "untdid-tax-category": "N" + } + } + ] }, "supplier": { "name": "Supplier Legal Name", @@ -150,7 +160,7 @@ "taxes": [ { "cat": "VAT", - "key": "margin-scheme", + "key": "exempt", "ext": { "untdid-tax-category": "N" } @@ -196,7 +206,7 @@ "code": "VAT", "rates": [ { - "key": "margin-scheme", + "key": "exempt", "ext": { "untdid-tax-category": "N" }, diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 9e953e1..621f51e 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -149,17 +149,19 @@ func TestDetectAndImportAE(t *testing.T) { // TRNs and TINs fail the check digit the Federal Tax Authority defines, some // email addresses are placeholders, and the deemed supply has no payment // terms, which EN 16931 requires (BR-CO-25). Any other fault is a defect in -// the import. +// the import. margin-scheme-credit-note.xml is the official margin scheme +// example turned into a credit note, as there is no official one. var importFaultsAE = map[string][]string{ - "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, - "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, - "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, } // faultCodePattern matches the fault codes in a validation error. From 142249f11b0d4d63ecf32c234312b8f60bf70d23 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:24:24 +0000 Subject: [PATCH 39/73] Leave the TRN format to the AE regime, checking only its 03 ending Co-Authored-By: Claude Opus 5.5 --- addon/pint/tax_identity.go | 12 ++++++------ addon/pint/tax_identity_test.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/addon/pint/tax_identity.go b/addon/pint/tax_identity.go index 98f8447..99b8c9f 100644 --- a/addon/pint/tax_identity.go +++ b/addon/pint/tax_identity.go @@ -6,18 +6,18 @@ import ( "github.com/invopop/gobl/tax" ) -// taxIdentityRules enforces the UAE TRN format on every UAE tax identity of a -// UAE document (IBR-132-AE). The AE regime checks the 15 digits and the -// TIN they start with; PINT AE also requires the trailing 03 of a VAT -// registration. +// taxIdentityRules requires the trailing 03 of a VAT registration on every +// UAE tax identity of a UAE document (IBR-132-AE). The rest of IBR-132-AE's +// format, 15 digits starting with 1, is checked by the AE regime, together +// with the check digit of the TIN they start with. func taxIdentityRules() *rules.Set { return rules.For(new(tax.Identity), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.When(tax.IdentityIn("AE"), rules.Field("code", - rules.AssertIfPresent("01", "UAE TRN must be 15 digits, start with 1 and end with 03 (IBR-132-AE)", - is.Matches(`^1\d{12}03$`)), + rules.AssertIfPresent("01", "UAE TRN must end with 03 (IBR-132-AE)", + is.Matches(`03$`)), ), ), ), diff --git a/addon/pint/tax_identity_test.go b/addon/pint/tax_identity_test.go index 52f5051..ccb744b 100644 --- a/addon/pint/tax_identity_test.go +++ b/addon/pint/tax_identity_test.go @@ -22,15 +22,20 @@ func TestTaxIdentityRulesAE(t *testing.T) { assert.NoError(t, validate(&tax.Identity{Country: "AE", Code: "100000001600003"})) }) - t.Run("malformed TRNs are rejected (IBR-132-AE)", func(t *testing.T) { + t.Run("TRN not ending with 03 is rejected (IBR-132-AE)", func(t *testing.T) { + err := validate(&tax.Identity{Country: "AE", Code: "100000001600004"}) + assert.ErrorContains(t, err, faultTRN) + }) + + t.Run("the rest of the TRN format is left to the AE regime (IBR-132-AE)", func(t *testing.T) { for name, code := range map[string]cbc.Code{ "does not start with 1": "200000000000003", - "does not end with 03": "100000001600004", "too short": "10000000000003", "too long": "1000000000000003", } { err := validate(&tax.Identity{Country: "AE", Code: code}) - assert.ErrorContains(t, err, faultTRN, name) + assert.ErrorContains(t, err, "GOBL-AE-TAX-IDENTITY-01", name) + assert.NotContains(t, err.Error(), faultTRN, name) } }) From 6e84969a70698f68c384006aeb6be6dce5e1afd0 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:35:19 +0000 Subject: [PATCH 40/73] Pin gobl to the PR head without the all-zeros TIN check Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ac761de..86e4e53 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5 + github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index 53b6898..0d5a013 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5 h1:GDhOQmvQSgRBSoLEKvjiwUYrvyucAEuBFYq/EuzF6Eg= -github.com/invopop/gobl v0.512.1-0.20261117101430-cd707d691ad5/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c h1:lkZ0mBNXLeLl3sFuD3+5RqJFSrMIwO7bav0qpNNYuz4= +github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= From 96dcbfa9c965db04fb1eac6595e708551bfc4e7a Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:46:05 +0000 Subject: [PATCH 41/73] Keep exempt lines with a UAE exemption reason out of the margin scheme A line with a UAE exemption reason is a real exempt supply. On a margin scheme invoice it was mapped to N with the rest, and went out as margin scheme with its exemption code. It now keeps E, so rule 41 rejects the mixed invoice. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 2 +- addon/pint/bill_test.go | 7 +++++++ addon/pint/tax_combo.go | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 36edee6..ed8b17f 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -353,7 +353,7 @@ func billInvoiceRules() *rules.Set { // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("41", "margin scheme invoice must only have exempt lines, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + rules.Assert("41", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index be904b1..e02f231 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -1300,6 +1300,13 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { }) assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + // A line with a UAE exemption reason is a real exempt supply, not a + // margin scheme one. + inv = margin(pint.TagMarginScheme) + inv.Lines[0].Taxes[0].Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: "DL8.46.1"}) + assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyStandard} { inv = margin(pint.TagMarginScheme) inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(key)}}} diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 94a4ae9..0592410 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -67,7 +67,8 @@ func normalizeTaxCombo(tc *tax.Combo) { // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the // discount and charge rules 02 and rule 41 reject them (IBR-114-AE, -// IBR-115-AE, IBR-116-AE). +// IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real +// exempt supply, so they keep E and rule 41 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return @@ -77,7 +78,7 @@ func normalizeMarginSchemeAE(inv *bill.Invoice) { continue } for _, c := range l.Taxes { - if c != nil && c.Category == tax.CategoryVAT && c.Key == tax.KeyExempt { + if c != nil && c.Category == tax.CategoryVAT && c.Key == tax.KeyExempt && !c.Ext.Has(ExtKeyExemption) { c.Ext = c.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) } } From 30103fa4189b663aadfa317848a924cd0a284b8b Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:08:32 +0000 Subject: [PATCH 42/73] Check that each AE convert fixture survives an import round trip TestRoundTripAE exports each AE convert fixture, imports the XML and exports it again, and expects the same XML, so whatever FormatAE writes it also reads back. Co-Authored-By: Claude Opus 5.5 --- ubl/ubl_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 621f51e..0ad5a68 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -189,6 +189,38 @@ func TestImportAEFaults(t *testing.T) { } } +// TestRoundTripAE checks that each AE convert example gives the same XML +// after an import and a second export, so whatever FormatAE writes it also +// reads back. +func TestRoundTripAE(t *testing.T) { + examples, err := filepath.Glob(filepath.Join("testdata", "convert", "pint", "ae", "*.json")) + require.NoError(t, err) + require.NotEmpty(t, examples) + for _, example := range examples { + name := filepath.Base(example) + t.Run(name, func(t *testing.T) { + env := loadTestEnvelope(t, filepath.Join("pint", "ae", name)) + doc, err := ubl.ExportInvoice(env, ubl.WithFormat(peppolubl.FormatAE)) + require.NoError(t, err) + first, err := ubl.Encode(doc) + require.NoError(t, err) + + in, err := ubl.Decode(first) + require.NoError(t, err) + out, err := ubl.Import(in) + require.NoError(t, err) + require.NoError(t, out.Calculate()) + require.NoError(t, out.Validate()) + doc, err = ubl.ExportInvoice(out, ubl.WithFormat(peppolubl.FormatAE)) + require.NoError(t, err) + second, err := ubl.Encode(doc) + require.NoError(t, err) + + assert.Equal(t, string(first), string(second)) + }) + } +} + // TestImportAESellerTIN checks that a seller with a TIN and no TRN, as out of // scope documents allow, keeps the TIN as a tax registration when imported, // instead of getting it as its tax ID. From b79e7b97487c081841600708176bde7ebea008dd Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:08:32 +0000 Subject: [PATCH 43/73] Pin phorm to 2.2.14 in CI The latest tag can change validation results with no code change. 2.2.14 is what latest points to now; it has the PINT AE 2026.5 rule sets and every fixture passes it, as it does 2.2.13. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0863c47..0d3d4af 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,7 +34,7 @@ jobs: # fixtures. services: phorm: - image: phelger/phorm:latest + image: phelger/phorm:2.2.14 ports: - 8080:8080 From e171398a941ffde2f01d42ecc095abf65fdeed2f Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:14:43 +0000 Subject: [PATCH 44/73] Drop BR-CO-25 under PINT AE in favour of its own payment rules PINT has no BR-CO-25. PINT AE asks for payment instructions and a due date instead (IBR-191-AE, IBR-127-AE, rules 25 to 27), except on credit notes and deemed supplies. The EN 16931 payment rules still ran underneath, so a deemed supply without payment terms was rejected, and the official deemed supply example failed to import. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 5 +++++ addon/pint/bill_test.go | 7 +++++++ ubl/ubl_test.go | 9 ++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index ed8b17f..10e329f 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -36,6 +36,11 @@ func billInvoiceRules() *rules.Set { ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), + // PINT has no BR-CO-25. PINT AE asks for payment instructions + // (IBR-191-AE, rules 25 and 26) and a due date (IBR-127-AE, rule 27) + // instead, except on credit notes and deemed supplies. + rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-06"), + rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-07"), // EN 16931 wants an EU VATEX code or an exemption note for every E, O // and AE breakdown (BR-E-10, BR-O-10, BR-AE-10). PINT AE has no such // rule: it only asks for the UAE exemption reason on exempt lines diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index e02f231..5a51205 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -927,6 +927,13 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.NotContains(t, out, faultPaymentInstructions) assert.NotContains(t, out, faultDueDate) + // PINT has no BR-CO-25, so neither payment nor terms are required. + inv = aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) + inv.Payment.Terms = nil + assert.Empty(t, aeFaults(t, inv)) + inv.Payment = nil + assert.Empty(t, aeFaults(t, inv)) + inv = aeDocument(bill.InvoiceTypeStandard) inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{Notes: "No consideration"}} out = aeFaults(t, inv) diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 0ad5a68..25bcde8 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -146,15 +146,14 @@ func TestDetectAndImportAE(t *testing.T) { // importFaultsAE are the faults the official PINT AE examples give once // imported. They pass the PINT AE Schematron, but their data is made up: the -// TRNs and TINs fail the check digit the Federal Tax Authority defines, some -// email addresses are placeholders, and the deemed supply has no payment -// terms, which EN 16931 requires (BR-CO-25). Any other fault is a defect in -// the import. margin-scheme-credit-note.xml is the official margin scheme +// TRNs and TINs fail the check digit the Federal Tax Authority defines, and +// some email addresses are placeholders. Any other fault is a defect in the +// import. margin-scheme-credit-note.xml is the official margin scheme // example turned into a credit note, as there is no official one. var importFaultsAE = map[string][]string{ "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-EU-EN16931-BILL-INVOICE-07", "GOBL-ORG-EMAIL-02"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, From 69e7d58e4ec524974e6b96182f75cf62838b29b1 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:14:50 +0000 Subject: [PATCH 45/73] Join the notes into one on PINT AE documents and lines PINT allows a single note on the document and on each line (ibr-sr-51, ibr-sr-34), but each GOBL note went out as its own cbc:Note, so an invoice with two notes failed the Schematron. FormatAE now joins them, separated by a blank line. The rules are shared PINT, and EN 16931 has the line one too, so a TODO notes the other formats need the same. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +- ubl/ae.go | 18 ++++++++- ubl/ae_internal_test.go | 6 +++ .../pint/ae/invoice-ae-shared-fields.json | 38 +++++++++++++++++-- .../pint/ae/out/invoice-ae-shared-fields.xml | 2 + 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 19ad0e0..b003724 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,9 @@ item's type of goods or services subject to the reverse charge as its `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and identities labelled `SAC` are written as service accounting codes. The delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the -delivery terms. +delivery terms. Several notes on the document, or on a line, are joined into +one separated by a blank line, as PINT allows a single note on each +(ibr-sr-51, ibr-sr-34), and are imported back as a single note. **Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's `margin-scheme` tag, with the `exempt` VAT key on every line: diff --git a/ubl/ae.go b/ubl/ae.go index e95a929..93f3fe5 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -65,6 +65,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error } exportAEUUID(out, inv) exportAEIssueTime(out, inv) + out.Note = aeJoinNotes(out.Note) exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) exportAEBillingFrequency(out, inv) @@ -945,8 +946,23 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// exportAELine completes a line's price details and VAT rate. +// aeJoinNotes joins the notes into one, separated by a blank line, as PINT +// allows a single note on the document and on each line (ibr-sr-51, +// ibr-sr-34). A joined note is imported back as a single note. +// +// TODO: these are shared PINT rules, and EN 16931 has the line one too +// (UBL-SR-34), so FormatPINT and FormatAUNZ need the same, and FormatBIS on +// its lines. +func aeJoinNotes(notes []string) []string { + if len(notes) < 2 { + return notes + } + return []string{strings.Join(notes, "\n\n")} +} + +// exportAELine completes a line's notes, price details and VAT rate. func exportAELine(line *goblubl.InvoiceLine) { + line.Note = aeJoinNotes(line.Note) exportAEPrice(line) if line.Item != nil && line.Item.ClassifiedTaxCategory != nil { c := line.Item.ClassifiedTaxCategory diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 6905273..5904bce 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -985,6 +985,12 @@ func TestExportAEExchangeRate(t *testing.T) { }) } +func TestAEJoinNotes(t *testing.T) { + assert.Nil(t, aeJoinNotes(nil)) + assert.Equal(t, []string{"First"}, aeJoinNotes([]string{"First"})) + assert.Equal(t, []string{"First\n\nSecond"}, aeJoinNotes([]string{"First", "Second"})) +} + func TestExportAEIssueTime(t *testing.T) { out := new(goblubl.Invoice) exportAEIssueTime(out, &bill.Invoice{}) diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index bbbda68..2d9449b 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "14c06bfb428554fe2b384e85f4d9eba22850ae9cd5cfc8e334830caf3ede3a2e" + "val": "90574999a3a16f69c2bb67f50382d58a25f1ddac42678ec20829e60aa531c6c3" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -149,7 +149,23 @@ } } ], - "total": "1900.00" + "total": "1900.00", + "notes": [ + { + "key": "general", + "text": "Delivered in two batches.", + "ext": { + "untdid-text-subject": "AAI" + } + }, + { + "key": "general", + "text": "Packed on pallets.", + "ext": { + "untdid-text-subject": "AAI" + } + } + ] }, { "i": 2, @@ -314,6 +330,22 @@ "tax": "103.95", "total_with_tax": "2182.95", "payable": "2182.95" - } + }, + "notes": [ + { + "key": "general", + "text": "Goods remain the property of the seller until paid in full.", + "ext": { + "untdid-text-subject": "AAI" + } + }, + { + "key": "general", + "text": "Please quote the invoice number when paying.", + "ext": { + "untdid-text-subject": "AAI" + } + } + ] } } \ No newline at end of file diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index 61e0382..45cce17 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -9,6 +9,7 @@ 17:31:00 2025-02-28 380 + #AAI#Goods remain the property of the seller until paid in full. #AAI#Please quote the invoice number when paying. 2025-01-28 AED @@ -201,6 +202,7 @@ 1 + #AAI#Delivered in two batches. #AAI#Packed on pallets. 10 1900.00 From af031350703cde440ee972b85bc4da3de34ca9e3 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:15:02 +0000 Subject: [PATCH 46/73] Allow one buyer identifier on PINT AE documents PINT allows a single buyer identifier (ibr-sr-16), but a UAE customer could have several identities written as cac:PartyIdentification, and the XML then failed the Schematron. Rule 55 rejects them, counting what gobl.ubl writes there: every identity except the tax ones and the first legal one. The rule is shared PINT, and EN 16931 has it too, so a TODO notes the other formats need the same. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +++++- addon/pint/bill.go | 5 +++++ addon/pint/bill_test.go | 14 ++++++++++++++ addon/pint/org_party.go | 23 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b003724..af49875 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,11 @@ identities labelled `SAC` are written as service accounting codes. The delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the delivery terms. Several notes on the document, or on a line, are joined into one separated by a blank line, as PINT allows a single note on each -(ibr-sr-51, ibr-sr-34), and are imported back as a single note. +(ibr-sr-51, ibr-sr-34), and are imported back as a single note. PINT also +allows a single buyer identifier (ibr-sr-16), so the PINT addon rejects a UAE +customer with more than one identity written as `cac:PartyIdentification`: +any identity other than the tax ones and the first legal one, including the +customer's TIN. **Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's `margin-scheme` tag, with the `exempt` VAT key on every line: diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 10e329f..1697d3d 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -114,6 +114,11 @@ func billInvoiceRules() *rules.Set { rules.Assert("13", "customer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyAddressHasEmirate), ), + // TODO: ibr-sr-16 is a shared PINT rule, and EN 16931 has it too + // (UBL-SR-16), so every PINT jurisdiction and BIS need this. + rules.Assert("55", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", + is.Func("at most one buyer identifier", partyHasOneIdentification), + ), // IBR-183-AE's test also accepts CL, which only its rule text's // "Commercial/Trade license" explains. FormatAE reads CL as a // trade licence on import, but GOBL writes TL, which is valid for diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 5a51205..f7e2389 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -673,6 +673,20 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, aeIdentityDocument())) }) + t.Run("customer has at most one identifier besides its legal one (ibr-sr-16)", func(t *testing.T) { + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + gln := &org.Identity{Code: "5790000435975"} + duns := &org.Identity{Code: "123456789"} + + inv := aeIdentityDocument() + inv.Customer.Identities = append(inv.Customer.Identities, gln) + assert.Empty(t, aeFaults(t, inv)) + + inv = aeIdentityDocument() + inv.Customer.Identities = append(inv.Customer.Identities, gln, duns) + assert.Contains(t, aeFaults(t, inv), fault) + }) + t.Run("supplier with a UAE endpoint needs a legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index 7aeb680..7e2466b 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -62,6 +62,29 @@ func partyHasLegalIdentity(val any) bool { return false } +// partyHasOneIdentification reports whether gobl.ubl writes at most one +// cac:PartyIdentification for the party, as PINT allows a single buyer +// identifier (ibr-sr-16). gobl.ubl writes every identity there except those +// with the tax scope and the first with the legal scope. +func partyHasOneIdentification(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil { + return true + } + n := 0 + legal := false + for _, id := range p.Identities { + switch { + case id == nil || id.Scope == org.IdentityScopeTax: + case id.Scope == org.IdentityScopeLegal && !legal: + legal = true + default: + n++ + } + } + return n <= 1 +} + // partyFirstAddress returns the party's first address, the only one gobl.ubl // writes as cac:PostalAddress, or nil if there is none. func partyFirstAddress(val any) *org.Address { From 9b87df5dff6fc63a3843b03709083feaa83766d4 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:18:30 +0000 Subject: [PATCH 47/73] Pin gobl to the PR head that rejects informative charges again Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 86e4e53..61e2f99 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c + github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701 github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index 0d5a013..c72b5dd 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c h1:lkZ0mBNXLeLl3sFuD3+5RqJFSrMIwO7bav0qpNNYuz4= -github.com/invopop/gobl v0.512.1-0.20261117103301-97fa3796da3c/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701 h1:se+0Iu/99zKh1OECxBsYDqhkJkEoox3rnGLSFG9YY50= +github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= From 79d6184baecf89b6920376fc9f9d153000b08973 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:56:07 +0000 Subject: [PATCH 48/73] Prefix the PINT AE extension names with "PINT AE:" The addons README asks for the issuer followed by a colon, as in "SII: Invoice Type". Co-Authored-By: Claude Opus 5.5 --- addon/pint/extensions.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 865a0ce..0164734 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -108,7 +108,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyTransactionType, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Transaction Type", + i18n.EN: "PINT AE: Transaction Type", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -135,7 +135,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyBeneficiaryID, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Beneficiary ID", + i18n.EN: "PINT AE: Beneficiary ID", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -148,7 +148,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyPrincipalID, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Principal ID", + i18n.EN: "PINT AE: Principal ID", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -162,7 +162,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyCreditNoteReason, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Credit Note Reason", + i18n.EN: "PINT AE: Credit Note Reason", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -209,7 +209,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyBillingFrequency, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Frequency of Billing", + i18n.EN: "PINT AE: Frequency of Billing", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -241,7 +241,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyExemption, Usage: usageAETaxCombo, Name: i18n.String{ - i18n.EN: "PINT AE VAT Exemption Reason", + i18n.EN: "PINT AE: VAT Exemption Reason", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -262,7 +262,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyGoodsType, Usage: usageAEItem, Name: i18n.String{ - i18n.EN: "PINT AE Type of Goods or Services", + i18n.EN: "PINT AE: Type of Goods or Services", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -289,7 +289,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyCustomsReference, Usage: usageAEInvoiceTax, Name: i18n.String{ - i18n.EN: "PINT AE Customs Reference Number", + i18n.EN: "PINT AE: Customs Reference Number", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -302,7 +302,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyBatchNumber, Usage: usageAEItem, Name: i18n.String{ - i18n.EN: "PINT AE Batch Number", + i18n.EN: "PINT AE: Batch Number", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -314,7 +314,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeySchemeVersion, Usage: usageAEIdentity, Name: i18n.String{ - i18n.EN: "PINT AE Scheme Version", + i18n.EN: "PINT AE: Scheme Version", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -328,7 +328,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyContractValue, Usage: usageAEDocumentRef, Name: i18n.String{ - i18n.EN: "PINT AE Contract Value", + i18n.EN: "PINT AE: Contract Value", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -341,7 +341,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyPurchaseOrder, Usage: usageAELine, Name: i18n.String{ - i18n.EN: "PINT AE Line Purchase Order Reference", + i18n.EN: "PINT AE: Line Purchase Order Reference", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -354,7 +354,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyDespatchAdvice, Usage: usageAELine, Name: i18n.String{ - i18n.EN: "PINT AE Line Despatch Advice Reference", + i18n.EN: "PINT AE: Line Despatch Advice Reference", }, Desc: i18n.String{ i18n.EN: here.Doc(` @@ -366,7 +366,7 @@ var extensions = []*cbc.Definition{ Key: ExtKeyRemittanceScheme, Usage: usageAEInstructions, Name: i18n.String{ - i18n.EN: "PINT AE Remittance Reference Scheme", + i18n.EN: "PINT AE: Remittance Reference Scheme", }, Desc: i18n.String{ i18n.EN: here.Doc(` From bdd8cb0df7904583892148798de706a86e703b1a Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:33:28 +0000 Subject: [PATCH 49/73] Write the PINT AE line amounts in AED The line amount payable (BTAE-10) and line VAT amount (BTAE-08) are now converted to AED with the invoice's rate to AED when the invoice is in another currency. Their names, IBR-104-AE and the implementation guide ask for AED, and IBR-126 leaves them out of the document currency check as amounts in the tax currency. No test checks their currency; the two official examples in USD are zero rated exports. Co-Authored-By: Claude Opus 5.5 --- ubl/ae.go | 44 +++++++++++++------ ubl/ae_internal_test.go | 23 +++++++--- .../convert/pint/ae/out/invoice-ae-usd.xml | 14 +++--- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/ubl/ae.go b/ubl/ae.go index 93f3fe5..467dd4d 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -931,10 +931,14 @@ func extensionHasCode(key cbc.Key, code cbc.Code) bool { // exportAELines completes the UBL lines, which gobl.ubl writes in the same // order as the invoice's lines. func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { + var rate *currency.ExchangeRate + if inv.Currency != currency.AED { + rate = currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) + } for i := range lines { exportAELine(&lines[i]) if len(lines) == len(inv.Lines) { - exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency) + exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency, rate) exportAELineExemption(&lines[i], inv.Lines[i], inv.Tax) exportAELineSAC(&lines[i]) exportAELineGoods(&lines[i], inv.Lines[i]) @@ -972,13 +976,21 @@ func exportAELine(line *goblubl.InvoiceLine) { // exportAELineAmounts writes the line amount payable (BTAE-10) and the line VAT // amount (BTAE-08) in cac:ItemPriceExtension, which every line needs -// (IBR-194-AE, IBR-104-AE). Despite their names, the official examples write -// both in the document currency, not in AED. GOBL keeps no VAT per line, so it -// is the line total at the line's rate, rounded to the currency. Exempt lines -// get no VAT amount (IBR-163-AE), and zero rated, reverse charge and margin -// scheme lines a zero one (IBR-165-AE, IBR-162-AE, as the official margin -// scheme example). -func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.Code) { +// (IBR-194-AE, IBR-104-AE). Both are in AED, as their names and IBR-104-AE +// say, so for invoices in another currency they are converted with the rate +// to AED. The implementation guide (section 3.1.1) asks for AED whatever the +// invoice currency, and IBR-126 leaves cac:ItemPriceExtension out of the +// document currency check as amounts in the tax currency, which IBR-140-AE +// fixes to AED. No test checks their currency. The two official examples in +// another currency write them in USD, but both are zero rated exports, so +// their VAT is zero either way. Without a rate, which the PINT addon requires +// (GOBL-PEPPOL-PINT-BILL-INVOICE-22), they stay in the document currency. +// +// GOBL keeps no VAT per line, so it is the line total at the line's rate, +// rounded to the document currency, then converted. Exempt lines get no VAT +// amount (IBR-163-AE), and zero rated, reverse charge and margin scheme lines +// a zero one (IBR-165-AE, IBR-162-AE, as the official margin scheme example). +func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.Code, rate *currency.ExchangeRate) { if l == nil || l.Total == nil { return } @@ -986,12 +998,18 @@ func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.C if def == nil { return } - total := def.Rescale(*l.Total) - ext := &goblubl.ItemPriceExtension{Amount: aeAmount(total, cur)} + out := cur + convert := func(a num.Amount) num.Amount { return a } + if rate != nil { + out = currency.AED + convert = rate.Convert + } + total := convert(def.Rescale(*l.Total)) + ext := &goblubl.ItemPriceExtension{Amount: aeAmount(total, out)} if vat, ok := aeLineVAT(line, l); ok { - vat = def.Rescale(vat) - ext.Amount = aeAmount(total.Add(vat), cur) - ext.TaxTotal = []goblubl.TaxTotal{{TaxAmount: aeAmount(vat, cur)}} + vat = convert(def.Rescale(vat)) + ext.Amount = aeAmount(total.Add(vat), out) + ext.TaxTotal = []goblubl.TaxTotal{{TaxAmount: aeAmount(vat, out)}} } line.ItemPriceExtension = ext } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 5904bce..c2a88a9 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -900,7 +900,7 @@ func TestExportAELineAmounts(t *testing.T) { t.Run("standard rated line gets its VAT and the total with VAT", func(t *testing.T) { out := line("S") - exportAELineAmounts(out, goblLine("10486.00", tax.KeyStandard, num.NewPercentage(5, 2)), currency.AED) + exportAELineAmounts(out, goblLine("10486.00", tax.KeyStandard, num.NewPercentage(5, 2)), currency.AED, nil) ext := out.ItemPriceExtension require.NotNil(t, ext) assert.Equal(t, "11010.30", ext.Amount.Value) @@ -911,10 +911,21 @@ func TestExportAELineAmounts(t *testing.T) { t.Run("line VAT is rounded to the currency", func(t *testing.T) { out := line("S") - exportAELineAmounts(out, goblLine("99.99", tax.KeyStandard, num.NewPercentage(5, 2)), currency.USD) + exportAELineAmounts(out, goblLine("99.99", tax.KeyStandard, num.NewPercentage(5, 2)), currency.USD, nil) assert.Equal(t, "5.00", out.ItemPriceExtension.TaxTotal[0].TaxAmount.Value) assert.Equal(t, "104.99", out.ItemPriceExtension.Amount.Value) - assert.Equal(t, "USD", *out.ItemPriceExtension.Amount.CurrencyID, "document currency, as in the examples") + assert.Equal(t, "USD", *out.ItemPriceExtension.Amount.CurrencyID, "no rate, so the document currency") + }) + + t.Run("other currencies are converted to AED", func(t *testing.T) { + out := line("S") + rate := ¤cy.ExchangeRate{From: currency.USD, To: currency.AED, Amount: num.MakeAmount(367285, 5)} + exportAELineAmounts(out, goblLine("99.99", tax.KeyStandard, num.NewPercentage(5, 2)), currency.USD, rate) + ext := out.ItemPriceExtension + assert.Equal(t, "AED", *ext.Amount.CurrencyID) + assert.Equal(t, "AED", *ext.TaxTotal[0].TaxAmount.CurrencyID) + assert.Equal(t, "18.36", ext.TaxTotal[0].TaxAmount.Value, "5.00 USD") + assert.Equal(t, "385.61", ext.Amount.Value, "99.99 USD is 367.25 AED, plus the VAT") }) t.Run("zero rated and reverse charge lines get a zero VAT amount", func(t *testing.T) { @@ -923,7 +934,7 @@ func TestExportAELineAmounts(t *testing.T) { key cbc.Key }{{"Z", tax.KeyZero}, {"AE", tax.KeyReverseCharge}} { out := line(c.category) - exportAELineAmounts(out, goblLine("200.00", c.key, nil), currency.AED) + exportAELineAmounts(out, goblLine("200.00", c.key, nil), currency.AED, nil) ext := out.ItemPriceExtension assert.Equal(t, "200.00", ext.Amount.Value, c.category) require.Len(t, ext.TaxTotal, 1, c.category) @@ -933,14 +944,14 @@ func TestExportAELineAmounts(t *testing.T) { t.Run("exempt lines get no VAT amount", func(t *testing.T) { out := line("E") - exportAELineAmounts(out, goblLine("120.00", tax.KeyExempt, nil), currency.AED) + exportAELineAmounts(out, goblLine("120.00", tax.KeyExempt, nil), currency.AED, nil) assert.Equal(t, "120.00", out.ItemPriceExtension.Amount.Value) assert.Empty(t, out.ItemPriceExtension.TaxTotal) }) t.Run("lines without a total are left alone", func(t *testing.T) { out := line("S") - exportAELineAmounts(out, &bill.Line{}, currency.AED) + exportAELineAmounts(out, &bill.Line{}, currency.AED, nil) assert.Nil(t, out.ItemPriceExtension) }) } diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 586dafe..55da20e 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -176,9 +176,9 @@ - 1050.00 + 3856.49 - 50.00 + 183.64 @@ -211,9 +211,9 @@ - 500.00 + 1836.43 - 0.00 + 0.00 @@ -248,7 +248,7 @@ - 120.00 + 440.74 @@ -284,9 +284,9 @@ - 99.99 + 367.25 - 0.00 + 0.00 From 989c63313260fad5666fa4714e86bc71c01df4a0 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:36:27 +0000 Subject: [PATCH 50/73] Write the PINT AE delivery party ID (BTAE-23) The delivery receiver's UAE TRN, or its TIN without one, is written as cac:DeliveryParty/cac:PartyIdentification/cbc:ID, and read back as the receiver's tax ID or TIN identity. The implementation guide (section 2.3.11) calls it the Deliver to Party ID. The PINT AE syntax has the element, unlike generic PINT, but neither the syntax nor the semantic model number it, and no rule checks it. The README also says the line amounts are in AED. Co-Authored-By: Claude Opus 5.5 --- README.md | 47 ++++++------ ubl/ae.go | 74 +++++++++++++++++++ ubl/ae_internal_test.go | 71 ++++++++++++++++++ .../pint/ae/invoice-ae-shared-fields.json | 6 +- .../pint/ae/out/invoice-ae-shared-fields.xml | 3 + 5 files changed, 177 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index af49875..719e67b 100644 --- a/README.md +++ b/README.md @@ -103,32 +103,33 @@ and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with `FormatAUNZ`. `FormatAE` does the same with `SpecificationAESelfBilling` (`urn:peppol:pint:selfbilling-1@ae-1`). -`FormatAE` also adjusts the output to the PINT AE rules: it writes the -invoice UUID, the price base quantity and gross price, the UAE TRN without -its country prefix, the 5% rate on reverse charge lines and breakdowns, no -rate on exempt ones, one VAT breakdown per category, and each line's amount -with VAT and VAT amount. For invoices not in AED, it also writes the exchange -rate to AED and the total with VAT in AED. The seller and buyer legal -identities get their PINT AE type (`TL`, `EID`, `PAS` or `CD`, from the AE -regime's identity keys and `passport`), with the trade licence authority -(the identity's description) or the passport's issuing country, and the -seller's TIN goes under the `TIN` tax scheme. It also writes the transaction -type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and -the disclosed agent's principal as the buyer and seller parties, and the -credit note reason as `cac:DiscrepancyResponse`, the billing frequency in -`cac:InvoicePeriod`, the UAE VAT exemption reason of exempt lines, and each -item's type of goods or services subject to the reverse charge as its -`cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed +`FormatAE` also adjusts the output to the PINT AE rules: it writes the invoice +UUID, the price base quantity and gross price, the UAE TRN without its country +prefix, the 5% rate on reverse charge lines and breakdowns, no rate on exempt +ones, one VAT breakdown per category, and each line's amount with VAT and VAT +amount in AED. For invoices not in AED, it also writes the exchange rate to +AED and the total with VAT in AED, and converts the line amounts with that +rate. The seller and buyer legal identities get their PINT AE type (`TL`, +`EID`, `PAS` or `CD`, from the AE regime's identity keys and `passport`), with +the trade licence authority (the identity's description) or the passport's +issuing country, and the seller's TIN goes under the `TIN` tax scheme. It also +writes the transaction type as `cbc:ProfileExecutionID`, with the free trade +zone beneficiary and the disclosed agent's principal as the buyer and seller +parties, and the credit note reason as `cac:DiscrepancyResponse`, the billing +frequency in `cac:InvoicePeriod`, the UAE VAT exemption reason of exempt +lines, and each item's type of goods or services subject to the reverse charge +as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and identities labelled `SAC` are written as service accounting codes. The delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the -delivery terms. Several notes on the document, or on a line, are joined into -one separated by a blank line, as PINT allows a single note on each -(ibr-sr-51, ibr-sr-34), and are imported back as a single note. PINT also -allows a single buyer identifier (ibr-sr-16), so the PINT addon rejects a UAE -customer with more than one identity written as `cac:PartyIdentification`: -any identity other than the tax ones and the first legal one, including the -customer's TIN. +delivery terms, and the delivery receiver's UAE TRN, or its TIN without one, +as the delivery party's identification (BTAE-23). Several notes on the +document, or on a line, are joined into one separated by a blank line, as PINT +allows a single note on each (ibr-sr-51, ibr-sr-34), and are imported back as +a single note. PINT also allows a single buyer identifier (ibr-sr-16), so the +PINT addon rejects a UAE customer with more than one identity written as +`cac:PartyIdentification`: any identity other than the tax ones and the first +legal one, including the customer's TIN. **Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's `margin-scheme` tag, with the `exempt` VAT key on every line: diff --git a/ubl/ae.go b/ubl/ae.go index 467dd4d..73e66c6 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1,6 +1,7 @@ package ubl import ( + "regexp" "slices" "strings" @@ -70,6 +71,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAECreditNoteReason(out, inv) exportAEBillingFrequency(out, inv) exportAEIncoterms(out, inv) + exportAEDeliveryPartyID(out, inv) exportAECustomsReference(out, inv) exportAEContractValue(out, inv) exportAEPayment(out, inv) @@ -102,6 +104,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAECreditNoteReason(in, inv) importAEBillingFrequency(in, inv) importAEIncoterms(in, inv) + importAEDeliveryPartyID(in, inv) importAECustomsReference(in, inv) importAEContractValue(in, inv) importAERemittanceScheme(in, inv) @@ -922,6 +925,77 @@ func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { inv.Delivery.Ext = inv.Delivery.Ext.Set(key, code) } +// exportAEDeliveryPartyID writes the delivery receiver's UAE TRN, or its TIN +// when it has no TRN, as cac:DeliveryParty/cac:PartyIdentification/cbc:ID: +// the Deliver to Party ID (BTAE-23) the implementation guide (section 2.3.11) +// asks for when the goods go to someone other than the buyer. The PINT AE +// syntax has the element, the generic PINT one doesn't, but neither the +// syntax nor the semantic model give it a business term, and no rule checks +// it. gobl.ubl writes the delivery party with only its name and contact. +func exportAEDeliveryPartyID(out *goblubl.Invoice, inv *bill.Invoice) { + if inv.Delivery == nil { + return + } + id := aeReceiverID(inv.Delivery.Receiver) + if id == "" { + return + } + if len(out.Delivery) == 0 { + out.Delivery = []*goblubl.Delivery{{}} + } + d := out.Delivery[0] + if d.DeliveryParty == nil { + d.DeliveryParty = new(goblubl.Party) + } + d.DeliveryParty.PartyIdentification = []goblubl.Identification{ + {ID: &goblubl.IDType{Value: id.String()}}, + } +} + +// aeReceiverID provides the receiver's UAE TRN, or else its TIN. +func aeReceiverID(p *org.Party) cbc.Code { + if p == nil { + return "" + } + if p.TaxID != nil && p.TaxID.Country.Code() == l10n.AE && p.TaxID.Code != "" { + return p.TaxID.Code + } + for _, id := range p.Identities { + if id != nil && id.Type == ae.IdentityTypeTIN && id.Code != "" { + return id.Code + } + } + return "" +} + +// importAEDeliveryPartyID reads back what exportAEDeliveryPartyID writes: a +// TRN, 15 digits starting with 1, as the receiver's UAE tax ID, and anything +// else as a TIN identity, the only other ID the implementation guide allows. +func importAEDeliveryPartyID(in *goblubl.Invoice, inv *bill.Invoice) { + if len(in.Delivery) == 0 || in.Delivery[0] == nil { + return + } + code := partyIdentificationID(in.Delivery[0].DeliveryParty) + if code == "" { + return + } + if inv.Delivery == nil { + inv.Delivery = new(bill.DeliveryDetails) + } + if inv.Delivery.Receiver == nil { + inv.Delivery.Receiver = new(org.Party) + } + r := inv.Delivery.Receiver + if trnFormat.MatchString(code.String()) { + r.TaxID = &tax.Identity{Country: l10n.AE.Tax(), Code: code} + return + } + r.Identities = append(r.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: code}) +} + +// trnFormat is the format of a UAE TRN. +var trnFormat = regexp.MustCompile(`^1\d{14}$`) + // extensionHasCode reports whether the extension lists the code. func extensionHasCode(key cbc.Key, code cbc.Code) bool { def := tax.ExtensionForKey(key) diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index c2a88a9..260f650 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -822,6 +822,77 @@ func TestAELineItems(t *testing.T) { }) } +func TestAEDeliveryPartyID(t *testing.T) { + delivery := func(r *org.Party) *bill.Invoice { + return &bill.Invoice{Delivery: &bill.DeliveryDetails{Receiver: r}} + } + partyID := func(out *goblubl.Invoice) string { + require.Len(t, out.Delivery, 1) + require.NotNil(t, out.Delivery[0].DeliveryParty) + require.Len(t, out.Delivery[0].DeliveryParty.PartyIdentification, 1) + return out.Delivery[0].DeliveryParty.PartyIdentification[0].ID.Value + } + + t.Run("writes the receiver's TRN", func(t *testing.T) { + out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: &goblubl.Party{PartyName: &goblubl.PartyName{Name: "Warehouse"}}}}} + exportAEDeliveryPartyID(out, delivery(&org.Party{ + Name: "Warehouse", + TaxID: &tax.Identity{Country: "AE", Code: "155667745601003"}, + Identities: []*org.Identity{{Type: ae.IdentityTypeTIN, Code: "1345678906"}}, + })) + assert.Equal(t, "155667745601003", partyID(out)) + assert.Equal(t, "Warehouse", out.Delivery[0].DeliveryParty.PartyName.Name) + }) + + t.Run("or its TIN without a TRN", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEDeliveryPartyID(out, delivery(&org.Party{ + Identities: []*org.Identity{{Type: ae.IdentityTypeTIN, Code: "1345678906"}}, + })) + assert.Equal(t, "1345678906", partyID(out)) + }) + + t.Run("nothing without a UAE tax ID or TIN", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEDeliveryPartyID(out, delivery(&org.Party{Name: "Warehouse", TaxID: &tax.Identity{Country: "GB", Code: "123456789"}})) + exportAEDeliveryPartyID(out, delivery(nil)) + exportAEDeliveryPartyID(out, &bill.Invoice{}) + assert.Empty(t, out.Delivery) + }) + + t.Run("reads a TRN back as the receiver's tax ID", func(t *testing.T) { + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: identifiedParty(" 155667745601003 ")}}} + inv := delivery(&org.Party{Name: "Warehouse"}) + importAEDeliveryPartyID(in, inv) + r := inv.Delivery.Receiver + assert.Equal(t, "Warehouse", r.Name) + require.NotNil(t, r.TaxID) + assert.Equal(t, l10n.TaxCountryCode("AE"), r.TaxID.Country) + assert.Equal(t, cbc.Code("155667745601003"), r.TaxID.Code) + assert.Empty(t, r.Identities) + }) + + t.Run("and anything else as a TIN, on a new receiver", func(t *testing.T) { + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: identifiedParty("1345678906")}}} + inv := new(bill.Invoice) + importAEDeliveryPartyID(in, inv) + require.NotNil(t, inv.Delivery) + r := inv.Delivery.Receiver + require.NotNil(t, r) + assert.Nil(t, r.TaxID) + require.Len(t, r.Identities, 1) + assert.Equal(t, ae.IdentityTypeTIN, r.Identities[0].Type) + assert.Equal(t, cbc.Code("1345678906"), r.Identities[0].Code) + }) + + t.Run("nothing to read without an ID", func(t *testing.T) { + inv := new(bill.Invoice) + importAEDeliveryPartyID(&goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: &goblubl.Party{}}}}, inv) + importAEDeliveryPartyID(new(goblubl.Invoice), inv) + assert.Nil(t, inv.Delivery) + }) +} + func TestAEIncoterms(t *testing.T) { delivery := func(key cbc.Key, code cbc.Code) *bill.Invoice { return &bill.Invoice{Delivery: &bill.DeliveryDetails{Ext: tax.ExtensionsOf(cbc.CodeMap{key: code})}} diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index 2d9449b..d6d92c4 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "90574999a3a16f69c2bb67f50382d58a25f1ddac42678ec20829e60aa531c6c3" + "val": "8481a29d392134057728d066188693f072d8aec4b8e9b982b26b31f075d043ad" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -289,6 +289,10 @@ "delivery": { "receiver": { "name": "Buyer Warehouse", + "tax_id": { + "country": "AE", + "code": "155667745601003" + }, "addresses": [ { "street": "Industrial Area 4", diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index 45cce17..bed2674 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -126,6 +126,9 @@ + + 155667745601003 + Buyer Warehouse From b0b2062d1fa386c5fbbd5a707cc00d378b3e0dea Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:10:21 +0000 Subject: [PATCH 51/73] Pin gobl to the PR head updated from main gobl#1033 now includes the latest main through #1039. Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 61e2f99..de2f46b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701 + github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983 github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index c72b5dd..f288274 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701 h1:se+0Iu/99zKh1OECxBsYDqhkJkEoox3rnGLSFG9YY50= -github.com/invopop/gobl v0.512.1-0.20261117121600-1b63efccb701/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983 h1:mFl15eCATmNknyWJz87a6Ef0D0HbImRwUA+en4HVrsA= +github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= From d807b5eef83cbc59a901963253ce01264c50f279 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:52:07 +0000 Subject: [PATCH 52/73] Check every party's tax schemes and the customer endpoint under PINT AE IBR-133-AE's test runs on every tax scheme in the document, so a non-VAT tax registration of the tax representative, issuer, payee or a line seller needs a supplier TIN too, not only the customer's. Rule 23 now checks all of them, and a tax scope identity of type VAT counts as VAT, as gobl.ubl writes it under that scheme. Rule 14 requires a customer electronic address that gobl.ubl writes as cbc:EndpointID: an ISO 6523 or email endpoint, or an inbox. Rule 04 only checks there is an endpoint, so one with another URI scheme failed ibr-080 and IBR-149-AE in the XML. ibr-080 is a shared PINT rule, so a TODO notes the other formats need the same. The customer rules are grouped again: the buyer identifier rule moves from 55 to 15, and the IBR-133-AE rule, which needs the supplier too, gets its own group after the tax representative and issuer. The rules after them move up by two. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 182 +++++++++++++++++++++++++++------------- addon/pint/bill_test.go | 146 +++++++++++++++++++++----------- addon/pint/org_party.go | 26 ++++++ addon/pint/tax_combo.go | 4 +- ubl/ae.go | 4 +- 5 files changed, 248 insertions(+), 114 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 1697d3d..22c8c06 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -37,7 +37,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // PINT has no BR-CO-25. PINT AE asks for payment instructions - // (IBR-191-AE, rules 25 and 26) and a due date (IBR-127-AE, rule 27) + // (IBR-191-AE, rules 27 and 28) and a due date (IBR-127-AE, rule 29) // instead, except on credit notes and deemed supplies. rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-06"), rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-07"), @@ -55,8 +55,8 @@ func billInvoiceRules() *rules.Set { // cac:PostalAddress, comes after their address rules (IBR-143-AE, // IBR-144-AE) in the same pattern, where a node only fires the first // rule it matches. Rules 06 and 13 follow the text there, as the - // official examples do, so they check more than the test. Rules 20 - // and 21, and line rule 11, follow the test: gobl.ubl also writes the + // official examples do, so they check more than the test. Rules 21 + // and 22, and line rule 11, follow the test: gobl.ubl also writes the // issuer and the line sellers with a cac:PostalAddress. rules.Field("supplier", rules.Assert("05", "supplier address must have a street, city and region (IBR-143-AE)", @@ -114,9 +114,15 @@ func billInvoiceRules() *rules.Set { rules.Assert("13", "customer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyAddressHasEmirate), ), + // TODO: ibr-080 is a shared PINT rule, so every PINT jurisdiction + // needs this: rule 04 only checks that there is an endpoint, but + // gobl.ubl writes none as cbc:EndpointID for other URI schemes. + rules.Assert("14", "customer electronic address must be an ISO 6523 or email endpoint, or an inbox (IBR-080)", + is.Func("electronic address written as endpoint ID", partyHasEndpointID), + ), // TODO: ibr-sr-16 is a shared PINT rule, and EN 16931 has it too // (UBL-SR-16), so every PINT jurisdiction and BIS need this. - rules.Assert("55", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", + rules.Assert("15", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", is.Func("at most one buyer identifier", partyHasOneIdentification), ), // IBR-183-AE's test also accepts CL, which only its rule text's @@ -128,7 +134,7 @@ func billInvoiceRules() *rules.Set { rules.Field("identities", rules.Each( rules.When( is.Func("legal scope", identityHasLegalScope), - rules.Assert("14", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", + rules.Assert("16", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), @@ -138,13 +144,13 @@ func billInvoiceRules() *rules.Set { rules.When( org.IdentityKeyIn(org.IdentityKeyPassport), rules.Field("country", - rules.Assert("15", "customer passport must have the issuing country (IBR-010-AE)", is.Present), + rules.Assert("17", "customer passport must have the issuing country (IBR-010-AE)", is.Present), ), ), rules.When( org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", - rules.Assert("16", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Present), + rules.Assert("18", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Present), ), ), )), @@ -153,42 +159,50 @@ func billInvoiceRules() *rules.Set { // cac:PartyTaxScheme/cbc:CompanyID. We follow the test. rules.When( is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), - rules.Assert("17", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", + rules.Assert("19", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), - rules.Assert("18", "customer must have at most one tax registration (IBR-179-AE)", + rules.Assert("20", "customer must have at most one tax registration (IBR-179-AE)", is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), ), ), - rules.Assert("19", "customer tax registrations other than VAT require a supplier TIN (IBR-133-AE)", - is.Func("customer non-VAT tax registrations with supplier TIN", customerNonVATTaxRegistrationsHaveSupplierTIN), - ), // AE tax representative and issuer rules.Field("ordering", rules.Field("seller", - rules.Assert("20", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", + rules.Assert("21", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), rules.Field("issuer", - rules.Assert("21", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", + rules.Assert("22", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), ), + // AE tax schemes of every party + // + // IBR-133-AE's test runs on every cac:TaxScheme/cbc:ID: a scheme + // other than VAT needs a seller TIN. gobl.ubl writes tax schemes for + // the customer, tax representative, issuer, payee and line sellers. + // The supplier's own pass: its tax ID is under VAT, and rule 11 makes + // any tax scope identity of it a TIN. Every tax category here is VAT. + rules.Assert("23", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", + is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), + ), + // AE currency - rules.Assert("22", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("24", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("23", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("25", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("24", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("26", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -199,11 +213,11 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceIsDeemedSupply), )), rules.Field("payment", - rules.Assert("25", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("27", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("26", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("28", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -220,7 +234,7 @@ func billInvoiceRules() *rules.Set { )), rules.When( is.Func("amount due is positive", invoiceIsDue), - rules.Assert("27", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("29", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Func("has due date", invoiceHasDueDate), ), ), @@ -231,7 +245,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("28", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("30", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -242,7 +256,7 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - rules.Assert("29", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("31", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), ), @@ -251,7 +265,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("30", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("32", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -264,7 +278,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("31", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("33", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -277,7 +291,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("32", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("34", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -285,7 +299,7 @@ func billInvoiceRules() *rules.Set { ), )), )), - rules.Assert("33", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + rules.Assert("35", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), ), ), @@ -294,7 +308,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("34", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("36", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -308,13 +322,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("35", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("37", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("36", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("38", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -324,7 +338,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("37", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("39", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -332,7 +346,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("38", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("40", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -342,7 +356,7 @@ func billInvoiceRules() *rules.Set { // AE transaction type rules.Field("tax", rules.Field("ext", - rules.Assert("39", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + rules.Assert("41", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", tax.ExtensionsRequire(ExtKeyTransactionType), tax.ExtensionHasValidCode(ExtKeyTransactionType), ), @@ -352,7 +366,7 @@ func billInvoiceRules() *rules.Set { is.Func("free trade zone", invoiceIsFreeTradeZone), rules.Field("tax", rules.Field("ext", - rules.Assert("40", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("42", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), @@ -363,13 +377,13 @@ func billInvoiceRules() *rules.Set { // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("41", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + rules.Assert("43", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( is.Func("summary invoice", invoiceIsSummary), - rules.Assert("42", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + rules.Assert("44", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), @@ -377,23 +391,23 @@ func billInvoiceRules() *rules.Set { is.Func("disclosed agent billing", invoiceIsDisclosedAgent), rules.Field("tax", rules.Field("ext", - rules.Assert("43", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("45", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), ), - rules.Assert("44", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", + rules.Assert("46", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", is.Func("principal ID is not the supplier tax ID", principalIsNotSupplier), ), rules.Field("supplier", - rules.Assert("45", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", + rules.Assert("47", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), ), rules.When( is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("46", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + rules.Assert("48", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), @@ -403,7 +417,7 @@ func billInvoiceRules() *rules.Set { // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), - rules.Assert("47", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + rules.Assert("49", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), ), ), @@ -412,7 +426,7 @@ func billInvoiceRules() *rules.Set { rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("48", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("50", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), ), ), @@ -423,7 +437,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("has reverse charge lines", invoiceHasReverseChargeLine), rules.Field("customer", - rules.Assert("49", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("51", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), @@ -432,10 +446,10 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("50", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("52", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("51", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("53", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), ), @@ -443,7 +457,7 @@ func billInvoiceRules() *rules.Set { // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, // and IBR-005-AE only accepts frequencies there. rules.Field("point", - rules.Assert("52", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("54", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", is.Not(is.Present), ), ), @@ -451,7 +465,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), rules.Field("notes", - rules.Assert("53", "a note is required with the billing frequency Others (IBR-160-AE)", + rules.Assert("55", "a note is required with the billing frequency Others (IBR-160-AE)", is.Present, ), ), @@ -466,7 +480,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("54", "PINT AE tags can only be used on UAE documents", + rules.Assert("56", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -574,7 +588,7 @@ func invoiceHasNoAETags(val any) bool { // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 22 reports them. +// without it pass: they are in AED, or rule 24 reports them. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -668,23 +682,71 @@ func invoiceHasDueDate(val any) bool { return false } -// customerNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier -// has a tax scope identity, the TIN (IBT-032), whenever the customer has a tax -// registration that gobl.ubl writes under a tax scheme other than VAT: a tax -// scope identity, or a tax ID from a regime with another scheme, such as GST -// in Australia. PINT AE only allows those when the seller has a TIN -// (IBR-133-AE). The official exports example sends a foreign buyer's tax -// number as its electronic address and legal identifier instead. -func customerNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { +// invoiceNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier +// has a TIN (IBT-032) whenever another party has a tax registration that +// gobl.ubl writes under a tax scheme other than VAT: a tax scope identity +// whose type isn't VAT, or a tax ID from a regime with another scheme, such +// as GST in Australia. PINT AE only allows those when the seller has a TIN +// (IBR-133-AE). The parties are the ones gobl.ubl writes tax schemes for: +// the customer, tax representative, issuer, payee and line sellers. The +// official exports example sends a foreign buyer's tax number as its +// electronic address and legal identifier instead. +func invoiceNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { return false } - c := inv.Customer - if c == nil || (partyTaxIdentityCount(c) == 0 && !partyTaxIDIsNotVAT(c)) { + parties := []*org.Party{inv.Customer} + if inv.Ordering != nil { + parties = append(parties, inv.Ordering.Seller, inv.Ordering.Issuer) + } + if inv.Payment != nil { + parties = append(parties, inv.Payment.Payee) + } + for _, l := range inv.Lines { + if l != nil { + parties = append(parties, l.Seller) + } + } + for _, p := range parties { + if partyHasNonVATTaxRegistration(p) { + return partyHasTIN(inv.Supplier) + } + } + return true +} + +// partyHasNonVATTaxRegistration reports whether gobl.ubl writes a tax scheme +// other than VAT for the party: its tax ID's, or a tax scope identity's, +// which is the identity type, or LOC without one. +func partyHasNonVATTaxRegistration(p *org.Party) bool { + if p == nil { + return false + } + if partyTaxIDIsNotVAT(p) { return true } - return inv.Supplier != nil && partyTaxIdentityCount(inv.Supplier) > 0 + for _, id := range p.Identities { + if identityHasTaxScope(id) && id.Type != tax.CategoryVAT { + return true + } + } + return false +} + +// partyHasTIN reports whether the party has a tax scope identity with the +// code IBR-133-AE looks for in the seller's tax schemes: 10 digits starting +// with 1. +func partyHasTIN(p *org.Party) bool { + if p == nil { + return false + } + for _, id := range p.Identities { + if identityHasTaxScope(id) && tinRegexp.MatchString(id.Code.String()) { + return true + } + } + return false } // partyTaxIDIsNotVAT reports whether the party has a tax ID code whose scheme @@ -730,7 +792,7 @@ func invoiceHasInvoicePeriod(val any) bool { // principalIsNotSupplier reports whether the principal ID differs from the // supplier's tax registrations, the cbc:CompanyID values of its // PartyTaxSchemes (IBR-176-AE). A missing principal ID or supplier tax -// registration passes, as rules 43 and 45 report those. +// registration passes, as rules 45 and 47 report those. func principalIsNotSupplier(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index f7e2389..4eff001 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -115,10 +115,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -308,16 +308,16 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -516,8 +516,8 @@ func TestBillAddressRulesAE(t *testing.T) { faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" - faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" - faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-11" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -661,12 +661,13 @@ func TestBillIdentityRulesAE(t *testing.T) { faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" - faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" - faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" - faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" - faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" - faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultCustomerTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" ) t.Run("trade licences with authorities pass", func(t *testing.T) { @@ -674,7 +675,7 @@ func TestBillIdentityRulesAE(t *testing.T) { }) t.Run("customer has at most one identifier besides its legal one (ibr-sr-16)", func(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" gln := &org.Identity{Code: "5790000435975"} duns := &org.Identity{Code: "123456789"} @@ -818,7 +819,7 @@ func TestBillIdentityRulesAE(t *testing.T) { out := aeFaults(t, inv) assert.Empty(t, inv.Customer.Identities[1].Scope) assert.NotContains(t, out, faultCustomerTaxCount) - assert.NotContains(t, out, faultCustomerTaxSupplier) + assert.NotContains(t, out, faultTaxSupplier) }) t.Run("customer tax identity needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { @@ -826,11 +827,11 @@ func TestBillIdentityRulesAE(t *testing.T) { inv.Customer.TaxID = nil inv.Customer.Identities = append(inv.Customer.Identities, &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) - assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) - assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) }) t.Run("customer tax ID under GST needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { @@ -838,17 +839,62 @@ func TestBillIdentityRulesAE(t *testing.T) { // The scheme is set here as these tests don't register the AU regime, // which gives AU tax IDs the GST scheme. inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} - assert.Contains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) - assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) }) t.Run("customer tax ID under VAT needs no supplier TIN", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} - assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxSupplier) + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) + }) + + t.Run("customer tax identity under VAT needs no supplier TIN (IBR-133-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = nil + inv.Customer.Identities = append(inv.Customer.Identities, + &org.Identity{Scope: org.IdentityScopeTax, Type: tax.CategoryVAT, Code: "1345678906"}) + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) + }) + + t.Run("other parties' tax IDs under GST need a supplier TIN (IBR-133-AE)", func(t *testing.T) { + gst := func() *org.Party { + return &org.Party{Name: "Party", TaxID: &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST}} + } + parties := map[string]func(inv *bill.Invoice){ + "tax representative": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Seller: gst()} }, + "issuer": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Issuer: gst()} }, + "payee": func(inv *bill.Invoice) { inv.Payment.Payee = gst() }, + "line seller": func(inv *bill.Invoice) { inv.Lines[0].Seller = gst() }, + } + for name, set := range parties { + t.Run(name, func(t *testing.T) { + inv := aeIdentityDocument() + set(inv) + assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) + + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) + }) + } + }) + + t.Run("customer electronic address must be written as an endpoint ID (IBR-080)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + assert.Contains(t, aeFaults(t, inv), faultCustomerEndpoint) + + inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) + assert.NotContains(t, aeFaults(t, inv), faultCustomerEndpoint) + + inv = aeIdentityDocument() + inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + inv.Customer.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1345678906"}} + assert.NotContains(t, aeFaults(t, inv), faultCustomerEndpoint) }) } @@ -892,18 +938,18 @@ func TestNormalizeRounding(t *testing.T) { func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" - faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1051,10 +1097,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1115,9 +1161,9 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" ) withFrequency := func(code cbc.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1221,7 +1267,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1338,7 +1384,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index 7e2466b..c2bfca0 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -19,6 +19,10 @@ var emirateCodes = []cbc.Code{ // endpoints, which the PINT AE legal registration rules depend on. const endpointSchemeUAE cbc.Code = "0235" +// endpointSchemeMailto is the URI scheme of email endpoints, which gobl.ubl +// writes as cbc:EndpointID. +const endpointSchemeMailto = "mailto" + // partyHasIdentifier reports whether the party can be identified through a tax // identity code or at least one organisation identity. func partyHasIdentifier(val any) bool { @@ -150,6 +154,28 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { return "", "" } +// partyHasEndpointID reports whether gobl.ubl writes the party's electronic +// address as cbc:EndpointID: an ISO 6523 or email endpoint, or an inbox. A +// party without endpoints passes, as rule 04 reports it. +func partyHasEndpointID(val any) bool { + p, ok := val.(*org.Party) + if !ok || p == nil || len(p.Endpoints) == 0 { + return true + } + if s, _ := partyEndpointID(p); s != "" { + return true + } + if e := p.Endpoint(endpointSchemeMailto); e != nil && e.URI.Opaque() != "" { + return true + } + for _, ib := range p.Inboxes { + if ib != nil && ib.Email != "" { + return true + } + } + return false +} + // partyHasUAEEndpointWith returns a predicate that reports whether the party's // electronic address uses the UAE Peppol scheme 0235 with a code that match // accepts. diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 0592410..68984b2 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -66,9 +66,9 @@ func normalizeTaxCombo(tc *tax.Combo) { // exempt VAT lines of a UAE margin scheme invoice. The line combos already have // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the -// discount and charge rules 02 and rule 41 reject them (IBR-114-AE, +// discount and charge rules 02 and rule 43 reject them (IBR-114-AE, // IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real -// exempt supply, so they keep E and rule 41 rejects the mixed invoice. +// exempt supply, so they keep E and rule 43 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return diff --git a/ubl/ae.go b/ubl/ae.go index 73e66c6..52efdb0 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1058,7 +1058,7 @@ func exportAELine(line *goblubl.InvoiceLine) { // fixes to AED. No test checks their currency. The two official examples in // another currency write them in USD, but both are zero rated exports, so // their VAT is zero either way. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-22), they stay in the document currency. +// (GOBL-PEPPOL-PINT-BILL-INVOICE-24), they stay in the document currency. // // GOBL keeps no VAT per line, so it is the line total at the line's rate, // rounded to the document currency, then converted. Exempt lines get no VAT @@ -1112,7 +1112,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-22) with at most 6 decimals (-23). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-24) with at most 6 decimals (-25). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return From 3775a40ad0240ee664206972f0e3fc337e8b8a0f Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:18:28 +0000 Subject: [PATCH 53/73] Pin gobl to the PR head restacked on the BR-37 PR gobl#1033 is now stacked on gobl#1040, which has the EN 16931 charge taxes rule. The code is the same; only the changelog files moved. Co-Authored-By: Claude Fable 5.2 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index de2f46b..9d3c80f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983 + github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93 github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index f288274..c6fc541 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983 h1:mFl15eCATmNknyWJz87a6Ef0D0HbImRwUA+en4HVrsA= -github.com/invopop/gobl v0.512.1-0.20261117150419-547ed0197983/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93 h1:Gs6KWw6tTZVyd+yl0ImEZpNoq+hyGsaKRKb/pQo7lrA= +github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= From 661a93330f576241ea65344bfbc5a27f8689b5d2 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:26:06 +0000 Subject: [PATCH 54/73] Pin gobl to the PR head without the extra charge test Co-Authored-By: Claude Fable 5.2 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9d3c80f..65efc86 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93 + github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139 github.com/invopop/gobl.cii v0.84.0 github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 github.com/invopop/phorm v0.1.5 diff --git a/go.sum b/go.sum index c6fc541..e428233 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93 h1:Gs6KWw6tTZVyd+yl0ImEZpNoq+hyGsaKRKb/pQo7lrA= -github.com/invopop/gobl v0.512.1-0.20261117161625-1f6494ac7b93/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139 h1:8YY/Iz2KQCO19UkFHxAi8IxgnMYw8zAWRxM0ieSRQ5s= +github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= From 6d45a8a8d27343063ace878cf05f9c9ab38d0b01 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:32:50 +0000 Subject: [PATCH 55/73] Reject the document types, currencies and email endpoints PINT AE fails Three shapes passed GOBL and failed the PINT AE Schematron: - Rule 56 limits the document type to PINT AE's list: 380, 480, 381 and 81, plus 389 and 261 for self-billing. Pro forma, corrective and debit note types, and the partial, prepayment and factoring tags, set codes that fail ibr-cl-01. - Rule 57 rejects currencies with more than two decimals, such as BHD, KWD and OMR. gobl.ubl writes the totals with the currency's decimals, which fails ibr-091 and ibr-121 to ibr-125. - Rule 14 no longer accepts an email address as the customer's electronic address. gobl.ubl writes it with the scheme EM, which is not in PINT AE's list (ibr-cl-25). partyEndpointID now picks the address in the same order as gobl.ubl. The tag rule moves from 56 to 58, after the two new ones. Rules on optional parties (14, 15, 20, 21, 22 and line rule 11) use AssertIfPresent, so a missing customer no longer raises rule 20, and their helpers return false for a nil or unknown value. Co-Authored-By: Claude Fable 5.2 --- addon/pint/bill.go | 63 +++++++++++++++++++++++++++----- addon/pint/bill_line.go | 2 +- addon/pint/bill_test.go | 80 +++++++++++++++++++++++++++++++++-------- addon/pint/org_party.go | 47 ++++++++++++++---------- addon/pint/pay.go | 2 +- addon/pint/pint.go | 5 +++ addon/pint/scenarios.go | 14 ++++++++ 7 files changed, 169 insertions(+), 44 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 22c8c06..067d227 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -116,13 +116,16 @@ func billInvoiceRules() *rules.Set { ), // TODO: ibr-080 is a shared PINT rule, so every PINT jurisdiction // needs this: rule 04 only checks that there is an endpoint, but - // gobl.ubl writes none as cbc:EndpointID for other URI schemes. - rules.Assert("14", "customer electronic address must be an ISO 6523 or email endpoint, or an inbox (IBR-080)", + // gobl.ubl writes none as cbc:EndpointID for other URI schemes. It + // writes an email address with the scheme EM, which is not in + // PINT AE's electronic address scheme list (ibr-cl-25). The + // supplier has the same gap (ibr-081). + rules.AssertIfPresent("14", "customer electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-080, ibr-cl-25)", is.Func("electronic address written as endpoint ID", partyHasEndpointID), ), // TODO: ibr-sr-16 is a shared PINT rule, and EN 16931 has it too // (UBL-SR-16), so every PINT jurisdiction and BIS need this. - rules.Assert("15", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", + rules.AssertIfPresent("15", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", is.Func("at most one buyer identifier", partyHasOneIdentification), ), // IBR-183-AE's test also accepts CL, which only its rule text's @@ -163,7 +166,7 @@ func billInvoiceRules() *rules.Set { is.Func("has tax registration", partyHasTaxRegistration), ), ), - rules.Assert("20", "customer must have at most one tax registration (IBR-179-AE)", + rules.AssertIfPresent("20", "customer must have at most one tax registration (IBR-179-AE)", is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), ), ), @@ -171,12 +174,12 @@ func billInvoiceRules() *rules.Set { // AE tax representative and issuer rules.Field("ordering", rules.Field("seller", - rules.Assert("21", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("21", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), rules.Field("issuer", - rules.Assert("22", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("22", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), @@ -470,6 +473,33 @@ func billInvoiceRules() *rules.Set { ), ), ), + + // AE document type list + // + // PINT AE's list is shorter than EN 16931's: 380 and 480 on invoices, + // 381 and 81 on credit notes, and 389 and 261 for self-billing. The + // other codes the EN 16931 scenarios set, for pro forma, corrective + // and debit note types and the partial, prepayment and factoring + // tags, fail ibr-cl-01. + rules.Field("tax", + rules.Field("ext", + rules.Assert("56", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), + ), + ), + ), + + // AE currency decimals + // + // PINT allows at most two decimals in the document totals (ibr-091, + // ibr-121 to ibr-125), and gobl.ubl writes them with the decimals + // of the currency, so every document in a currency with three or + // more, such as BHD, KWD or OMR, fails. + rules.Field("currency", + rules.Assert("57", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), + ), + ), ), // Tags @@ -480,7 +510,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("56", "PINT AE tags can only be used on UAE documents", + rules.Assert("58", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -565,7 +595,7 @@ func invoiceExtIn(key cbc.Key, codes ...cbc.Code) func(any) bool { func invoiceHasNoAETags(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { - return true + return false } others := bill.DefaultInvoiceTags() if r := inv.RegimeDef(); r != nil { @@ -585,6 +615,18 @@ func invoiceHasNoAETags(val any) bool { return true } +// currencyHasAtMost2Decimals reports whether a currency has two decimals or +// fewer, the most PINT allows in the document totals (ibr-091, ibr-121 to +// ibr-125). A missing or unknown currency fails. +func currencyHasAtMost2Decimals(val any) bool { + code, ok := val.(currency.Code) + if !ok { + return false + } + def := code.Def() + return def != nil && def.Subunits <= 2 +} + // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices @@ -643,7 +685,10 @@ func invoiceHasLineComboOtherThanEorO(val any) bool { // (IBR-141-AE). Invoices without a value date pass. func pointDateBeforeIssueDate(val any) bool { inv, ok := val.(*bill.Invoice) - if !ok || inv == nil || inv.ValueDate == nil { + if !ok || inv == nil { + return false + } + if inv.ValueDate == nil { return true } return inv.IssueDate.DaysSince(inv.ValueDate.Date) > 0 diff --git a/addon/pint/bill_line.go b/addon/pint/bill_line.go index 40311e8..d96ee9e 100644 --- a/addon/pint/bill_line.go +++ b/addon/pint/bill_line.go @@ -104,7 +104,7 @@ func billLineRules() *rules.Set { ), ), rules.Field("seller", - rules.Assert("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 4eff001..0d1c5e7 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -308,16 +308,18 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultCurrencyDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -499,12 +501,51 @@ func TestBillDocumentRulesAE(t *testing.T) { } }) + t.Run("document type must be in the PINT AE list (ibr-cl-01)", func(t *testing.T) { + for name, inv := range map[string]*bill.Invoice{ + "380": standard(), + "381": aeDocument(bill.InvoiceTypeCreditNote), + "480": outsideScope(), + "81": outsideScopeCredit(), + "389": aeDocument(bill.InvoiceTypeStandard, tax.TagSelfBilled), + "261": aeDocument(bill.InvoiceTypeCreditNote, tax.TagSelfBilled), + } { + assert.NotContains(t, aeFaults(t, inv), faultDocumentType, name) + } + for name, inv := range map[string]*bill.Invoice{ + "325 pro forma": aeDocument(bill.InvoiceTypeProforma), + "384 corrective": aeDocument(bill.InvoiceTypeCorrective), + "383 debit note": aeDocument(bill.InvoiceTypeDebitNote), + "326 partial": aeDocument(bill.InvoiceTypeStandard, tax.TagPartial), + "386 prepayment": aeDocument(bill.InvoiceTypeStandard, tax.TagPrepayment), + "393 factoring": aeDocument(bill.InvoiceTypeStandard, tax.TagFactoring), + "396 credit note": aeDocument(bill.InvoiceTypeCreditNote, tax.TagFactoring), + } { + assert.Contains(t, aeFaults(t, inv), faultDocumentType, name) + } + }) + + t.Run("currency must have at most 2 decimals (ibr-091)", func(t *testing.T) { + inv := standard() + inv.Currency = currency.BHD + inv.ExchangeRates = []*currency.ExchangeRate{{From: currency.BHD, To: currency.AED, Amount: num.MakeAmount(974, 2)}} + assert.Contains(t, aeFaults(t, inv), faultCurrencyDecimals) + + for _, cur := range []currency.Code{currency.USD, currency.JPY} { + inv = standard() + inv.Currency = cur + inv.ExchangeRates = []*currency.ExchangeRate{{From: cur, To: currency.AED, Amount: num.MakeAmount(367, 2)}} + assert.NotContains(t, aeFaults(t, inv), faultCurrencyDecimals, cur) + } + }) + t.Run("document rules do not apply outside AE", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeProforma) + inv.Currency = currency.BHD require.NoError(t, inv.Calculate()) err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) require.Error(t, err) - for _, code := range []string{faultSellerTRN, faultDueDate, faultOnlyExempt} { + for _, code := range []string{faultSellerTRN, faultDueDate, faultOnlyExempt, faultDocumentType, faultCurrencyDecimals} { assert.NotContains(t, err.Error(), code) } }) @@ -688,6 +729,15 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), fault) }) + t.Run("a missing customer raises no customer faults but its own (IBR-007)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer = nil + out := aeFaults(t, inv) + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-03") + assert.NotContains(t, out, faultCustomerEndpoint) + assert.NotContains(t, out, faultCustomerTaxCount) + }) + t.Run("supplier with a UAE endpoint needs a legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil @@ -888,8 +938,10 @@ func TestBillIdentityRulesAE(t *testing.T) { inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} assert.Contains(t, aeFaults(t, inv), faultCustomerEndpoint) + // An email address is written with the scheme EM, which PINT AE + // doesn't accept (ibr-cl-25). inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) - assert.NotContains(t, aeFaults(t, inv), faultCustomerEndpoint) + assert.Contains(t, aeFaults(t, inv), faultCustomerEndpoint) inv = aeIdentityDocument() inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} @@ -1384,7 +1436,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index c2bfca0..b4a8fe8 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -20,9 +20,13 @@ var emirateCodes = []cbc.Code{ const endpointSchemeUAE cbc.Code = "0235" // endpointSchemeMailto is the URI scheme of email endpoints, which gobl.ubl -// writes as cbc:EndpointID. +// writes as cbc:EndpointID with the scheme endpointSchemeEmail. const endpointSchemeMailto = "mailto" +// endpointSchemeEmail is the electronic address scheme gobl.ubl writes for +// email addresses. +const endpointSchemeEmail cbc.Code = "EM" + // partyHasIdentifier reports whether the party can be identified through a tax // identity code or at least one organisation identity. func partyHasIdentifier(val any) bool { @@ -73,7 +77,7 @@ func partyHasLegalIdentity(val any) bool { func partyHasOneIdentification(val any) bool { p, ok := val.(*org.Party) if !ok || p == nil { - return true + return false } n := 0 legal := false @@ -125,7 +129,7 @@ func partyAddressHasEmirate(val any) bool { func partyPostalAddressHasEmirate(val any) bool { p, ok := val.(*org.Party) if !ok || p == nil { - return true + return false } a := partyFirstAddress(p) inAE := a != nil && a.Country == l10n.AE.ISO() @@ -137,7 +141,8 @@ func partyPostalAddressHasEmirate(val any) bool { // partyEndpointID returns the scheme and code of the party's electronic // address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 -// endpoint, or else the first inbox with a scheme. +// endpoint, or else the first email endpoint, or else the first inbox with an +// email or a scheme. Email addresses have the scheme EM. func partyEndpointID(p *org.Party) (cbc.Code, string) { if e := p.Endpoint(iso.ActorIDScheme); e != nil { // An ISO 6523 URI reads "iso6523-actorid-upis:::". @@ -146,8 +151,17 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { return cbc.Code(scheme), code } } + if e := p.Endpoint(endpointSchemeMailto); e != nil && e.URI.Opaque() != "" { + return endpointSchemeEmail, e.URI.Opaque() + } for _, ib := range p.Inboxes { - if ib != nil && ib.Email == "" && ib.Scheme != "" { + if ib == nil { + continue + } + if ib.Email != "" { + return endpointSchemeEmail, ib.Email + } + if ib.Scheme != "" { return ib.Scheme, ib.Code.String() } } @@ -155,25 +169,20 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { } // partyHasEndpointID reports whether gobl.ubl writes the party's electronic -// address as cbc:EndpointID: an ISO 6523 or email endpoint, or an inbox. A -// party without endpoints passes, as rule 04 reports it. +// address as a cbc:EndpointID that PINT AE accepts: an ISO 6523 endpoint or an +// inbox with a scheme. An email address is written with the scheme EM, which +// is not in PINT AE's list (ibr-cl-25). A party without endpoints passes, as +// rule 04 reports it. func partyHasEndpointID(val any) bool { p, ok := val.(*org.Party) - if !ok || p == nil || len(p.Endpoints) == 0 { - return true - } - if s, _ := partyEndpointID(p); s != "" { - return true + if !ok || p == nil { + return false } - if e := p.Endpoint(endpointSchemeMailto); e != nil && e.URI.Opaque() != "" { + if len(p.Endpoints) == 0 { return true } - for _, ib := range p.Inboxes { - if ib != nil && ib.Email != "" { - return true - } - } - return false + s, _ := partyEndpointID(p) + return s != "" && s != endpointSchemeEmail } // partyHasUAEEndpointWith returns a predicate that reports whether the party's diff --git a/addon/pint/pay.go b/addon/pint/pay.go index 3259582..66ca29f 100644 --- a/addon/pint/pay.go +++ b/addon/pint/pay.go @@ -97,7 +97,7 @@ func creditTransferHasAccountID(val any) bool { func instructionsHaveAccountID(val any) bool { instr, ok := val.(*pay.Instructions) if !ok || instr == nil { - return true + return false } if len(instr.CreditTransfer) == 0 { return false diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 297d034..05a9fc6 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -88,6 +88,11 @@ func newV1Addon() *tax.AddonDef { UAE documents out of scope of VAT use the "outside-scope" tag, which sets the document type to 480 on invoices and 81 on credit notes. + UAE documents can only be invoices and credit notes, without the + "partial", "prepayment" or "factoring" tags, as PINT AE has no + document type for anything else. Their currency can have two + decimals at most. + UAE trade licences carry their issuing authority in the description, and passports their issuing country. diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index 2600252..6b41b78 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -27,8 +27,22 @@ const ( // docTypeSelfBilledCreditNote is the code the EN 16931 scenarios set on // self-billed credit notes. docTypeSelfBilledCreditNote cbc.Code = "261" + // docTypeSelfBilledInvoice is the code the EN 16931 scenarios set on + // self-billed invoices. + docTypeSelfBilledInvoice cbc.Code = "389" ) +// docTypesAE are the UNTDID 1001 codes PINT AE accepts: ibr-cl-01's list for +// billing, and the self-billing codes. +var docTypesAE = []cbc.Code{ + docTypeCommercialInvoice, + docTypeInvoiceOutsideScope, + docTypeCreditNote, + docTypeCreditNoteGoodsServices, + docTypeSelfBilledInvoice, + docTypeSelfBilledCreditNote, +} + // invoiceTags are the document tags the PINT addon adds to invoices. var invoiceTags = &tax.TagSet{ Schema: bill.ShortSchemaInvoice, From 65dc96a96ae8a8202dcb932f633df11b4b03ae5b Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:19:15 +0000 Subject: [PATCH 56/73] Stop writing the third address line gobl no longer has a third address line (org.Address.StreetThird), so the bank branch address only writes the street and the additional street, as gobl.ubl does for every other address. The fixtures drop their street_third values, and the parse outputs no longer carry the UBL AddressLine. Co-Authored-By: Claude Opus 5.5 --- ubl/ae.go | 6 +++--- ubl/ae_internal_test.go | 4 +--- .../convert/pint/ae/invoice-ae-shared-fields.json | 6 +----- ubl/testdata/convert/pint/ae/invoice-ae.json | 4 +--- .../convert/pint/ae/out/invoice-ae-shared-fields.xml | 12 ------------ ubl/testdata/convert/pint/ae/out/invoice-ae.xml | 6 ------ ubl/testdata/parse/bis/out/Allowance-example.json | 3 +-- ubl/testdata/parse/bis/out/Vat-category-S.json | 3 +-- .../parse/pint/ae/out/margin-scheme-credit-note.json | 4 +--- ubl/testdata/parse/pint/ae/out/margin-scheme.json | 4 +--- 10 files changed, 10 insertions(+), 42 deletions(-) diff --git a/ubl/ae.go b/ubl/ae.go index 52efdb0..1cf1153 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -315,6 +315,9 @@ func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfe scheme := accountSchemeIBAN acc.ID.SchemeID = &scheme } + // TODO: gobl.ubl reads the branch address for every UBL format, but only + // FormatAE writes it, so BIS, PINT and A-NZ drop it on export. Move this + // export into gobl.ubl, reusing its address builder, and remove aeAddress. if addr := aeAddress(ct.Branch); addr != nil { if acc.FinancialInstitutionBranch == nil { acc.FinancialInstitutionBranch = new(goblubl.Branch) @@ -337,9 +340,6 @@ func aeAddress(a *org.Address) *goblubl.PostalAddress { } set(&addr.StreetName, a.LineOne()) set(&addr.AdditionalStreetName, a.LineTwo()) - if l := a.LineThree(); l != "" { - addr.AddressLine = []goblubl.AddressLine{{Line: l}} - } set(&addr.CityName, a.Locality) set(&addr.PostalZone, a.Code.String()) set(&addr.CountrySubentity, a.Region) diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 260f650..82ca73b 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -1174,7 +1174,7 @@ func TestExportAEPayment(t *testing.T) { out := ublInvoice() exportAEPayment(out, goblInvoice(&pay.CreditTransfer{ IBAN: iban, - Branch: &org.Address{Street: "Baniyas Road", StreetExtra: "Deira", StreetThird: "Main Branch", Locality: "Dubai", Region: "DXB", Code: "777", Country: "AE"}, + Branch: &org.Address{Street: "Baniyas Road", StreetExtra: "Deira", Locality: "Dubai", Region: "DXB", Code: "777", Country: "AE"}, }, nil)) acc := out.PaymentMeans[0].PayeeFinancialAccount assert.Equal(t, "IBAN", *acc.ID.SchemeID) @@ -1182,8 +1182,6 @@ func TestExportAEPayment(t *testing.T) { require.NotNil(t, addr) assert.Equal(t, "Baniyas Road", *addr.StreetName) assert.Equal(t, "Deira", *addr.AdditionalStreetName) - require.Len(t, addr.AddressLine, 1) - assert.Equal(t, "Main Branch", addr.AddressLine[0].Line) assert.Equal(t, "Dubai", *addr.CityName) assert.Equal(t, "DXB", *addr.CountrySubentity) assert.Equal(t, "777", *addr.PostalZone) diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index d6d92c4..df410e9 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "8481a29d392134057728d066188693f072d8aec4b8e9b982b26b31f075d043ad" + "val": "2fd34ae748de52889dcb37e92ee1b77f66c8aa1bc9642e24dd940f44533757ee" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -64,7 +64,6 @@ { "street": "Sheikh Zayed Road", "street_extra": "Trade Centre", - "street_third": "Tower 2, Office 1405", "locality": "Dubai", "region": "DXB", "country": "AE" @@ -101,7 +100,6 @@ { "street": "Corniche Road", "street_extra": "Al Bateen", - "street_third": "Building 7, Floor 3", "locality": "Abu Dhabi", "region": "AUH", "country": "AE" @@ -245,7 +243,6 @@ { "street": "Al Maktoum Road", "street_extra": "Deira", - "street_third": "Office 210", "locality": "Dubai", "region": "DXB", "country": "AE" @@ -297,7 +294,6 @@ { "street": "Industrial Area 4", "street_extra": "Musaffah", - "street_third": "Gate 3", "locality": "Abu Dhabi", "region": "AUH", "country": "AE" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 0f50859..16991ba 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "139a5d40d4f5ff439072a65bbabc517e0c70b7e83020ab63c2a3ba4197ddb8c7" + "val": "3370f550c6b4f636857d7d6cf990604d2a29448e31ec5c519e1d588ac83f1ea2" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -60,7 +60,6 @@ { "street": "Sheikh Zayed Road", "street_extra": "Trade Centre", - "street_third": "Tower 2, Office 1405", "locality": "Dubai", "region": "DXB", "country": "AE" @@ -163,7 +162,6 @@ "branch": { "street": "Baniyas Road", "street_extra": "Deira", - "street_third": "Main Branch", "locality": "Dubai", "code": "777", "country": "AE" diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index bed2674..4a49805 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -26,9 +26,6 @@ Trade Centre Dubai DXB - - Tower 2, Office 1405 - AE @@ -56,9 +53,6 @@ Al Bateen Abu Dhabi AUH - - Building 7, Floor 3 - AE @@ -92,9 +86,6 @@ Deira Dubai DXB - - Office 210 - AE @@ -117,9 +108,6 @@ Musaffah Abu Dhabi AUH - - Gate 3 - AE diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index d849216..8b55629 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -28,9 +28,6 @@ Trade Centre Dubai DXB - - Tower 2, Office 1405 - AE @@ -87,9 +84,6 @@ Deira Dubai 777 - - Main Branch - AE diff --git a/ubl/testdata/parse/bis/out/Allowance-example.json b/ubl/testdata/parse/bis/out/Allowance-example.json index 2e675c4..10c60ea 100644 --- a/ubl/testdata/parse/bis/out/Allowance-example.json +++ b/ubl/testdata/parse/bis/out/Allowance-example.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5ecdc65beee6ae2bfab266e14e5a17eb7b6f2230ec9fa774d641b63b057e26f1" + "val": "2ac7756b37527bdb78d4162d8299a74c4a3f5139ef22446415cab69975670eb6" } }, "doc": { @@ -417,7 +417,6 @@ { "street": "Delivery street 2", "street_extra": "Building 56", - "street_third": "Gate 15", "locality": "Stockholm", "region": "Södermalm", "code": "21234", diff --git a/ubl/testdata/parse/bis/out/Vat-category-S.json b/ubl/testdata/parse/bis/out/Vat-category-S.json index 9a3844e..cf44327 100644 --- a/ubl/testdata/parse/bis/out/Vat-category-S.json +++ b/ubl/testdata/parse/bis/out/Vat-category-S.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f1af5ad8508725dbb280bb4b5d4b4528830786117f5d41b5e2f2c4a4cfad74c0" + "val": "dbaf58495e23c1d5e9d59cc877518b5428c3eacb9600aa11f71d3ea10c1dfc74" } }, "doc": { @@ -325,7 +325,6 @@ { "street": "Delivery street 2", "street_extra": "Building 56", - "street_third": "Gate 15", "locality": "Stockholm", "region": "Södermalm", "code": "21234", diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json b/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json index 25c3814..7861c97 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme-credit-note.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5d2210e055c6541dcab01ada5fa1f3e9b586c91711e514b39894d524d1f477a6" + "val": "ae9a8ee5911722acd6b4c4dde4b4187fbd715d757565188bb0786e1e71dfcb09" }, "from": "iso6523-actorid-upis::0235:112345678900003", "to": "iso6523-actorid-upis::0235:112345679000003" @@ -79,7 +79,6 @@ { "street": "Street Name", "street_extra": "Additional Street Name", - "street_third": "Additional Address line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", @@ -131,7 +130,6 @@ { "street": "Street Name", "street_extra": "Additional Street Name", - "street_third": "Additional Address Line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", diff --git a/ubl/testdata/parse/pint/ae/out/margin-scheme.json b/ubl/testdata/parse/pint/ae/out/margin-scheme.json index 070fed2..9e9431c 100644 --- a/ubl/testdata/parse/pint/ae/out/margin-scheme.json +++ b/ubl/testdata/parse/pint/ae/out/margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c26c3f64b0a1bd3704a2504990810aeea8a10a0cedbc352f4fe33d5c83a5fc4c" + "val": "8a4d1fd6cc1cf691229ff59ea2c68aa4001c4a2a71f8226e71574d02a84e0ea9" }, "from": "iso6523-actorid-upis::0235:112345678900003", "to": "iso6523-actorid-upis::0235:112345679000003" @@ -72,7 +72,6 @@ { "street": "Street Name", "street_extra": "Additional Street Name", - "street_third": "Additional Address line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", @@ -124,7 +123,6 @@ { "street": "Street Name", "street_extra": "Additional Street Name", - "street_third": "Additional Address Line", "locality": "Abu Dhabi", "region": "AUH", "code": "Postal Zone", From 590fdf5666d953184bf3e1343b9c9feac5395e87 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:20:07 +0000 Subject: [PATCH 57/73] Update the PINT AE rules to 1.0.5 PINT AE 1.0.5 changes several rules the addon followed from 1.0.4, and phorm now has its Schematron as 2026.11, so FormatAE and its self-billing specification validate against it. The addon follows the 1.0.5 tests: IBR-149-AE now asks customers for the legal identity, buyers with the predefined endpoints 9900000098 and 9900000099 are exempt from the legal identity type and trade licence authority rules, CL is no longer a legal identity type, outside scope documents only take E and O, service items no longer need a service accounting code, exempt discounts and charges need the exemption reason, suppliers on outside scope documents and credit notes related to goods and services (480, 81) need a TRN or TIN, delivery addresses need an emirate, the principal ID must be a TRN, and Metal Scrap Trading is a goods type. Deemed supplies must be addressed to the predefined endpoint 0235:9900000097, as the 1.0.5 BIS (section 1.5.3 and IBT-049) requires and its corrected example shows. No Schematron rule checks it, but a deemed supply sent to the buyer's own endpoint would be delivered instead of only reported. On export, reverse charge allowances and charges are written at 5%, as 1.0.5 expects, and the total in AED (BTAE-20) has no currency code. The 1.0.5 examples for those cases are imported as parse fixtures, and the comments that cited 1.0.4 now cite 1.0.5. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +- addon/pint/bill.go | 217 ++++++++-------- addon/pint/bill_line.go | 16 +- addon/pint/bill_line_test.go | 19 +- addon/pint/bill_test.go | 244 +++++++++++++----- addon/pint/extensions.go | 21 +- addon/pint/org_identity.go | 7 - addon/pint/org_identity_test.go | 2 +- addon/pint/org_party.go | 48 +++- addon/pint/tax_combo.go | 8 +- ubl/ae.go | 59 +++-- ubl/ae_internal_test.go | 25 +- .../pint/ae/invoice-ae-deemed-supply.json | 8 +- .../pint/ae/out/invoice-ae-deemed-supply.xml | 2 +- .../invoice-ae-reverse-charge-allowance.xml | 4 +- .../convert/pint/ae/out/invoice-ae-usd.xml | 2 +- .../parse/pint/ae/allowance-exempt.xml | 7 +- .../pint/ae/allowance-reverse-charge.xml | 165 ++++++++++++ ubl/testdata/parse/pint/ae/deemed-supply.xml | 4 +- .../parse/pint/ae/out/allowance-exempt.json | 21 +- .../pint/ae/out/allowance-reverse-charge.json | 241 +++++++++++++++++ .../parse/pint/ae/out/deemed-supply.json | 6 +- .../ae/out/seller-trn-tin-identifiers.json | 220 ++++++++++++++++ .../pint/ae/seller-trn-tin-identifiers.xml | 155 +++++++++++ ubl/ubl.go | 8 +- ubl/ubl_test.go | 22 +- 26 files changed, 1235 insertions(+), 302 deletions(-) create mode 100644 ubl/testdata/parse/pint/ae/allowance-reverse-charge.xml create mode 100644 ubl/testdata/parse/pint/ae/out/allowance-reverse-charge.json create mode 100644 ubl/testdata/parse/pint/ae/out/seller-trn-tin-identifiers.json create mode 100644 ubl/testdata/parse/pint/ae/seller-trn-tin-identifiers.xml diff --git a/README.md b/README.md index 719e67b..cae1448 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with `FormatAE` also adjusts the output to the PINT AE rules: it writes the invoice UUID, the price base quantity and gross price, the UAE TRN without its country -prefix, the 5% rate on reverse charge lines and breakdowns, no rate on exempt -ones, one VAT breakdown per category, and each line's amount with VAT and VAT -amount in AED. For invoices not in AED, it also writes the exchange rate to +prefix, the 5% rate on reverse charge lines, breakdowns, allowances and +charges, no rate on exempt lines and breakdowns, one VAT breakdown per +category, and each line's amount with VAT and VAT amount in AED. For invoices not in AED, it also writes the exchange rate to AED and the total with VAT in AED, and converts the line amounts with that rate. The seller and buyer legal identities get their PINT AE type (`TL`, `EID`, `PAS` or `CD`, from the AE regime's identity keys and `passport`), with diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 067d227..db653aa 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -37,7 +37,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // PINT has no BR-CO-25. PINT AE asks for payment instructions - // (IBR-191-AE, rules 27 and 28) and a due date (IBR-127-AE, rule 29) + // (IBR-191-AE, rules 28 and 29) and a due date (IBR-127-AE, rule 30) // instead, except on credit notes and deemed supplies. rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-06"), rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-07"), @@ -49,15 +49,10 @@ func billInvoiceRules() *rules.Set { // AE supplier // - // IBR-128-AE's text names the seller, buyer, tax representative and - // delivery subdivisions (IBT-039, IBT-054, IBT-068, IBT-079), but its - // test never runs on the seller's and buyer's addresses: its context, - // cac:PostalAddress, comes after their address rules (IBR-143-AE, - // IBR-144-AE) in the same pattern, where a node only fires the first - // rule it matches. Rules 06 and 13 follow the text there, as the - // official examples do, so they check more than the test. Rules 21 - // and 22, and line rule 11, follow the test: gobl.ubl also writes the - // issuer and the line sellers with a cac:PostalAddress. + // IBR-128-AE asks every UAE address for an emirate code as its + // region: the seller's and buyer's here, the tax representative's, + // the issuer's and the delivery address below, and the line sellers' + // in line rule 10. rules.Field("supplier", rules.Assert("05", "supplier address must have a street, city and region (IBR-143-AE)", is.Func("first address has street, city and region", partyAddressIsComplete), @@ -128,16 +123,16 @@ func billInvoiceRules() *rules.Set { rules.AssertIfPresent("15", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", is.Func("at most one buyer identifier", partyHasOneIdentification), ), - // IBR-183-AE's test also accepts CL, which only its rule text's - // "Commercial/Trade license" explains. FormatAE reads CL as a - // trade licence on import, but GOBL writes TL, which is valid for - // both seller and buyer. + // IBR-180-AE, IBR-183-AE and IBR-101-AE exempt the buyers with the + // predefined endpoints 9900000098 and 9900000099. IBR-183-AE also + // exempts other 1XXXXXXXXX endpoints, but IBR-180-AE still asks + // them for a type, and GOBL can only write the four in the list. rules.When( - is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), + is.Func("has UAE Peppol endpoint other than 9900000098 or 9900000099", partyHasUAEEndpointNotPredefined), rules.Field("identities", rules.Each( rules.When( is.Func("legal scope", identityHasLegalScope), - rules.Assert("16", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-180-AE, IBR-183-AE)", + rules.Assert("16", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint other than 9900000098 or 9900000099 (IBR-180-AE, IBR-183-AE)", is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), @@ -150,20 +145,22 @@ func billInvoiceRules() *rules.Set { rules.Assert("17", "customer passport must have the issuing country (IBR-010-AE)", is.Present), ), ), - rules.When( - org.IdentityTypeIn(ae.IdentityTypeTradeLicense), - rules.Field("description", - rules.Assert("18", "customer trade license must have the issuing authority in the description (IBR-101-AE)", is.Present), - ), - ), )), - // IBR-149-AE's text asks for the buyer legal registration identifier - // (IBT-047), but its test checks the tax registration, - // cac:PartyTaxScheme/cbc:CompanyID. We follow the test. rules.When( - is.Func("has UAE Peppol endpoint not starting with 1 or 9", partyHasUAEEndpointNotStartingWith1or9), - rules.Assert("19", "customer tax registration is required with a UAE Peppol endpoint not starting with 1 or 9 (IBR-149-AE)", - is.Func("has tax registration", partyHasTaxRegistration), + is.Not(is.Func("has UAE Peppol endpoint 9900000098 or 9900000099", partyHasUAEEndpointPredefined)), + rules.Field("identities", rules.Each( + rules.When( + org.IdentityTypeIn(ae.IdentityTypeTradeLicense), + rules.Field("description", + rules.Assert("18", "customer trade license must have the issuing authority in the description, except with a UAE Peppol endpoint 9900000098 or 9900000099 (IBR-101-AE)", is.Present), + ), + ), + )), + ), + rules.When( + is.Func("has UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX", partyHasUAEEndpointNot1or9), + rules.Assert("19", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", + is.Func("has legal identity", partyHasLegalIdentity), ), ), rules.AssertIfPresent("20", "customer must have at most one tax registration (IBR-179-AE)", @@ -185,6 +182,15 @@ func billInvoiceRules() *rules.Set { ), ), + // AE delivery address + rules.Field("delivery", + rules.Field("receiver", + rules.AssertIfPresent("23", "delivery address region must be an emirate code when the country is AE (IBR-128-AE)", + is.Func("first address region is an emirate", partyFirstAddressHasEmirate), + ), + ), + ), + // AE tax schemes of every party // // IBR-133-AE's test runs on every cac:TaxScheme/cbc:ID: a scheme @@ -192,20 +198,20 @@ func billInvoiceRules() *rules.Set { // the customer, tax representative, issuer, payee and line sellers. // The supplier's own pass: its tax ID is under VAT, and rule 11 makes // any tax scope identity of it a TIN. Every tax category here is VAT. - rules.Assert("23", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", + rules.Assert("24", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), ), // AE currency - rules.Assert("24", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("25", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("25", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("26", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("26", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("27", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -216,11 +222,11 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceIsDeemedSupply), )), rules.Field("payment", - rules.Assert("27", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("28", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("28", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("29", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -237,7 +243,7 @@ func billInvoiceRules() *rules.Set { )), rules.When( is.Func("amount due is positive", invoiceIsDue), - rules.Assert("29", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("30", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Func("has due date", invoiceHasDueDate), ), ), @@ -248,7 +254,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("30", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("31", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -259,7 +265,7 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - rules.Assert("31", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("32", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), ), @@ -268,7 +274,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("32", "line VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("33", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -281,7 +287,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("33", "discount VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("34", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -294,7 +300,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("34", "charge VAT category code must be an E, Z, or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("35", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -302,7 +308,7 @@ func billInvoiceRules() *rules.Set { ), )), )), - rules.Assert("35", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + rules.Assert("36", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), ), ), @@ -311,7 +317,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("36", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("37", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -325,13 +331,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("37", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("38", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("38", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("39", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -341,7 +347,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("39", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("40", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -349,7 +355,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("40", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("41", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -359,7 +365,7 @@ func billInvoiceRules() *rules.Set { // AE transaction type rules.Field("tax", rules.Field("ext", - rules.Assert("41", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + rules.Assert("42", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", tax.ExtensionsRequire(ExtKeyTransactionType), tax.ExtensionHasValidCode(ExtKeyTransactionType), ), @@ -369,24 +375,35 @@ func billInvoiceRules() *rules.Set { is.Func("free trade zone", invoiceIsFreeTradeZone), rules.Field("tax", rules.Field("ext", - rules.Assert("42", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("43", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), ), ), + // PINT AE BIS 1.5.3 predefines the buyer electronic address of a + // deemed supply. The other predefined endpoints, 9900000098 and + // 9900000099, depend on facts GOBL doesn't know. + rules.When( + is.Func("deemed supply", invoiceIsDeemedSupply), + rules.Field("customer", + rules.AssertIfPresent("44", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", + is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpointDeemedSupply), + ), + ), + ), // With the discount and charge rules 02, a margin scheme invoice can // have no discounts or charges, as GOBL requires them to have taxes // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("43", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + rules.Assert("45", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( is.Func("summary invoice", invoiceIsSummary), - rules.Assert("44", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + rules.Assert("46", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), @@ -394,23 +411,30 @@ func billInvoiceRules() *rules.Set { is.Func("disclosed agent billing", invoiceIsDisclosedAgent), rules.Field("tax", rules.Field("ext", - rules.Assert("45", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("47", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), ), - rules.Assert("46", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", + rules.Assert("48", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", is.Func("principal ID is not the supplier tax ID", principalIsNotSupplier), ), + ), + // IBR-177-AE asks for the TRN or the TIN on every document. Rule 31 + // already asks for the TRN except on 480 and 81, so this rule only + // covers those, where the TIN is enough. + rules.When( + is.Func("document type is invoice outside scope or credit note related to goods and services", + invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("supplier", - rules.Assert("47", "supplier tax registration is required on disclosed agent billing (IBR-177-AE)", + rules.Assert("49", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), ), rules.When( is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("48", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + rules.Assert("50", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), @@ -420,7 +444,7 @@ func billInvoiceRules() *rules.Set { // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), - rules.Assert("49", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + rules.Assert("51", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), ), ), @@ -429,7 +453,7 @@ func billInvoiceRules() *rules.Set { rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("50", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("52", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), ), ), @@ -440,7 +464,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("has reverse charge lines", invoiceHasReverseChargeLine), rules.Field("customer", - rules.Assert("51", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("53", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), @@ -449,18 +473,21 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("52", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("54", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("53", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("55", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), + rules.Assert("56", "principal ID must be a TRN of 15 digits starting with 1 and ending with 03 (IBR-132-AE)", + tax.ExtensionHasValidCode(ExtKeyPrincipalID), + ), ), // PINT AE writes the billing frequency where EN writes the VAT // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, // and IBR-005-AE only accepts frequencies there. rules.Field("point", - rules.Assert("54", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("57", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", is.Not(is.Present), ), ), @@ -468,7 +495,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), rules.Field("notes", - rules.Assert("55", "a note is required with the billing frequency Others (IBR-160-AE)", + rules.Assert("58", "a note is required with the billing frequency Others (IBR-160-AE)", is.Present, ), ), @@ -483,7 +510,7 @@ func billInvoiceRules() *rules.Set { // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", - rules.Assert("56", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("59", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), @@ -496,7 +523,7 @@ func billInvoiceRules() *rules.Set { // of the currency, so every document in a currency with three or // more, such as BHD, KWD or OMR, fails. rules.Field("currency", - rules.Assert("57", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("60", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -510,7 +537,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("58", "PINT AE tags can only be used on UAE documents", + rules.Assert("61", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -523,18 +550,15 @@ func billDiscountRules() *rules.Set { return rules.For(new(bill.Discount), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - // IBR-168-AE names the exemption reason code, but its test checks the - // allowance reason code, cbc:AllowanceChargeReasonCode. We follow the - // test. - rules.When( - is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), - rules.Field("ext", - rules.Assert("01", "exempt discount needs an allowance reason code (IBR-168-AE)", - tax.ExtensionsRequire(untdid.ExtKeyAllowance), + rules.Field("taxes", rules.Each( + rules.When( + is.Func("exempt VAT", comboIsExemptVAT), + rules.Field("ext", + rules.Assert("01", "exempt discount VAT needs a UAE VAT exemption reason (IBR-168-AE)", + tax.ExtensionsRequire(ExtKeyExemption), + ), ), ), - ), - rules.Field("taxes", rules.Each( rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", @@ -554,18 +578,15 @@ func billChargeRules() *rules.Set { return rules.For(new(bill.Charge), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - // IBR-169-AE names the exemption reason code, but its test checks the - // charge reason code, cbc:AllowanceChargeReasonCode. We follow the - // test. - rules.When( - is.Func("has exempt VAT", taxesIn(comboIsExemptVAT)), - rules.Field("ext", - rules.Assert("01", "exempt charge needs a charge reason code (IBR-169-AE)", - tax.ExtensionsRequire(untdid.ExtKeyCharge), + rules.Field("taxes", rules.Each( + rules.When( + is.Func("exempt VAT", comboIsExemptVAT), + rules.Field("ext", + rules.Assert("01", "exempt charge VAT needs a UAE VAT exemption reason (IBR-169-AE)", + tax.ExtensionsRequire(ExtKeyExemption), + ), ), ), - ), - rules.Field("taxes", rules.Each( rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", @@ -630,7 +651,7 @@ func currencyHasAtMost2Decimals(val any) bool { // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 24 reports them. +// without it pass: they are in AED, or rule 25 reports them. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -837,7 +858,7 @@ func invoiceHasInvoicePeriod(val any) bool { // principalIsNotSupplier reports whether the principal ID differs from the // supplier's tax registrations, the cbc:CompanyID values of its // PartyTaxSchemes (IBR-176-AE). A missing principal ID or supplier tax -// registration passes, as rules 45 and 47 report those. +// registration passes, as rules 47 and 49 report those. func principalIsNotSupplier(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -899,30 +920,6 @@ func invoiceDeliveryAddressIsAEOrComplete(val any) bool { return a != nil && (a.Country == l10n.AE.ISO() || (a.Street != "" && a.Locality != "" && a.Region != "")) } -// taxesIn returns a predicate that reports whether a discount or charge has -// a tax combo that check accepts. -func taxesIn(check func(any) bool) func(any) bool { - return func(val any) bool { - var set tax.Set - switch v := val.(type) { - case *bill.Discount: - if v != nil { - set = v.Taxes - } - case *bill.Charge: - if v != nil { - set = v.Taxes - } - } - for _, c := range set { - if check(c) { - return true - } - } - return false - } -} - // invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's // lines, discounts and charges is VAT under the profit margin scheme. func invoiceTaxesAreMarginScheme(val any) bool { diff --git a/addon/pint/bill_line.go b/addon/pint/bill_line.go index d96ee9e..a48d497 100644 --- a/addon/pint/bill_line.go +++ b/addon/pint/bill_line.go @@ -76,19 +76,11 @@ func billLineRules() *rules.Set { ), ), ), - rules.When( - is.Func("services", itemKeyIs(org.ItemKeyServices)), - rules.Field("identities", - rules.Assert("08", "services item needs a service accounting code (IBR-185-AE)", - is.Func("has SAC", identitiesHaveLabel(IdentityLabelSAC)), - ), - ), - ), rules.When( is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), rules.Field("identities", - rules.Assert("09", "goods and services item needs an HS item classification and a service accounting code (IBR-186-AE)", - is.Func("has HS and SAC", identitiesHaveLabel(IdentityLabelHS, IdentityLabelSAC)), + rules.Assert("08", "goods and services item needs an HS item classification (IBR-186-AE)", + is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), ), ), ), @@ -98,13 +90,13 @@ func billLineRules() *rules.Set { // IBR-188-AE's text asks for HS on every classification, but its // test passes when any one is HS. rules.Field("identities", - rules.Assert("10", "item classifications must include one from the HS list (IBR-188-AE)", + rules.Assert("09", "item classifications must include one from the HS list (IBR-188-AE)", is.Func("classifications include HS", identitiesClassifiedWithHS), ), ), ), rules.Field("seller", - rules.AssertIfPresent("11", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("10", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), diff --git a/addon/pint/bill_line_test.go b/addon/pint/bill_line_test.go index e03c7a1..ecb39dd 100644 --- a/addon/pint/bill_line_test.go +++ b/addon/pint/bill_line_test.go @@ -75,6 +75,7 @@ func TestBillGoodsTypeRulesAE(t *testing.T) { }) t.Run("goods type must be from the AE list on any line (IBR-006-AE)", func(t *testing.T) { + assert.NotContains(t, aeFaults(t, reverseCharge("DL8.48.8.3", gtin("0160"))), faultGoodsTypeValue) assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.9", gtin("0160"))), faultGoodsTypeValue) inv := aeDocument(bill.InvoiceTypeStandard) @@ -97,9 +98,8 @@ func TestBillGoodsTypeRulesAE(t *testing.T) { func TestBillItemTypeRulesAE(t *testing.T) { const ( faultGoodsHS = "GOBL-PEPPOL-PINT-BILL-LINE-07" - faultServicesSAC = "GOBL-PEPPOL-PINT-BILL-LINE-08" - faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-09" - faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-10" + faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-08" + faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-09" ) hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} @@ -120,22 +120,19 @@ func TestBillItemTypeRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) }) - t.Run("services need a service accounting code (IBR-185-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(org.ItemKeyServices)), faultServicesSAC) - assert.Contains(t, aeFaults(t, item(org.ItemKeyServices, hs)), faultServicesSAC) - assert.NotContains(t, aeFaults(t, item(org.ItemKeyServices, sac)), faultServicesSAC) + t.Run("services need no service accounting code", func(t *testing.T) { + assert.Empty(t, aeFaults(t, item(org.ItemKeyServices))) }) - t.Run("goods and services need both (IBR-186-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) + t.Run("goods and services need an HS classification (IBR-186-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices)), faultGoodsServices) assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) - assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs, sac)), faultGoodsServices) + assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) }) t.Run("no item type needs neither", func(t *testing.T) { out := aeFaults(t, item("")) assert.NotContains(t, out, faultGoodsHS) - assert.NotContains(t, out, faultServicesSAC) assert.NotContains(t, out, faultGoodsServices) }) diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 0d1c5e7..119f3d6 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -115,10 +115,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -308,18 +308,18 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" - faultCurrencyDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" + faultCurrencyDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -391,19 +391,22 @@ func TestBillDocumentRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, standard()), faultBuyerLegalID) }) - t.Run("480 and 81 accept E, Z and O lines (IBR-122-AE)", func(t *testing.T) { - for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyZero, tax.KeyOutsideScope} { + t.Run("480 and 81 accept E and O lines (IBR-122-AE)", func(t *testing.T) { + for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyOutsideScope} { inv := outsideScope() inv.Lines[0].Taxes = tax.Set{lineCombo(key)} assert.NotContains(t, aeFaults(t, inv), faultLineCategory, key) } }) - t.Run("480 and 81 reject standard rated lines (IBR-122-AE)", func(t *testing.T) { + t.Run("480 and 81 reject standard and zero rated lines (IBR-122-AE)", func(t *testing.T) { for _, inv := range []*bill.Invoice{outsideScope(), outsideScopeCredit()} { inv.Lines[0].Taxes = tax.Set{standardVAT()} assert.Contains(t, aeFaults(t, inv), faultLineCategory) } + inv := outsideScope() + inv.Lines[0].Taxes = tax.Set{lineCombo(tax.KeyZero)} + assert.Contains(t, aeFaults(t, inv), faultLineCategory) }) t.Run("480 rejects standard rated discounts and charges (IBR-122-AE)", func(t *testing.T) { @@ -559,7 +562,8 @@ func TestBillAddressRulesAE(t *testing.T) { faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" - faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-11" + faultDeliveryEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-10" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -634,6 +638,21 @@ func TestBillAddressRulesAE(t *testing.T) { assert.NotContains(t, out, faultSellerEmirate) }) + t.Run("delivery address in AE needs an emirate code (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Delivery = &bill.DeliveryDetails{Receiver: &org.Party{Name: "Warehouse", Addresses: aeAddress("Dubai")}} + assert.Contains(t, aeFaults(t, inv), faultDeliveryEmirate) + + inv.Delivery.Receiver.Addresses = aeAddress("DXB") + assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) + + inv.Delivery.Receiver.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} + assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) + + inv.Delivery.Receiver.Addresses = nil + assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) + }) + t.Run("every emirate code is accepted (IBR-128-AE)", func(t *testing.T) { for _, code := range []string{"AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK"} { inv := standard() @@ -705,9 +724,9 @@ func TestBillIdentityRulesAE(t *testing.T) { faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultCustomerTaxRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" - faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" ) @@ -779,6 +798,34 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, out, faultCustomerLegalType) }) + t.Run("customer with a predefined UAE endpoint needs no legal identity type or authority (IBR-180-AE, IBR-183-AE, IBR-101-AE)", func(t *testing.T) { + for _, code := range []string{"9900000098", "9900000099"} { + inv := aeIdentityDocument() + inv.Customer.Endpoints = uaeEndpoints(code) + inv.Customer.Identities = []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, + } + assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalType, code) + + inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} + inv.Customer.Identities[0].Description = "" + assert.NotContains(t, aeFaults(t, inv), faultCustomerAuthority, code) + } + }) + + t.Run("customer with another predefined UAE endpoint still needs them (IBR-180-AE, IBR-183-AE, IBR-101-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.Endpoints = uaeEndpoints("9900000097") + inv.Customer.Identities = []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, + } + assert.Contains(t, aeFaults(t, inv), faultCustomerLegalType) + + inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} + inv.Customer.Identities[0].Description = "" + assert.Contains(t, aeFaults(t, inv), faultCustomerAuthority) + }) + t.Run("each PINT AE type is accepted (IBR-173-AE, IBR-183-AE)", func(t *testing.T) { for _, id := range []*org.Identity{ {Type: ae.IdentityTypeEmiratesID, Code: "784199012345671"}, @@ -837,22 +884,31 @@ func TestBillIdentityRulesAE(t *testing.T) { } }) - t.Run("customer with a UAE endpoint not starting with 1 or 9 needs a tax registration (IBR-149-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.TaxID = nil - inv.Customer.Endpoints = uaeEndpoints("2345678901") - assert.Contains(t, aeFaults(t, inv), faultCustomerTaxRequired) + t.Run("customer with a UAE endpoint that is not 1XXXXXXXXX or 9XXXXXXXXX needs a legal identity (IBR-149-AE)", func(t *testing.T) { + for _, code := range []string{"2345678901", "134567890", "13456789061"} { + inv := aeIdentityDocument() + inv.Customer.Identities = nil + inv.Customer.Endpoints = uaeEndpoints(code) + assert.Contains(t, aeFaults(t, inv), faultCustomerLegalRequired, code) + } }) - t.Run("customer with a UAE endpoint starting with 1 or 9 needs no tax registration (IBR-149-AE)", func(t *testing.T) { + t.Run("customer with a UAE endpoint of 1XXXXXXXXX or 9XXXXXXXXX needs no legal identity (IBR-149-AE)", func(t *testing.T) { for _, code := range []string{"1345678906", "9345678901"} { inv := aeIdentityDocument() - inv.Customer.TaxID = nil + inv.Customer.Identities = nil inv.Customer.Endpoints = uaeEndpoints(code) - assert.NotContains(t, aeFaults(t, inv), faultCustomerTaxRequired, code) + assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalRequired, code) } }) + t.Run("customer legal identity is enough without a tax registration (IBR-149-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = nil + inv.Customer.Endpoints = uaeEndpoints("2345678901") + assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalRequired) + }) + t.Run("customer has at most one tax registration (IBR-179-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, @@ -990,18 +1046,20 @@ func TestNormalizeRounding(t *testing.T) { func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultAgentSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1041,6 +1099,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { // PINT has no BR-CO-25, so neither payment nor terms are required. inv = aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) + inv.Customer.Endpoints = uaeEndpoints("9900000097") inv.Payment.Terms = nil assert.Empty(t, aeFaults(t, inv)) inv.Payment = nil @@ -1053,6 +1112,19 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Contains(t, out, faultDueDate) }) + t.Run("deemed supply buyer has the predefined endpoint 9900000097 (PINT AE BIS 1.5.3)", func(t *testing.T) { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) + inv.Customer.Endpoints = uaeEndpoints("9900000097") + assert.NotContains(t, aeFaults(t, inv), faultDeemedEndpoint) + + inv.Customer.Endpoints = uaeEndpoints("1000000024") + assert.Contains(t, aeFaults(t, inv), faultDeemedEndpoint) + + inv = aeDocument(bill.InvoiceTypeStandard) + inv.Customer.Endpoints = uaeEndpoints("1000000024") + assert.NotContains(t, aeFaults(t, inv), faultDeemedEndpoint) + }) + t.Run("free trade zone needs the beneficiary ID (IBR-007-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagFreeTradeZone) assert.Contains(t, aeFaults(t, inv), faultBeneficiary) @@ -1086,13 +1158,41 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultPrincipalSupplier) }) - t.Run("disclosed agent supplier needs a tax registration (IBR-177-AE)", func(t *testing.T) { + t.Run("principal ID must be a TRN (IBR-132-AE)", func(t *testing.T) { + for _, code := range []cbc.Code{"255667745601003", "15566774560100", "155667745601004", "1556677456010A3"} { + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) + setExt(inv, pint.ExtKeyPrincipalID, code) + assert.Contains(t, aeFaults(t, inv), faultPrincipalTRN, code) + } + + // It is checked without the disclosed agent tag too, as it is + // written whenever it is there. + inv := aeDocument(bill.InvoiceTypeStandard) + setExt(inv, pint.ExtKeyPrincipalID, "P-1234") + assert.Contains(t, aeFaults(t, inv), faultPrincipalTRN) + }) + + t.Run("supplier needs a TRN or TIN on outside scope documents (IBR-177-AE)", func(t *testing.T) { + // Elsewhere the TRN is already required (IBR-134-AE), so only that + // rule fails. inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") inv.Supplier.TaxID = &tax.Identity{Country: "AE"} out := aeFaults(t, inv) - assert.Contains(t, out, faultAgentSupplierTax) + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-31") + assert.NotContains(t, out, faultSupplierTax) assert.NotContains(t, out, faultPrincipalSupplier) + + for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { + inv = aeDocument(typ, pint.TagOutsideScope) + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} + assert.Contains(t, aeFaults(t, inv), faultSupplierTax, typ) + + // The TIN is enough on 480 and 81 (IBR-134-AE). + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) + assert.Empty(t, aeFaults(t, inv), typ) + } }) t.Run("e-commerce needs a complete delivery address (IBR-142-AE)", func(t *testing.T) { @@ -1149,10 +1249,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1213,9 +1313,9 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" ) withFrequency := func(code cbc.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1256,9 +1356,9 @@ func TestBillBillingFrequencyRulesAE(t *testing.T) { func TestBillExemptionRulesAE(t *testing.T) { const ( - faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultDiscountReason = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" - faultChargeReason = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" + faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" + faultDiscountExemption = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" + faultChargeExemption = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" ) exempt := func(code cbc.Code) *tax.Combo { c := lineCombo(tax.KeyExempt) @@ -1274,7 +1374,7 @@ func TestBillExemptionRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultLineExemption) // IBR-167-AE only checks a code is there, so codes outside the AE - // list, like the official examples' VATEX-AE-EDU, are accepted. + // list are accepted. for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4", "VATEX-AE-EDU"} { inv = aeDocument(bill.InvoiceTypeStandard) inv.Lines[0].Taxes = tax.Set{exempt(code)} @@ -1286,31 +1386,35 @@ func TestBillExemptionRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, aeDocument(bill.InvoiceTypeStandard)), faultLineExemption) }) - t.Run("exempt discount needs an allowance reason code (IBR-168-AE)", func(t *testing.T) { + t.Run("exempt discount needs a UAE exemption reason (IBR-168-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) - inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("DL8.46.1")}}} - assert.Contains(t, aeFaults(t, inv), faultDiscountReason) - + inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} inv.Discounts[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyAllowance: "95"}) - assert.NotContains(t, aeFaults(t, inv), faultDiscountReason) + assert.Contains(t, aeFaults(t, inv), faultDiscountExemption) + + inv.Discounts[0].Taxes = tax.Set{exempt("DL8.46.4")} + inv.Discounts[0].Ext = tax.Extensions{} + assert.NotContains(t, aeFaults(t, inv), faultDiscountExemption) }) - t.Run("exempt charge needs a charge reason code (IBR-169-AE)", func(t *testing.T) { + t.Run("exempt charge needs a UAE exemption reason (IBR-169-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) - inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("DL8.46.1")}}} - assert.Contains(t, aeFaults(t, inv), faultChargeReason) - + inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} inv.Charges[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyCharge: "AAT"}) - assert.NotContains(t, aeFaults(t, inv), faultChargeReason) + assert.Contains(t, aeFaults(t, inv), faultChargeExemption) + + inv.Charges[0].Taxes = tax.Set{exempt("DL8.46.4")} + inv.Charges[0].Ext = tax.Extensions{} + assert.NotContains(t, aeFaults(t, inv), faultChargeExemption) }) - t.Run("standard rated discounts and charges need no reason code", func(t *testing.T) { + t.Run("standard rated discounts and charges need no exemption reason", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} out := aeFaults(t, inv) - assert.NotContains(t, out, faultDiscountReason) - assert.NotContains(t, out, faultChargeReason) + assert.NotContains(t, out, faultDiscountExemption) + assert.NotContains(t, out, faultChargeExemption) }) } @@ -1319,7 +1423,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1436,7 +1540,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 0164734..a2a4ef1 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -23,10 +23,10 @@ const ( ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" // ExtKeyCreditNoteReason is the reason for a PINT AE credit note (BTAE-03). ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" - // ExtKeyBillingFrequency is the frequency of billing (BTAE-06). + // ExtKeyBillingFrequency is the frequency of billing (IBT-008). ExtKeyBillingFrequency cbc.Key = "peppol-pint-ae-billing-frequency" // ExtKeyExemption is the UAE VAT exemption reason of an exempt tax combo - // (IBT-186 on lines). + // (IBT-186 on lines, IBT-196 and IBT-198 on allowances and charges). ExtKeyExemption cbc.Key = "peppol-pint-ae-exemption" // ExtKeyGoodsType is the type of goods or services subject to the reverse // charge mechanism, on the item (BTAE-09). @@ -61,6 +61,10 @@ const CreditNoteReasonVolumeDiscount cbc.Code = "VD" // in an invoice note (IBR-160-AE). const BillingFrequencyOthers cbc.Code = "OTH" +// principalIDPattern is the format of the principal ID, a UAE TRN: 15 digits +// starting with 1 and ending with 03 (IBR-132-AE). +const principalIDPattern = `^1\d{12}03$` + // Usages of the PINT AE extensions: offered by the PINT addon under the AE // regime, on the object each one goes on. var ( @@ -154,9 +158,12 @@ var extensions = []*cbc.Definition{ i18n.EN: here.Doc(` Identifier of the principal a disclosed agent bills on behalf of (BTAE-14), required with the "disclosed-agent" transaction type - (IBR-137-AE). It must differ from the supplier's tax ID (IBR-176-AE). + (IBR-137-AE). It is the principal's TRN: 15 digits starting with 1 + and ending with 03 (IBR-132-AE), different from the supplier's tax + ID (IBR-176-AE). `), }, + Pattern: principalIDPattern, }, { Key: ExtKeyCreditNoteReason, @@ -213,7 +220,7 @@ var extensions = []*cbc.Definition{ }, Desc: i18n.String{ i18n.EN: here.Doc(` - Frequency of billing (BTAE-06), from the frequency of billing code list + Frequency of billing (IBT-008), from the frequency of billing code list (IBR-005-AE). With "OTH" (Others), the frequency is given in an invoice note (IBR-160-AE). `), @@ -247,8 +254,9 @@ var extensions = []*cbc.Definition{ i18n.EN: here.Doc(` Reason a supply is exempt from UAE VAT, such as one of the PINT AE "Reasons for exemption from tax" codes (DL8.46.1 to DL8.46.4). - Required on exempt lines (IBR-167-AE), where it is written as the - line's exemption reason code. + Required on exempt lines (IBR-167-AE), discounts (IBR-168-AE) and + charges (IBR-169-AE), where it is written as their exemption reason + code. `), }, Sources: []*cbc.Source{ @@ -280,6 +288,7 @@ var extensions = []*cbc.Definition{ Values: []*cbc.Definition{ {Code: "DL8.48.8.2", Name: i18n.String{i18n.EN: "Electronic Devices"}}, {Code: "DL8.48.8.1", Name: i18n.String{i18n.EN: "Gold and Diamonds"}}, + {Code: "DL8.48.8.3", Name: i18n.String{i18n.EN: "Metal Scrap Trading"}}, {Code: "DL8.48.3.1", Name: i18n.String{i18n.EN: "Crude or refined oil"}}, {Code: "DL8.48.3.2", Name: i18n.String{i18n.EN: "Unprocessed or processed natural gas"}}, {Code: "DL8.48.3.3", Name: i18n.String{i18n.EN: "Pure hydrocarbons"}}, diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 0a38c67..a35e097 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -24,11 +24,6 @@ var tinRegexp = regexp.MustCompile(`^1\d{9}$`) const ( // IdentityTypePassport is a passport. IdentityTypePassport cbc.Code = "PAS" - // identityTypeCommercialLicense is only accepted by IBR-183-AE's test, for - // the buyer. No other source lists it; its rule text names - // "Commercial/Trade license", so it is read as a trade licence and never - // written: TL is valid for both seller and buyer. - identityTypeCommercialLicense cbc.Code = "CL" ) // identityTypesAE are the AE regime's identity types that are PINT AE legal @@ -59,8 +54,6 @@ func SetIdentityTypeAE(id *org.Identity, typ cbc.Code) bool { switch { case typ == IdentityTypePassport: id.Key = org.IdentityKeyPassport - case typ == identityTypeCommercialLicense: - id.Type = ae.IdentityTypeTradeLicense case typ.In(identityTypesAE...): id.Type = typ default: diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index 12b87a0..bcdf235 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -36,7 +36,7 @@ func TestIdentityTypeAE(t *testing.T) { func TestSetIdentityTypeAE(t *testing.T) { tests := map[cbc.Code]org.Identity{ "TL": {Type: ae.IdentityTypeTradeLicense}, - "CL": {Type: ae.IdentityTypeTradeLicense}, + "CL": {}, "EID": {Type: ae.IdentityTypeEmiratesID}, "PAS": {Key: org.IdentityKeyPassport}, "CD": {Type: ae.IdentityTypeCabinetDecision}, diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index b4a8fe8..0edbf6f 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -1,6 +1,8 @@ package pint import ( + "regexp" + "slices" "strings" "github.com/invopop/gobl/catalogues/iso" @@ -121,6 +123,15 @@ func partyAddressHasEmirate(val any) bool { return partyFirstAddress(val) == nil || partyPostalAddressHasEmirate(val) } +// partyFirstAddressHasEmirate reports whether the party's first address, +// when in the UAE, has an emirate code as its region (IBR-128-AE). gobl.ubl +// writes it as the delivery's cac:DeliveryLocation/cac:Address, with the +// address's own country. A party without addresses passes. +func partyFirstAddressHasEmirate(val any) bool { + a := partyFirstAddress(val) + return a == nil || a.Country != l10n.AE.ISO() || cbc.Code(a.Region).In(emirateCodes...) +} + // partyPostalAddressHasEmirate reports whether the cac:PostalAddress gobl.ubl // writes for the party, when in the UAE, has an emirate code as its region // (IBR-128-AE). gobl.ubl writes the country of the tax ID over the address's @@ -185,6 +196,20 @@ func partyHasEndpointID(val any) bool { return s != "" && s != endpointSchemeEmail } +// endpointCodesPredefined are the predefined UAE Peppol endpoint codes that +// IBR-180-AE, IBR-183-AE and IBR-101-AE exempt from the buyer legal +// registration identifier type and authority. +var endpointCodesPredefined = []string{"9900000098", "9900000099"} + +// endpointCodeDeemedSupply is the predefined UAE Peppol endpoint code of the +// buyer of a deemed supply (PINT AE BIS 1.5.3). +const endpointCodeDeemedSupply = "9900000097" + +// endpoint1or9Regexp matches the UAE Peppol endpoint codes of 10 digits +// starting with 1 or 9, which need no buyer legal registration identifier +// (IBR-149-AE). +var endpoint1or9Regexp = regexp.MustCompile(`^[19]\d{9}$`) + // partyHasUAEEndpointWith returns a predicate that reports whether the party's // electronic address uses the UAE Peppol scheme 0235 with a code that match // accepts. @@ -202,9 +227,26 @@ func partyHasUAEEndpointWith(match func(code string) bool) func(any) bool { var ( // partyHasUAEEndpoint is the condition of the legal registration rules. partyHasUAEEndpoint = partyHasUAEEndpointWith(func(string) bool { return true }) - // partyHasUAEEndpointNotStartingWith1or9 is the condition of IBR-149-AE. - partyHasUAEEndpointNotStartingWith1or9 = partyHasUAEEndpointWith(func(code string) bool { - return !strings.HasPrefix(code, "1") && !strings.HasPrefix(code, "9") + // partyHasUAEEndpointPredefined reports whether the party has one of the + // predefined UAE endpoints, which IBR-180-AE, IBR-183-AE and IBR-101-AE + // exempt. + partyHasUAEEndpointPredefined = partyHasUAEEndpointWith(func(code string) bool { + return slices.Contains(endpointCodesPredefined, code) + }) + // partyHasUAEEndpointNotPredefined is the condition of IBR-180-AE and + // IBR-183-AE. + partyHasUAEEndpointNotPredefined = partyHasUAEEndpointWith(func(code string) bool { + return !slices.Contains(endpointCodesPredefined, code) + }) + // partyHasUAEEndpointDeemedSupply reports whether the party has the + // predefined UAE endpoint of a deemed supply buyer. + partyHasUAEEndpointDeemedSupply = partyHasUAEEndpointWith(func(code string) bool { + return code == endpointCodeDeemedSupply + }) + // partyHasUAEEndpointNot1or9 is the condition of IBR-149-AE: a code + // that is not 1XXXXXXXXX or 9XXXXXXXXX. + partyHasUAEEndpointNot1or9 = partyHasUAEEndpointWith(func(code string) bool { + return !endpoint1or9Regexp.MatchString(code) }) // partyHasUAEEndpointNotTIN is the condition of IBR-135-AE: a code that // is not a TIN, 1XXXXXXXXX. diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 68984b2..81c880c 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -66,9 +66,9 @@ func normalizeTaxCombo(tc *tax.Combo) { // exempt VAT lines of a UAE margin scheme invoice. The line combos already have // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the -// discount and charge rules 02 and rule 43 reject them (IBR-114-AE, +// discount and charge rules 02 and rule 45 reject them (IBR-114-AE, // IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real -// exempt supply, so they keep E and rule 43 rejects the mixed invoice. +// exempt supply, so they keep E and rule 45 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return @@ -176,11 +176,9 @@ func taxComboIsZero(val any) bool { } // taxCategoryCodesOutsideScope are the VAT category codes allowed on 480 and -// 81 documents: exempt (E), zero rated (Z) and not subject to VAT (O) -// (IBR-122-AE). +// 81 documents: exempt (E) and not subject to VAT (O) (IBR-122-AE). var taxCategoryCodesOutsideScope = []cbc.Code{ en16931.TaxCategoryExempt, - en16931.TaxCategoryZero, en16931.TaxCategoryOutsideScope, } diff --git a/ubl/ae.go b/ubl/ae.go index 1cf1153..dfad047 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -36,9 +36,11 @@ const ( const aedTotalDocumentType = "aedtotal-incl-vat" // aeStandardRate is the rate PINT AE expects on reverse charge and margin -// scheme lines and breakdowns. GOBL keeps both without a percent, as the -// invoice charges no VAT, but the PINT AE examples and the 5% standard rate -// (IBR-190-AE) write 5, and margin scheme lines need a rate (IBR-111-AE). +// scheme lines and breakdowns, and on reverse charge allowances and charges. +// GOBL keeps them without a percent, as the invoice charges no VAT, but the +// PINT AE examples and the 5% standard rate (IBR-190-AE) write 5, margin +// scheme lines need a rate (IBR-111-AE), and reverse charge allowances and +// charges one above 0 (aligned-ibrp-ae-06, aligned-ibrp-ae-07). const aeStandardRate = "5" // taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. @@ -76,6 +78,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAEContractValue(out, inv) exportAEPayment(out, inv) exportAEChargeExemptions(out, inv) + exportAEChargeRates(out) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -412,6 +415,22 @@ func exportAEChargeExemptions(out *goblubl.Invoice, inv *bill.Invoice) { } } +// exportAEChargeRates writes the rate of the reverse charge allowances and +// charges at 5, as PINT AE wants one above 0 (aligned-ibrp-ae-06, +// aligned-ibrp-ae-07) and gobl.ubl writes 0. Exempt ones keep the 0 PINT AE +// wants there (aligned-ibrp-e-06, aligned-ibrp-e-07), and the margin scheme +// isn't allowed on them (IBR-114-AE, IBR-115-AE). +func exportAEChargeRates(out *goblubl.Invoice) { + for _, ac := range out.AllowanceCharge { + for _, c := range ac.TaxCategory { + if c != nil && c.ID != nil && c.ID.Value == taxCategoryReverseCharge { + rate := aeStandardRate + c.Percent = &rate + } + } + } +} + // importAEChargeExemptions reads the exemption reasons of the charges and // discounts back onto their VAT combos. gobl.ubl imports the charges and the // discounts apart, each in the order of the document. @@ -510,9 +529,9 @@ func exportAECreditNoteReason(out *goblubl.Invoice, inv *bill.Invoice) { } } -// importAECreditNoteReason reads the first credit note reason back. PINT AE -// examples can repeat the element, as the volume discount one does with VD -// then DL8.61.1.E; GOBL keeps one reason, the first. +// importAECreditNoteReason reads the credit note reason back from the first +// cac:DiscrepancyResponse with a code, the only one PINT AE allows +// (ibr-198-ae). func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { for _, r := range in.DiscrepancyResponse { if r.ResponseCode != nil && strings.TrimSpace(r.ResponseCode.Value) != "" { @@ -853,13 +872,9 @@ func setAESchemeVersion(id *org.Identity, version *string) { } // exportAEBillingFrequency writes the billing frequency as -// cac:InvoicePeriod/cbc:DescriptionCode (BTAE-06), on the period gobl.ubl +// cac:InvoicePeriod/cbc:DescriptionCode (IBT-008), on the period gobl.ubl // writes from the ordering period, or on its own: IBR-CO-19 accepts a period // with only a description code. -// -// The PINT AE syntax binds BTAE-06 to cbc:Description, but the IBR-005-AE -// and IBR-160-AE tests read cbc:DescriptionCode, so we follow the tests. The -// official examples use both. func exportAEBillingFrequency(out *goblubl.Invoice, inv *bill.Invoice) { freq := inv.Tax.GetExt(pint.ExtKeyBillingFrequency) if freq == "" { @@ -1055,10 +1070,9 @@ func exportAELine(line *goblubl.InvoiceLine) { // to AED. The implementation guide (section 3.1.1) asks for AED whatever the // invoice currency, and IBR-126 leaves cac:ItemPriceExtension out of the // document currency check as amounts in the tax currency, which IBR-140-AE -// fixes to AED. No test checks their currency. The two official examples in -// another currency write them in USD, but both are zero rated exports, so -// their VAT is zero either way. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-24), they stay in the document currency. +// fixes to AED. No test checks their currency, and the official exports in +// USD write them in AED too. Without a rate, which the PINT addon requires +// (GOBL-PEPPOL-PINT-BILL-INVOICE-25), they stay in the document currency. // // GOBL keeps no VAT per line, so it is the line total at the line's rate, // rounded to the document currency, then converted. Exempt lines get no VAT @@ -1112,7 +1126,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-24) with at most 6 decimals (-25). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-25) with at most 6 decimals (-26). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return @@ -1132,7 +1146,7 @@ func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { out.AdditionalDocumentReference = append(out.AdditionalDocumentReference, goblubl.Reference{ ID: goblubl.IDType{Value: currency.AED.String()}, DocumentTypeCode: aedTotalDocumentType, - DocumentDescription: currency.AED.String() + " " + total.String(), + DocumentDescription: total.String(), }) } } @@ -1185,8 +1199,8 @@ func lineUnitCode(line *goblubl.InvoiceLine) string { // category. gobl.ubl writes 0 when a combo has no percent, which is right for // A-NZ but not for AE: exempt must have no rate (aligned-ibrp-e-05, // IBR-121-AE), and reverse charge and margin scheme must have one -// (aligned-ibrp-ae-05-ae, IBR-119-AE, IBR-111-AE). Document allowances and charges keep gobl.ubl's 0, which is -// what PINT AE wants there for both (aligned-ibrp-e-06/07, ae-06/07). +// (aligned-ibrp-ae-05-ae, IBR-119-AE, IBR-111-AE). Document allowances and +// charges are set by exportAEChargeRates. func aeRate(id *goblubl.IDType, percent *string) *string { if id == nil { return percent @@ -1344,9 +1358,10 @@ func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { // No rule asks for TIN: the BIS only says the scheme of the seller TIN // (IBT-032) must not be VAT, the syntax binding gives no code list, and // IBR-133-AE and IBR-178-AE only check for "not VAT", so LOC would pass too. -// TIN is the value the only official example with a seller TIN uses -// (Seller-TIN-identifier.xml), so receivers are most likely to expect it. -// It is not the TIN of UNCL 1153, which is a transport instruction number. +// The official examples don't agree: Seller-TIN-identifier.xml uses TIN and +// Seller-TRN-and-TIN-identifiers.xml uses TAX. FormatAE writes TIN and reads +// both. It is not the TIN of UNCL 1153, which is a transport instruction +// number. func exportAETINScheme(out *goblubl.Party, p *org.Party) { for _, id := range p.Identities { if id == nil || id.Type != ae.IdentityTypeTIN || id.Scope != org.IdentityScopeTax { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 82ca73b..aa9bcd6 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -343,12 +343,6 @@ func TestImportAEPartyIdentities(t *testing.T) { assert.Equal(t, "Trade License issuing Authority", id.Description) }) - t.Run("CL is read as a trade licence", func(t *testing.T) { - id := imported(companyID("CL", "Dubai Economy and Tourism"), false).Identities[0] - assert.Equal(t, ae.IdentityTypeTradeLicense, id.Type) - assert.Equal(t, "Dubai Economy and Tourism", id.Description) - }) - t.Run("passport with its issuing country", func(t *testing.T) { id := imported(companyID("PAS", "IN"), false).Identities[0] assert.Equal(t, org.IdentityKeyPassport, id.Key) @@ -365,7 +359,7 @@ func TestImportAEPartyIdentities(t *testing.T) { }) t.Run("unknown or missing types are left alone", func(t *testing.T) { - for _, typ := range []string{"XYZ", ""} { + for _, typ := range []string{"XYZ", "CL", ""} { id := imported(companyID(typ, "Some Authority"), false).Identities[0] assert.Empty(t, id.Key, typ) assert.Empty(t, id.Type, typ) @@ -1048,7 +1042,7 @@ func TestExportAEExchangeRate(t *testing.T) { ref := out.AdditionalDocumentReference[0] assert.Equal(t, "AED", ref.ID.Value) assert.Equal(t, "aedtotal-incl-vat", ref.DocumentTypeCode) - assert.Equal(t, "AED 913621.44", ref.DocumentDescription, "the Exports.xml example: 248750 USD at 3.67285") + assert.Equal(t, "913621.44", ref.DocumentDescription, "the Exports.xml example: 248750 USD at 3.67285") }) t.Run("AED invoices need neither", func(t *testing.T) { @@ -1345,6 +1339,21 @@ func TestAEChargeExemptions(t *testing.T) { }) } +func TestExportAEChargeRates(t *testing.T) { + category := func(id string) []*goblubl.TaxCategory { + return []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: id}, Percent: strPtr("0")}} + } + out := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ + {ChargeIndicator: true, TaxCategory: category("AE")}, + {TaxCategory: category("AE")}, + {TaxCategory: category("E")}, + }} + exportAEChargeRates(out) + assert.Equal(t, "5", *out.AllowanceCharge[0].TaxCategory[0].Percent, "reverse charge charge (aligned-ibrp-ae-07)") + assert.Equal(t, "5", *out.AllowanceCharge[1].TaxCategory[0].Percent, "reverse charge allowance (aligned-ibrp-ae-06)") + assert.Equal(t, "0", *out.AllowanceCharge[2].TaxCategory[0].Percent, "exempt keeps 0 (aligned-ibrp-e-06)") +} + func TestAELineExemptionReason(t *testing.T) { ublLine := func(category string, reason *string) goblubl.InvoiceLine { return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index aa5e449..f5b6ef9 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "fe39c4389ff3c50db52fc45ac4444a44a8ff0642f9d32fdb3799c01b76d1bb5a" + "val": "55dcb74770d046483515b1cd3d5ece09926f716fb5fc23dc630150dd9a04f03b" }, "from": "iso6523-actorid-upis::0235:1357902467", - "to": "iso6523-actorid-upis::0235:1345678906" + "to": "iso6523-actorid-upis::0235:9900000097" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -83,14 +83,14 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1345678906" + "uri": "iso6523-actorid-upis::0235:9900000097" } ], "inboxes": [ { "key": "peppol", "scheme": "0235", - "code": "1345678906" + "code": "9900000097" } ], "addresses": [ diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml index 2a2507e..2f2cdea 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -39,7 +39,7 @@ - 1345678906 + 9900000097 Buyer Legal Name diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index f042f6e..193efac 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -83,7 +83,7 @@ 25.00 AE - 0 + 5 VAT @@ -95,7 +95,7 @@ 50.00 AE - 0 + 5 VAT diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 55da20e..6daaa08 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -16,7 +16,7 @@ AED aedtotal-incl-vat - AED 6500.91 + 6500.91 diff --git a/ubl/testdata/parse/pint/ae/allowance-exempt.xml b/ubl/testdata/parse/pint/ae/allowance-exempt.xml index 3a1fa47..64ca77d 100644 --- a/ubl/testdata/parse/pint/ae/allowance-exempt.xml +++ b/ubl/testdata/parse/pint/ae/allowance-exempt.xml @@ -98,6 +98,7 @@ E 0 + DL8.46.4 VAT @@ -129,11 +130,11 @@ 10 1000 - Educational services exempt from VAT - Education Services + Local passenger transport services exempt from VAT + Local Passenger Transport E - VATEX-AE-EDU + DL8.46.4 VAT diff --git a/ubl/testdata/parse/pint/ae/allowance-reverse-charge.xml b/ubl/testdata/parse/pint/ae/allowance-reverse-charge.xml new file mode 100644 index 0000000..373ba0b --- /dev/null +++ b/ubl/testdata/parse/pint/ae/allowance-reverse-charge.xml @@ -0,0 +1,165 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-ALLOW-AE-01 + a1b2c3d4-e5f6-7890-abcd-100000000001 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + false + 95 + Discount + 100 + + AE + 5 + + VAT + + + + + 0 + false + + 900 + 0 + + AE + 5 + + VAT + + + + + + 1000 + 900 + 900 + 100 + 900 + + + 1 + 10 + 1000 + + Consulting services subject to reverse charge + Consulting Services + + 9876543210 + + + DL8.48.3.1 + + + AE + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/deemed-supply.xml b/ubl/testdata/parse/pint/ae/deemed-supply.xml index 0ca3fa2..333189a 100644 --- a/ubl/testdata/parse/pint/ae/deemed-supply.xml +++ b/ubl/testdata/parse/pint/ae/deemed-supply.xml @@ -40,7 +40,7 @@ Sample-05 - KmJzZTY0IGNvbnRlbnQgZXhhbXBsZQ== + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== @@ -74,7 +74,7 @@ - 1012345678 + 9900000097 Street Name Dubai diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 1b52a46..9163cb1 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "26edb1ca821be6f0f2cf40f00364b25743dabf864152a5af661ac818842ace4c" + "val": "02c4879b0f8179f5a03a19b4fe302e578e54c8b2977c4fd52b524494ab1b929f" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -132,8 +132,8 @@ "i": 1, "quantity": "10", "item": { - "name": "Education Services", - "description": "Educational services exempt from VAT", + "name": "Local Passenger Transport", + "description": "Local passenger transport services exempt from VAT", "list": "100", "price": "100.00", "unit": "piece", @@ -147,7 +147,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "VATEX-AE-EDU", + "peppol-pint-ae-exemption": "DL8.46.4", "untdid-tax-category": "E" } } @@ -165,6 +165,7 @@ "cat": "VAT", "key": "exempt", "ext": { + "peppol-pint-ae-exemption": "DL8.46.4", "untdid-tax-category": "E" } } @@ -212,18 +213,10 @@ { "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "VATEX-AE-EDU", + "peppol-pint-ae-exemption": "DL8.46.4", "untdid-tax-category": "E" }, - "base": "1000.00", - "amount": "0.00" - }, - { - "key": "exempt", - "ext": { - "untdid-tax-category": "E" - }, - "base": "-100.00", + "base": "900.00", "amount": "0.00" } ], diff --git a/ubl/testdata/parse/pint/ae/out/allowance-reverse-charge.json b/ubl/testdata/parse/pint/ae/out/allowance-reverse-charge.json new file mode 100644 index 0000000..2da02db --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/allowance-reverse-charge.json @@ -0,0 +1,241 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "16bb63941425bbc3eea244eb7eacf8f4a2b53b4963585fb4d4171cdd9858c090" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-ALLOW-AE-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Consulting Services", + "identities": [ + { + "code": "9876543210", + "ext": { + "iso-scheme-id": "0160" + } + } + ], + "description": "Consulting services subject to reverse charge", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1", + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "total": "1000.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Discount", + "amount": "100.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "900.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "discount": "100.00", + "total": "900.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + }, + "base": "900.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "900.00", + "payable": "900.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index abe452c..821ea51 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,10 +4,10 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "750a5aeb7b61cdb0e7684cce2c9bb5d964c883a235ef611e4987e4d46801f061" + "val": "ae580dcdbf90cc53bdab20abbb7e2d3f264c9a867e4688a947a499ae7773e5ad" }, "from": "iso6523-actorid-upis::0235:1246801357", - "to": "iso6523-actorid-upis::0235:1012345678" + "to": "iso6523-actorid-upis::0235:9900000097" }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", @@ -102,7 +102,7 @@ ], "endpoints": [ { - "uri": "iso6523-actorid-upis::0235:1012345678" + "uri": "iso6523-actorid-upis::0235:9900000097" } ], "addresses": [ diff --git a/ubl/testdata/parse/pint/ae/out/seller-trn-tin-identifiers.json b/ubl/testdata/parse/pint/ae/out/seller-trn-tin-identifiers.json new file mode 100644 index 0000000..fda0149 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/seller-trn-tin-identifiers.json @@ -0,0 +1,220 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "635cb20ce4a78943e68461c766a84635059bae43b418ffddd3628acbdc565228" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-SELLER-TRN-TIN-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "country": "AE", + "type": "TIN", + "code": "1234567892" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Electronic Components", + "description": "Standard rated goods", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1000.00" + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1050.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "total": "1000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "1000.00", + "percent": "5%", + "amount": "50.00" + } + ], + "amount": "50.00" + } + ], + "sum": "50.00" + }, + "tax": "50.00", + "total_with_tax": "1050.00", + "payable": "1050.00" + }, + "notes": [ + { + "text": "Tax invoice - Seller carrying both a VAT registration (TRN) and a non-VAT tax registration (TIN)" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/seller-trn-tin-identifiers.xml b/ubl/testdata/parse/pint/ae/seller-trn-tin-identifiers.xml new file mode 100644 index 0000000..751cba7 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/seller-trn-tin-identifiers.xml @@ -0,0 +1,155 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-SELLER-TRN-TIN-01 + a1b2c3d4-e5f6-7890-abcd-100000000014 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice - Seller carrying both a VAT registration (TRN) and a non-VAT tax registration (TIN) + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + + 198765432102003 + + VAT + + + + + 1234567892 + + TAX + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + 50 + false + + 1000 + 50 + + S + 5 + + VAT + + + + + + 1000 + 1000 + 1050 + 1050 + + + 1 + 10 + 1000 + + Standard rated goods + Electronic Components + + S + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1050 + + 50 + + + + \ No newline at end of file diff --git a/ubl/ubl.go b/ubl/ubl.go index c702bc1..aa8b098 100644 --- a/ubl/ubl.go +++ b/ubl/ubl.go @@ -151,8 +151,8 @@ var FormatAE = goblubl.Format{ ProfileID: "urn:peppol:bis:billing", Addons: []cbc.Key{pint.V1}, VESIDs: goblubl.VESIDMapping{ - Invoice: "org.peppol.pint.ae:invoice:2026.5", - CreditNote: "org.peppol.pint.ae:creditnote:2026.5", + Invoice: "org.peppol.pint.ae:invoice:2026.11", + CreditNote: "org.peppol.pint.ae:creditnote:2026.11", }, Specifications: []goblubl.Specification{ SpecificationAESelfBilling, @@ -172,8 +172,8 @@ var SpecificationAESelfBilling = goblubl.Specification{ ProfileID: "urn:peppol:bis:selfbilling", Addons: []cbc.Key{pint.V1}, VESIDs: goblubl.VESIDMapping{ - Invoice: "org.peppol.pint.ae:invoice-self-billing:2026.5", - CreditNote: "org.peppol.pint.ae:creditnote-self-billing:2026.5", + Invoice: "org.peppol.pint.ae:invoice-self-billing:2026.11", + CreditNote: "org.peppol.pint.ae:creditnote-self-billing:2026.11", }, Applies: isSelfBilled, } diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 25bcde8..74eecfe 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -151,16 +151,18 @@ func TestDetectAndImportAE(t *testing.T) { // import. margin-scheme-credit-note.xml is the official margin scheme // example turned into a credit note, as there is no official one. var importFaultsAE = map[string][]string{ - "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, - "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "allowance-reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "seller-trn-tin-identifiers.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, } // faultCodePattern matches the fault codes in a validation error. From d497e77b411bc08abfa86ea4cab2637512cbf33c Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:21:25 +0000 Subject: [PATCH 58/73] Simplify the PINT AE addon Several parts of the addon did work that gobl, the AE regime or the UBL writer already does, or kept a check our output can never fail. - The currency rounding normalizer goes: gobl.ubl and gobl.cii round every amount to the currency on export, so the XML adds up without changing the invoice's rounding rule. - The document tag "outside-scope" read like GOBL's tax key of the same name, so it is now "outside-tax-scope". Import reads 480 and 81 back as the new tag. - A UAE TRN starts with the supplier's TIN, and the UAE PASR gives every end user the Peppol endpoint 0235:. A supplier with a TRN now gets that TIN as a tax identity and that endpoint when it has neither, so every UAE supplier has a 0235 endpoint and the IBR-150-AE, IBR-173-AE and IBR-181-AE rules apply without checking for one. A TRN whose TIN fails the check digit gives nothing, so the AE regime reports it once, not again on a derived TIN. - The seller TIN is found by its identity type, and the TIN and TRN formats come from the AE regime's patterns instead of local copies. The principal ID's trailing 03 is its own rule (IBR-132-AE). - IBR-176-AE goes: its test compares the principal ID with any of the seller's tax registrations, and a seller with a TRN always has its TIN written too, so our output can never fail it. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- addon/pint/bill.go | 125 +++++--------- addon/pint/bill_test.go | 155 +++++++----------- addon/pint/extensions.go | 9 +- addon/pint/org_identity.go | 9 - addon/pint/org_party.go | 65 +++++++- addon/pint/org_party_test.go | 92 +++++++++++ addon/pint/pint.go | 4 +- addon/pint/scenarios.go | 12 +- addon/pint/scenarios_test.go | 10 +- addon/pint/tax_identity.go | 5 +- examples/out/invoice-ae.json | 8 +- ubl/ae.go | 95 ++++++----- ubl/ae_internal_test.go | 38 ++++- .../pint/ae/credit-note-ae-margin-scheme.json | 8 +- .../pint/ae/credit-note-ae-outside-scope.json | 10 +- .../pint/ae/credit-note-ae-self-billed.json | 8 +- .../ae/credit-note-ae-volume-discount.json | 8 +- .../convert/pint/ae/credit-note-ae.json | 8 +- .../pint/ae/invoice-ae-continuous-supply.json | 8 +- .../pint/ae/invoice-ae-deemed-supply.json | 8 +- .../convert/pint/ae/invoice-ae-exempt.json | 8 +- .../pint/ae/invoice-ae-export-summary.json | 8 +- .../ae/invoice-ae-free-trade-zone-agent.json | 8 +- .../pint/ae/invoice-ae-margin-scheme.json | 8 +- .../pint/ae/invoice-ae-outside-scope.json | 10 +- .../invoice-ae-reverse-charge-allowance.json | 8 +- .../pint/ae/invoice-ae-reverse-charge.json | 8 +- .../pint/ae/invoice-ae-self-billed.json | 8 +- .../pint/ae/invoice-ae-shared-fields.json | 12 +- .../pint/ae/invoice-ae-tin-passport.json | 3 +- .../convert/pint/ae/invoice-ae-usd.json | 8 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 8 +- .../ae/out/credit-note-ae-margin-scheme.xml | 6 + .../ae/out/credit-note-ae-outside-scope.xml | 6 + .../ae/out/credit-note-ae-self-billed.xml | 6 + .../ae/out/credit-note-ae-volume-discount.xml | 6 + .../convert/pint/ae/out/credit-note-ae.xml | 6 + .../ae/out/invoice-ae-continuous-supply.xml | 6 + .../pint/ae/out/invoice-ae-deemed-supply.xml | 6 + .../convert/pint/ae/out/invoice-ae-exempt.xml | 6 + .../pint/ae/out/invoice-ae-export-summary.xml | 6 + .../out/invoice-ae-free-trade-zone-agent.xml | 6 + .../pint/ae/out/invoice-ae-margin-scheme.xml | 6 + .../pint/ae/out/invoice-ae-outside-scope.xml | 6 + .../invoice-ae-reverse-charge-allowance.xml | 6 + .../pint/ae/out/invoice-ae-reverse-charge.xml | 6 + .../pint/ae/out/invoice-ae-self-billed.xml | 6 + .../pint/ae/out/invoice-ae-shared-fields.xml | 9 + .../convert/pint/ae/out/invoice-ae-usd.xml | 6 + .../convert/pint/ae/out/invoice-ae.xml | 6 + .../parse/pint/ae/out/allowance-exempt.json | 4 +- ubl/ubl_test.go | 8 +- 53 files changed, 601 insertions(+), 306 deletions(-) create mode 100644 addon/pint/org_party_test.go diff --git a/README.md b/README.md index cae1448..603ac42 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ number (`peppol-pint-ae-batch-number`) as its lot; and the scheme version (`peppol-pint-ae-scheme-version`) of the item's classification and service accounting codes. On import, it reads the invoice UUID, the out-of-scope type codes 480 and 81 back as the -`outside-scope` tag, and +`outside-tax-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and tags, and the credit note reason, billing frequency, line exemption diff --git a/addon/pint/bill.go b/addon/pint/bill.go index db653aa..75153ca 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -1,6 +1,8 @@ package pint import ( + "regexp" + "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/untdid" @@ -60,20 +62,20 @@ func billInvoiceRules() *rules.Set { rules.Assert("06", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyAddressHasEmirate), ), - rules.When( - is.Func("has UAE Peppol endpoint", partyHasUAEEndpoint), - rules.Assert("07", "supplier legal identity is required with a UAE Peppol endpoint (IBR-150-AE)", - is.Func("has legal identity", partyHasLegalIdentity), - ), - rules.Field("identities", rules.Each( - rules.When( - is.Func("legal scope", identityHasLegalScope), - rules.Assert("08", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint (IBR-173-AE, IBR-181-AE)", - is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), - ), - ), - )), + // IBR-150-AE, IBR-173-AE and IBR-181-AE apply to sellers with a + // 0235 endpoint, which every UAE supplier has, as the UAE PASR + // gives every end user 0235:. + rules.Assert("07", "supplier legal identity is required (IBR-150-AE)", + is.Func("has legal identity", partyHasLegalIdentity), ), + rules.Field("identities", rules.Each( + rules.When( + is.Func("legal scope", identityHasLegalScope), + rules.Assert("08", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision (IBR-173-AE, IBR-181-AE)", + is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), + ), + ), + )), rules.Field("identities", rules.Each( rules.When( org.IdentityKeyIn(org.IdentityKeyPassport), @@ -90,12 +92,11 @@ func billInvoiceRules() *rules.Set { // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two // PartyTaxSchemes with one VAT that it accepts. + // The AE regime checks the TIN's format and check digit. rules.When( is.Func("tax scope", identityHasTaxScope), - rules.Field("code", - rules.Assert("11", "supplier tax scope identity must be a TIN of 10 digits starting with 1 (IBR-148-AE)", - is.MatchesRegexp(tinRegexp), - ), + rules.Assert("11", "supplier tax scope identity must be a TIN (IBR-148-AE)", + org.IdentityTypeIn(ae.IdentityTypeTIN), ), ), )), @@ -416,9 +417,6 @@ func billInvoiceRules() *rules.Set { ), ), ), - rules.Assert("48", "principal ID must differ from the supplier tax ID on disclosed agent billing (IBR-176-AE)", - is.Func("principal ID is not the supplier tax ID", principalIsNotSupplier), - ), ), // IBR-177-AE asks for the TRN or the TIN on every document. Rule 31 // already asks for the TRN except on 480 and 81, so this rule only @@ -427,14 +425,14 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("supplier", - rules.Assert("49", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", + rules.Assert("48", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), ), rules.When( is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("50", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + rules.Assert("49", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), @@ -444,7 +442,7 @@ func billInvoiceRules() *rules.Set { // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), - rules.Assert("51", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + rules.Assert("50", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), ), ), @@ -453,7 +451,7 @@ func billInvoiceRules() *rules.Set { rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("52", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("51", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), ), ), @@ -464,7 +462,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("has reverse charge lines", invoiceHasReverseChargeLine), rules.Field("customer", - rules.Assert("53", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("52", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), @@ -473,15 +471,18 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("54", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("53", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("55", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("54", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), - rules.Assert("56", "principal ID must be a TRN of 15 digits starting with 1 and ending with 03 (IBR-132-AE)", + rules.Assert("55", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), + rules.Assert("56", "principal ID must end with 03 (IBR-132-AE)", + is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), + ), ), // PINT AE writes the billing frequency where EN writes the VAT // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, @@ -600,6 +601,17 @@ func billChargeRules() *rules.Set { ) } +// extensionMatches returns a predicate that reports whether the extension +// for the key, if there, matches the pattern. +func extensionMatches(key cbc.Key, pattern string) func(any) bool { + re := regexp.MustCompile(pattern) + return func(val any) bool { + ext, _ := tax.ExtensionsFromValue(val) + code := ext.Get(key) + return code == "" || re.MatchString(code.String()) + } +} + // invoiceExtIn returns a predicate that reports whether the invoice's tax // extension for the key is one of the codes. A missing extension is the empty // code. @@ -800,15 +812,14 @@ func partyHasNonVATTaxRegistration(p *org.Party) bool { return false } -// partyHasTIN reports whether the party has a tax scope identity with the -// code IBR-133-AE looks for in the seller's tax schemes: 10 digits starting -// with 1. +// partyHasTIN reports whether the party has a tax scope identity of the TIN +// type, the seller TIN IBR-133-AE looks for in the seller's tax schemes. func partyHasTIN(p *org.Party) bool { if p == nil { return false } for _, id := range p.Identities { - if identityHasTaxScope(id) && tinRegexp.MatchString(id.Code.String()) { + if identityHasTaxScope(id) && id.Type == ae.IdentityTypeTIN { return true } } @@ -825,23 +836,6 @@ func partyTaxIDIsNotVAT(p *org.Party) bool { return scheme != "" && scheme != tax.CategoryVAT } -// normalizeRounding gives UAE invoices without a rounding rule the currency -// one. PINT sends each line amount rounded to the currency, and each VAT -// breakdown must equal the sum of its lines (ALIGNED-IBRP-S-08 and the other -// breakdown rules). With the default precise rule, the breakdown is the sum -// of the unrounded lines, which can differ by a few cents. -func normalizeRounding(inv *bill.Invoice) { - if inv == nil { - return - } - if inv.Tax == nil { - inv.Tax = new(bill.Tax) - } - if inv.Tax.Rounding == "" { - inv.Tax.Rounding = tax.RoundingRuleCurrency - } -} - // invoiceHasInvoicePeriod reports whether the invoice has what is written as // cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's // text asks for the invoicing period, but its test only checks the element @@ -855,39 +849,6 @@ func invoiceHasInvoicePeriod(val any) bool { inv.Tax.GetExt(ExtKeyBillingFrequency) != "" } -// principalIsNotSupplier reports whether the principal ID differs from the -// supplier's tax registrations, the cbc:CompanyID values of its -// PartyTaxSchemes (IBR-176-AE). A missing principal ID or supplier tax -// registration passes, as rules 47 and 49 report those. -func principalIsNotSupplier(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return false - } - principal := inv.Tax.GetExt(ExtKeyPrincipalID) - if principal == "" || inv.Supplier == nil { - return true - } - var codes []cbc.Code - if inv.Supplier.TaxID != nil && inv.Supplier.TaxID.Code != "" { - codes = append(codes, inv.Supplier.TaxID.Code) - } - for _, id := range inv.Supplier.Identities { - if identityHasTaxScope(id) { - codes = append(codes, id.Code) - } - } - if len(codes) == 0 { - return true - } - for _, c := range codes { - if c != principal { - return true - } - } - return false -} - // invoiceDeliveryAddress returns the first address of the delivery receiver, // which gobl.ubl writes as cac:DeliveryLocation/cac:Address, or nil. func invoiceDeliveryAddress(inv *bill.Invoice) *org.Address { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 119f3d6..dfe1301 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -238,10 +238,11 @@ func TestBillInvoiceRulesAE(t *testing.T) { func aeDocument(typ cbc.Key, tags ...cbc.Key) *bill.Invoice { inv := scenarioInvoice(l10n.AE.Tax(), typ, tags...) inv.Supplier = &org.Party{ - Name: "Seller LLC", - TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, - Endpoints: validEndpoints("100000001600003"), - Addresses: aeAddress("DXB"), + Name: "Seller LLC", + TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, + Identities: []*org.Identity{tradeLicense("112345678900003")}, + Endpoints: validEndpoints("100000001600003"), + Addresses: aeAddress("DXB"), } inv.Customer = &org.Party{ Name: "Buyer LLC", @@ -251,7 +252,7 @@ func aeDocument(typ cbc.Key, tags ...cbc.Key) *bill.Invoice { } inv.Lines[0].Item.Description = "Consulting services" inv.Lines[0].Taxes = tax.Set{standardVAT()} - if inv.HasTags(pint.TagOutsideScope) { + if inv.HasTags(pint.TagOutsideTaxScope) { inv.Lines[0].Taxes = tax.Set{{Category: tax.CategoryVAT, Key: tax.KeyOutsideScope}} inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} } @@ -309,7 +310,7 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" @@ -323,10 +324,10 @@ func TestBillDocumentRulesAE(t *testing.T) { ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { - return aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope) + return aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideTaxScope) } outsideScopeCredit := func() *bill.Invoice { - return aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + return aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideTaxScope) } t.Run("valid documents raise no PINT faults", func(t *testing.T) { @@ -703,6 +704,12 @@ func tradeLicense(code string) *org.Identity { return &org.Identity{Type: ae.IdentityTypeTradeLicense, Code: cbc.Code(code), Description: "Dubai Economy and Tourism"} } +// withoutTRN removes the supplier's TRN, from which the supplier gets its +// TIN. +func withoutTRN(inv *bill.Invoice) { + inv.Supplier.TaxID = &tax.Identity{Country: "AE"} +} + // aeIdentityDocument returns a valid UAE invoice whose parties have UAE Peppol // endpoints and trade licences, the case the legal registration rules apply to. func aeIdentityDocument() *bill.Invoice { @@ -757,27 +764,12 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, out, faultCustomerTaxCount) }) - t.Run("supplier with a UAE endpoint needs a legal identity (IBR-150-AE)", func(t *testing.T) { + t.Run("supplier needs a legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) }) - t.Run("supplier without a UAE endpoint needs no legal identity (IBR-150-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities = nil - inv.Supplier.Endpoints = validEndpoints("1357902467") - assert.NotContains(t, aeFaults(t, inv), faultSupplierLegalRequired) - }) - - t.Run("UAE endpoint in an inbox counts too (IBR-150-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities = nil - inv.Supplier.Endpoints = nil - inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1357902467"}} - assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) - }) - t.Run("legal identity needs a PINT AE type with a UAE endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} @@ -787,15 +779,11 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, out, faultCustomerLegalType) }) - t.Run("legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { + t.Run("customer legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { inv := aeIdentityDocument() - inv.Supplier.Endpoints = validEndpoints("1357902467") - inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} inv.Customer.Endpoints = validEndpoints("1345678906") inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} - out := aeFaults(t, inv) - assert.NotContains(t, out, faultSupplierLegalType) - assert.NotContains(t, out, faultCustomerLegalType) + assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalType) }) t.Run("customer with a predefined UAE endpoint needs no legal identity type or authority (IBR-180-AE, IBR-183-AE, IBR-101-AE)", func(t *testing.T) { @@ -875,12 +863,23 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, inv)) }) - t.Run("supplier tax identity must be a TIN starting with 1 (IBR-148-AE)", func(t *testing.T) { + t.Run("supplier tax identity must be a TIN (IBR-148-AE)", func(t *testing.T) { + for _, typ := range []cbc.Code{"", "TAX"} { + inv := aeIdentityDocument() + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Scope: org.IdentityScopeTax, Type: typ, Code: "1234567897"}) + assert.Contains(t, aeFaults(t, inv), faultSupplierTIN, typ) + } + }) + + t.Run("the AE regime checks the supplier TIN's format (IBR-148-AE)", func(t *testing.T) { for _, code := range []cbc.Code{"2234567890", "123456789"} { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Scope: org.IdentityScopeTax, Type: "TIN", Code: code}) - assert.Contains(t, aeFaults(t, inv), faultSupplierTIN, code) + &org.Identity{Scope: org.IdentityScopeTax, Type: ae.IdentityTypeTIN, Code: code}) + out := aeFaults(t, inv) + assert.Contains(t, out, "GOBL-AE-ORG-IDENTITY-01", code) + assert.NotContains(t, out, faultSupplierTIN, code) } }) @@ -930,6 +929,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run("customer tax identity needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() + withoutTRN(inv) inv.Customer.TaxID = nil inv.Customer.Identities = append(inv.Customer.Identities, &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) @@ -945,6 +945,7 @@ func TestBillIdentityRulesAE(t *testing.T) { // The scheme is set here as these tests don't register the AU regime, // which gives AU tax IDs the GST scheme. inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} + withoutTRN(inv) assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, @@ -952,6 +953,12 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) }) + t.Run("supplier TIN from the TRN is enough (IBR-133-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} + assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) + }) + t.Run("customer tax ID under VAT needs no supplier TIN", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} @@ -980,6 +987,7 @@ func TestBillIdentityRulesAE(t *testing.T) { t.Run(name, func(t *testing.T) { inv := aeIdentityDocument() set(inv) + withoutTRN(inv) assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) inv.Supplier.Identities = append(inv.Supplier.Identities, @@ -1006,44 +1014,6 @@ func TestBillIdentityRulesAE(t *testing.T) { }) } -func TestNormalizeRounding(t *testing.T) { - t.Run("AE invoices get the currency rule", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - require.NoError(t, inv.Calculate()) - assert.Equal(t, tax.RoundingRuleCurrency, inv.Tax.Rounding) - }) - - t.Run("a rule set on the invoice is kept", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Tax = &bill.Tax{Rounding: tax.RoundingRulePrecise} - require.NoError(t, inv.Calculate()) - assert.Equal(t, tax.RoundingRulePrecise, inv.Tax.Rounding) - }) - - t.Run("lines and VAT breakdown add up", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - line := inv.Lines[0] - line.Quantity = num.MakeAmount(3335, 4) - line.Item.Price = num.NewAmount(1000, 2) - inv.Lines = nil - for i := 0; i < 12; i++ { - l := *line - inv.Lines = append(inv.Lines, &l) - } - require.NoError(t, inv.Calculate()) - assert.Equal(t, "40.08", inv.Totals.Sum.String()) - assert.Equal(t, "40.08", inv.Totals.Taxes.Categories[0].Rates[0].Base.String()) - }) - - t.Run("other regimes keep the default", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) - require.NoError(t, inv.Calculate()) - if inv.Tax != nil { - assert.Empty(t, inv.Tax.Rounding) - } - }) -} - func TestBillTransactionTypeRulesAE(t *testing.T) { const ( faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" @@ -1053,13 +1023,13 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultPrincipalSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" - faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" - faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1152,22 +1122,22 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, inv)) }) - t.Run("principal ID must differ from the supplier TRN (IBR-176-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) - setExt(inv, pint.ExtKeyPrincipalID, inv.Supplier.TaxID.Code) - assert.Contains(t, aeFaults(t, inv), faultPrincipalSupplier) - }) - t.Run("principal ID must be a TRN (IBR-132-AE)", func(t *testing.T) { - for _, code := range []cbc.Code{"255667745601003", "15566774560100", "155667745601004", "1556677456010A3"} { + for _, code := range []cbc.Code{"255667745601003", "15566774560100", "1556677456010A3"} { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) setExt(inv, pint.ExtKeyPrincipalID, code) assert.Contains(t, aeFaults(t, inv), faultPrincipalTRN, code) } + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) + setExt(inv, pint.ExtKeyPrincipalID, "155667745601004") + out := aeFaults(t, inv) + assert.NotContains(t, out, faultPrincipalTRN) + assert.Contains(t, out, faultPrincipalVAT) + // It is checked without the disclosed agent tag too, as it is // written whenever it is there. - inv := aeDocument(bill.InvoiceTypeStandard) + inv = aeDocument(bill.InvoiceTypeStandard) setExt(inv, pint.ExtKeyPrincipalID, "P-1234") assert.Contains(t, aeFaults(t, inv), faultPrincipalTRN) }) @@ -1181,10 +1151,9 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { out := aeFaults(t, inv) assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-31") assert.NotContains(t, out, faultSupplierTax) - assert.NotContains(t, out, faultPrincipalSupplier) for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { - inv = aeDocument(typ, pint.TagOutsideScope) + inv = aeDocument(typ, pint.TagOutsideTaxScope) inv.Supplier.TaxID = &tax.Identity{Country: "AE"} assert.Contains(t, aeFaults(t, inv), faultSupplierTax, typ) @@ -1217,10 +1186,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { t.Run("outside scope documents can't be summary, deemed supply or margin scheme (IBR-157-AE)", func(t *testing.T) { for _, tag := range []cbc.Key{pint.TagSummary, pint.TagDeemedSupply, pint.TagMarginScheme} { - inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope, tag) + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideTaxScope, tag) assert.Contains(t, aeFaults(t, inv), faultOutsideScopeFlags, tag) } - inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideScope, pint.TagContinuousSupply) + inv := aeDocument(bill.InvoiceTypeStandard, pint.TagOutsideTaxScope, pint.TagContinuousSupply) assert.NotContains(t, aeFaults(t, inv), faultOutsideScopeFlags) }) @@ -1252,7 +1221,7 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1272,7 +1241,7 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { }) t.Run("credit note related to goods and services needs a reason (IBR-055-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + inv := aeDocument(bill.InvoiceTypeCreditNote, pint.TagOutsideTaxScope) inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyCreditNoteReason) assert.Contains(t, aeFaults(t, inv), faultReasonRequired) }) @@ -1313,7 +1282,7 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" ) @@ -1551,7 +1520,7 @@ func TestBillTagsOutsideAE(t *testing.T) { return err.Error() } aeTags := []cbc.Key{ - pint.TagOutsideScope, pint.TagFreeTradeZone, pint.TagDeemedSupply, pint.TagMarginScheme, + pint.TagOutsideTaxScope, pint.TagFreeTradeZone, pint.TagDeemedSupply, pint.TagMarginScheme, pint.TagSummary, pint.TagContinuousSupply, pint.TagDisclosedAgent, pint.TagECommerce, tax.TagExport, } diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index a2a4ef1..afdaded 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -61,10 +61,6 @@ const CreditNoteReasonVolumeDiscount cbc.Code = "VD" // in an invoice note (IBR-160-AE). const BillingFrequencyOthers cbc.Code = "OTH" -// principalIDPattern is the format of the principal ID, a UAE TRN: 15 digits -// starting with 1 and ending with 03 (IBR-132-AE). -const principalIDPattern = `^1\d{12}03$` - // Usages of the PINT AE extensions: offered by the PINT addon under the AE // regime, on the object each one goes on. var ( @@ -159,11 +155,10 @@ var extensions = []*cbc.Definition{ Identifier of the principal a disclosed agent bills on behalf of (BTAE-14), required with the "disclosed-agent" transaction type (IBR-137-AE). It is the principal's TRN: 15 digits starting with 1 - and ending with 03 (IBR-132-AE), different from the supplier's tax - ID (IBR-176-AE). + and ending with 03 (IBR-132-AE). `), }, - Pattern: principalIDPattern, + Pattern: ae.TRNPattern, }, { Key: ExtKeyCreditNoteReason, diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index a35e097..21f52a3 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -1,8 +1,6 @@ package pint import ( - "regexp" - "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" @@ -10,13 +8,6 @@ import ( "github.com/invopop/gobl/regimes/ae" ) -// tinRegexp matches a UAE TIN as PINT AE expects it: 10 digits starting with -// 1 (IBR-148-AE). The AE regime checks the identities of the TIN type, check -// digit included; this one covers any tax scope identity, as the Schematron -// tests the value written. UAE Peppol endpoints (0235) are TINs too, so it -// also tells whether an endpoint is one (IBR-135-AE). -var tinRegexp = regexp.MustCompile(`^1\d{9}$`) - // PINT AE legal registration identifier types, written as @schemeAgencyID on // the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The trade licence // (TL), Emirates ID (EID) and Cabinet Decision (CD) are the AE regime's diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index 0edbf6f..c3face4 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -5,10 +5,13 @@ import ( "slices" "strings" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pkg/luhn" + "github.com/invopop/gobl/regimes/ae" ) // emirateCodes are the country subdivision codes PINT AE accepts for UAE @@ -225,8 +228,6 @@ func partyHasUAEEndpointWith(match func(code string) bool) func(any) bool { } var ( - // partyHasUAEEndpoint is the condition of the legal registration rules. - partyHasUAEEndpoint = partyHasUAEEndpointWith(func(string) bool { return true }) // partyHasUAEEndpointPredefined reports whether the party has one of the // predefined UAE endpoints, which IBR-180-AE, IBR-183-AE and IBR-101-AE // exempt. @@ -251,7 +252,7 @@ var ( // partyHasUAEEndpointNotTIN is the condition of IBR-135-AE: a code that // is not a TIN, 1XXXXXXXXX. partyHasUAEEndpointNotTIN = partyHasUAEEndpointWith(func(code string) bool { - return !tinRegexp.MatchString(code) + return !tinRegexpAE.MatchString(code) }) ) @@ -318,3 +319,61 @@ func partyHasIdentificationOrTaxRegistration(val any) bool { } return false } + +// tinRegexpAE matches a UAE TIN, in the AE regime's format. UAE Peppol +// endpoints (0235) are TINs too, so it also tells whether an endpoint is one +// (IBR-135-AE). +var tinRegexpAE = regexp.MustCompile(ae.TINPattern) + +// trnRegexpAE matches a UAE TRN, in the AE regime's format. Its first 10 +// digits are the TIN. +var trnRegexpAE = regexp.MustCompile(ae.TRNPattern) + +// normalizeSupplierAE fills in what the supplier's UAE TRN implies, when it +// is missing: the TIN the TRN starts with, as a tax scope identity of the +// TIN type (IBT-032), and the UAE Peppol endpoint, 0235 with the TIN, the +// one the UAE PASR gives every end user. An identity of the TIN type or with +// the tax scope is kept as it is, and the endpoint is only added to a +// supplier with no endpoint or inbox at all. +// +// TODO: the customer's endpoint could be derived from its TRN the same way, +// as every UAE end user is 0235:, but it is not done yet. +func normalizeSupplierAE(inv *bill.Invoice) { + if inv == nil || inv.Supplier == nil { + return + } + p := inv.Supplier + tin := partyTINFromTRN(p) + if tin == "" { + return + } + if !slices.ContainsFunc(p.Identities, func(id *org.Identity) bool { + return id != nil && (id.Type == ae.IdentityTypeTIN || id.Scope == org.IdentityScopeTax) + }) { + p.Identities = append(p.Identities, &org.Identity{ + Type: ae.IdentityTypeTIN, + Code: tin, + Scope: org.IdentityScopeTax, + }) + } + if len(p.Endpoints) == 0 && len(p.Inboxes) == 0 { + p.Endpoints = append(p.Endpoints, &org.Endpoint{ + URI: cbc.URI(iso.ActorIDScheme + "::" + endpointSchemeUAE.String() + ":" + tin.String()), + }) + } +} + +// partyTINFromTRN returns the TIN the party's UAE tax ID starts with, when +// the code has the TRN format and the TIN a valid check digit, as the AE +// regime checks them. It returns an empty code otherwise, so an invalid TRN +// gives one error, not a second one on a derived TIN. +func partyTINFromTRN(p *org.Party) cbc.Code { + if p.TaxID == nil || p.TaxID.Country != l10n.AE.Tax() { + return "" + } + code := p.TaxID.Code.String() + if !trnRegexpAE.MatchString(code) || !luhn.Check(cbc.Code(code[:10])) { + return "" + } + return cbc.Code(code[:10]) +} diff --git a/addon/pint/org_party_test.go b/addon/pint/org_party_test.go new file mode 100644 index 0000000..290f785 --- /dev/null +++ b/addon/pint/org_party_test.go @@ -0,0 +1,92 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/addons/eu/en16931" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/cbc" + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/norm" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" +) + +func TestNormalizeSupplierAE(t *testing.T) { + // normalize returns the supplier after normalizing an invoice under the + // regime. + normalize := func(regime l10n.TaxCountryCode, p *org.Party) *org.Party { + inv := &bill.Invoice{Supplier: p} + norm.Normalize(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(regime)) + return inv.Supplier + } + trn := func() *org.Party { + return &org.Party{Name: "Supplier", TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}} + } + tinIdentity := &org.Identity{Type: ae.IdentityTypeTIN, Code: "1000000016", Scope: org.IdentityScopeTax} + tinEndpoint := &org.Endpoint{URI: "iso6523-actorid-upis::0235:1000000016"} + + t.Run("the TRN gives the TIN identity and the UAE Peppol endpoint", func(t *testing.T) { + p := normalize(l10n.AE.Tax(), trn()) + assert.Equal(t, []*org.Identity{tinIdentity}, p.Identities) + assert.Equal(t, []*org.Endpoint{tinEndpoint}, p.Endpoints) + }) + + t.Run("a TIN or tax scope identity is kept", func(t *testing.T) { + for _, id := range []*org.Identity{ + {Type: ae.IdentityTypeTIN, Code: "1234567897"}, + {Scope: org.IdentityScopeTax, Code: "1234567897"}, + } { + p := trn() + p.Identities = []*org.Identity{id} + p = normalize(l10n.AE.Tax(), p) + assert.Len(t, p.Identities, 1) + assert.Equal(t, cbc.Code("1234567897"), p.Identities[0].Code) + } + }) + + t.Run("a Peppol endpoint or inbox is kept", func(t *testing.T) { + p := trn() + p.Endpoints = []*org.Endpoint{{URI: "iso6523-actorid-upis::0088:5790000435975"}} + assert.Len(t, normalize(l10n.AE.Tax(), p).Endpoints, 1) + + p = trn() + p.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1234567897"}} + assert.Empty(t, normalize(l10n.AE.Tax(), p).Endpoints) + }) + + t.Run("an email endpoint or inbox is kept, without the UAE Peppol endpoint", func(t *testing.T) { + p := trn() + p.Endpoints = []*org.Endpoint{{URI: "mailto:billing@example.com"}} + assert.NotContains(t, normalize(l10n.AE.Tax(), p).Endpoints, tinEndpoint) + + p = trn() + p.Inboxes = []*org.Inbox{{Email: "billing@example.com"}} + assert.Empty(t, normalize(l10n.AE.Tax(), p).Endpoints) + }) + + t.Run("a tax ID that is not a valid TRN gives nothing", func(t *testing.T) { + // The last one has the TRN format, but its TIN fails the check digit. + for _, code := range []cbc.Code{"", "10000000160000", "200000001600003", "1000000016000A3", "100000001700003"} { + p := trn() + p.TaxID.Code = code + p = normalize(l10n.AE.Tax(), p) + assert.Empty(t, p.Identities, code) + assert.Empty(t, p.Endpoints, code) + } + p := trn() + p.TaxID = &tax.Identity{Country: "SA", Code: "100000001600003"} + p = normalize(l10n.AE.Tax(), p) + assert.Empty(t, p.Identities) + assert.Empty(t, p.Endpoints) + }) + + t.Run("only under the AE regime", func(t *testing.T) { + p := normalize(l10n.AU.Tax(), trn()) + assert.Empty(t, p.Identities) + assert.Empty(t, p.Endpoints) + }) +} diff --git a/addon/pint/pint.go b/addon/pint/pint.go index 05a9fc6..eabc96e 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -53,7 +53,7 @@ func init() { norm.When( is.InContext(tax.RegimeIn(regimesAE...)), norm.For(normalizeTransactionType), - norm.For(normalizeRounding), + norm.For(normalizeSupplierAE), norm.For(normalizeIdentityScopes), norm.For(normalizeMarginSchemeAE), norm.For(normalizeMarginSchemeNoteAE), @@ -85,7 +85,7 @@ func newV1Addon() *tax.AddonDef { document's tax regime: Australian and New Zealand documents are also validated against the PINT A-NZ rules; and UAE documents are validated against the PINT AE rules. - UAE documents out of scope of VAT use the "outside-scope" tag, which + UAE documents out of scope of VAT use the "outside-tax-scope" tag, which sets the document type to 480 on invoices and 81 on credit notes. UAE documents can only be invoices and credit notes, without the diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index 6b41b78..e90ae7e 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -11,9 +11,9 @@ import ( // Document tags and the UNTDID 1001 codes they map to. const ( - // TagOutsideScope marks a PINT AE document as out of scope of VAT, + // TagOutsideTaxScope marks a PINT AE document as out of scope of VAT, // the UAE "commercial invoice". - TagOutsideScope cbc.Key = "outside-scope" + TagOutsideTaxScope cbc.Key = "outside-tax-scope" // UNTDID 1001 codes PINT AE uses for out-of-scope documents. 480 is in // UNTDID D.23A but not in the EN 16931 code list, so it lives here. @@ -48,9 +48,9 @@ var invoiceTags = &tax.TagSet{ Schema: bill.ShortSchemaInvoice, List: append([]*cbc.Definition{ { - Key: TagOutsideScope, + Key: TagOutsideTaxScope, Name: i18n.String{ - i18n.EN: "Outside Scope", + i18n.EN: "Outside Tax Scope", }, Desc: i18n.String{ i18n.EN: "Marks a PINT AE document as out of scope of VAT, the UAE 'commercial invoice'. Invoices are sent with document type 480 and credit notes with 81. Only for UAE documents.", @@ -69,7 +69,7 @@ var invoiceScenarios = &tax.ScenarioSet{ // ** Out of scope of VAT (UAE only) ** { Types: []cbc.Key{bill.InvoiceTypeStandard}, - Tags: []cbc.Key{TagOutsideScope}, + Tags: []cbc.Key{TagOutsideTaxScope}, Filter: invoiceIsAE, Ext: tax.ExtensionsOf(cbc.CodeMap{ untdid.ExtKeyDocumentType: docTypeInvoiceOutsideScope, @@ -77,7 +77,7 @@ var invoiceScenarios = &tax.ScenarioSet{ }, { Types: []cbc.Key{bill.InvoiceTypeCreditNote}, - Tags: []cbc.Key{TagOutsideScope}, + Tags: []cbc.Key{TagOutsideTaxScope}, Filter: invoiceIsAE, Ext: tax.ExtensionsOf(cbc.CodeMap{ untdid.ExtKeyDocumentType: docTypeCreditNoteGoodsServices, diff --git a/addon/pint/scenarios_test.go b/addon/pint/scenarios_test.go index e9e4412..b206711 100644 --- a/addon/pint/scenarios_test.go +++ b/addon/pint/scenarios_test.go @@ -56,12 +56,12 @@ func TestInvoiceScenarios(t *testing.T) { ae := l10n.AE.Tax() t.Run("AE out-of-scope invoice is 480", func(t *testing.T) { - inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideScope) + inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideTaxScope) assert.Equal(t, cbc.Code("480"), documentType(t, inv)) }) t.Run("AE out-of-scope credit note is 81", func(t *testing.T) { - inv := scenarioInvoice(ae, bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + inv := scenarioInvoice(ae, bill.InvoiceTypeCreditNote, pint.TagOutsideTaxScope) assert.Equal(t, cbc.Code("81"), documentType(t, inv)) }) @@ -76,16 +76,16 @@ func TestInvoiceScenarios(t *testing.T) { }) t.Run("a hand-set code is replaced by the scenario", func(t *testing.T) { - inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideScope) + inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideTaxScope) inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyDocumentType: "380"})} assert.Equal(t, cbc.Code("480"), documentType(t, inv)) }) t.Run("the tag has no effect outside AE", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, pint.TagOutsideScope) + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, pint.TagOutsideTaxScope) assert.Equal(t, cbc.Code("380"), documentType(t, inv)) - inv = scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeCreditNote, pint.TagOutsideScope) + inv = scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeCreditNote, pint.TagOutsideTaxScope) assert.Equal(t, cbc.Code("381"), documentType(t, inv)) }) } diff --git a/addon/pint/tax_identity.go b/addon/pint/tax_identity.go index 99b8c9f..ddb0566 100644 --- a/addon/pint/tax_identity.go +++ b/addon/pint/tax_identity.go @@ -10,6 +10,9 @@ import ( // UAE tax identity of a UAE document (IBR-132-AE). The rest of IBR-132-AE's // format, 15 digits starting with 1, is checked by the AE regime, together // with the check digit of the TIN they start with. +// vatTRNSuffixPattern is the trailing 03 of a UAE TRN for VAT (IBR-132-AE). +const vatTRNSuffixPattern = `03$` + func taxIdentityRules() *rules.Set { return rules.For(new(tax.Identity), rules.When( @@ -17,7 +20,7 @@ func taxIdentityRules() *rules.Set { rules.When(tax.IdentityIn("AE"), rules.Field("code", rules.AssertIfPresent("01", "UAE TRN must end with 03 (IBR-132-AE)", - is.Matches(`03$`)), + is.Matches(vatTRNSuffixPattern)), ), ), ), diff --git a/examples/out/invoice-ae.json b/examples/out/invoice-ae.json index efdc6f3..0bd0fbd 100644 --- a/examples/out/invoice-ae.json +++ b/examples/out/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", "dig": { "alg": "sha256", - "val": "cb23ddfc55e8643654f9c6adc73a72b65ab885128bec511bd3de620b4f0af22a" + "val": "d924a491f980aeff6dd9b1d5f21f22f7bbc602574cef0080551546a052896f71" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -41,6 +40,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/ae.go b/ubl/ae.go index dfad047..6b8838c 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -43,8 +43,6 @@ const aedTotalDocumentType = "aedtotal-incl-vat" // charges one above 0 (aligned-ibrp-ae-06, aligned-ibrp-ae-07). const aeStandardRate = "5" -// taxSchemeTIN is the tax scheme PINT AE writes the seller TIN under. -const taxSchemeTIN = "TIN" // accountSchemeIBAN is the scheme PINT AE gives the ID of an IBAN account // (IBT-084-1), as the official examples do. @@ -101,7 +99,7 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } importAEUUID(in, inv) - importAEOutsideScope(in, inv) + importAEOutsideTaxScope(in, inv) importAEMarginScheme(inv) importAETransactionType(in, inv) importAECreditNoteReason(in, inv) @@ -127,11 +125,11 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } -// importAEOutsideScope reads the PINT AE out-of-scope document types, which +// importAEOutsideTaxScope reads the PINT AE out-of-scope document types, which // gobl.ubl does not know and imports as "other": 480 becomes a standard -// invoice and 81 a credit note, both with the outside-scope tag. The PINT +// invoice and 81 a credit note, both with the outside-tax-scope tag. The PINT // scenarios then set the type code back when the document is calculated. -func importAEOutsideScope(in *goblubl.Invoice, inv *bill.Invoice) { +func importAEOutsideTaxScope(in *goblubl.Invoice, inv *bill.Invoice) { code := in.InvoiceTypeCode if code == nil { code = in.CreditNoteTypeCode @@ -147,8 +145,8 @@ func importAEOutsideScope(in *goblubl.Invoice, inv *bill.Invoice) { default: return } - if !inv.HasTags(pint.TagOutsideScope) { - inv.Tags.List = append(inv.Tags.List, pint.TagOutsideScope) + if !inv.HasTags(pint.TagOutsideTaxScope) { + inv.Tags.List = append(inv.Tags.List, pint.TagOutsideTaxScope) } } @@ -1001,15 +999,15 @@ func importAEDeliveryPartyID(in *goblubl.Invoice, inv *bill.Invoice) { inv.Delivery.Receiver = new(org.Party) } r := inv.Delivery.Receiver - if trnFormat.MatchString(code.String()) { + if trnRegexp.MatchString(code.String()) { r.TaxID = &tax.Identity{Country: l10n.AE.Tax(), Code: code} return } r.Identities = append(r.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: code}) } -// trnFormat is the format of a UAE TRN. -var trnFormat = regexp.MustCompile(`^1\d{14}$`) +// trnRegexp matches a UAE TRN. +var trnRegexp = regexp.MustCompile(ae.TRNPattern) // extensionHasCode reports whether the extension lists the code. func extensionHasCode(key cbc.Key, code cbc.Code) bool { @@ -1239,7 +1237,24 @@ func exportAEPartyIdentities(out *goblubl.Party, p *org.Party) { return } exportAELegalIdentity(out, p) - exportAETINScheme(out, p) + exportAETINIdentification(out) +} + +// identitySchemeTIN is the ISO 6523 ICD of the UAE TIN, the scheme of UAE +// Peppol endpoints too. +const identitySchemeTIN = "0235" + +// exportAETINIdentification writes the scheme of a TIN identity in +// cac:PartyIdentification as its ISO 6523 ICD, 0235. gobl.ubl writes the +// identity's type, TIN, which is not an ICD (ibr-cl-10). +func exportAETINIdentification(out *goblubl.Party) { + for i := range out.PartyIdentification { + id := out.PartyIdentification[i].ID + if id != nil && id.SchemeID != nil && *id.SchemeID == ae.IdentityTypeTIN.String() { + scheme := identitySchemeTIN + id.SchemeID = &scheme + } + } } // exportAELegalIdentity writes the legal registration identifier type of the @@ -1288,9 +1303,13 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { // importAEPartyIdentities reads back what exportAEPartyIdentities writes: // the legal identity's key or type from @schemeAgencyID, with // @schemeAgencyName as the passport's country or the trade licence's -// description, and, for the supplier, the TIN type on the tax registration -// that is not VAT, as PINT AE -// defines IBT-032 as the seller TIN. +// description, and a TIN identification from its 0235 scheme. For the +// supplier, it also reads every tax registration that +// is not VAT as a TIN, as PINT AE defines IBT-032 as the seller TIN. +// +// TODO: the BIS gives the seller TIN's scheme no code list, and the official +// examples use TIN and TAX. A scheme like TAX is read as a TIN, and written +// back as TIN. func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { if in == nil || p == nil { return @@ -1305,10 +1324,26 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { break } } - if supplier { + // A cac:PartyIdentification with the scheme 0235 is a TIN, which export + // writes with that scheme. + for _, id := range p.Identities { + if id != nil && id.Scope == "" && id.Ext.Get(iso.ExtKeySchemeID) == identitySchemeTIN { + id.Type = ae.IdentityTypeTIN + id.Ext = id.Ext.Delete(iso.ExtKeySchemeID) + } + } + if !supplier { + return + } + for _, pts := range in.PartyTaxScheme { + if pts.CompanyID == nil || pts.TaxScheme == nil || + strings.EqualFold(strings.TrimSpace(pts.TaxScheme.ID.Value), goblubl.TaxSchemeVAT) { + continue + } for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeTax && id.Key == "" && id.Type == "" { + if id != nil && id.Scope == org.IdentityScopeTax && id.Code.String() == pts.CompanyID.Value { id.Type = ae.IdentityTypeTIN + break } } } @@ -1351,32 +1386,6 @@ func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { } } -// exportAETINScheme writes the TIN tax scheme on the party tax schemes that -// gobl.ubl writes for the party's TIN identities, which it gives the generic -// LOC scheme. -// -// No rule asks for TIN: the BIS only says the scheme of the seller TIN -// (IBT-032) must not be VAT, the syntax binding gives no code list, and -// IBR-133-AE and IBR-178-AE only check for "not VAT", so LOC would pass too. -// The official examples don't agree: Seller-TIN-identifier.xml uses TIN and -// Seller-TRN-and-TIN-identifiers.xml uses TAX. FormatAE writes TIN and reads -// both. It is not the TIN of UNCL 1153, which is a transport instruction -// number. -func exportAETINScheme(out *goblubl.Party, p *org.Party) { - for _, id := range p.Identities { - if id == nil || id.Type != ae.IdentityTypeTIN || id.Scope != org.IdentityScopeTax { - continue - } - for i := range out.PartyTaxScheme { - pts := &out.PartyTaxScheme[i] - if pts.CompanyID != nil && pts.CompanyID.Value == id.Code.String() && - pts.TaxScheme != nil && pts.TaxScheme.ID.Value != goblubl.TaxSchemeVAT { - pts.TaxScheme.ID.Value = taxSchemeTIN - } - } - } -} - // exportAETaxTotal fixes the rates of the VAT breakdowns, and merges the ones // left with the same category and rate. The total with breakdowns, which is // the one in the document currency, also says its prices don't include VAT diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index aa9bcd6..3a2a720 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -310,6 +310,15 @@ func TestExportAEPartyIdentities(t *testing.T) { assert.Equal(t, goblubl.TaxSchemeTaxRegistration, out.PartyTaxScheme[0].TaxScheme.ID.Value) }) + t.Run("a TIN identification has the scheme 0235", func(t *testing.T) { + out := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{ + {Type: ae.IdentityTypeTIN, Code: "1234567897"}, + }}) + require.Len(t, out.PartyIdentification, 1) + assert.Equal(t, "1234567897", out.PartyIdentification[0].ID.Value) + assert.Equal(t, "0235", *out.PartyIdentification[0].ID.SchemeID) + }) + t.Run("nil parties are skipped", func(t *testing.T) { assert.NotPanics(t, func() { exportAEPartyIdentities(nil, &org.Party{}) @@ -343,6 +352,16 @@ func TestImportAEPartyIdentities(t *testing.T) { assert.Equal(t, "Trade License issuing Authority", id.Description) }) + t.Run("an identification with the scheme 0235 is a TIN", func(t *testing.T) { + scheme := "0235" + in := &goblubl.Party{PartyIdentification: []goblubl.Identification{ + {ID: &goblubl.IDType{Value: "1234567897", SchemeID: &scheme}}, + }} + id := imported(in, false).Identities[0] + assert.Equal(t, ae.IdentityTypeTIN, id.Type) + assert.False(t, id.Ext.Has(iso.ExtKeySchemeID)) + }) + t.Run("passport with its issuing country", func(t *testing.T) { id := imported(companyID("PAS", "IN"), false).Identities[0] assert.Equal(t, org.IdentityKeyPassport, id.Key) @@ -380,6 +399,11 @@ func TestImportAEPartyIdentities(t *testing.T) { p = imported(in, false) assert.Empty(t, p.Identities[1].Type, "only the seller has a TIN") + + // Any scheme other than VAT, like the official example's TAX. + in.PartyTaxScheme[1].TaxScheme.ID.Value = "TAX" + p = imported(in, true) + assert.Equal(t, ae.IdentityTypeTIN, p.Identities[1].Type) }) t.Run("nil parties are skipped", func(t *testing.T) { @@ -464,27 +488,27 @@ func TestImportAEOutsideScope(t *testing.T) { in.CreditNoteTypeCode = &goblubl.IDType{Value: creditNoteCode} } inv := &bill.Invoice{Type: bill.InvoiceTypeOther} - importAEOutsideScope(in, inv) + importAEOutsideTaxScope(in, inv) return inv } inv := importCode("480", "") assert.Equal(t, bill.InvoiceTypeStandard, inv.Type) - assert.True(t, inv.HasTags(pint.TagOutsideScope)) + assert.True(t, inv.HasTags(pint.TagOutsideTaxScope)) inv = importCode("", "81") assert.Equal(t, bill.InvoiceTypeCreditNote, inv.Type) - assert.True(t, inv.HasTags(pint.TagOutsideScope)) + assert.True(t, inv.HasTags(pint.TagOutsideTaxScope)) inv = importCode("380", "") assert.Equal(t, bill.InvoiceTypeOther, inv.Type, "other codes are left to gobl.ubl") - assert.False(t, inv.HasTags(pint.TagOutsideScope)) + assert.False(t, inv.HasTags(pint.TagOutsideTaxScope)) t.Run("does not add the tag twice", func(t *testing.T) { in := &goblubl.Invoice{InvoiceTypeCode: &goblubl.IDType{Value: "480"}} - inv := &bill.Invoice{Tags: tax.WithTags(pint.TagOutsideScope)} - importAEOutsideScope(in, inv) - assert.Equal(t, []cbc.Key{pint.TagOutsideScope}, inv.Tags.List) + inv := &bill.Invoice{Tags: tax.WithTags(pint.TagOutsideTaxScope)} + importAEOutsideTaxScope(in, inv) + assert.Equal(t, []cbc.Key{pint.TagOutsideTaxScope}, inv.Tags.List) }) } diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json index b35253a..5b5b874 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2d2e574d3be6d3b5dde197b4a960a887e4b37dee64b63e562e338afa3d090c1d" + "val": "35eef84f986a2810ed82e1772d98af5fd1b14b32c0329ea661d24ca64dd0ded5" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -33,7 +33,6 @@ } ], "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00100000", @@ -62,6 +61,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json index 8d8125e..5276c74 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3a431eac1384de1fea831158c59bca26dc40761b586b27b5bb1943cbf169859a" + "val": "60fa84102f1210245ec1fe632ccd9b43ac603e341c3aeb82def20c8aa4cd9c61" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -17,7 +17,7 @@ "peppol-pint-v1" ], "$tags": [ - "outside-scope" + "outside-tax-scope" ], "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "type": "credit-note", @@ -32,7 +32,6 @@ } ], "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", @@ -51,6 +50,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json index 170f9de..f106365 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f5eec2c2922021f63a877e11dfdf1735d639118e099c0691b52d4b18978cbfe2" + "val": "40bc2e024dec9695857cd853ca5a52e981d15747a1590fe64bfd4c2d2e6fd80f" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -32,7 +32,6 @@ } ], "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", @@ -51,6 +50,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json index 56f79f2..de01d0b 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "dd609e84e97665d69c7ae82639d359f36460682972e78d17aba5e4d926c96b25" + "val": "d6ea15e94a76cb4fbb2f76a99b67f85dfe583e23ffe2a1327fc0769b168b2c47" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "VD", "peppol-pint-ae-transaction-type": "00000000", @@ -42,6 +41,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index a14b08f..bc77d04 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c5e60d8847b7be4c53b9295b201d1a1c7bb4fbb8711f566ae14e06ba8d3ea298" + "val": "8bdd6b94dbe52767ac19841f4fc35610a2b95feb60e9aac4f023dc60a201156f" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -29,7 +29,6 @@ } ], "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", "peppol-pint-ae-transaction-type": "00000000", @@ -48,6 +47,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index 5dc17a2..69f2dac 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "abb82a8714a0db36b7d0a8d6e7b2888d12391bb43d40ad2bf99d9913ae148a79" + "val": "4949e5919d0ecbf199f4db2735518cf5b19a9d8cb3e1af8ad6f85ad23477c53e" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,7 +26,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-billing-frequency": "OTH", "peppol-pint-ae-transaction-type": "00001000", @@ -45,6 +44,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index f5b6ef9..68fe735 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "55dcb74770d046483515b1cd3d5ece09926f716fb5fc23dc630150dd9a04f03b" + "val": "2dc8dc4acf91ad6143537cc2ef4fc1e7dd3866128ad3038584fe798ce281e5e8" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:9900000097" @@ -26,7 +26,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "01000000", "untdid-document-type": "380" @@ -44,6 +43,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index dad3af5..cbc7dc7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "18bc57c6da55d0b030eb734989fdc6832eb18582db33a67a9374f76734fe7300" + "val": "7c8153e46a7d5643db38f51697101a8139c522a5f0fb947d35cdc79611a7296c" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -51,6 +50,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 8fab8b6..85fa061 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "aebc8acc4f386c67a51b974e8f5cc0f0c1abd4e056255c72c2f221f57dfec748" + "val": "15860a41e57e77bdbf8ec0e413f9f0b929a364461d36701a26f50270e3c3cf27" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -28,7 +28,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-customs-reference": "EXP010101234", "peppol-pint-ae-transaction-type": "00010011", @@ -47,6 +46,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json index c02fc91..fc976a0 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "71e2dfa98d40f6c76e25623b60de2e97612c8ef4efbf76a39bd765d98ec1d34c" + "val": "5588c3e14d0ea5da245078293ae567acb56e8a2d2e0a558192e5917181eb0799" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -27,7 +27,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-beneficiary-id": "189098765401003", "peppol-pint-ae-principal-id": "155667745601003", @@ -47,6 +46,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index fad80ba..8f69b91 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "96de7b44eeaa9558c2f4d286a5eb9b7f6bbaf7cc6fb5c8bec4c41c36b67a8409" + "val": "193f975acb4d73d89551b498c2dbe98c4678386a49498e542c5466d3aa30917f" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -26,7 +26,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00100000", "untdid-document-type": "380" @@ -54,6 +53,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index dee0094..bacf593 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b0e8d5cf4ad8f98b0612581b762e5eb87ff0e399c8e0e4b1118eaed6651174b8" + "val": "656b11a6945b2cab5eabf9bfc33d8e2dfa2812eb2d2d422ab307db8848e59125" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -17,7 +17,7 @@ "peppol-pint-v1" ], "$tags": [ - "outside-scope" + "outside-tax-scope" ], "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "type": "standard", @@ -26,7 +26,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "480" @@ -44,6 +43,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index fff42c6..8034694 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "b85ca28bacdafd0b5e34f9f5462ade76d1b685cd6ac09ed060012a3e154c7f8e" + "val": "61932740cf37f995b99440ee29acf1df6c4c09f269cacd44fe772db5719bf9d1" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -41,6 +40,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 8aa2bff..8abae5e 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "815e6543badbe3ca4c442dfe0c9601e41d65dc83eccfe4fbb5c5cb8c69059e14" + "val": "30d69d344cf5b9091c763eae12e8deed8c57e0a78384df40ad576e4453ed12e9" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -41,6 +40,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json index aad0ce1..b63b413 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e8d615b6e0d5515c1af87ab6ea363577379e21176423242106d2d7a72303ac24" + "val": "094056c7e0e238df9aa930453507b1e7eac477445a437413351218349ee142d7" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -26,7 +26,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "389" @@ -44,6 +43,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index df410e9..587ef89 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2fd34ae748de52889dcb37e92ee1b77f66c8aa1bc9642e24dd940f44533757ee" + "val": "c5556348fbbfc482ae579b572ca67c1f574c2c7992fb3a630e5f04163ffa5e8b" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -28,7 +28,6 @@ "value_date": "2025-01-28", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000010", "untdid-document-type": "380" @@ -46,6 +45,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ @@ -82,6 +86,10 @@ "type": "TL", "code": "112345679000001", "description": "Trade License issuing Authority" + }, + { + "type": "TIN", + "code": "1345678906" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index 569e1c9..04790a1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2b7e494e361bc3474671b5556c44fe4530a97eaefeba8d773c2b52caa1c40cea" + "val": "459f5560212a0ba47252606e4ed8a9d1fc7a12161388dd6f33e54797d2cbd8f2" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -23,7 +23,6 @@ "issue_date": "2025-01-30", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index 3cc5b1b..b4b54ec 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d60f1147f35580e51db8bfced20d1426f497ec2b8220512578741804484f9730" + "val": "bde767b250bf2b3e8b494edae364fe3eee894b6f41463614db9d21e10f2bc2eb" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -30,7 +30,6 @@ } ], "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -48,6 +47,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index 16991ba..efff076 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3370f550c6b4f636857d7d6cf990604d2a29448e31ec5c519e1d588ac83f1ea2" + "val": "2efb95563815d20be7d39ea1abff4b5aeb1ea01e3234a449731ef9bdd2320646" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -24,7 +24,6 @@ "issue_time": "17:31:00", "currency": "AED", "tax": { - "rounding": "currency", "ext": { "peppol-pint-ae-transaction-type": "00000000", "untdid-document-type": "380" @@ -42,6 +41,11 @@ "type": "TL", "code": "112345678900003", "description": "Trade License issuing Authority" + }, + { + "scope": "tax", + "type": "TIN", + "code": "1357902467" } ], "endpoints": [ diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml index e8cfd65..7ff7514 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml @@ -40,6 +40,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml index 10f9a6f..631bbb7 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml @@ -40,6 +40,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml index d48993d..ae851c5 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml @@ -40,6 +40,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml index f7d41c6..aec76af 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -34,6 +34,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index 75fa8d0..ede7d6a 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -40,6 +40,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 9d89ab6..5b33604 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -38,6 +38,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml index 2f2cdea..b5e1465 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-deemed-supply.xml @@ -31,6 +31,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index af76299..90352d4 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index f727652..65c9a78 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -39,6 +39,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index ed82e06..1890cdc 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 3b4f9e2..1deb70d 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 23aaaa4..d4c411c 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 193efac..681c487 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index acec5aa..487f911 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml index d9c1010..3d58053 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -32,6 +32,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index 4a49805..e29bef3 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -36,6 +36,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 @@ -45,6 +51,9 @@ 1345678906 + + 1345678906 + Buyer Legal Name diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 6daaa08..4c2fd82 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -38,6 +38,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 8b55629..41a9812 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -38,6 +38,12 @@ VAT + + 1357902467 + + TIN + + Supplier Legal Name 112345678900003 diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 9163cb1..4b6c121 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "02c4879b0f8179f5a03a19b4fe302e578e54c8b2977c4fd52b524494ab1b929f" + "val": "f48f5993b43bdc897ba9fcd15a4295ccbae0a9bafb6ab93b54718dee47016c91" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -17,7 +17,7 @@ "peppol-pint-v1" ], "$tags": [ - "outside-scope" + "outside-tax-scope" ], "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "type": "standard", diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 74eecfe..af7ec23 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -146,8 +146,9 @@ func TestDetectAndImportAE(t *testing.T) { // importFaultsAE are the faults the official PINT AE examples give once // imported. They pass the PINT AE Schematron, but their data is made up: the -// TRNs and TINs fail the check digit the Federal Tax Authority defines, and -// some email addresses are placeholders. Any other fault is a defect in the +// TRNs and TINs fail the check digit the Federal Tax Authority defines (the +// supplier gets no TIN from such a TRN), and some email addresses are +// placeholders. Any other fault is a defect in the // import. margin-scheme-credit-note.xml is the official margin scheme // example turned into a credit note, as there is no official one. var importFaultsAE = map[string][]string{ @@ -229,8 +230,9 @@ func TestImportAESellerTIN(t *testing.T) { env := loadTestEnvelope(t, "pint/ae/invoice-ae-outside-scope.json") inv, ok := env.Extract().(*bill.Invoice) require.True(t, ok) + // The fixture's supplier has its TIN as a tax identity; without the TRN, + // the TIN is its only tax registration. inv.Supplier.TaxID = &tax.Identity{Country: "AE"} - inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1357902467"}) require.NoError(t, env.Calculate()) require.NoError(t, env.Validate()) From dd9d8911bef78f50c322fa3efa307afbed2359e8 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:23:18 +0000 Subject: [PATCH 59/73] Apply the shared PINT rules to every regime Several rules the addon only checked on UAE documents are shared PINT rules, so FormatPINT and FormatAUNZ documents fail them too. They now apply in every regime: - The supplier's and customer's electronic addresses must be written as cbc:EndpointID, an ISO 6523 endpoint or an inbox with a scheme (IBR-081, IBR-080, ibr-cl-25). gobl.ubl writes an email address with the scheme EM, which PINT does not list. - The customer can have at most one identity written as cac:PartyIdentification (ibr-sr-16) and one tax registration (ibr-104), which also covers IBR-179-AE. - The payee needs a name and must differ from the supplier (ibr-017). - The document totals must not have more decimals than PINT allows for the currency (ibr-091, ibr-121 to ibr-125). PINT AE 1.0.5 builds on PINT 1.1.4, which follows each currency's precision, while PINT 1.1.3 still allows 2 for every currency. EN 16931's exemption note rule (BR-E-10, BR-O-10, BR-AE-10) has no PINT counterpart, so it is ignored on every PINT document. The BR-CO-25 ignores on UAE documents go, as EN 16931 1.3.16 dropped the rule and GOBL's en16931 addon no longer checks it. FormatPINT, FormatAUNZ and A-NZ self-billing validate against PINT 1.1.3. The four invoice rule codes the released addon has keep their meaning, and the rest are numbered after them. Co-Authored-By: Claude Opus 5.5 --- README.md | 19 ++- addon/pint/bill.go | 246 ++++++++++++++++----------- addon/pint/bill_test.go | 362 +++++++++++++++++++++++++++------------- addon/pint/org_party.go | 84 +++++++--- addon/pint/tax_combo.go | 4 +- ubl/ae.go | 4 +- ubl/ubl.go | 12 +- 7 files changed, 482 insertions(+), 249 deletions(-) diff --git a/README.md b/README.md index 603ac42..b75701b 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,20 @@ $addons: See the [`examples`](./examples) directory for complete invoices. +### PINT + +Documents with the PINT addon, in any regime: + +- Have supplier and customer electronic addresses that are written as + `cbc:EndpointID`: an ISO 6523 endpoint, or an inbox with a scheme. An email + address is written with the scheme `EM`, which PINT does not accept. +- Have at most one customer identity written as `cac:PartyIdentification` + (any identity other than the tax ones and the first legal one, including a + UAE customer's TIN), and at most one customer tax registration (the tax ID + or a `tax` identity). +- Give the payee a name, and a payee that differs from the supplier in its + legal identity, identity or name. + ## Layout - `addon/` — the GOBL addons: normalizers, scenarios and validation rules that @@ -126,10 +140,7 @@ delivery terms, and the delivery receiver's UAE TRN, or its TIN without one, as the delivery party's identification (BTAE-23). Several notes on the document, or on a line, are joined into one separated by a blank line, as PINT allows a single note on each (ibr-sr-51, ibr-sr-34), and are imported back as -a single note. PINT also allows a single buyer identifier (ibr-sr-16), so the -PINT addon rejects a UAE customer with more than one identity written as -`cac:PartyIdentification`: any identity other than the tax ones and the first -legal one, including the customer's TIN. +a single note. **Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's `margin-scheme` tag, with the `exempt` VAT key on every line: diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 75153ca..d029e4c 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -20,7 +20,14 @@ import ( // jurisdiction, and the PINT AE rules on UAE documents. func billInvoiceRules() *rules.Set { return rules.For(new(bill.Invoice), - // Supplier + // EN 16931 wants an EU VATEX code or an exemption note for every E, O + // and AE VAT breakdown (BR-E-10, BR-O-10, BR-AE-10). PINT has no such + // rule. PINT AE only asks for the UAE exemption reason on exempt lines, + // discounts and charges (IBR-167-AE, IBR-168-AE, IBR-169-AE), and no + // official example has a reason on a breakdown. + rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-08"), + + // Supplier and customer rules.Field("supplier", rules.Assert("01", "invoice supplier must have a tax ID or identity (IBR-CO-26)", is.Func("has identifier", partyHasIdentifier), @@ -29,26 +36,46 @@ func billInvoiceRules() *rules.Set { rules.Assert("02", "invoice supplier electronic address is required (IBR-081)", is.Present), ), ), - // Customer rules.Field("customer", rules.Assert("03", "invoice customer is required (IBR-007)", is.Present), rules.Field("endpoints", rules.Assert("04", "invoice customer electronic address is required (IBR-080)", is.Present), ), ), + // Electronic addresses and customer identification + // + // gobl.ubl writes an email address as cbc:EndpointID with the scheme + // EM, which is not in PINT's electronic address scheme list + // (ibr-cl-25), and writes no cbc:EndpointID for other URI schemes. + rules.Field("supplier", + rules.AssertIfPresent("05", "supplier electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-081, ibr-cl-25)", + is.Func("electronic address written as endpoint ID", partyHasEndpointID), + ), + ), + rules.Field("customer", + rules.AssertIfPresent("06", "customer electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-080, ibr-cl-25)", + is.Func("electronic address written as endpoint ID", partyHasEndpointID), + ), + rules.AssertIfPresent("07", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", + is.Func("at most one buyer identifier", partyHasOneIdentification), + ), + rules.AssertIfPresent("08", "customer must have at most one tax registration (ibr-104, IBR-179-AE)", + is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), + ), + ), + // Payee + rules.Field("payment", + rules.Field("payee", + rules.Field("name", + rules.Assert("09", "payee name is required (ibr-017)", is.Present), + ), + ), + ), + rules.Assert("10", "payee must differ from the supplier by legal identity, identity or name (ibr-017)", + is.Func("payee is not the supplier", payeeIsNotSupplier), + ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - // PINT has no BR-CO-25. PINT AE asks for payment instructions - // (IBR-191-AE, rules 28 and 29) and a due date (IBR-127-AE, rule 30) - // instead, except on credit notes and deemed supplies. - rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-06"), - rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-07"), - // EN 16931 wants an EU VATEX code or an exemption note for every E, O - // and AE breakdown (BR-E-10, BR-O-10, BR-AE-10). PINT AE has no such - // rule: it only asks for the UAE exemption reason on exempt lines - // (IBR-167-AE), and no official example has a reason on a breakdown. - rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-08"), - // AE supplier // // IBR-128-AE asks every UAE address for an emirate code as its @@ -56,22 +83,22 @@ func billInvoiceRules() *rules.Set { // the issuer's and the delivery address below, and the line sellers' // in line rule 10. rules.Field("supplier", - rules.Assert("05", "supplier address must have a street, city and region (IBR-143-AE)", + rules.Assert("11", "supplier address must have a street, city and region (IBR-143-AE)", is.Func("first address has street, city and region", partyAddressIsComplete), ), - rules.Assert("06", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", + rules.Assert("12", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyAddressHasEmirate), ), // IBR-150-AE, IBR-173-AE and IBR-181-AE apply to sellers with a // 0235 endpoint, which every UAE supplier has, as the UAE PASR // gives every end user 0235:. - rules.Assert("07", "supplier legal identity is required (IBR-150-AE)", + rules.Assert("13", "supplier legal identity is required (IBR-150-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), rules.Field("identities", rules.Each( rules.When( is.Func("legal scope", identityHasLegalScope), - rules.Assert("08", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision (IBR-173-AE, IBR-181-AE)", + rules.Assert("14", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision (IBR-173-AE, IBR-181-AE)", is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), @@ -80,13 +107,13 @@ func billInvoiceRules() *rules.Set { rules.When( org.IdentityKeyIn(org.IdentityKeyPassport), rules.Field("country", - rules.Assert("09", "supplier passport must have the issuing country (IBR-012-AE)", is.Present), + rules.Assert("15", "supplier passport must have the issuing country (IBR-012-AE)", is.Present), ), ), rules.When( org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", - rules.Assert("10", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Present), + rules.Assert("16", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Present), ), ), // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity @@ -95,7 +122,7 @@ func billInvoiceRules() *rules.Set { // The AE regime checks the TIN's format and check digit. rules.When( is.Func("tax scope", identityHasTaxScope), - rules.Assert("11", "supplier tax scope identity must be a TIN (IBR-148-AE)", + rules.Assert("17", "supplier tax scope identity must be a TIN (IBR-148-AE)", org.IdentityTypeIn(ae.IdentityTypeTIN), ), ), @@ -104,26 +131,12 @@ func billInvoiceRules() *rules.Set { // AE customer rules.Field("customer", - rules.Assert("12", "customer address must have a street, city and region (IBR-144-AE)", + rules.Assert("18", "customer address must have a street, city and region (IBR-144-AE)", is.Func("first address has street, city and region", partyAddressIsComplete), ), - rules.Assert("13", "customer region must be an emirate code when the country is AE (IBR-128-AE)", + rules.Assert("19", "customer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyAddressHasEmirate), ), - // TODO: ibr-080 is a shared PINT rule, so every PINT jurisdiction - // needs this: rule 04 only checks that there is an endpoint, but - // gobl.ubl writes none as cbc:EndpointID for other URI schemes. It - // writes an email address with the scheme EM, which is not in - // PINT AE's electronic address scheme list (ibr-cl-25). The - // supplier has the same gap (ibr-081). - rules.AssertIfPresent("14", "customer electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-080, ibr-cl-25)", - is.Func("electronic address written as endpoint ID", partyHasEndpointID), - ), - // TODO: ibr-sr-16 is a shared PINT rule, and EN 16931 has it too - // (UBL-SR-16), so every PINT jurisdiction and BIS need this. - rules.AssertIfPresent("15", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", - is.Func("at most one buyer identifier", partyHasOneIdentification), - ), // IBR-180-AE, IBR-183-AE and IBR-101-AE exempt the buyers with the // predefined endpoints 9900000098 and 9900000099. IBR-183-AE also // exempts other 1XXXXXXXXX endpoints, but IBR-180-AE still asks @@ -133,7 +146,7 @@ func billInvoiceRules() *rules.Set { rules.Field("identities", rules.Each( rules.When( is.Func("legal scope", identityHasLegalScope), - rules.Assert("16", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint other than 9900000098 or 9900000099 (IBR-180-AE, IBR-183-AE)", + rules.Assert("20", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint other than 9900000098 or 9900000099 (IBR-180-AE, IBR-183-AE)", is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), ), ), @@ -143,7 +156,7 @@ func billInvoiceRules() *rules.Set { rules.When( org.IdentityKeyIn(org.IdentityKeyPassport), rules.Field("country", - rules.Assert("17", "customer passport must have the issuing country (IBR-010-AE)", is.Present), + rules.Assert("21", "customer passport must have the issuing country (IBR-010-AE)", is.Present), ), ), )), @@ -153,31 +166,28 @@ func billInvoiceRules() *rules.Set { rules.When( org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", - rules.Assert("18", "customer trade license must have the issuing authority in the description, except with a UAE Peppol endpoint 9900000098 or 9900000099 (IBR-101-AE)", is.Present), + rules.Assert("22", "customer trade license must have the issuing authority in the description, except with a UAE Peppol endpoint 9900000098 or 9900000099 (IBR-101-AE)", is.Present), ), ), )), ), rules.When( is.Func("has UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX", partyHasUAEEndpointNot1or9), - rules.Assert("19", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", + rules.Assert("23", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), ), - rules.AssertIfPresent("20", "customer must have at most one tax registration (IBR-179-AE)", - is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), - ), ), // AE tax representative and issuer rules.Field("ordering", rules.Field("seller", - rules.AssertIfPresent("21", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("24", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), rules.Field("issuer", - rules.AssertIfPresent("22", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("25", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), @@ -186,7 +196,7 @@ func billInvoiceRules() *rules.Set { // AE delivery address rules.Field("delivery", rules.Field("receiver", - rules.AssertIfPresent("23", "delivery address region must be an emirate code when the country is AE (IBR-128-AE)", + rules.AssertIfPresent("26", "delivery address region must be an emirate code when the country is AE (IBR-128-AE)", is.Func("first address region is an emirate", partyFirstAddressHasEmirate), ), ), @@ -197,22 +207,22 @@ func billInvoiceRules() *rules.Set { // IBR-133-AE's test runs on every cac:TaxScheme/cbc:ID: a scheme // other than VAT needs a seller TIN. gobl.ubl writes tax schemes for // the customer, tax representative, issuer, payee and line sellers. - // The supplier's own pass: its tax ID is under VAT, and rule 11 makes + // The supplier's own pass: its tax ID is under VAT, and rule 17 makes // any tax scope identity of it a TIN. Every tax category here is VAT. - rules.Assert("24", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", + rules.Assert("27", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), ), // AE currency - rules.Assert("25", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("28", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("26", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("29", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("27", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("30", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -223,11 +233,11 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceIsDeemedSupply), )), rules.Field("payment", - rules.Assert("28", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("31", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("29", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("32", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -244,7 +254,7 @@ func billInvoiceRules() *rules.Set { )), rules.When( is.Func("amount due is positive", invoiceIsDue), - rules.Assert("30", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("33", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Func("has due date", invoiceHasDueDate), ), ), @@ -255,7 +265,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("31", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("34", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -266,7 +276,7 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - rules.Assert("32", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("35", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal identity", partyHasLegalIdentity), ), ), @@ -275,7 +285,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("33", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("36", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -288,7 +298,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("34", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("37", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -301,7 +311,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("35", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("38", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -309,7 +319,7 @@ func billInvoiceRules() *rules.Set { ), )), )), - rules.Assert("36", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + rules.Assert("39", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), ), ), @@ -318,7 +328,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("37", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("40", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -332,13 +342,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("38", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("41", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("39", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("42", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -348,7 +358,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("40", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("43", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -356,7 +366,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("41", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("44", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -366,7 +376,7 @@ func billInvoiceRules() *rules.Set { // AE transaction type rules.Field("tax", rules.Field("ext", - rules.Assert("42", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + rules.Assert("45", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", tax.ExtensionsRequire(ExtKeyTransactionType), tax.ExtensionHasValidCode(ExtKeyTransactionType), ), @@ -376,7 +386,7 @@ func billInvoiceRules() *rules.Set { is.Func("free trade zone", invoiceIsFreeTradeZone), rules.Field("tax", rules.Field("ext", - rules.Assert("43", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("46", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), @@ -388,7 +398,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("deemed supply", invoiceIsDeemedSupply), rules.Field("customer", - rules.AssertIfPresent("44", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", + rules.AssertIfPresent("47", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpointDeemedSupply), ), ), @@ -398,13 +408,13 @@ func billInvoiceRules() *rules.Set { // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("45", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + rules.Assert("48", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( is.Func("summary invoice", invoiceIsSummary), - rules.Assert("46", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + rules.Assert("49", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), @@ -412,27 +422,27 @@ func billInvoiceRules() *rules.Set { is.Func("disclosed agent billing", invoiceIsDisclosedAgent), rules.Field("tax", rules.Field("ext", - rules.Assert("47", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("50", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), ), ), - // IBR-177-AE asks for the TRN or the TIN on every document. Rule 31 + // IBR-177-AE asks for the TRN or the TIN on every document. Rule 34 // already asks for the TRN except on 480 and 81, so this rule only // covers those, where the TIN is enough. rules.When( is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("supplier", - rules.Assert("48", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", + rules.Assert("51", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), ), rules.When( is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("49", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", + rules.Assert("52", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), ), ), @@ -442,7 +452,7 @@ func billInvoiceRules() *rules.Set { // test, which fails exports without a delivery address. rules.When( is.Func("export", invoiceIsExport), - rules.Assert("50", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", + rules.Assert("53", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), ), ), @@ -451,7 +461,7 @@ func billInvoiceRules() *rules.Set { rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("51", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("54", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), ), ), @@ -462,7 +472,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("has reverse charge lines", invoiceHasReverseChargeLine), rules.Field("customer", - rules.Assert("52", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("55", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax registration", partyHasTaxRegistration), ), ), @@ -471,16 +481,16 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("53", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("56", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("54", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("57", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), - rules.Assert("55", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", + rules.Assert("58", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), - rules.Assert("56", "principal ID must end with 03 (IBR-132-AE)", + rules.Assert("59", "principal ID must end with 03 (IBR-132-AE)", is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), ), ), @@ -488,7 +498,7 @@ func billInvoiceRules() *rules.Set { // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, // and IBR-005-AE only accepts frequencies there. rules.Field("point", - rules.Assert("57", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("60", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", is.Not(is.Present), ), ), @@ -496,7 +506,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), rules.Field("notes", - rules.Assert("58", "a note is required with the billing frequency Others (IBR-160-AE)", + rules.Assert("61", "a note is required with the billing frequency Others (IBR-160-AE)", is.Present, ), ), @@ -511,20 +521,37 @@ func billInvoiceRules() *rules.Set { // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", - rules.Assert("59", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("62", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), ), + ), - // AE currency decimals - // - // PINT allows at most two decimals in the document totals (ibr-091, - // ibr-121 to ibr-125), and gobl.ubl writes them with the decimals - // of the currency, so every document in a currency with three or - // more, such as BHD, KWD or OMR, fails. + // Currency decimals + // + // PINT 1.1.4, which PINT AE 1.0.5 builds on, allows as many decimals + // in the document totals as the official precision of the currency + // (ibr-091, ibr-121 to ibr-125): 3 for BHD, IQD, JOD, KWD, LYD, OMR + // and TND, 4 for CLF and UYW, and 2 for the rest. PINT 1.1.3, which + // FormatPINT and FormatAUNZ validate against, allows 2 for every + // currency. gobl.ubl writes the totals with GOBL's decimals for the + // currency, which are more than PINT's for a few, such as MGA and MRU. + // + // TODO: check the other regimes against the precision of the currency + // too once their VESIDs move to PINT 1.1.4. + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", - rules.Assert("60", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("63", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + is.Func("currency decimals within the PINT precision", currencyHasPINTDecimals), + ), + ), + ), + rules.When( + is.Not(is.InContext(tax.RegimeIn(regimesAE...))), + rules.Field("currency", + rules.Assert("63", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -538,7 +565,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("61", "PINT AE tags can only be used on UAE documents", + rules.Assert("64", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -648,9 +675,36 @@ func invoiceHasNoAETags(val any) bool { return true } -// currencyHasAtMost2Decimals reports whether a currency has two decimals or -// fewer, the most PINT allows in the document totals (ibr-091, ibr-121 to -// ibr-125). A missing or unknown currency fails. +// currencyDecimalsPINT are the currencies whose official precision in PINT 1.1.4 +// is other than 2 decimals. PINT also gives UYW 4, but GOBL has no UYW. +var currencyDecimalsPINT = map[currency.Code]uint32{ + currency.BHD: 3, currency.IQD: 3, currency.JOD: 3, currency.KWD: 3, + currency.LYD: 3, currency.OMR: 3, currency.TND: 3, + currency.CLF: 4, +} + +// currencyHasPINTDecimals reports whether GOBL's decimals for a currency, +// those gobl.ubl writes the totals with, are no more than its precision in +// PINT 1.1.4 (ibr-091, ibr-121 to ibr-125). A missing or unknown currency fails. +func currencyHasPINTDecimals(val any) bool { + code, ok := val.(currency.Code) + if !ok { + return false + } + def := code.Def() + if def == nil { + return false + } + limit, ok := currencyDecimalsPINT[code] + if !ok { + limit = 2 + } + return def.Subunits <= limit +} + +// currencyHasAtMost2Decimals reports whether GOBL's decimals for a currency, +// those gobl.ubl writes the totals with, are 2 at most, the limit in PINT +// 1.1.3 (ibr-091, ibr-121 to ibr-125). A missing or unknown currency fails. func currencyHasAtMost2Decimals(val any) bool { code, ok := val.(currency.Code) if !ok { @@ -663,7 +717,7 @@ func currencyHasAtMost2Decimals(val any) bool { // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 25 reports them. +// without it pass: they are in AED, or rule 28 reports them. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index dfe1301..7cc6920 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -4,8 +4,10 @@ import ( "testing" "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" @@ -96,6 +98,148 @@ func TestBillInvoiceRules(t *testing.T) { }) } +func TestBillPartyRules(t *testing.T) { + const ( + faultCustomer = "GOBL-PEPPOL-PINT-BILL-INVOICE-03" + faultSupplierEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" + faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" + faultCustomerIDs = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" + faultPayeeName = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" + faultPayeeIsSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + ) + faults := func(t *testing.T, inv *bill.Invoice) string { + t.Helper() + err := rules.Validate(inv, tax.AddonContext(pint.V1)) + if err == nil { + return "" + } + return err.Error() + } + + t.Run("electronic address must be written as an endpoint ID (IBR-081, IBR-080, ibr-cl-25)", func(t *testing.T) { + inv := baseInvoice() + inv.Supplier.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + out := faults(t, inv) + assert.Contains(t, out, faultSupplierEndpoint) + assert.Contains(t, out, faultCustomerEndpoint) + + // An email address is written with the scheme EM, which PINT doesn't + // accept (ibr-cl-25). + inv.Supplier.Endpoints = append(inv.Supplier.Endpoints, &org.Endpoint{URI: "mailto:sales@example.com"}) + inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) + out = faults(t, inv) + assert.Contains(t, out, faultSupplierEndpoint) + assert.Contains(t, out, faultCustomerEndpoint) + + inv = baseInvoice() + inv.Supplier.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0151", Code: "51824753556"}} + inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + inv.Customer.Inboxes = []*org.Inbox{{Scheme: "0151", Code: "53004085616"}} + out = faults(t, inv) + assert.NotContains(t, out, faultSupplierEndpoint) + assert.NotContains(t, out, faultCustomerEndpoint) + }) + + t.Run("customer has at most one identifier besides its legal one (ibr-sr-16)", func(t *testing.T) { + legal := &org.Identity{Scope: org.IdentityScopeLegal, Code: "53004085616"} + gln := &org.Identity{Code: "5790000435975"} + duns := &org.Identity{Code: "123456789"} + + inv := baseInvoice() + inv.Customer.Identities = []*org.Identity{legal, gln} + assert.NotContains(t, faults(t, inv), faultCustomerIDs) + + inv.Customer.Identities = []*org.Identity{legal, gln, duns} + assert.Contains(t, faults(t, inv), faultCustomerIDs) + }) + + t.Run("customer has at most one tax registration (ibr-104)", func(t *testing.T) { + inv := baseInvoice() + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeTax, Code: "123456789"}} + assert.Contains(t, faults(t, inv), faultCustomerTaxCount) + + inv.Customer.TaxID = nil + assert.NotContains(t, faults(t, inv), faultCustomerTaxCount) + }) + + t.Run("a missing customer raises no customer faults but its own (IBR-007)", func(t *testing.T) { + inv := baseInvoice() + inv.Customer = nil + out := faults(t, inv) + assert.Contains(t, out, faultCustomer) + assert.NotContains(t, out, faultCustomerEndpoint) + assert.NotContains(t, out, faultCustomerIDs) + assert.NotContains(t, out, faultCustomerTaxCount) + }) + + t.Run("payee needs a name (ibr-017)", func(t *testing.T) { + inv := baseInvoice() + inv.Payment = &bill.PaymentDetails{Payee: &org.Party{Alias: "Factor"}} + assert.Contains(t, faults(t, inv), faultPayeeName) + + inv.Payment.Payee.Name = "Factor Pty Ltd" + assert.NotContains(t, faults(t, inv), faultPayeeName) + }) + + t.Run("payee must not be the supplier (ibr-017)", func(t *testing.T) { + gln := func(code cbc.Code) *org.Identity { + return &org.Identity{Code: code, Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} + } + legal := func(code cbc.Code) *org.Identity { + id := gln(code) + id.Scope = org.IdentityScopeLegal + return id + } + tests := []struct { + name string + supplier []*org.Identity + payee *org.Party + same bool + }{ + {"same name", nil, &org.Party{Name: " seller pty ltd"}, true}, + {"same name as alias", nil, &org.Party{Name: "Factor", Alias: "SELLER PTY LTD"}, true}, + {"other name", nil, &org.Party{Name: "Factor Pty Ltd"}, false}, + {"same legal identity", []*org.Identity{legal("5790000435975")}, + &org.Party{Name: "Factor", Identities: []*org.Identity{legal("5790000435975")}}, true}, + {"other legal identity, same name", []*org.Identity{legal("5790000435975")}, + &org.Party{Name: "Seller Pty Ltd", Identities: []*org.Identity{legal("5790000435982")}}, false}, + {"same identity", []*org.Identity{gln("5790000435975")}, + &org.Party{Name: "Factor", Identities: []*org.Identity{gln("5790000435975")}}, true}, + {"same code in another scheme", []*org.Identity{gln("5790000435975")}, + &org.Party{Name: "Factor", Identities: []*org.Identity{{Code: "5790000435975"}}}, false}, + {"only one legal identity, same name", []*org.Identity{legal("5790000435975")}, + &org.Party{Name: "Seller Pty Ltd", Identities: []*org.Identity{gln("5790000435982")}}, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + inv := baseInvoice() + inv.Supplier.Identities = tt.supplier + inv.Payment = &bill.PaymentDetails{Payee: tt.payee} + if tt.same { + assert.Contains(t, faults(t, inv), faultPayeeIsSupplier) + } else { + assert.NotContains(t, faults(t, inv), faultPayeeIsSupplier) + } + }) + } + }) +} + +func TestBillExemptionNoteRules(t *testing.T) { + t.Run("VAT breakdowns outside the scope need no exemption note (BR-O-10 is not in PINT)", func(t *testing.T) { + inv := scenarioInvoice(l10n.GB.Tax(), bill.InvoiceTypeStandard) + inv.Currency = currency.GBP + require.NoError(t, inv.Calculate()) + err := rules.Validate(inv, tax.AddonContext(en16931.V2017, pint.V1), tax.RegimeContext(l10n.GB.Tax())) + if err != nil { + assert.NotContains(t, err.Error(), "GOBL-EU-EN16931-BILL-INVOICE-08") + } + }) +} + // aeInvoice is a skeleton UAE invoice in AED with payment instructions, which // passes the AE invoice rules. Like baseInvoice, it trips unrelated core rules, // so the tests check for specific fault codes. @@ -115,10 +259,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -309,18 +453,17 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" - faultCurrencyDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -529,41 +672,70 @@ func TestBillDocumentRulesAE(t *testing.T) { } }) - t.Run("currency must have at most 2 decimals (ibr-091)", func(t *testing.T) { - inv := standard() - inv.Currency = currency.BHD - inv.ExchangeRates = []*currency.ExchangeRate{{From: currency.BHD, To: currency.AED, Amount: num.MakeAmount(974, 2)}} - assert.Contains(t, aeFaults(t, inv), faultCurrencyDecimals) - - for _, cur := range []currency.Code{currency.USD, currency.JPY} { - inv = standard() - inv.Currency = cur - inv.ExchangeRates = []*currency.ExchangeRate{{From: cur, To: currency.AED, Amount: num.MakeAmount(367, 2)}} - assert.NotContains(t, aeFaults(t, inv), faultCurrencyDecimals, cur) - } - }) - t.Run("document rules do not apply outside AE", func(t *testing.T) { inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeProforma) inv.Currency = currency.BHD require.NoError(t, inv.Calculate()) err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) require.Error(t, err) - for _, code := range []string{faultSellerTRN, faultDueDate, faultOnlyExempt, faultDocumentType, faultCurrencyDecimals} { + for _, code := range []string{faultSellerTRN, faultDueDate, faultOnlyExempt, faultDocumentType} { assert.NotContains(t, err.Error(), code) } }) } +func TestBillCurrencyDecimalsRules(t *testing.T) { + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" + ae := func(cur currency.Code) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Currency = cur + inv.ExchangeRates = []*currency.ExchangeRate{{From: cur, To: currency.AED, Amount: num.MakeAmount(100, 2)}} + return inv + } + + t.Run("currencies within the PINT precision pass (ibr-091)", func(t *testing.T) { + for _, cur := range []currency.Code{currency.USD, currency.JPY, currency.BHD, currency.KWD, currency.OMR, currency.CLF} { + assert.NotContains(t, aeFaults(t, ae(cur)), fault, cur) + } + }) + + t.Run("currencies with more decimals than PINT allows fail (ibr-091)", func(t *testing.T) { + for _, cur := range []currency.Code{currency.MGA, currency.MRU} { + assert.Contains(t, aeFaults(t, ae(cur)), fault, cur) + } + }) + + t.Run("other regimes allow at most 2 decimals (ibr-091)", func(t *testing.T) { + au := func(cur currency.Code) error { + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) + inv.Currency = cur + inv.ExchangeRates = []*currency.ExchangeRate{{From: cur, To: currency.AUD, Amount: num.MakeAmount(100, 2)}} + require.NoError(t, inv.Calculate()) + return rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) + } + for _, cur := range []currency.Code{currency.USD, currency.JPY} { + err := au(cur) + if err != nil { + assert.NotContains(t, err.Error(), fault, cur) + } + } + for _, cur := range []currency.Code{currency.BHD, currency.CLF, currency.MGA} { + err := au(cur) + require.Error(t, err, cur) + assert.Contains(t, err.Error(), fault, cur) + } + }) +} + func TestBillAddressRulesAE(t *testing.T) { const ( - faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" - faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" - faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" - faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" - faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" - faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" - faultDeliveryEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" + faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" + faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultDeliveryEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-10" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -723,47 +895,23 @@ func aeIdentityDocument() *bill.Invoice { func TestBillIdentityRulesAE(t *testing.T) { const ( - faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" - faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" - faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" - faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" - faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" - faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" - faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" - faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" - faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" - faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" + faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" + faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" + faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" ) t.Run("trade licences with authorities pass", func(t *testing.T) { assert.Empty(t, aeFaults(t, aeIdentityDocument())) }) - t.Run("customer has at most one identifier besides its legal one (ibr-sr-16)", func(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" - gln := &org.Identity{Code: "5790000435975"} - duns := &org.Identity{Code: "123456789"} - - inv := aeIdentityDocument() - inv.Customer.Identities = append(inv.Customer.Identities, gln) - assert.Empty(t, aeFaults(t, inv)) - - inv = aeIdentityDocument() - inv.Customer.Identities = append(inv.Customer.Identities, gln, duns) - assert.Contains(t, aeFaults(t, inv), fault) - }) - - t.Run("a missing customer raises no customer faults but its own (IBR-007)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer = nil - out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-03") - assert.NotContains(t, out, faultCustomerEndpoint) - assert.NotContains(t, out, faultCustomerTaxCount) - }) - t.Run("supplier needs a legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil @@ -908,7 +1056,7 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalRequired) }) - t.Run("customer has at most one tax registration (IBR-179-AE)", func(t *testing.T) { + t.Run("customer TIN with the tax scope is a second tax registration (ibr-104, IBR-179-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) @@ -917,7 +1065,7 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) }) - t.Run("customer TIN without a scope is a plain identity (IBR-179-AE, IBR-133-AE)", func(t *testing.T) { + t.Run("customer TIN without a scope is a plain identity (ibr-104, IBR-179-AE, IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.Identities = append(inv.Customer.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1345678906"}) @@ -996,40 +1144,24 @@ func TestBillIdentityRulesAE(t *testing.T) { }) } }) - - t.Run("customer electronic address must be written as an endpoint ID (IBR-080)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} - assert.Contains(t, aeFaults(t, inv), faultCustomerEndpoint) - - // An email address is written with the scheme EM, which PINT AE - // doesn't accept (ibr-cl-25). - inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) - assert.Contains(t, aeFaults(t, inv), faultCustomerEndpoint) - - inv = aeIdentityDocument() - inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} - inv.Customer.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1345678906"}} - assert.NotContains(t, aeFaults(t, inv), faultCustomerEndpoint) - }) } func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" - faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" - faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1149,7 +1281,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") inv.Supplier.TaxID = &tax.Identity{Country: "AE"} out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-31") + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-34") assert.NotContains(t, out, faultSupplierTax) for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { @@ -1218,10 +1350,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1282,9 +1414,9 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" ) withFrequency := func(code cbc.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1392,7 +1524,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1509,7 +1641,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index c3face4..0662064 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -81,21 +81,66 @@ func partyHasLegalIdentity(val any) bool { // with the tax scope and the first with the legal scope. func partyHasOneIdentification(val any) bool { p, ok := val.(*org.Party) - if !ok || p == nil { - return false + return ok && p != nil && len(partyIdentifications(p)) <= 1 +} + +// payeeIsNotSupplier reports whether the invoice's payee differs from the +// supplier, compared as ibr-017 does: on the legal identities gobl.ubl writes +// as cac:PartyLegalEntity/cbc:CompanyID when both have one, else on the +// identities it writes as cac:PartyIdentification when both have any, else on +// the payee's name against the supplier's, regardless of case. Identities +// match on code and the scheme gobl.ubl writes. An invoice without a payee +// passes. +func payeeIsNotSupplier(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil || inv.Payment == nil || inv.Payment.Payee == nil || inv.Supplier == nil { + return true } - n := 0 - legal := false + payee, supplier := inv.Payment.Payee, inv.Supplier + if p, s := partyFirstLegalIdentity(payee), partyFirstLegalIdentity(supplier); p != nil && s != nil { + return p.Code != s.Code || p.Ext.Get(iso.ExtKeySchemeID) != s.Ext.Get(iso.ExtKeySchemeID) + } + if ps, ss := partyIdentifications(payee), partyIdentifications(supplier); len(ps) > 0 && len(ss) > 0 { + for _, p := range ps { + if slices.ContainsFunc(ss, func(s *org.Identity) bool { + return p.Code == s.Code && identificationScheme(p) == identificationScheme(s) + }) { + return false + } + } + return true + } + name := payee.Name + if payee.Alias != "" { + // gobl.ubl writes the alias as the payee's cac:PartyName. + name = payee.Alias + } + return name == "" || supplier.Name == "" || + !strings.EqualFold(strings.TrimSpace(name), strings.TrimSpace(supplier.Name)) +} + +// partyIdentifications returns the party's identities gobl.ubl writes as +// cac:PartyIdentification: all but the tax scope ones and the first legal +// one. +func partyIdentifications(p *org.Party) []*org.Identity { + legal := partyFirstLegalIdentity(p) + var ids []*org.Identity for _, id := range p.Identities { - switch { - case id == nil || id.Scope == org.IdentityScopeTax: - case id.Scope == org.IdentityScopeLegal && !legal: - legal = true - default: - n++ + if id != nil && id != legal && id.Scope != org.IdentityScopeTax { + ids = append(ids, id) } } - return n <= 1 + return ids +} + +// identificationScheme returns the scheme gobl.ubl writes as the @schemeID +// of an identity's cac:PartyIdentification: its ISO 6523 scheme, or its type +// when it has no extensions. +func identificationScheme(id *org.Identity) cbc.Code { + if id.Ext.IsZero() { + return id.Type + } + return id.Ext.Get(iso.ExtKeySchemeID) } // partyFirstAddress returns the party's first address, the only one gobl.ubl @@ -183,10 +228,10 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { } // partyHasEndpointID reports whether gobl.ubl writes the party's electronic -// address as a cbc:EndpointID that PINT AE accepts: an ISO 6523 endpoint or an +// address as a cbc:EndpointID that PINT accepts: an ISO 6523 endpoint or an // inbox with a scheme. An email address is written with the scheme EM, which -// is not in PINT AE's list (ibr-cl-25). A party without endpoints passes, as -// rule 04 reports it. +// is not in PINT's list (ibr-cl-25). A party without endpoints passes, as +// rules 02 and 04 report it. func partyHasEndpointID(val any) bool { p, ok := val.(*org.Party) if !ok || p == nil { @@ -308,16 +353,7 @@ func partyHasIdentificationOrTaxRegistration(val any) bool { return true } p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - legal := partyFirstLegalIdentity(p) - for _, id := range p.Identities { - if id != nil && id != legal && id.Scope != org.IdentityScopeTax { - return true - } - } - return false + return ok && p != nil && len(partyIdentifications(p)) > 0 } // tinRegexpAE matches a UAE TIN, in the AE regime's format. UAE Peppol diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 81c880c..a929565 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -66,9 +66,9 @@ func normalizeTaxCombo(tc *tax.Combo) { // exempt VAT lines of a UAE margin scheme invoice. The line combos already have // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the -// discount and charge rules 02 and rule 45 reject them (IBR-114-AE, +// discount and charge rules 02 and rule 48 reject them (IBR-114-AE, // IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real -// exempt supply, so they keep E and rule 45 rejects the mixed invoice. +// exempt supply, so they keep E and rule 48 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return diff --git a/ubl/ae.go b/ubl/ae.go index 6b8838c..a75e990 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -1070,7 +1070,7 @@ func exportAELine(line *goblubl.InvoiceLine) { // document currency check as amounts in the tax currency, which IBR-140-AE // fixes to AED. No test checks their currency, and the official exports in // USD write them in AED too. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-25), they stay in the document currency. +// (GOBL-PEPPOL-PINT-BILL-INVOICE-28), they stay in the document currency. // // GOBL keeps no VAT per line, so it is the line total at the line's rate, // rounded to the document currency, then converted. Exempt lines get no VAT @@ -1124,7 +1124,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-25) with at most 6 decimals (-26). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-28) with at most 6 decimals (-29). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return diff --git a/ubl/ubl.go b/ubl/ubl.go index aa8b098..dfaca8e 100644 --- a/ubl/ubl.go +++ b/ubl/ubl.go @@ -94,8 +94,8 @@ var FormatPINT = goblubl.Format{ ProfileID: "urn:peppol:bis:billing", Addons: []cbc.Key{pint.V1}, VESIDs: goblubl.VESIDMapping{ - Invoice: "org.peppol.pint:invoice:1.1.2", - CreditNote: "org.peppol.pint:credit-note:1.1.2", + Invoice: "org.peppol.pint:invoice:1.1.3", + CreditNote: "org.peppol.pint:credit-note:1.1.3", }, ImportFuncs: []goblubl.ImportFunc{importPINT}, // A jurisdiction specialization no dedicated format claimed still follows @@ -115,8 +115,8 @@ var FormatAUNZ = goblubl.Format{ ProfileID: "urn:peppol:bis:billing", Addons: []cbc.Key{pint.V1}, VESIDs: goblubl.VESIDMapping{ - Invoice: "org.peppol.pint.aunz:invoice:1.1.2", - CreditNote: "org.peppol.pint.aunz:creditnote:1.1.2", + Invoice: "org.peppol.pint.aunz:invoice:1.1.3", + CreditNote: "org.peppol.pint.aunz:creditnote:1.1.3", }, Specifications: []goblubl.Specification{ SpecificationAUNZSelfBilling, @@ -132,8 +132,8 @@ var SpecificationAUNZSelfBilling = goblubl.Specification{ ProfileID: "urn:peppol:bis:selfbilling", Addons: []cbc.Key{pint.V1}, VESIDs: goblubl.VESIDMapping{ - Invoice: "org.peppol.pint.aunz:invoice-self-billing:1.1.2", - CreditNote: "org.peppol.pint.aunz:creditnote-self-billing:1.1.2", + Invoice: "org.peppol.pint.aunz:invoice-self-billing:1.1.3", + CreditNote: "org.peppol.pint.aunz:creditnote-self-billing:1.1.3", }, Applies: isSelfBilled, } From 4de60febf72ba25fe9b2d9a8e47533d8f438a578 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:24:18 +0000 Subject: [PATCH 60/73] Reorganise the PINT rule sets Many PINT AE rules only need the party, address, item or identity they run on, but were built into the invoice and line rules with a code per caller, through helpers that each wrapped one check. That missed the parties, addresses and items no caller reached, such as sub-line items, and made every new rule renumber the invoice rules after it. - The emirate (IBR-128-AE), item classification (IBR-184-AE, IBR-186-AE, IBR-188-AE), passport country, trade licence authority (IBR-172-AE, IBR-101-AE), legal identity type (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE) and identity scope rules move to type-level sets on org.Address, org.Party, org.Item and org.Identity under the AE regime, so they reach every one of them. A party with a UAE tax ID is checked on the country gobl.ubl writes for it, the tax ID's, so it needs an address with an emirate. The legal identity type only applies with a 0235 endpoint, as its tests do, so foreign payees, receivers and factors are not checked. The trade licence rule can't see the endpoint, so it loses IBR-101-AE's exemption for buyers on 9900000098 and 9900000099. - The electronic address rules reject email addresses, in endpoints and inboxes, as gobl.ubl writes them with the scheme EM, which PINT doesn't accept. They assume no party has both a Peppol endpoint and an email address. - The UAE exemption reason on exempt lines, discounts and charges (IBR-167-AE, IBR-168-AE, IBR-169-AE) is one tax combo rule instead of three. - The invoice rules drill down to the field they check, the addresses, identities, due date, delivery address and credit transfer account, with one assertion each, so most helpers go. - Emirates and the UAE Peppol endpoints are matched with patterns, the transaction type rules read their flags from the tags, and the A-NZ and AE credit transfer rules share one payment means helper. The addon description becomes an overview of what PINT adds to EN 16931, and the UAE details move to a PINT AE section in the README. Co-Authored-By: Claude Opus 5.5 --- README.md | 38 +- addon/pint/bill.go | 490 +++++++++--------- addon/pint/bill_line.go | 49 +- addon/pint/bill_line_test.go | 61 +-- addon/pint/bill_test.go | 387 ++++---------- addon/pint/org_address.go | 37 ++ addon/pint/org_address_test.go | 68 +++ addon/pint/org_identity.go | 61 ++- addon/pint/org_identity_test.go | 34 ++ addon/pint/org_item.go | 65 ++- addon/pint/org_item_test.go | 58 +++ addon/pint/org_party.go | 290 +++-------- addon/pint/org_party_test.go | 119 +++++ addon/pint/pay.go | 61 +-- addon/pint/pay_test.go | 10 +- addon/pint/pint.go | 35 +- addon/pint/tax_combo.go | 15 +- addon/pint/tax_combo_test.go | 7 +- addon/pint/transaction_type.go | 35 +- ubl/ae.go | 17 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 3 +- .../convert/pint/ae/out/invoice-ae.xml | 1 + 22 files changed, 948 insertions(+), 993 deletions(-) create mode 100644 addon/pint/org_address.go create mode 100644 addon/pint/org_address_test.go diff --git a/README.md b/README.md index b75701b..b6e8aa2 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,10 @@ See the [`examples`](./examples) directory for complete invoices. Documents with the PINT addon, in any regime: -- Have supplier and customer electronic addresses that are written as - `cbc:EndpointID`: an ISO 6523 endpoint, or an inbox with a scheme. An email - address is written with the scheme `EM`, which PINT does not accept. +- Have supplier and customer electronic addresses, and no email address as + an endpoint or inbox. gobl.ubl writes an email address as `cbc:EndpointID` + with the scheme `EM`, which PINT does not accept, so a party can't have one + next to its Peppol endpoint either. - Have at most one customer identity written as `cac:PartyIdentification` (any identity other than the tax ones and the first legal one, including a UAE customer's TIN), and at most one customer tax registration (the tax ID @@ -68,6 +69,32 @@ Documents with the PINT addon, in any regime: - Give the payee a name, and a payee that differs from the supplier in its legal identity, identity or name. +### PINT AE + +UAE documents with the PINT addon follow the PINT AE rules: + +- They can only be invoices and credit notes, without the `partial`, + `prepayment` or `factoring` tags, as PINT AE has no document type for + anything else. Documents out of scope of VAT take the `outside-tax-scope` + tag, which sets the document type to 480 on invoices and 81 on credit notes. +- Trade licences carry their issuing authority in the description, and + passports their issuing country. +- The supplier's and customer's UAE identities without a scope get the one + PINT AE reads them from: `legal` for the first trade licence, Emirates ID, + passport or Cabinet Decision of a party that has no legal identity yet, and + `tax` for the supplier's TIN. +- A supplier with a UAE TRN gets the TIN it starts with as a `tax` identity, + and the UAE Peppol endpoint `0235:`, when it has neither. +- The PINT AE transaction type comes from the tags `free-trade-zone`, + `deemed-supply`, `margin-scheme`, `summary`, `continuous-supply`, + `disclosed-agent`, `e-commerce` and `export`. +- PINT AE predefines three customer endpoints: `0235:9900000097` on deemed + supplies, which the addon checks, and `0235:9900000099` for exports to a + receiver not on Peppol and `0235:9900000098` for a buyer not subject to UAE + e-invoicing, which the user sets. +- Supplies under the profit margin scheme take the AE regime's + `margin-scheme` tag; see [Conversion](#conversion) for how they are written. + ## Layout - `addon/` — the GOBL addons: normalizers, scenarios and validation rules that @@ -119,7 +146,7 @@ and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with `FormatAE` also adjusts the output to the PINT AE rules: it writes the invoice UUID, the price base quantity and gross price, the UAE TRN without its country -prefix, the 5% rate on reverse charge lines, breakdowns, allowances and +prefix, the standard rate on reverse charge lines, breakdowns, allowances and charges, no rate on exempt lines and breakdowns, one VAT breakdown per category, and each line's amount with VAT and VAT amount in AED. For invoices not in AED, it also writes the exchange rate to AED and the total with VAT in AED, and converts the line amounts with that @@ -147,7 +174,8 @@ a single note. - Issue one invoice per margin scheme sale, with no other VAT treatments and no document-level discounts or charges (IBR-116-AE). -- The lines go out in the `N` category at 5%, with no VAT amount. +- The lines go out in the `N` category at the standard rate, with no VAT + amount. - The statement that VAT is charged under the scheme, which the regime's scenario adds as a VAT note, goes out as the VAT exemption reason text of the `N` breakdown and lines. diff --git a/addon/pint/bill.go b/addon/pint/bill.go index d029e4c..57d7bea 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -8,7 +8,6 @@ import ( "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" - "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" @@ -29,8 +28,11 @@ func billInvoiceRules() *rules.Set { // Supplier and customer rules.Field("supplier", - rules.Assert("01", "invoice supplier must have a tax ID or identity (IBR-CO-26)", - is.Func("has identifier", partyHasIdentifier), + rules.When( + is.Not(org.PartyHasTaxIDCode()), + rules.Field("identities", + rules.Assert("01", "invoice supplier must have a tax ID or identity (IBR-CO-26)", is.Present), + ), ), rules.Field("endpoints", rules.Assert("02", "invoice supplier electronic address is required (IBR-081)", is.Present), @@ -44,84 +46,99 @@ func billInvoiceRules() *rules.Set { ), // Electronic addresses and customer identification // - // gobl.ubl writes an email address as cbc:EndpointID with the scheme - // EM, which is not in PINT's electronic address scheme list - // (ibr-cl-25), and writes no cbc:EndpointID for other URI schemes. + // gobl.ubl writes an email address, from an endpoint or an inbox, as + // cbc:EndpointID with the scheme EM, which is not in PINT's electronic + // address scheme list (ibr-cl-25). We assume no party has both a + // Peppol endpoint and an email address, so any email address is + // rejected. rules.Field("supplier", - rules.AssertIfPresent("05", "supplier electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-081, ibr-cl-25)", - is.Func("electronic address written as endpoint ID", partyHasEndpointID), - ), + rules.Field("endpoints", rules.Each( + rules.Field("uri", + rules.Assert("05", "supplier electronic address must not be an email address (IBR-081, ibr-cl-25)", + is.Not(cbc.URISchemeIn(endpointSchemeMailto)), + ), + ), + )), + rules.Field("inboxes", rules.Each( + rules.Field("email", + rules.Assert("06", "supplier inbox must not be an email address (IBR-081, ibr-cl-25)", is.Empty), + ), + )), ), rules.Field("customer", - rules.AssertIfPresent("06", "customer electronic address must be an ISO 6523 endpoint, or an inbox with a scheme (IBR-080, ibr-cl-25)", - is.Func("electronic address written as endpoint ID", partyHasEndpointID), - ), - rules.AssertIfPresent("07", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", + rules.Field("endpoints", rules.Each( + rules.Field("uri", + rules.Assert("07", "customer electronic address must not be an email address (IBR-080, ibr-cl-25)", + is.Not(cbc.URISchemeIn(endpointSchemeMailto)), + ), + ), + )), + rules.Field("inboxes", rules.Each( + rules.Field("email", + rules.Assert("08", "customer inbox must not be an email address (IBR-080, ibr-cl-25)", is.Empty), + ), + )), + rules.AssertIfPresent("09", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", is.Func("at most one buyer identifier", partyHasOneIdentification), ), - rules.AssertIfPresent("08", "customer must have at most one tax registration (ibr-104, IBR-179-AE)", - is.Func("at most one tax registration", partyHasAtMostOneTaxRegistration), + // EN 16931 allows one tax scope identity (GOBL-EU-EN16931-ORG-PARTY-03), + // so only one with a tax ID code is too many. + rules.When( + org.PartyHasTaxIDCode(), + rules.Field("identities", + rules.Assert("10", "customer must have at most one tax registration (ibr-104, IBR-179-AE)", + is.Not(is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax))), + ), + ), ), ), // Payee rules.Field("payment", rules.Field("payee", rules.Field("name", - rules.Assert("09", "payee name is required (ibr-017)", is.Present), + rules.Assert("11", "payee name is required (ibr-017)", is.Present), ), ), ), - rules.Assert("10", "payee must differ from the supplier by legal identity, identity or name (ibr-017)", + rules.Assert("12", "payee must differ from the supplier by legal identity, identity or name (ibr-017)", is.Func("payee is not the supplier", payeeIsNotSupplier), ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // AE supplier // - // IBR-128-AE asks every UAE address for an emirate code as its - // region: the seller's and buyer's here, the tax representative's, - // the issuer's and the delivery address below, and the line sellers' - // in line rule 10. + // The party and address rules ask every UAE address for an emirate + // code as its region (IBR-128-AE). rules.Field("supplier", - rules.Assert("11", "supplier address must have a street, city and region (IBR-143-AE)", - is.Func("first address has street, city and region", partyAddressIsComplete), - ), - rules.Assert("12", "supplier region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), - ), - // IBR-150-AE, IBR-173-AE and IBR-181-AE apply to sellers with a - // 0235 endpoint, which every UAE supplier has, as the UAE PASR - // gives every end user 0235:. - rules.Assert("13", "supplier legal identity is required (IBR-150-AE)", - is.Func("has legal identity", partyHasLegalIdentity), - ), - rules.Field("identities", rules.Each( - rules.When( - is.Func("legal scope", identityHasLegalScope), - rules.Assert("14", "supplier legal identity must be a trade license, Emirates ID, passport or Cabinet Decision (IBR-173-AE, IBR-181-AE)", - is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), + rules.Field("addresses", + rules.Each( + rules.Field("street", + rules.Assert("13", "supplier address street is required (IBR-143-AE)", is.Present), ), - ), - )), - rules.Field("identities", rules.Each( - rules.When( - org.IdentityKeyIn(org.IdentityKeyPassport), - rules.Field("country", - rules.Assert("15", "supplier passport must have the issuing country (IBR-012-AE)", is.Present), + rules.Field("locality", + rules.Assert("14", "supplier address city is required (IBR-143-AE)", is.Present), ), - ), - rules.When( - org.IdentityTypeIn(ae.IdentityTypeTradeLicense), - rules.Field("description", - rules.Assert("16", "supplier trade license must have the issuing authority in the description (IBR-172-AE)", is.Present), + rules.Field("region", + rules.Assert("15", "supplier address region is required (IBR-143-AE)", is.Present), ), ), - // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity - // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two - // PartyTaxSchemes with one VAT that it accepts. - // The AE regime checks the TIN's format and check digit. + ), + // IBR-150-AE applies to sellers with a 0235 endpoint, which every + // UAE supplier has, as the UAE PASR gives every end user + // 0235:. The party rules check the type of the legal + // identities (IBR-173-AE, IBR-181-AE). + rules.Field("identities", + rules.Assert("16", "supplier legal identity is required (IBR-150-AE)", + is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), + ), + ), + // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity + // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two + // PartyTaxSchemes with one VAT that it accepts. + // The AE regime checks the TIN's format and check digit. + rules.Field("identities", rules.Each( rules.When( - is.Func("tax scope", identityHasTaxScope), + is.Func("tax scope", identityScopeIn(org.IdentityScopeTax)), rules.Assert("17", "supplier tax scope identity must be a TIN (IBR-148-AE)", org.IdentityTypeIn(ae.IdentityTypeTIN), ), @@ -131,73 +148,25 @@ func billInvoiceRules() *rules.Set { // AE customer rules.Field("customer", - rules.Assert("18", "customer address must have a street, city and region (IBR-144-AE)", - is.Func("first address has street, city and region", partyAddressIsComplete), - ), - rules.Assert("19", "customer region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyAddressHasEmirate), - ), - // IBR-180-AE, IBR-183-AE and IBR-101-AE exempt the buyers with the - // predefined endpoints 9900000098 and 9900000099. IBR-183-AE also - // exempts other 1XXXXXXXXX endpoints, but IBR-180-AE still asks - // them for a type, and GOBL can only write the four in the list. - rules.When( - is.Func("has UAE Peppol endpoint other than 9900000098 or 9900000099", partyHasUAEEndpointNotPredefined), - rules.Field("identities", rules.Each( - rules.When( - is.Func("legal scope", identityHasLegalScope), - rules.Assert("20", "customer legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint other than 9900000098 or 9900000099 (IBR-180-AE, IBR-183-AE)", - is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), - ), + rules.Field("addresses", + rules.Each( + rules.Field("street", + rules.Assert("18", "customer address street is required (IBR-144-AE)", is.Present), ), - )), - ), - rules.Field("identities", rules.Each( - rules.When( - org.IdentityKeyIn(org.IdentityKeyPassport), - rules.Field("country", - rules.Assert("21", "customer passport must have the issuing country (IBR-010-AE)", is.Present), + rules.Field("locality", + rules.Assert("19", "customer address city is required (IBR-144-AE)", is.Present), ), - ), - )), - rules.When( - is.Not(is.Func("has UAE Peppol endpoint 9900000098 or 9900000099", partyHasUAEEndpointPredefined)), - rules.Field("identities", rules.Each( - rules.When( - org.IdentityTypeIn(ae.IdentityTypeTradeLicense), - rules.Field("description", - rules.Assert("22", "customer trade license must have the issuing authority in the description, except with a UAE Peppol endpoint 9900000098 or 9900000099 (IBR-101-AE)", is.Present), - ), + rules.Field("region", + rules.Assert("20", "customer address region is required (IBR-144-AE)", is.Present), ), - )), - ), - rules.When( - is.Func("has UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX", partyHasUAEEndpointNot1or9), - rules.Assert("23", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", - is.Func("has legal identity", partyHasLegalIdentity), - ), - ), - ), - - // AE tax representative and issuer - rules.Field("ordering", - rules.Field("seller", - rules.AssertIfPresent("24", "tax representative region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), - ), - ), - rules.Field("issuer", - rules.AssertIfPresent("25", "issuer region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), ), ), - ), - - // AE delivery address - rules.Field("delivery", - rules.Field("receiver", - rules.AssertIfPresent("26", "delivery address region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("first address region is an emirate", partyFirstAddressHasEmirate), + rules.When( + is.Func("has UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX", partyHasUAEEndpoint(endpointPattern1or9, false)), + rules.Field("identities", + rules.Assert("21", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", + is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), + ), ), ), ), @@ -209,20 +178,20 @@ func billInvoiceRules() *rules.Set { // the customer, tax representative, issuer, payee and line sellers. // The supplier's own pass: its tax ID is under VAT, and rule 17 makes // any tax scope identity of it a TIN. Every tax category here is VAT. - rules.Assert("27", "tax registrations other than VAT require a supplier TIN (IBR-133-AE)", + rules.Assert("22", "tax registrations must be VAT when the supplier does not have a TIN (IBR-133-AE)", is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), ), // AE currency - rules.Assert("28", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("23", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("29", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("24", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("30", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("25", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -230,14 +199,14 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.Or( bill.InvoiceTypeIn(bill.InvoiceTypeCreditNote), - is.Func("deemed supply", invoiceIsDeemedSupply), + is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), )), rules.Field("payment", - rules.Assert("31", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("26", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("32", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("27", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -245,17 +214,27 @@ func billInvoiceRules() *rules.Set { ), // Self-billed credit notes (261) are exempt too. The rule text only // names 381 and 81, but the Schematron test also exempts 261, and we - // follow the test. + // follow the test. Rule 26 already asks these documents for the + // payment details, and GOBL due dates for their date. rules.When( is.Not(is.Or( is.Func("document type is 381, 81 or 261", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices, docTypeSelfBilledCreditNote)), - is.Func("deemed supply", invoiceIsDeemedSupply), + is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), )), rules.When( is.Func("amount due is positive", invoiceIsDue), - rules.Assert("33", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", - is.Func("has due date", invoiceHasDueDate), + rules.Field("payment", + rules.Field("terms", + rules.Assert("28", "payment terms are required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + is.Present, + ), + rules.Field("due_dates", + rules.Assert("29", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + is.Present, + ), + ), + ), ), ), ), @@ -265,7 +244,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("34", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("30", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -276,8 +255,10 @@ func billInvoiceRules() *rules.Set { is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", - rules.Assert("35", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", - is.Func("has legal identity", partyHasLegalIdentity), + rules.Field("identities", + rules.Assert("31", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), + ), ), ), rules.Field("lines", rules.Each( @@ -285,7 +266,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("36", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("32", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -298,7 +279,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("37", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("33", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -311,7 +292,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("38", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("34", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -319,8 +300,12 @@ func billInvoiceRules() *rules.Set { ), )), )), - rules.Assert("39", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", - is.Not(is.Func("summary, deemed supply or margin scheme", invoiceIsSummaryDeemedOrMargin)), + rules.Assert("35", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + is.Not(is.Or( + is.Func("summary", invoiceHasTags(TagSummary)), + is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), + is.Func("margin scheme", invoiceHasTags(TagMarginScheme)), + )), ), ), @@ -328,7 +313,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("40", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("36", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -342,13 +327,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("41", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("37", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("42", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("38", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -358,7 +343,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("43", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("39", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -366,7 +351,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("44", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("40", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -376,17 +361,17 @@ func billInvoiceRules() *rules.Set { // AE transaction type rules.Field("tax", rules.Field("ext", - rules.Assert("45", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + rules.Assert("41", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", tax.ExtensionsRequire(ExtKeyTransactionType), tax.ExtensionHasValidCode(ExtKeyTransactionType), ), ), ), rules.When( - is.Func("free trade zone", invoiceIsFreeTradeZone), + is.Func("free trade zone", invoiceHasTags(TagFreeTradeZone)), rules.Field("tax", rules.Field("ext", - rules.Assert("46", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("42", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), @@ -396,73 +381,136 @@ func billInvoiceRules() *rules.Set { // deemed supply. The other predefined endpoints, 9900000098 and // 9900000099, depend on facts GOBL doesn't know. rules.When( - is.Func("deemed supply", invoiceIsDeemedSupply), + is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), rules.Field("customer", - rules.AssertIfPresent("47", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", - is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpointDeemedSupply), + rules.AssertIfPresent("43", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", + is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpoint(endpointPatternDeemedSupply, true)), ), ), ), - // With the discount and charge rules 02, a margin scheme invoice can + // With the discount and charge rules 01, a margin scheme invoice can // have no discounts or charges, as GOBL requires them to have taxes // (BR-32, BR-37). rules.When( - is.Func("margin scheme", invoiceIsMarginScheme), - rules.Assert("48", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + is.Func("margin scheme", invoiceHasTags(TagMarginScheme)), + rules.Assert("44", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( - is.Func("summary invoice", invoiceIsSummary), - rules.Assert("49", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", + is.Func("summary invoice", invoiceHasTags(TagSummary)), + rules.Assert("45", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", is.Func("has invoice period", invoiceHasInvoicePeriod), ), ), rules.When( - is.Func("disclosed agent billing", invoiceIsDisclosedAgent), + is.Func("disclosed agent billing", invoiceHasTags(TagDisclosedAgent)), rules.Field("tax", rules.Field("ext", - rules.Assert("50", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("46", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), ), ), - // IBR-177-AE asks for the TRN or the TIN on every document. Rule 34 + // IBR-177-AE asks for the TRN or the TIN on every document. Rule 30 // already asks for the TRN except on 480 and 81, so this rule only // covers those, where the TIN is enough. rules.When( is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("supplier", - rules.Assert("51", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", - is.Func("has tax registration", partyHasTaxRegistration), + rules.When( + is.Not(org.PartyHasTaxIDCode()), + rules.Field("identities", + rules.Assert("47", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", + is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), + ), + ), + ), + ), + ), + // IBR-142-AE and IBR-152-AE read the delivery address, which + // gobl.ubl writes from the delivery receiver's first address as + // cac:DeliveryLocation/cac:Address. Their tests fail a document + // without one. + rules.When( + is.Or( + is.Func("e-commerce supply", invoiceHasTags(TagECommerce)), + is.Func("export", invoiceHasTags(tax.TagExport)), + ), + rules.Field("delivery", + rules.Assert("48", "delivery is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Field("receiver", + rules.Assert("49", "delivery receiver is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Field("addresses", + rules.Assert("50", "delivery address is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + ), ), ), ), rules.When( - is.Func("e-commerce supply", invoiceIsECommerce), - rules.Assert("52", "delivery address must have a street, city and region on e-commerce supplies (IBR-142-AE)", - is.Func("delivery address is complete", invoiceDeliveryAddressIsComplete), + is.Func("e-commerce supply", invoiceHasTags(TagECommerce)), + rules.Field("delivery", + rules.Field("receiver", + rules.Field("addresses", + rules.Each( + rules.Field("street", + rules.Assert("51", "e-commerce delivery address street is required (IBR-142-AE)", is.Present), + ), + rules.Field("locality", + rules.Assert("52", "e-commerce delivery address city is required (IBR-142-AE)", is.Present), + ), + rules.Field("region", + rules.Assert("53", "e-commerce delivery address region is required (IBR-142-AE)", is.Present), + ), + ), + ), + ), ), ), // IBR-152-AE's text says the delivery country should not be AE on // exports, but its test accepts a delivery address in the UAE, and // only asks the others for a street, city and region. We follow the - // test, which fails exports without a delivery address. + // test. rules.When( - is.Func("export", invoiceIsExport), - rules.Assert("53", "delivery address outside the UAE must have a street, city and region on exports (IBR-152-AE)", - is.Func("delivery address is in the UAE or complete", invoiceDeliveryAddressIsAEOrComplete), + is.Func("export", invoiceHasTags(tax.TagExport)), + rules.Field("delivery", + rules.Field("receiver", + rules.Field("addresses", + rules.Each( + rules.When( + is.Not(is.Func("UAE address", addressIsAE)), + rules.Field("street", + rules.Assert("54", "export delivery address street is required (IBR-152-AE)", is.Present), + ), + rules.Field("locality", + rules.Assert("55", "export delivery address city is required (IBR-152-AE)", is.Present), + ), + rules.Field("region", + rules.Assert("56", "export delivery address region is required (IBR-152-AE)", is.Present), + ), + ), + ), + ), + ), ), ), rules.When( - is.Not(is.Func("export", invoiceIsExport)), + is.Not(is.Func("export", invoiceHasTags(tax.TagExport))), rules.Field("customer", rules.When( - is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpointNotTIN), - rules.Assert("54", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", - is.Func("has identifier or tax registration", partyHasIdentificationOrTaxRegistration), + is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpoint(ae.TINPattern, false)), + // gobl.ubl writes the identities without a scope as + // cac:PartyIdentification. The legal one, of which EN 16931 + // allows one, goes to cac:PartyLegalEntity. + rules.When( + is.Not(org.PartyHasTaxIDCode()), + rules.Field("identities", + rules.Assert("57", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + is.Func("has tax scope or unscoped identity", identitiesScopeIn(org.IdentityScopeTax, cbc.KeyEmpty)), + ), + ), ), ), ), @@ -472,8 +520,13 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("has reverse charge lines", invoiceHasReverseChargeLine), rules.Field("customer", - rules.Assert("55", "customer tax registration is required with reverse charge (IBR-103-AE)", - is.Func("has tax registration", partyHasTaxRegistration), + rules.When( + is.Not(org.PartyHasTaxIDCode()), + rules.Field("identities", + rules.Assert("58", "customer tax registration is required with reverse charge (IBR-103-AE)", + is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), + ), + ), ), ), ), @@ -481,16 +534,16 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("56", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("59", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("57", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", + rules.Assert("60", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", tax.ExtensionHasValidCode(ExtKeyBillingFrequency), ), - rules.Assert("58", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", + rules.Assert("61", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), - rules.Assert("59", "principal ID must end with 03 (IBR-132-AE)", + rules.Assert("62", "principal ID must end with 03 (IBR-132-AE)", is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), ), ), @@ -498,7 +551,7 @@ func billInvoiceRules() *rules.Set { // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, // and IBR-005-AE only accepts frequencies there. rules.Field("point", - rules.Assert("60", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("63", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", is.Not(is.Present), ), ), @@ -506,7 +559,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), rules.Field("notes", - rules.Assert("61", "a note is required with the billing frequency Others (IBR-160-AE)", + rules.Assert("64", "a note is required with the billing frequency Others (IBR-160-AE)", is.Present, ), ), @@ -521,7 +574,7 @@ func billInvoiceRules() *rules.Set { // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", - rules.Assert("62", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("65", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), @@ -543,7 +596,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", - rules.Assert("63", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("66", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency decimals within the PINT precision", currencyHasPINTDecimals), ), ), @@ -551,7 +604,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), rules.Field("currency", - rules.Assert("63", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("66", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -565,7 +618,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("64", "PINT AE tags can only be used on UAE documents", + rules.Assert("67", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -579,18 +632,10 @@ func billDiscountRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("taxes", rules.Each( - rules.When( - is.Func("exempt VAT", comboIsExemptVAT), - rules.Field("ext", - rules.Assert("01", "exempt discount VAT needs a UAE VAT exemption reason (IBR-168-AE)", - tax.ExtensionsRequire(ExtKeyExemption), - ), - ), - ), rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("02", "discount VAT category cannot be margin scheme (IBR-115-AE)", + rules.Assert("01", "discount VAT category cannot be margin scheme (IBR-115-AE)", tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), ), ), @@ -607,18 +652,10 @@ func billChargeRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("taxes", rules.Each( - rules.When( - is.Func("exempt VAT", comboIsExemptVAT), - rules.Field("ext", - rules.Assert("01", "exempt charge VAT needs a UAE VAT exemption reason (IBR-169-AE)", - tax.ExtensionsRequire(ExtKeyExemption), - ), - ), - ), rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("02", "charge VAT category cannot be margin scheme (IBR-114-AE)", + rules.Assert("01", "charge VAT category cannot be margin scheme (IBR-114-AE)", tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), ), ), @@ -717,7 +754,7 @@ func currencyHasAtMost2Decimals(val any) bool { // exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from // the invoice currency to AED has at most 6 decimals, the limit for // cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 28 reports them. +// without it pass: they are in AED, or rule 23 reports them. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -795,25 +832,6 @@ func invoiceIsDue(val any) bool { return inv.Totals.Payable.IsPositive() } -// invoiceHasDueDate reports whether the invoice's payment terms have a due date, -// which gobl.ubl writes as cbc:DueDate (IBR-127-AE). Missing payment details or -// terms fail. -func invoiceHasDueDate(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil || inv.Payment == nil || inv.Payment.Terms == nil { - return false - } - - dueDates := inv.Payment.Terms.DueDates - - for _, dd := range dueDates { - if dd != nil && dd.Date != nil { - return true - } - } - return false -} - // invoiceNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier // has a TIN (IBT-032) whenever another party has a tax registration that // gobl.ubl writes under a tax scheme other than VAT: a tax scope identity @@ -859,7 +877,7 @@ func partyHasNonVATTaxRegistration(p *org.Party) bool { return true } for _, id := range p.Identities { - if identityHasTaxScope(id) && id.Type != tax.CategoryVAT { + if id != nil && id.Scope == org.IdentityScopeTax && id.Type != tax.CategoryVAT { return true } } @@ -873,7 +891,7 @@ func partyHasTIN(p *org.Party) bool { return false } for _, id := range p.Identities { - if identityHasTaxScope(id) && id.Type == ae.IdentityTypeTIN { + if id != nil && id.Scope == org.IdentityScopeTax && id.Type == ae.IdentityTypeTIN { return true } } @@ -903,38 +921,6 @@ func invoiceHasInvoicePeriod(val any) bool { inv.Tax.GetExt(ExtKeyBillingFrequency) != "" } -// invoiceDeliveryAddress returns the first address of the delivery receiver, -// which gobl.ubl writes as cac:DeliveryLocation/cac:Address, or nil. -func invoiceDeliveryAddress(inv *bill.Invoice) *org.Address { - if inv == nil || inv.Delivery == nil || inv.Delivery.Receiver == nil { - return nil - } - return partyFirstAddress(inv.Delivery.Receiver) -} - -// invoiceDeliveryAddressIsComplete reports whether the invoice has a delivery -// address with a street, city and region (IBR-142-AE). -func invoiceDeliveryAddressIsComplete(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok { - return false - } - a := invoiceDeliveryAddress(inv) - return a != nil && a.Street != "" && a.Locality != "" && a.Region != "" -} - -// invoiceDeliveryAddressIsAEOrComplete reports whether the invoice has a -// delivery address in the UAE, or one with a street, city and region -// (IBR-152-AE). -func invoiceDeliveryAddressIsAEOrComplete(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok { - return false - } - a := invoiceDeliveryAddress(inv) - return a != nil && (a.Country == l10n.AE.ISO() || (a.Street != "" && a.Locality != "" && a.Region != "")) -} - // invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's // lines, discounts and charges is VAT under the profit margin scheme. func invoiceTaxesAreMarginScheme(val any) bool { diff --git a/addon/pint/bill_line.go b/addon/pint/bill_line.go index a48d497..d7dc1c5 100644 --- a/addon/pint/bill_line.go +++ b/addon/pint/bill_line.go @@ -28,21 +28,11 @@ func billLineRules() *rules.Set { rules.Assert("02", "item description is required (IBR-125-AE)", is.Present), ), ), - rules.Field("taxes", rules.Each( - rules.When( - is.Func("exempt VAT", comboIsExemptVAT), - rules.Field("ext", - rules.Assert("03", "exempt line needs a UAE VAT exemption reason (IBR-167-AE)", - tax.ExtensionsRequire(ExtKeyExemption), - ), - ), - ), - )), rules.When( is.Func("reverse charge VAT", lineHasReverseChargeVAT), rules.Field("item", rules.Field("ext", - rules.Assert("04", "reverse charge line item needs the type of goods or services (IBR-166-AE)", + rules.Assert("03", "reverse charge line item needs the type of goods or services (IBR-166-AE)", tax.ExtensionsRequire(ExtKeyGoodsType), ), ), @@ -52,7 +42,7 @@ func billLineRules() *rules.Set { // reverse charge lines as its text says. rules.Field("item", rules.Field("ext", - rules.Assert("05", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", + rules.Assert("04", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", tax.ExtensionHasValidCode(ExtKeyGoodsType), ), ), @@ -61,45 +51,12 @@ func billLineRules() *rules.Set { is.Func("reverse charge VAT", lineHasReverseChargeVAT), rules.Field("item", rules.Field("identities", - rules.Assert("06", "reverse charge line item needs a GTIN identity, scheme 0160 (IBR-174-AE)", + rules.Assert("05", "reverse charge line item needs a GTIN identity, scheme 0160 (IBR-174-AE)", org.IdentitiesExtensionIn(iso.ExtKeySchemeID, IdentitySchemeGTIN), ), ), ), ), - rules.Field("item", - rules.When( - is.Func("goods", itemKeyIs(org.ItemKeyGoods)), - rules.Field("identities", - rules.Assert("07", "goods item needs an HS item classification (IBR-184-AE)", - is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), - ), - ), - ), - rules.When( - is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), - rules.Field("identities", - rules.Assert("08", "goods and services item needs an HS item classification (IBR-186-AE)", - is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), - ), - ), - ), - // gobl.ubl writes identities with a label and no scheme ID as item - // classifications, with the label as their list. FormatAE writes the - // SAC ones as service accounting codes instead (IBR-189-AE). - // IBR-188-AE's text asks for HS on every classification, but its - // test passes when any one is HS. - rules.Field("identities", - rules.Assert("09", "item classifications must include one from the HS list (IBR-188-AE)", - is.Func("classifications include HS", identitiesClassifiedWithHS), - ), - ), - ), - rules.Field("seller", - rules.AssertIfPresent("10", "line seller region must be an emirate code when the country is AE (IBR-128-AE)", - is.Func("postal address region is an emirate", partyPostalAddressHasEmirate), - ), - ), ), ) } diff --git a/addon/pint/bill_line_test.go b/addon/pint/bill_line_test.go index ecb39dd..39a60f0 100644 --- a/addon/pint/bill_line_test.go +++ b/addon/pint/bill_line_test.go @@ -49,9 +49,9 @@ func TestBillLineRulesAE(t *testing.T) { func TestBillGoodsTypeRulesAE(t *testing.T) { const ( - faultGoodsType = "GOBL-PEPPOL-PINT-BILL-LINE-04" - faultGoodsTypeValue = "GOBL-PEPPOL-PINT-BILL-LINE-05" - faultGTIN = "GOBL-PEPPOL-PINT-BILL-LINE-06" + faultGoodsType = "GOBL-PEPPOL-PINT-BILL-LINE-03" + faultGoodsTypeValue = "GOBL-PEPPOL-PINT-BILL-LINE-04" + faultGTIN = "GOBL-PEPPOL-PINT-BILL-LINE-05" ) gtin := func(scheme cbc.Code) []*org.Identity { return []*org.Identity{{Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})}} @@ -94,58 +94,3 @@ func TestBillGoodsTypeRulesAE(t *testing.T) { assert.NotContains(t, out, faultGTIN) }) } - -func TestBillItemTypeRulesAE(t *testing.T) { - const ( - faultGoodsHS = "GOBL-PEPPOL-PINT-BILL-LINE-07" - faultGoodsServices = "GOBL-PEPPOL-PINT-BILL-LINE-08" - faultClassification = "GOBL-PEPPOL-PINT-BILL-LINE-09" - ) - hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} - sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} - item := func(key cbc.Key, ids ...*org.Identity) *bill.Invoice { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Item.Key = key - inv.Lines[0].Item.Identities = ids - return inv - } - - t.Run("goods need an HS classification (IBR-184-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) - assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) - - // An identity with a scheme ID isn't written as a classification. - withScheme := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} - assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) - }) - - t.Run("services need no service accounting code", func(t *testing.T) { - assert.Empty(t, aeFaults(t, item(org.ItemKeyServices))) - }) - - t.Run("goods and services need an HS classification (IBR-186-AE)", func(t *testing.T) { - assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices)), faultGoodsServices) - assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) - assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) - }) - - t.Run("no item type needs neither", func(t *testing.T) { - out := aeFaults(t, item("")) - assert.NotContains(t, out, faultGoodsHS) - assert.NotContains(t, out, faultGoodsServices) - }) - - t.Run("item classifications must include an HS one (IBR-188-AE)", func(t *testing.T) { - cpv := &org.Identity{Label: "CPV", Code: "30200000"} - assert.Contains(t, aeFaults(t, item("", cpv)), faultClassification) - assert.Contains(t, aeFaults(t, item("", cpv, sac)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", hs, cpv)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) - assert.NotContains(t, aeFaults(t, item("", sac)), faultClassification) - - // Identities with a scheme ID aren't classifications. - gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} - assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) - }) -} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 7cc6920..75ef037 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -102,11 +102,13 @@ func TestBillPartyRules(t *testing.T) { const ( faultCustomer = "GOBL-PEPPOL-PINT-BILL-INVOICE-03" faultSupplierEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-05" - faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" - faultCustomerIDs = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" - faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" - faultPayeeName = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" - faultPayeeIsSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + faultSupplierInbox = "GOBL-PEPPOL-PINT-BILL-INVOICE-06" + faultCustomerEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-07" + faultCustomerInbox = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" + faultCustomerIDs = "GOBL-PEPPOL-PINT-BILL-INVOICE-09" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + faultPayeeName = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" + faultPayeeIsSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" ) faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() @@ -117,30 +119,31 @@ func TestBillPartyRules(t *testing.T) { return err.Error() } - t.Run("electronic address must be written as an endpoint ID (IBR-081, IBR-080, ibr-cl-25)", func(t *testing.T) { + t.Run("electronic address must not be an email address (IBR-081, IBR-080, ibr-cl-25)", func(t *testing.T) { + // An email address is written with the scheme EM, which PINT doesn't + // accept (ibr-cl-25), even next to a Peppol endpoint. inv := baseInvoice() - inv.Supplier.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} - inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} + inv.Supplier.Endpoints = append(inv.Supplier.Endpoints, &org.Endpoint{URI: "mailto:sales@example.com"}) + inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) out := faults(t, inv) assert.Contains(t, out, faultSupplierEndpoint) assert.Contains(t, out, faultCustomerEndpoint) - // An email address is written with the scheme EM, which PINT doesn't - // accept (ibr-cl-25). - inv.Supplier.Endpoints = append(inv.Supplier.Endpoints, &org.Endpoint{URI: "mailto:sales@example.com"}) - inv.Customer.Endpoints = append(inv.Customer.Endpoints, &org.Endpoint{URI: "mailto:billing@example.com"}) + inv = baseInvoice() + inv.Supplier.Inboxes = []*org.Inbox{{Email: "sales@example.com"}} + inv.Customer.Inboxes = []*org.Inbox{{Email: "billing@example.com"}} out = faults(t, inv) - assert.Contains(t, out, faultSupplierEndpoint) - assert.Contains(t, out, faultCustomerEndpoint) + assert.Contains(t, out, faultSupplierInbox) + assert.Contains(t, out, faultCustomerInbox) inv = baseInvoice() - inv.Supplier.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} inv.Supplier.Inboxes = []*org.Inbox{{Scheme: "0151", Code: "51824753556"}} - inv.Customer.Endpoints = []*org.Endpoint{{URI: "https://example.com/inbox"}} inv.Customer.Inboxes = []*org.Inbox{{Scheme: "0151", Code: "53004085616"}} out = faults(t, inv) assert.NotContains(t, out, faultSupplierEndpoint) + assert.NotContains(t, out, faultSupplierInbox) assert.NotContains(t, out, faultCustomerEndpoint) + assert.NotContains(t, out, faultCustomerInbox) }) t.Run("customer has at most one identifier besides its legal one (ibr-sr-16)", func(t *testing.T) { @@ -259,10 +262,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -453,17 +456,19 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -613,19 +618,23 @@ func TestBillDocumentRulesAE(t *testing.T) { t.Run("due date is required when an amount is due (IBR-127-AE)", func(t *testing.T) { inv := standard() - inv.Payment.Terms = nil + inv.Payment.Terms.DueDates = nil assert.Contains(t, aeFaults(t, inv), faultDueDate) + inv = standard() + inv.Payment.Terms = nil + assert.Contains(t, aeFaults(t, inv), faultDueTerms) + inv = standard() inv.Payment = nil - assert.Contains(t, aeFaults(t, inv), faultDueDate) + assert.Contains(t, aeFaults(t, inv), faultPayment) }) t.Run("due date is not required when nothing is due (IBR-127-AE)", func(t *testing.T) { inv := standard() inv.Payment.Terms = nil inv.Payment.Advances = []*pay.Record{{Description: "Paid in full", Percent: num.NewPercentage(100, 2)}} - assert.NotContains(t, aeFaults(t, inv), faultDueDate) + assert.NotContains(t, aeFaults(t, inv), faultDueTerms) }) t.Run("due date is not required when the amount due is negative (IBR-127-AE)", func(t *testing.T) { @@ -634,7 +643,7 @@ func TestBillDocumentRulesAE(t *testing.T) { inv.Payment.Advances = []*pay.Record{{Description: "Overpaid", Percent: num.NewPercentage(150, 2)}} out := aeFaults(t, inv) require.True(t, inv.Totals.Due.IsNegative()) - assert.NotContains(t, out, faultDueDate) + assert.NotContains(t, out, faultDueTerms) }) t.Run("due date is not required on 381, 81 and 261 (IBR-127-AE)", func(t *testing.T) { @@ -644,7 +653,7 @@ func TestBillDocumentRulesAE(t *testing.T) { "261": aeDocument(bill.InvoiceTypeCreditNote, tax.TagSelfBilled), } { inv.Payment.Terms = nil - assert.NotContains(t, aeFaults(t, inv), faultDueDate, name) + assert.NotContains(t, aeFaults(t, inv), faultDueTerms, name) } }) @@ -685,7 +694,7 @@ func TestBillDocumentRulesAE(t *testing.T) { } func TestBillCurrencyDecimalsRules(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" ae := func(cur currency.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) inv.Currency = cur @@ -729,142 +738,54 @@ func TestBillCurrencyDecimalsRules(t *testing.T) { func TestBillAddressRulesAE(t *testing.T) { const ( - faultSupplierAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" - faultSupplierEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" - faultCustomerAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultCustomerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" - faultTaxRepEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultIssuerEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultDeliveryEmirate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultSellerEmirate = "GOBL-PEPPOL-PINT-BILL-LINE-10" + faultSupplierStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" + faultSupplierCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + faultSupplierRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" + faultCustomerStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultCustomerCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } t.Run("supplier address needs street, city and region (IBR-143-AE)", func(t *testing.T) { - for _, clear := range []func(a *org.Address){ - func(a *org.Address) { a.Street = "" }, - func(a *org.Address) { a.Locality = "" }, - func(a *org.Address) { a.Region = "" }, + for fault, clear := range map[string]func(a *org.Address){ + faultSupplierStreet: func(a *org.Address) { a.Street = "" }, + faultSupplierCity: func(a *org.Address) { a.Locality = "" }, + faultSupplierRegion: func(a *org.Address) { a.Region = "" }, } { inv := standard() clear(inv.Supplier.Addresses[0]) - assert.Contains(t, aeFaults(t, inv), faultSupplierAddress) + assert.Contains(t, aeFaults(t, inv), fault) } }) t.Run("customer address needs street, city and region (IBR-144-AE)", func(t *testing.T) { inv := standard() inv.Customer.Addresses[0].Locality = "" - assert.Contains(t, aeFaults(t, inv), faultCustomerAddress) + assert.Contains(t, aeFaults(t, inv), faultCustomerCity) }) t.Run("foreign customer address also needs a region (IBR-144-AE)", func(t *testing.T) { inv := standard() inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Country: "DE"}} - assert.Contains(t, aeFaults(t, inv), faultCustomerAddress) + assert.Contains(t, aeFaults(t, inv), faultCustomerRegion) }) - t.Run("only the first address is checked (IBR-143-AE, IBR-128-AE)", func(t *testing.T) { + t.Run("every address is checked (IBR-143-AE)", func(t *testing.T) { inv := standard() - inv.Supplier.Addresses = append(inv.Supplier.Addresses, &org.Address{Country: "AE", Region: "Dubai"}) - out := aeFaults(t, inv) - assert.NotContains(t, out, faultSupplierAddress) - assert.NotContains(t, out, faultSupplierEmirate) + inv.Supplier.Addresses = append(inv.Supplier.Addresses, &org.Address{Country: "AE", Region: "DXB"}) + assert.Contains(t, aeFaults(t, inv), faultSupplierStreet) }) t.Run("party without addresses is left to EN 16931 (BR-8, BR-10)", func(t *testing.T) { inv := standard() inv.Customer.Addresses = nil + inv.Customer.TaxID = nil out := aeFaults(t, inv) assert.Contains(t, out, "BR-10") - assert.NotContains(t, out, faultCustomerAddress) - assert.NotContains(t, out, faultCustomerEmirate) - }) - - t.Run("UAE address region must be an emirate code (IBR-128-AE)", func(t *testing.T) { - inv := standard() - inv.Supplier.Addresses[0].Region = "Dubai" - inv.Customer.Addresses[0].Region = "DBX" - inv.Ordering = &bill.Ordering{Seller: &org.Party{Name: "Tax Rep", Addresses: aeAddress("XXX")}} - out := aeFaults(t, inv) - assert.Contains(t, out, faultSupplierEmirate) - assert.Contains(t, out, faultCustomerEmirate) - assert.Contains(t, out, faultTaxRepEmirate) - }) - - t.Run("issuer and line seller UAE regions must be emirate codes too (IBR-128-AE)", func(t *testing.T) { - inv := standard() - inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer", Addresses: aeAddress("Dubai")}} - inv.Lines[0].Seller = &org.Party{Name: "Maker", Addresses: aeAddress("Dubai")} - out := aeFaults(t, inv) - assert.Contains(t, out, faultIssuerEmirate) - assert.Contains(t, out, faultSellerEmirate) - - inv = standard() - inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer", Addresses: aeAddress("DXB")}} - inv.Lines[0].Seller = &org.Party{ - Name: "Maker", - Addresses: []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}}, + for _, fault := range []string{faultCustomerStreet, faultCustomerCity, faultCustomerRegion} { + assert.NotContains(t, out, fault) } - out = aeFaults(t, inv) - assert.NotContains(t, out, faultIssuerEmirate) - assert.NotContains(t, out, faultSellerEmirate) - }) - - t.Run("delivery address in AE needs an emirate code (IBR-128-AE)", func(t *testing.T) { - inv := standard() - inv.Delivery = &bill.DeliveryDetails{Receiver: &org.Party{Name: "Warehouse", Addresses: aeAddress("Dubai")}} - assert.Contains(t, aeFaults(t, inv), faultDeliveryEmirate) - - inv.Delivery.Receiver.Addresses = aeAddress("DXB") - assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) - - inv.Delivery.Receiver.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} - assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) - - inv.Delivery.Receiver.Addresses = nil - assert.NotContains(t, aeFaults(t, inv), faultDeliveryEmirate) - }) - - t.Run("every emirate code is accepted (IBR-128-AE)", func(t *testing.T) { - for _, code := range []string{"AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK"} { - inv := standard() - inv.Supplier.Addresses[0].Region = code - assert.NotContains(t, aeFaults(t, inv), faultSupplierEmirate, code) - } - }) - - t.Run("foreign address region is not checked (IBR-128-AE)", func(t *testing.T) { - inv := standard() - inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} - inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} - assert.NotContains(t, aeFaults(t, inv), faultCustomerEmirate) - }) - - t.Run("the tax ID country counts, as it is the one written (IBR-128-AE)", func(t *testing.T) { - trn := &tax.Identity{Country: "AE", Code: "100000003200003"} - oman := []*org.Address{{Street: "Street 1", Locality: "Muscat", Region: "Muscat", Country: "OM"}} - - inv := standard() - inv.Ordering = &bill.Ordering{ - Seller: &org.Party{Name: "Tax Rep", TaxID: trn, Addresses: oman}, - Issuer: &org.Party{Name: "Issuer", TaxID: trn}, - } - out := aeFaults(t, inv) - assert.Contains(t, out, faultTaxRepEmirate) - assert.Contains(t, out, faultIssuerEmirate, "an address with only the country is written") - - inv = standard() - inv.Lines[0].Seller = &org.Party{ - Name: "Maker", - TaxID: &tax.Identity{Country: "DE", Code: "111111125"}, - Addresses: aeAddress("Dubai"), - } - assert.NotContains(t, aeFaults(t, inv), faultSellerEmirate) - - inv = standard() - inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer"}} - assert.NotContains(t, aeFaults(t, inv), faultIssuerEmirate, "no tax ID and no address") }) } @@ -895,17 +816,11 @@ func aeIdentityDocument() *bill.Invoice { func TestBillIdentityRulesAE(t *testing.T) { const ( - faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" - faultSupplierLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" - faultSupplierPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" - faultSupplierAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" - faultCustomerLegalType = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" - faultCustomerPassport = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" - faultCustomerAuthority = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" - faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" - faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-08" - faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" + faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" ) t.Run("trade licences with authorities pass", func(t *testing.T) { @@ -918,91 +833,6 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) }) - t.Run("legal identity needs a PINT AE type with a UAE endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} - inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} - out := aeFaults(t, inv) - assert.Contains(t, out, faultSupplierLegalType) - assert.Contains(t, out, faultCustomerLegalType) - }) - - t.Run("customer legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.Endpoints = validEndpoints("1345678906") - inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} - assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalType) - }) - - t.Run("customer with a predefined UAE endpoint needs no legal identity type or authority (IBR-180-AE, IBR-183-AE, IBR-101-AE)", func(t *testing.T) { - for _, code := range []string{"9900000098", "9900000099"} { - inv := aeIdentityDocument() - inv.Customer.Endpoints = uaeEndpoints(code) - inv.Customer.Identities = []*org.Identity{ - {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, - } - assert.NotContains(t, aeFaults(t, inv), faultCustomerLegalType, code) - - inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} - inv.Customer.Identities[0].Description = "" - assert.NotContains(t, aeFaults(t, inv), faultCustomerAuthority, code) - } - }) - - t.Run("customer with another predefined UAE endpoint still needs them (IBR-180-AE, IBR-183-AE, IBR-101-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.Endpoints = uaeEndpoints("9900000097") - inv.Customer.Identities = []*org.Identity{ - {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, - } - assert.Contains(t, aeFaults(t, inv), faultCustomerLegalType) - - inv.Customer.Identities = []*org.Identity{tradeLicense("112345679000001")} - inv.Customer.Identities[0].Description = "" - assert.Contains(t, aeFaults(t, inv), faultCustomerAuthority) - }) - - t.Run("each PINT AE type is accepted (IBR-173-AE, IBR-183-AE)", func(t *testing.T) { - for _, id := range []*org.Identity{ - {Type: ae.IdentityTypeEmiratesID, Code: "784199012345671"}, - {Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"}, - {Type: ae.IdentityTypeCabinetDecision, Code: "CD-12-2020"}, - } { - inv := aeIdentityDocument() - inv.Supplier.Identities = []*org.Identity{id} - assert.Empty(t, aeFaults(t, inv), id.Key) - } - }) - - t.Run("every legal identity is checked (IBR-173-AE)", func(t *testing.T) { - // EN 16931 already rejects a second legal identity. - inv := aeIdentityDocument() - inv.Supplier.Identities[0].Scope = org.IdentityScopeLegal - inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) - out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-EU-EN16931-ORG-PARTY-02") - assert.Contains(t, out, faultSupplierLegalType) - }) - - t.Run("passport needs the issuing country (IBR-012-AE, IBR-010-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P9876543210"}} - inv.Customer.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P1234567890"}} - out := aeFaults(t, inv) - assert.Contains(t, out, faultSupplierPassport) - assert.Contains(t, out, faultCustomerPassport) - }) - - t.Run("trade licence needs the issuing authority (IBR-172-AE, IBR-101-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Supplier.Identities[0].Description = "" - inv.Customer.Identities[0].Description = "" - out := aeFaults(t, inv) - assert.Contains(t, out, faultSupplierAuthority) - assert.Contains(t, out, faultCustomerAuthority) - }) - t.Run("supplier TIN is accepted, before or after the legal identity (IBR-148-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append([]*org.Identity{ @@ -1148,20 +978,23 @@ func TestBillIdentityRulesAE(t *testing.T) { func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" - faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" - faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" - faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultECommerceDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" - faultExportDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" + faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" + faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1281,7 +1114,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") inv.Supplier.TaxID = &tax.Identity{Country: "AE"} out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-34") + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-30") assert.NotContains(t, out, faultSupplierTax) for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { @@ -1298,22 +1131,28 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { t.Run("e-commerce needs a complete delivery address (IBR-142-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagECommerce) - assert.Contains(t, aeFaults(t, inv), faultECommerceDelivery) + assert.Contains(t, aeFaults(t, inv), faultDelivery) + inv.Delivery = &bill.DeliveryDetails{Receiver: &org.Party{Name: "Warehouse"}} + assert.Contains(t, aeFaults(t, inv), faultDeliveryAddress) inv.Delivery = receiver(&org.Address{Locality: "Dubai", Region: "DXB", Country: "AE"}) - assert.Contains(t, aeFaults(t, inv), faultECommerceDelivery) + assert.Contains(t, aeFaults(t, inv), faultECommerceStreet) inv.Delivery = receiver(aeAddress("DXB")[0]) assert.Empty(t, aeFaults(t, inv)) }) t.Run("export needs a complete delivery address outside the UAE (IBR-152-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, tax.TagExport) - assert.Contains(t, aeFaults(t, inv), faultExportDelivery) + assert.Contains(t, aeFaults(t, inv), faultDelivery) inv.Delivery = receiver(&org.Address{Locality: "London", Country: "GB"}) - assert.Contains(t, aeFaults(t, inv), faultExportDelivery) + out := aeFaults(t, inv) + assert.Contains(t, out, faultExportStreet) + assert.Contains(t, out, faultExportRegion) inv.Delivery = receiver(foreign) assert.Empty(t, aeFaults(t, inv)) inv.Delivery = receiver(&org.Address{Locality: "Dubai", Country: "AE"}) - assert.NotContains(t, aeFaults(t, inv), faultExportDelivery) + out = aeFaults(t, inv) + assert.NotContains(t, out, faultExportStreet) + assert.NotContains(t, out, faultExportRegion) }) t.Run("outside scope documents can't be summary, deemed supply or margin scheme (IBR-157-AE)", func(t *testing.T) { @@ -1350,10 +1189,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1414,9 +1253,9 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { func TestBillBillingFrequencyRulesAE(t *testing.T) { const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" + faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" + faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" ) withFrequency := func(code cbc.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1457,9 +1296,9 @@ func TestBillBillingFrequencyRulesAE(t *testing.T) { func TestBillExemptionRulesAE(t *testing.T) { const ( - faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultDiscountExemption = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" - faultChargeExemption = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" + faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + faultDiscountExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + faultChargeExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" ) exempt := func(code cbc.Code) *tax.Combo { c := lineCombo(tax.KeyExempt) @@ -1521,10 +1360,10 @@ func TestBillExemptionRulesAE(t *testing.T) { func TestBillMarginSchemeRulesAE(t *testing.T) { const ( - faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-02" - faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-02" - faultLineExemption = "GOBL-PEPPOL-PINT-BILL-LINE-03" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" + faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" + faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1641,7 +1480,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-67" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/org_address.go b/addon/pint/org_address.go new file mode 100644 index 0000000..99e3b56 --- /dev/null +++ b/addon/pint/org_address.go @@ -0,0 +1,37 @@ +package pint + +import ( + "github.com/invopop/gobl/l10n" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" +) + +// emiratePattern matches the country subdivision codes PINT AE accepts for +// UAE addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. +const emiratePattern = `^(AUH|DXB|SHJ|UAQ|FUJ|AJM|RAK)$` + +// orgAddressRules asks every UAE address of a UAE document for an emirate +// code as its region (IBR-128-AE), written as cbc:CountrySubentity. +func orgAddressRules() *rules.Set { + return rules.For(new(org.Address), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When( + is.Func("UAE address", addressIsAE), + rules.Field("region", + rules.Assert("01", "region must be an emirate code when the country is AE (IBR-128-AE)", + is.Present, is.Matches(emiratePattern), + ), + ), + ), + ), + ) +} + +// addressIsAE reports whether an address is in the UAE. +func addressIsAE(val any) bool { + a, ok := val.(*org.Address) + return ok && a != nil && a.Country == l10n.AE.ISO() +} diff --git a/addon/pint/org_address_test.go b/addon/pint/org_address_test.go new file mode 100644 index 0000000..e2f5b5e --- /dev/null +++ b/addon/pint/org_address_test.go @@ -0,0 +1,68 @@ +package pint_test + +import ( + "testing" + + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/pay" + "github.com/stretchr/testify/assert" +) + +func TestOrgAddressRulesAE(t *testing.T) { + const fault = "GOBL-PEPPOL-PINT-ORG-ADDRESS-01" + standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } + + t.Run("UAE address region must be an emirate code (IBR-128-AE)", func(t *testing.T) { + for _, region := range []string{"Dubai", "DBX", ""} { + inv := standard() + inv.Customer.Addresses[0].Region = region + assert.Contains(t, aeFaults(t, inv), fault, region) + } + }) + + t.Run("every emirate code is accepted (IBR-128-AE)", func(t *testing.T) { + for _, code := range []string{"AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK"} { + inv := standard() + inv.Supplier.Addresses[0].Region = code + assert.NotContains(t, aeFaults(t, inv), fault, code) + } + }) + + t.Run("every party's UAE address is checked (IBR-128-AE)", func(t *testing.T) { + for name, set := range map[string]func(inv *bill.Invoice, p *org.Party){ + "tax representative": func(inv *bill.Invoice, p *org.Party) { inv.Ordering = &bill.Ordering{Seller: p} }, + "issuer": func(inv *bill.Invoice, p *org.Party) { inv.Ordering = &bill.Ordering{Issuer: p} }, + "line seller": func(inv *bill.Invoice, p *org.Party) { inv.Lines[0].Seller = p }, + "delivery receiver": func(inv *bill.Invoice, p *org.Party) { inv.Delivery = &bill.DeliveryDetails{Receiver: p} }, + "payee": func(inv *bill.Invoice, p *org.Party) { inv.Payment = &bill.PaymentDetails{Payee: p} }, + } { + inv := standard() + set(inv, &org.Party{Name: "Party", Addresses: aeAddress("Dubai")}) + assert.Contains(t, aeFaults(t, inv), fault, name) + + inv = standard() + set(inv, &org.Party{Name: "Party", Addresses: aeAddress("DXB")}) + assert.NotContains(t, aeFaults(t, inv), fault, name) + } + }) + + t.Run("bank branch UAE address is checked too (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Payment = &bill.PaymentDetails{Instructions: &pay.Instructions{ + Key: pay.MeansKeyCreditTransfer, + CreditTransfer: []*pay.CreditTransfer{{ + IBAN: "AE070331234567890123456", + Branch: &org.Address{Locality: "Dubai", Region: "Dubai", Country: "AE"}, + }}, + }} + assert.Contains(t, aeFaults(t, inv), fault) + }) + + t.Run("foreign address region is not checked (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Customer.TaxID = nil + inv.Customer.Addresses = []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}} + assert.NotContains(t, aeFaults(t, inv), fault) + }) +} diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 21f52a3..75abcb9 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -1,11 +1,16 @@ package pint import ( + "slices" + "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" ) // PINT AE legal registration identifier types, written as @schemeAgencyID on @@ -25,6 +30,34 @@ var identityTypesAE = []cbc.Code{ ae.IdentityTypeCabinetDecision, } +// orgIdentityRules asks the passports of UAE documents for their issuing +// country and the trade licences for their issuing authority, which are +// written as the @schemeAgencyName of the seller's and buyer's +// cac:PartyLegalEntity/cbc:CompanyID (IBR-012-AE, IBR-010-AE, IBR-172-AE, +// IBR-101-AE). +func orgIdentityRules() *rules.Set { + return rules.For(new(org.Identity), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When( + org.IdentityKeyIn(org.IdentityKeyPassport), + rules.Field("country", + rules.Assert("01", "passport must have the issuing country (IBR-012-AE, IBR-010-AE)", is.Present), + ), + ), + // IBR-101-AE exempts the buyers with the predefined endpoints + // 9900000098 and 9900000099, but an identity can't see its party's + // endpoint, so their trade licences need the authority too. + rules.When( + org.IdentityTypeIn(ae.IdentityTypeTradeLicense), + rules.Field("description", + rules.Assert("02", "trade license must have the issuing authority in the description (IBR-172-AE, IBR-101-AE)", is.Present), + ), + ), + ), + ) +} + // IdentityTypeAE returns the PINT AE legal registration identifier type of an // identity, or an empty code if it has none. func IdentityTypeAE(id *org.Identity) cbc.Code { @@ -118,16 +151,24 @@ func GTINIdentity(ids []*org.Identity) *org.Identity { return nil } -// identityHasLegalScope reports whether an identity has the legal scope. -// EN 16931 allows one per party (GOBL-EU-EN16931-ORG-PARTY-02), the one -// gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID. -func identityHasLegalScope(val any) bool { - id, ok := val.(*org.Identity) - return ok && id != nil && id.Scope == org.IdentityScopeLegal +// identityScopeIn returns a predicate that reports whether an identity has +// one of the scopes, the empty one for none. gobl.ubl writes the identity +// with the tax scope as a cac:PartyTaxScheme and the first with the legal +// scope as cac:PartyLegalEntity/cbc:CompanyID, and the rest as +// cac:PartyIdentification. +func identityScopeIn(scopes ...cbc.Key) func(any) bool { + return func(val any) bool { + id, ok := val.(*org.Identity) + return ok && id != nil && id.Scope.In(scopes...) + } } -// identityHasTaxScope reports whether an identity has the tax scope. -func identityHasTaxScope(val any) bool { - id, ok := val.(*org.Identity) - return ok && id != nil && id.Scope == org.IdentityScopeTax +// identitiesScopeIn returns a predicate that reports whether any of the +// identities has one of the scopes, the empty one for none. +func identitiesScopeIn(scopes ...cbc.Key) func(any) bool { + match := identityScopeIn(scopes...) + return func(val any) bool { + ids, ok := val.([]*org.Identity) + return ok && slices.ContainsFunc(ids, func(id *org.Identity) bool { return match(id) }) + } } diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index bcdf235..5f2b699 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -142,3 +142,37 @@ func TestNormalizeIdentityScopes(t *testing.T) { assert.Equal(t, []cbc.Key{"", ""}, customer) }) } + +func TestOrgIdentityRulesAE(t *testing.T) { + const ( + fault = "GOBL-PEPPOL-PINT-ORG-IDENTITY-01" + faultAuthority = "GOBL-PEPPOL-PINT-ORG-IDENTITY-02" + ) + + t.Run("passport needs the issuing country (IBR-012-AE, IBR-010-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P9876543210"}} + assert.Contains(t, aeFaults(t, inv), fault) + + inv = aeIdentityDocument() + inv.Customer.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P1234567890"}} + assert.Contains(t, aeFaults(t, inv), fault) + + inv = aeIdentityDocument() + inv.Customer.Identities = []*org.Identity{{Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"}} + assert.NotContains(t, aeFaults(t, inv), fault) + }) + t.Run("trade licence needs the issuing authority (IBR-172-AE, IBR-101-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities[0].Description = "" + assert.Contains(t, aeFaults(t, inv), faultAuthority) + + // IBR-101-AE exempts these buyers, but the rule can't see the endpoint. + inv = aeIdentityDocument() + inv.Customer.Endpoints = uaeEndpoints("9900000098") + inv.Customer.Identities[0].Description = "" + assert.Contains(t, aeFaults(t, inv), faultAuthority) + + assert.NotContains(t, aeFaults(t, aeIdentityDocument()), faultAuthority) + }) +} diff --git a/addon/pint/org_item.go b/addon/pint/org_item.go index 79d9807..199b64d 100644 --- a/addon/pint/org_item.go +++ b/addon/pint/org_item.go @@ -4,6 +4,9 @@ import ( "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" ) // ItemKeyGoodsServices is the item key for an item that is both goods and @@ -54,6 +57,42 @@ func ItemKeyAE(typ cbc.Code) cbc.Key { return "" } +// orgItemRules asks the items of UAE documents for the HS item +// classifications PINT AE needs. +func orgItemRules() *rules.Set { + return rules.For(new(org.Item), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When( + is.Func("goods", itemKeyIs(org.ItemKeyGoods)), + rules.Field("identities", + rules.Assert("01", "goods item needs an HS item classification (IBR-184-AE)", + is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), + ), + ), + ), + rules.When( + is.Func("goods and services", itemKeyIs(ItemKeyGoodsServices)), + rules.Field("identities", + rules.Assert("02", "goods and services item needs an HS item classification (IBR-186-AE)", + is.Func("has HS", identitiesHaveLabel(IdentityLabelHS)), + ), + ), + ), + // gobl.ubl writes identities with a label and no scheme ID as item + // classifications, with the label as their list. FormatAE writes the + // SAC ones as service accounting codes instead (IBR-189-AE). + // IBR-188-AE's text asks for HS on every classification, but its + // test passes when any one is HS. + rules.Field("identities", + rules.Assert("03", "item classifications must include one from the HS list (IBR-188-AE)", + is.Func("classifications include HS", identitiesClassifiedWithHS), + ), + ), + ), + ) +} + // itemKeyIs returns a predicate that reports whether an item has the key. func itemKeyIs(key cbc.Key) func(any) bool { return func(val any) bool { @@ -62,32 +101,22 @@ func itemKeyIs(key cbc.Key) func(any) bool { } } -// identitiesHaveLabel returns a predicate that reports whether an item has -// identities with all the labels. -func identitiesHaveLabel(labels ...string) func(any) bool { +// identitiesHaveLabel returns a predicate that reports whether one of the +// identities gobl.ubl writes as item classifications, those with a label and +// no scheme ID, has the label. +func identitiesHaveLabel(label string) func(any) bool { return func(val any) bool { ids, ok := val.([]*org.Identity) if !ok { return false } - for _, label := range labels { - if !identitiesHaveLabelOf(ids, label) { - return false + for _, id := range ids { + if id != nil && id.Label == label && !id.Ext.Has(iso.ExtKeySchemeID) { + return true } } - return true - } -} - -// identitiesHaveLabelOf reports whether one of the identities gobl.ubl writes -// as item classifications, those with a label and no scheme ID, has the label. -func identitiesHaveLabelOf(ids []*org.Identity, label string) bool { - for _, id := range ids { - if id != nil && id.Label == label && !id.Ext.Has(iso.ExtKeySchemeID) { - return true - } + return false } - return false } // identitiesClassifiedWithHS reports whether the identities gobl.ubl writes diff --git a/addon/pint/org_item_test.go b/addon/pint/org_item_test.go index 7d45dc3..10941af 100644 --- a/addon/pint/org_item_test.go +++ b/addon/pint/org_item_test.go @@ -4,8 +4,11 @@ import ( "testing" "github.com/invopop/gobl.peppol/addon/pint" + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/org" + "github.com/invopop/gobl/tax" "github.com/stretchr/testify/assert" ) @@ -34,3 +37,58 @@ func TestItemKeyAE(t *testing.T) { assert.Equal(t, want, pint.ItemKeyAE(typ), typ) } } + +func TestOrgItemRulesAE(t *testing.T) { + const ( + faultGoodsHS = "GOBL-PEPPOL-PINT-ORG-ITEM-01" + faultGoodsServices = "GOBL-PEPPOL-PINT-ORG-ITEM-02" + faultClassification = "GOBL-PEPPOL-PINT-ORG-ITEM-03" + ) + hs := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471"} + sac := &org.Identity{Label: pint.IdentityLabelSAC, Code: "998713"} + item := func(key cbc.Key, ids ...*org.Identity) *bill.Invoice { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Item.Key = key + inv.Lines[0].Item.Identities = ids + return inv + } + + t.Run("goods need an HS classification (IBR-184-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods)), faultGoodsHS) + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, sac)), faultGoodsHS) + assert.NotContains(t, aeFaults(t, item(org.ItemKeyGoods, hs)), faultGoodsHS) + + // An identity with a scheme ID isn't written as a classification. + withScheme := &org.Identity{Label: pint.IdentityLabelHS, Code: "8471", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"})} + assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) + }) + + t.Run("services need no service accounting code", func(t *testing.T) { + assert.Empty(t, aeFaults(t, item(org.ItemKeyServices))) + }) + + t.Run("goods and services need an HS classification (IBR-186-AE)", func(t *testing.T) { + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices)), faultGoodsServices) + assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) + assert.NotContains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, hs)), faultGoodsServices) + }) + + t.Run("no item type needs neither", func(t *testing.T) { + out := aeFaults(t, item("")) + assert.NotContains(t, out, faultGoodsHS) + assert.NotContains(t, out, faultGoodsServices) + }) + + t.Run("item classifications must include an HS one (IBR-188-AE)", func(t *testing.T) { + cpv := &org.Identity{Label: "CPV", Code: "30200000"} + assert.Contains(t, aeFaults(t, item("", cpv)), faultClassification) + assert.Contains(t, aeFaults(t, item("", cpv, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, cpv)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", hs, sac)), faultClassification) + assert.NotContains(t, aeFaults(t, item("", sac)), faultClassification) + + // Identities with a scheme ID aren't classifications. + gtin := &org.Identity{Label: "GTIN", Code: "4006381333931", Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0160"})} + assert.NotContains(t, aeFaults(t, item("", gtin)), faultClassification) + }) +} diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index 0662064..a817bd1 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -12,18 +12,11 @@ import ( "github.com/invopop/gobl/org" "github.com/invopop/gobl/pkg/luhn" "github.com/invopop/gobl/regimes/ae" + "github.com/invopop/gobl/rules" + "github.com/invopop/gobl/rules/is" + "github.com/invopop/gobl/tax" ) -// emirateCodes are the country subdivision codes PINT AE accepts for UAE -// addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. -var emirateCodes = []cbc.Code{ - "AUH", "DXB", "SHJ", "UAQ", "FUJ", "AJM", "RAK", -} - -// endpointSchemeUAE is the Peppol participant identifier scheme for UAE -// endpoints, which the PINT AE legal registration rules depend on. -const endpointSchemeUAE cbc.Code = "0235" - // endpointSchemeMailto is the URI scheme of email endpoints, which gobl.ubl // writes as cbc:EndpointID with the scheme endpointSchemeEmail. const endpointSchemeMailto = "mailto" @@ -32,47 +25,65 @@ const endpointSchemeMailto = "mailto" // email addresses. const endpointSchemeEmail cbc.Code = "EM" -// partyHasIdentifier reports whether the party can be identified through a tax -// identity code or at least one organisation identity. -func partyHasIdentifier(val any) bool { - p, ok := val.(*org.Party) - return ok && p != nil && ((p.TaxID != nil && p.TaxID.Code != "") || len(p.Identities) > 0) -} - -// partyHasTaxRegistration reports whether the party has a tax registration: -// a tax ID code or an identity with the tax scope. IBR-103-AE accepts any -// buyer PartyTaxScheme/CompanyID, and gobl.ubl writes either one there. -func partyHasTaxRegistration(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - if p.TaxID != nil && p.TaxID.Code != "" { - return true - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeTax { - return true - } - } - return false +// orgPartyRules asks every party of a UAE document with a UAE tax ID for an +// address with an emirate code as its region (IBR-128-AE). gobl.ubl writes +// the country of a party's tax ID over the address's own in +// cac:PostalAddress, and an address with only that country when the party +// has none, so every address of the party is in the UAE there. The address +// rules already check the addresses whose own country is AE. +// +// It also checks the type of the legal identities of the parties with a UAE +// Peppol endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE). Every one +// of those tests only fires with a 0235 cbc:EndpointID, so only UAE Peppol +// participants are checked; foreign payees, receivers and factors have none. +// +// TODO: gobl.ubl writes the delivery receiver's address with its own +// country, as cac:DeliveryLocation/cac:Address, so a receiver with a UAE tax +// ID and a foreign address gets an emirate error PINT AE wouldn't give. +func orgPartyRules() *rules.Set { + return rules.For(new(org.Party), + rules.When( + is.InContext(tax.RegimeIn(regimesAE...)), + rules.When( + is.Func("UAE tax ID", partyHasAETaxID), + rules.Field("addresses", + rules.Assert("01", "address is required with a UAE tax ID (IBR-128-AE)", is.Present), + rules.Each( + rules.When( + is.Not(is.Func("UAE address", addressIsAE)), + rules.Field("region", + rules.Assert("02", "region must be an emirate code with a UAE tax ID (IBR-128-AE)", + is.Present, is.Matches(emiratePattern), + ), + ), + ), + ), + ), + ), + // IBR-180-AE and IBR-183-AE exempt the buyers with the predefined + // endpoints 9900000098 and 9900000099. IBR-183-AE also exempts + // other 1XXXXXXXXX endpoints, but IBR-180-AE still asks them for a + // type, and GOBL can only write the four in the list. + rules.When( + is.Func("has UAE Peppol endpoint other than 9900000098 or 9900000099", partyHasUAEEndpoint(endpointPatternPredefined, false)), + rules.Field("identities", rules.Each( + rules.When( + is.Func("legal scope", identityScopeIn(org.IdentityScopeLegal)), + rules.Assert("03", "legal identity must be a trade license, Emirates ID, passport or Cabinet Decision with a UAE Peppol endpoint other than 9900000098 or 9900000099 (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE)", + is.Or(org.IdentityKeyIn(org.IdentityKeyPassport), org.IdentityTypeIn(identityTypesAE...)), + ), + ), + )), + ), + ), + ) } -// partyHasLegalIdentity reports whether the party has an identity with the -// legal scope. gobl.ubl writes the first one as -// PartyLegalEntity/CompanyID, the buyer legal registration identifier -// IBR-136-AE requires on 480 and 81. -func partyHasLegalIdentity(val any) bool { +// partyHasAETaxID reports whether the party has a UAE tax ID with a code, +// which gobl.ubl writes with its country. +func partyHasAETaxID(val any) bool { p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeLegal { - return true - } - } - return false + return ok && p != nil && p.TaxID != nil && p.TaxID.Code != "" && p.TaxID.Country.Code() == l10n.AE } // partyHasOneIdentification reports whether gobl.ubl writes at most one @@ -143,61 +154,6 @@ func identificationScheme(id *org.Identity) cbc.Code { return id.Ext.Get(iso.ExtKeySchemeID) } -// partyFirstAddress returns the party's first address, the only one gobl.ubl -// writes as cac:PostalAddress, or nil if there is none. -func partyFirstAddress(val any) *org.Address { - p, ok := val.(*org.Party) - if !ok || p == nil || len(p.Addresses) == 0 { - return nil - } - return p.Addresses[0] -} - -// partyAddressIsComplete reports whether the party's first address has a -// street, city and region, written as cbc:StreetName, cbc:CityName and -// cbc:CountrySubentity (IBR-143-AE, IBR-144-AE). A party without an address -// passes: EN 16931 already requires supplier and customer addresses (BR-8, -// BR-10). -func partyAddressIsComplete(val any) bool { - a := partyFirstAddress(val) - return a == nil || (a.Street != "" && a.Locality != "" && a.Region != "") -} - -// partyAddressHasEmirate reports whether the party's first address, when in -// the UAE, has an emirate code as its region (IBR-128-AE). Addresses in other -// countries pass, and so does a party without addresses: it is for the -// supplier and customer, whose addresses EN 16931 requires (BR-8, BR-10). -func partyAddressHasEmirate(val any) bool { - return partyFirstAddress(val) == nil || partyPostalAddressHasEmirate(val) -} - -// partyFirstAddressHasEmirate reports whether the party's first address, -// when in the UAE, has an emirate code as its region (IBR-128-AE). gobl.ubl -// writes it as the delivery's cac:DeliveryLocation/cac:Address, with the -// address's own country. A party without addresses passes. -func partyFirstAddressHasEmirate(val any) bool { - a := partyFirstAddress(val) - return a == nil || a.Country != l10n.AE.ISO() || cbc.Code(a.Region).In(emirateCodes...) -} - -// partyPostalAddressHasEmirate reports whether the cac:PostalAddress gobl.ubl -// writes for the party, when in the UAE, has an emirate code as its region -// (IBR-128-AE). gobl.ubl writes the country of the tax ID over the address's -// own, and writes an address with only that country for a party without -// addresses, which fails the rule. -func partyPostalAddressHasEmirate(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - a := partyFirstAddress(p) - inAE := a != nil && a.Country == l10n.AE.ISO() - if p.TaxID != nil && p.TaxID.Code != "" { - inAE = p.TaxID.Country.Code() == l10n.AE - } - return !inAE || (a != nil && cbc.Code(a.Region).In(emirateCodes...)) -} - // partyEndpointID returns the scheme and code of the party's electronic // address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 // endpoint, or else the first email endpoint, or else the first inbox with an @@ -227,80 +183,34 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { return "", "" } -// partyHasEndpointID reports whether gobl.ubl writes the party's electronic -// address as a cbc:EndpointID that PINT accepts: an ISO 6523 endpoint or an -// inbox with a scheme. An email address is written with the scheme EM, which -// is not in PINT's list (ibr-cl-25). A party without endpoints passes, as -// rules 02 and 04 report it. -func partyHasEndpointID(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - if len(p.Endpoints) == 0 { - return true - } - s, _ := partyEndpointID(p) - return s != "" && s != endpointSchemeEmail -} - -// endpointCodesPredefined are the predefined UAE Peppol endpoint codes that -// IBR-180-AE, IBR-183-AE and IBR-101-AE exempt from the buyer legal -// registration identifier type and authority. -var endpointCodesPredefined = []string{"9900000098", "9900000099"} - -// endpointCodeDeemedSupply is the predefined UAE Peppol endpoint code of the -// buyer of a deemed supply (PINT AE BIS 1.5.3). -const endpointCodeDeemedSupply = "9900000097" - -// endpoint1or9Regexp matches the UAE Peppol endpoint codes of 10 digits -// starting with 1 or 9, which need no buyer legal registration identifier -// (IBR-149-AE). -var endpoint1or9Regexp = regexp.MustCompile(`^[19]\d{9}$`) +// Patterns of the UAE Peppol endpoint codes the PINT AE rules depend on. +const ( + // endpointPatternPredefined matches the predefined endpoints 9900000098 + // and 9900000099, which IBR-180-AE and IBR-183-AE exempt. + endpointPatternPredefined = `^99000000(98|99)$` + // endpointPatternDeemedSupply matches the predefined endpoint of the + // buyer of a deemed supply (PINT AE BIS 1.5.3). + endpointPatternDeemedSupply = `^9900000097$` + // endpointPattern1or9 matches the codes of 10 digits starting with 1 or + // 9, which need no buyer legal registration identifier (IBR-149-AE). + endpointPattern1or9 = `^[19]\d{9}$` +) -// partyHasUAEEndpointWith returns a predicate that reports whether the party's -// electronic address uses the UAE Peppol scheme 0235 with a code that match -// accepts. -func partyHasUAEEndpointWith(match func(code string) bool) func(any) bool { +// partyHasUAEEndpoint returns a predicate that reports whether the party's +// electronic address, as gobl.ubl chooses it, uses the UAE Peppol scheme 0235 +// with a code that matches the pattern, or that doesn't when match is false. +func partyHasUAEEndpoint(pattern string, match bool) func(any) bool { + re := regexp.MustCompile(pattern) return func(val any) bool { p, ok := val.(*org.Party) if !ok || p == nil { return false } scheme, code := partyEndpointID(p) - return scheme == endpointSchemeUAE && match(code) + return scheme == ae.TINScheme && re.MatchString(code) == match } } -var ( - // partyHasUAEEndpointPredefined reports whether the party has one of the - // predefined UAE endpoints, which IBR-180-AE, IBR-183-AE and IBR-101-AE - // exempt. - partyHasUAEEndpointPredefined = partyHasUAEEndpointWith(func(code string) bool { - return slices.Contains(endpointCodesPredefined, code) - }) - // partyHasUAEEndpointNotPredefined is the condition of IBR-180-AE and - // IBR-183-AE. - partyHasUAEEndpointNotPredefined = partyHasUAEEndpointWith(func(code string) bool { - return !slices.Contains(endpointCodesPredefined, code) - }) - // partyHasUAEEndpointDeemedSupply reports whether the party has the - // predefined UAE endpoint of a deemed supply buyer. - partyHasUAEEndpointDeemedSupply = partyHasUAEEndpointWith(func(code string) bool { - return code == endpointCodeDeemedSupply - }) - // partyHasUAEEndpointNot1or9 is the condition of IBR-149-AE: a code - // that is not 1XXXXXXXXX or 9XXXXXXXXX. - partyHasUAEEndpointNot1or9 = partyHasUAEEndpointWith(func(code string) bool { - return !endpoint1or9Regexp.MatchString(code) - }) - // partyHasUAEEndpointNotTIN is the condition of IBR-135-AE: a code that - // is not a TIN, 1XXXXXXXXX. - partyHasUAEEndpointNotTIN = partyHasUAEEndpointWith(func(code string) bool { - return !tinRegexpAE.MatchString(code) - }) -) - // partyFirstLegalIdentity returns the party's first identity with the legal // scope, the one gobl.ubl writes as cac:PartyLegalEntity/cbc:CompanyID, or nil // if there is none. @@ -317,50 +227,6 @@ func partyFirstLegalIdentity(val any) *org.Identity { return nil } -// partyTaxIdentityCount returns how many of the party's identities have the -// tax scope. gobl.ubl writes each one as a cac:PartyTaxScheme. -func partyTaxIdentityCount(p *org.Party) int { - n := 0 - for _, id := range p.Identities { - if identityHasTaxScope(id) { - n++ - } - } - return n -} - -// partyHasAtMostOneTaxRegistration reports whether the party has at most one -// tax registration, counting the tax ID code and the tax scope identities, as -// the buyer can only have one PartyTaxScheme/CompanyID (IBR-179-AE). -func partyHasAtMostOneTaxRegistration(val any) bool { - p, ok := val.(*org.Party) - if !ok || p == nil { - return false - } - n := partyTaxIdentityCount(p) - if p.TaxID != nil && p.TaxID.Code != "" { - n++ - } - return n <= 1 -} - -// partyHasIdentificationOrTaxRegistration reports whether the party has an -// identity gobl.ubl writes as cac:PartyIdentification (any identity that is -// neither a tax registration nor the first legal one) or a tax registration -// (IBR-135-AE). -func partyHasIdentificationOrTaxRegistration(val any) bool { - if partyHasTaxRegistration(val) { - return true - } - p, ok := val.(*org.Party) - return ok && p != nil && len(partyIdentifications(p)) > 0 -} - -// tinRegexpAE matches a UAE TIN, in the AE regime's format. UAE Peppol -// endpoints (0235) are TINs too, so it also tells whether an endpoint is one -// (IBR-135-AE). -var tinRegexpAE = regexp.MustCompile(ae.TINPattern) - // trnRegexpAE matches a UAE TRN, in the AE regime's format. Its first 10 // digits are the TIN. var trnRegexpAE = regexp.MustCompile(ae.TRNPattern) @@ -394,7 +260,7 @@ func normalizeSupplierAE(inv *bill.Invoice) { } if len(p.Endpoints) == 0 && len(p.Inboxes) == 0 { p.Endpoints = append(p.Endpoints, &org.Endpoint{ - URI: cbc.URI(iso.ActorIDScheme + "::" + endpointSchemeUAE.String() + ":" + tin.String()), + URI: cbc.URI(iso.ActorIDScheme + "::" + ae.TINScheme.String() + ":" + tin.String()), }) } } diff --git a/addon/pint/org_party_test.go b/addon/pint/org_party_test.go index 290f785..27def6f 100644 --- a/addon/pint/org_party_test.go +++ b/addon/pint/org_party_test.go @@ -90,3 +90,122 @@ func TestNormalizeSupplierAE(t *testing.T) { assert.Empty(t, p.Endpoints) }) } + +func TestOrgPartyRulesAE(t *testing.T) { + const ( + faultAddress = "GOBL-PEPPOL-PINT-ORG-PARTY-01" + faultEmirate = "GOBL-PEPPOL-PINT-ORG-PARTY-02" + faultLegalType = "GOBL-PEPPOL-PINT-ORG-PARTY-03" + ) + standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } + trn := func() *tax.Identity { return &tax.Identity{Country: "AE", Code: "100000003200003"} } + oman := func() []*org.Address { + return []*org.Address{{Street: "Street 1", Locality: "Muscat", Region: "Muscat", Country: "OM"}} + } + + t.Run("a UAE tax ID makes every address count as in the UAE (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Supplier.Addresses = oman() + assert.Contains(t, aeFaults(t, inv), faultEmirate) + + inv = standard() + inv.Ordering = &bill.Ordering{Seller: &org.Party{Name: "Tax Rep", TaxID: trn(), Addresses: oman()}} + assert.Contains(t, aeFaults(t, inv), faultEmirate) + + inv = standard() + inv.Supplier.Addresses = oman() + inv.Supplier.Addresses[0].Region = "DXB" + assert.NotContains(t, aeFaults(t, inv), faultEmirate) + }) + + t.Run("a UAE tax ID needs an address, as one is written (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer", TaxID: trn()}} + assert.Contains(t, aeFaults(t, inv), faultAddress) + + inv = standard() + inv.Payment = &bill.PaymentDetails{Payee: &org.Party{Name: "Payee", TaxID: trn()}} + assert.Contains(t, aeFaults(t, inv), faultAddress) + }) + + t.Run("UAE addresses are left to the address rules (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Supplier.Addresses[0].Region = "Dubai" + out := aeFaults(t, inv) + assert.Contains(t, out, "GOBL-PEPPOL-PINT-ORG-ADDRESS-01") + assert.NotContains(t, out, faultEmirate) + }) + + t.Run("other parties are not checked (IBR-128-AE)", func(t *testing.T) { + inv := standard() + inv.Lines[0].Seller = &org.Party{ + Name: "Maker", + TaxID: &tax.Identity{Country: "DE", Code: "111111125"}, + Addresses: []*org.Address{{Street: "Hauptstr. 1", Locality: "Berlin", Region: "Berlin", Country: "DE"}}, + } + inv.Ordering = &bill.Ordering{Issuer: &org.Party{Name: "Issuer"}} + out := aeFaults(t, inv) + assert.NotContains(t, out, faultAddress) + assert.NotContains(t, out, faultEmirate) + }) + + t.Run("legal identity needs a PINT AE type with a UAE endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}} + assert.Contains(t, aeFaults(t, inv), faultLegalType) + + inv = aeIdentityDocument() + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} + assert.Contains(t, aeFaults(t, inv), faultLegalType) + }) + + t.Run("customer legal identity without a type is fine without a UAE endpoint", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.Endpoints = validEndpoints("1345678906") + inv.Customer.Identities = []*org.Identity{{Scope: org.IdentityScopeLegal, Code: "CN-7654321"}} + assert.NotContains(t, aeFaults(t, inv), faultLegalType) + }) + + t.Run("customer with a predefined UAE endpoint needs no legal identity type (IBR-180-AE, IBR-183-AE)", func(t *testing.T) { + for _, code := range []string{"9900000098", "9900000099"} { + inv := aeIdentityDocument() + inv.Customer.Endpoints = uaeEndpoints(code) + inv.Customer.Identities = []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, + } + assert.NotContains(t, aeFaults(t, inv), faultLegalType, code) + } + }) + + t.Run("customer with another predefined UAE endpoint still needs one (IBR-180-AE, IBR-183-AE)", func(t *testing.T) { + inv := aeIdentityDocument() + inv.Customer.Endpoints = uaeEndpoints("9900000097") + inv.Customer.Identities = []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-7654321"}, + } + assert.Contains(t, aeFaults(t, inv), faultLegalType) + }) + + t.Run("each PINT AE type is accepted (IBR-173-AE, IBR-183-AE)", func(t *testing.T) { + for _, id := range []*org.Identity{ + {Type: ae.IdentityTypeEmiratesID, Code: "784199012345671"}, + {Key: org.IdentityKeyPassport, Code: "P1234567890", Country: "IN"}, + {Type: ae.IdentityTypeCabinetDecision, Code: "CD-12-2020"}, + } { + inv := aeIdentityDocument() + inv.Supplier.Identities = []*org.Identity{id} + assert.Empty(t, aeFaults(t, inv), id.Key) + } + }) + + t.Run("every legal identity is checked (IBR-173-AE)", func(t *testing.T) { + // EN 16931 already rejects a second legal identity. + inv := aeIdentityDocument() + inv.Supplier.Identities[0].Scope = org.IdentityScopeLegal + inv.Supplier.Identities = append(inv.Supplier.Identities, + &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) + out := aeFaults(t, inv) + assert.Contains(t, out, "GOBL-EU-EN16931-ORG-PARTY-02") + assert.Contains(t, out, faultLegalType) + }) +} diff --git a/addon/pint/pay.go b/addon/pint/pay.go index 66ca29f..6d4e881 100644 --- a/addon/pint/pay.go +++ b/addon/pint/pay.go @@ -23,7 +23,7 @@ func payInstructionsRules() *rules.Set { return rules.For(new(pay.Instructions), rules.When( is.InContext(tax.RegimeIn(regimesAUNZ...)), - rules.When(is.Func("payment means is credit transfer", instructionsMeanCreditTransfer), + rules.When(is.Func("payment means is credit transfer", instructionsMeansIn(meansCodeCreditTransfer, meansCodeSEPACreditTransfer)), rules.Field("credit_transfer", rules.Assert("01", "invoice credit transfer instructions must include a payment account identifier (ALIGNED-IBRP-018)", is.Present), ), @@ -31,9 +31,18 @@ func payInstructionsRules() *rules.Set { ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - rules.When(is.Func("payment means is credit transfer", instructionsMeanCreditTransferAE), - rules.Assert("02", "first credit transfer must include an IBAN or account number (IBR-192-AE)", - is.Func("has a payment account identifier", instructionsHaveAccountID), + // gobl.ubl only writes the first credit transfer, as + // cac:PayeeFinancialAccount, but every one needs the account. + // Unlike A-NZ, SEPA (58) is not included, as IBR-192-AE only + // checks 30. + rules.When(is.Func("payment means is credit transfer", instructionsMeansIn(meansCodeCreditTransfer)), + rules.Field("credit_transfer", + rules.Assert("02", "credit transfer is required with the payment means 30 (IBR-192-AE)", is.Present), + rules.Each( + rules.Assert("03", "credit transfer must include an IBAN or account number with the payment means 30 (IBR-192-AE)", + is.Func("has IBAN or account number", creditTransferHasAccountID), + ), + ), ), ), ), @@ -55,28 +64,13 @@ func creditTransferRules() *rules.Set { ) } -// instructionsMeanCreditTransfer reports whether the payment means code -// (ibt-081) of the instructions identifies a local, non-SEPA international or -// SEPA credit transfer. -func instructionsMeanCreditTransfer(val any) bool { - instr, ok := val.(*pay.Instructions) - if !ok || instr == nil { - return false - } - code := instr.Ext.Get(untdid.ExtKeyPaymentMeans) - return code == meansCodeCreditTransfer || code == meansCodeSEPACreditTransfer -} - -// instructionsMeanCreditTransferAE reports whether the payment means code -// (ibt-081) of the instructions is 30, a credit transfer. Unlike the A-NZ -// predicate, SEPA (58) is not included, as IBR-192-AE only checks 30. -func instructionsMeanCreditTransferAE(val any) bool { - instr, ok := val.(*pay.Instructions) - if !ok || instr == nil { - return false +// instructionsMeansIn returns a predicate that reports whether the payment +// means code (ibt-081) of the instructions is one of the codes. +func instructionsMeansIn(codes ...cbc.Code) func(any) bool { + return func(val any) bool { + instr, ok := val.(*pay.Instructions) + return ok && instr != nil && instr.Ext.Get(untdid.ExtKeyPaymentMeans).In(codes...) } - code := instr.Ext.Get(untdid.ExtKeyPaymentMeans) - return code == meansCodeCreditTransfer } // creditTransferHasAccountID reports whether the credit transfer carries an @@ -88,20 +82,3 @@ func creditTransferHasAccountID(val any) bool { } return ct.IBAN != "" || ct.Number != "" } - -// instructionsHaveAccountID reports whether the instructions' first credit -// transfer carries an account identifier (ibt-084), either an IBAN or an -// account number. gobl.ubl only writes the first credit transfer as -// cac:PayeeFinancialAccount, so the others can't satisfy IBR-192-AE. A missing -// credit transfer list fails, so one check covers both cases of the rule. -func instructionsHaveAccountID(val any) bool { - instr, ok := val.(*pay.Instructions) - if !ok || instr == nil { - return false - } - if len(instr.CreditTransfer) == 0 { - return false - } - ct := instr.CreditTransfer[0] - return ct != nil && (ct.IBAN != "" || ct.Number != "") -} diff --git a/addon/pint/pay_test.go b/addon/pint/pay_test.go index 63f07f6..dc1e040 100644 --- a/addon/pint/pay_test.go +++ b/addon/pint/pay_test.go @@ -115,17 +115,17 @@ func TestPayInstructionsRulesAE(t *testing.T) { instr := instructionsWithMeansCode("30") instr.CreditTransfer = []*pay.CreditTransfer{{BIC: "EBILAEAD", Name: "Emirates NBD"}} err := validate(instr) - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-03") }) - t.Run("only the first credit transfer counts, as it is the one written (IBR-192-AE)", func(t *testing.T) { + t.Run("every credit transfer needs an IBAN or account number (IBR-192-AE)", func(t *testing.T) { instr := instructionsWithMeansCode("30") instr.CreditTransfer = []*pay.CreditTransfer{ - {Name: "Emirates NBD"}, {IBAN: "AE070331234567890123456"}, + {Name: "Emirates NBD"}, } err := validate(instr) - assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-03") }) t.Run("other payment means are not checked", func(t *testing.T) { @@ -155,6 +155,6 @@ func TestPayInstructionsRulesAE(t *testing.T) { // A-NZ documents get their own rule for the same case, not the AE one. err = rules.Validate(instr, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) require.Error(t, err) - assert.NotContains(t, err.Error(), "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-02") + assert.NotContains(t, err.Error(), "GOBL-PEPPOL-PINT-PAY-INSTRUCTIONS-03") }) } diff --git a/addon/pint/pint.go b/addon/pint/pint.go index eabc96e..dd896e1 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -44,6 +44,10 @@ func init() { taxComboRules(), taxCategoryTotalRules(), taxIdentityRules(), + orgPartyRules(), + orgAddressRules(), + orgItemRules(), + orgIdentityRules(), payInstructionsRules(), creditTransferRules(), ) @@ -83,35 +87,8 @@ func newV1Addon() *tax.AddonDef { Jurisdiction-specific requirements are applied according to the document's tax regime: Australian and New Zealand documents are also - validated against the PINT A-NZ rules; and UAE documents are validated against the PINT AE rules. - - UAE documents out of scope of VAT use the "outside-tax-scope" tag, which - sets the document type to 480 on invoices and 81 on credit notes. - - UAE documents can only be invoices and credit notes, without the - "partial", "prepayment" or "factoring" tags, as PINT AE has no - document type for anything else. Their currency can have two - decimals at most. - - UAE trade licences carry their issuing authority in the description, - and passports their issuing country. - - The supplier's and customer's UAE identities without a scope get the - one PINT AE reads them from: "legal" for the first trade licence, - Emirates ID, passport or Cabinet Decision of a party that has no legal - identity yet, and "tax" for the supplier's TIN. - - UAE invoices get the PINT AE transaction type from their tags: - "free-trade-zone", "deemed-supply", "margin-scheme", "summary", - "continuous-supply", "disclosed-agent", "e-commerce" and "export". - - A UAE supply under the profit margin scheme takes the regime's - "margin-scheme" tag, with the "exempt" VAT key on every line. Issue - one invoice per sale, with no other VAT treatments and no - document-level discounts or charges. The lines get the PINT AE - category "N", written at 5% with no VAT amount, and the regime's - statement goes out as the VAT exemption reason of the "N" breakdown. - The margin VAT is reported in the VAT return. + validated against the PINT A-NZ rules, and UAE documents against the + PINT AE rules. `), }, Sources: []*cbc.Source{ diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index a929565..25df2e3 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -66,9 +66,9 @@ func normalizeTaxCombo(tc *tax.Combo) { // exempt VAT lines of a UAE margin scheme invoice. The line combos already have // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the -// discount and charge rules 02 and rule 48 reject them (IBR-114-AE, +// discount and charge rules 01 and invoice rule 44 reject them (IBR-114-AE, // IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real -// exempt supply, so they keep E and rule 48 rejects the mixed invoice. +// exempt supply, so they keep E and invoice rule 44 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return @@ -161,6 +161,17 @@ func taxComboRules() *rules.Set { ), ), ), + + // Lines, discounts and charges alike: the margin scheme lines have + // the category N instead of E, so they need none. + rules.When( + is.Func("exempt VAT", comboIsExemptVAT), + rules.Field("ext", + rules.Assert("06", "exempt VAT needs a UAE VAT exemption reason (IBR-167-AE, IBR-168-AE, IBR-169-AE)", + tax.ExtensionsRequire(ExtKeyExemption), + ), + ), + ), ), ) } diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index ce32d05..136f894 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -170,8 +170,11 @@ func TestTaxComboRulesAE(t *testing.T) { "O": tax.KeyOutsideScope, "AE": tax.KeyReverseCharge, } { - err := validateIn(vatCombo(key, cat, nil), ae) - assert.NoError(t, err, "category %s", cat) + c := vatCombo(key, cat, nil) + if cat == "E" { + c.Ext = c.Ext.Set(pint.ExtKeyExemption, "DL8.46.1") + } + assert.NoError(t, validateIn(c, ae), "category %s", cat) } assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index 0809f8a..383b22d 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -110,15 +110,6 @@ func transactionTypeFromTags(inv *bill.Invoice) TransactionType { return t } -// invoiceTransactionType returns the parsed transaction type of an invoice. -func invoiceTransactionType(val any) TransactionType { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return TransactionType{} - } - return ParseTransactionType(inv.Tax.GetExt(ExtKeyTransactionType)) -} - // normalizeTransactionType sets the transaction type of a UAE invoice from its // flag tags, "00000000" without any. Every PINT AE document needs one // (IBR-154-AE). The tags are the only source: a code from an earlier @@ -173,25 +164,13 @@ var transactionTypeTags = []*cbc.Definition{ }, } -// transactionTypeIs returns a predicate that reports whether an invoice's -// transaction type has the flag that check reads. -func transactionTypeIs(check func(TransactionType) bool) func(any) bool { +// invoiceHasTags returns a predicate that reports whether an invoice has all +// the tags. The transaction type rules read the flags from the tags, which +// the transaction type is built from (normalizeTransactionType) and the UBL +// import sets from it. +func invoiceHasTags(keys ...cbc.Key) func(any) bool { return func(val any) bool { - return check(invoiceTransactionType(val)) + inv, ok := val.(*bill.Invoice) + return ok && inv != nil && inv.HasTags(keys...) } } - -var ( - invoiceIsFreeTradeZone = transactionTypeIs(func(t TransactionType) bool { return t.FreeTradeZone }) - invoiceIsDeemedSupply = transactionTypeIs(func(t TransactionType) bool { return t.DeemedSupply }) - invoiceIsSummary = transactionTypeIs(func(t TransactionType) bool { return t.Summary }) - invoiceIsDisclosedAgent = transactionTypeIs(func(t TransactionType) bool { return t.DisclosedAgent }) - invoiceIsECommerce = transactionTypeIs(func(t TransactionType) bool { return t.ECommerce }) - invoiceIsExport = transactionTypeIs(func(t TransactionType) bool { return t.Export }) - invoiceIsMarginScheme = transactionTypeIs(func(t TransactionType) bool { return t.MarginScheme }) - // invoiceIsSummaryDeemedOrMargin reports the flags outside scope documents - // and credit notes related to goods and services can't have (IBR-157-AE). - invoiceIsSummaryDeemedOrMargin = transactionTypeIs(func(t TransactionType) bool { - return t.Summary || t.DeemedSupply || t.MarginScheme - }) -) diff --git a/ubl/ae.go b/ubl/ae.go index a75e990..9bcfe66 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -43,7 +43,6 @@ const aedTotalDocumentType = "aedtotal-incl-vat" // charges one above 0 (aligned-ibrp-ae-06, aligned-ibrp-ae-07). const aeStandardRate = "5" - // accountSchemeIBAN is the scheme PINT AE gives the ID of an IBAN account // (IBT-084-1), as the official examples do. const accountSchemeIBAN = "IBAN" @@ -687,6 +686,10 @@ func exportAELineItemType(line *goblubl.InvoiceLine, l *bill.Line) { // code (IBT-158-2), or as @schemeVersionID on their additional item // identification (BTAE-17-2), which is where the service accounting codes are // by now. +// +// TODO: IBT-158-2 is an EN 16931 term (BT-158-2), but its value is held in a +// PINT AE extension and only FormatAE writes it, so other formats drop it on +// export. Move it into gobl.ubl with a generic extension. func exportAELineSchemeVersions(line *goblubl.InvoiceLine, l *bill.Line) { if l == nil || l.Item == nil || line.Item == nil { return @@ -1070,7 +1073,7 @@ func exportAELine(line *goblubl.InvoiceLine) { // document currency check as amounts in the tax currency, which IBR-140-AE // fixes to AED. No test checks their currency, and the official exports in // USD write them in AED too. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-28), they stay in the document currency. +// (GOBL-PEPPOL-PINT-BILL-INVOICE-23), they stay in the document currency. // // GOBL keeps no VAT per line, so it is the line total at the line's rate, // rounded to the document currency, then converted. Exempt lines get no VAT @@ -1124,7 +1127,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-28) with at most 6 decimals (-29). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-23) with at most 6 decimals (-24). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return @@ -1240,10 +1243,6 @@ func exportAEPartyIdentities(out *goblubl.Party, p *org.Party) { exportAETINIdentification(out) } -// identitySchemeTIN is the ISO 6523 ICD of the UAE TIN, the scheme of UAE -// Peppol endpoints too. -const identitySchemeTIN = "0235" - // exportAETINIdentification writes the scheme of a TIN identity in // cac:PartyIdentification as its ISO 6523 ICD, 0235. gobl.ubl writes the // identity's type, TIN, which is not an ICD (ibr-cl-10). @@ -1251,7 +1250,7 @@ func exportAETINIdentification(out *goblubl.Party) { for i := range out.PartyIdentification { id := out.PartyIdentification[i].ID if id != nil && id.SchemeID != nil && *id.SchemeID == ae.IdentityTypeTIN.String() { - scheme := identitySchemeTIN + scheme := ae.TINScheme.String() id.SchemeID = &scheme } } @@ -1327,7 +1326,7 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { // A cac:PartyIdentification with the scheme 0235 is a TIN, which export // writes with that scheme. for _, id := range p.Identities { - if id != nil && id.Scope == "" && id.Ext.Get(iso.ExtKeySchemeID) == identitySchemeTIN { + if id != nil && id.Scope == "" && id.Ext.Get(iso.ExtKeySchemeID) == ae.TINScheme { id.Type = ae.IdentityTypeTIN id.Ext = id.Ext.Delete(iso.ExtKeySchemeID) } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index efff076..d540a9a 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2efb95563815d20be7d39ea1abff4b5aeb1ea01e3234a449731ef9bdd2320646" + "val": "a3f7cf956a8dc25227ae11efe23cc96474566e24f9d0b51395e5a8294f2efcf1" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -167,6 +167,7 @@ "street": "Baniyas Road", "street_extra": "Deira", "locality": "Dubai", + "region": "DXB", "code": "777", "country": "AE" } diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 41a9812..32b080f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -90,6 +90,7 @@ Deira Dubai 777 + DXB AE From f35d31c75a732a5e9c8391d07126c200e86703bd Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:47:01 +0000 Subject: [PATCH 61/73] Pin gobl and gobl.ubl to the PR heads gobl moves to the AE regime PR head (gobl#1033), which now exports the TIN and TRN patterns and the TIN scheme, and builds on the EN 16931 PR (gobl#1040) without the third address line. gobl.ubl moves to the PINT AE elements PR head (gobl.ubl#189), which no longer writes the third address line. Co-Authored-By: Claude Opus 5.5 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 65efc86..fbd0272 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139 + github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 + github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index e428233..b83e019 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139 h1:8YY/Iz2KQCO19UkFHxAi8IxgnMYw8zAWRxM0ieSRQ5s= -github.com/invopop/gobl v0.512.1-0.20261117162429-3575f3c57139/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 h1:xHvbve38r6TPvdquEJ0lJwPlqIU/6XCBJdACDTX1E+k= +github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953 h1:aQOFvtQ78M5L0ZJdTNQbXvI5mmkhsSTCmOsPf/L5hCI= -github.com/invopop/gobl.ubl v0.101.1-0.20261117094025-0dd63c9c8953/go.mod h1:uqsLL8vsbuTmsMJCqDifWxlxQaH+E1cmpV1UF13QIfc= +github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761 h1:fRKXWXrItcaYSvYVXzUBCNenGpEVahAI/CF93gBJYwM= +github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From 4e1b462db37701d60d15440c3bf0056724ef1f5a Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:49:47 +0000 Subject: [PATCH 62/73] Run the schematron validation on phorm 2.2.15 phorm 2.2.15 (phive-rules 4.7.1) is the first release with the PINT AE 1.0.5 rules, the 2026.11 VESIDs FormatAE validates against. It also has PINT and A-NZ 1.1.3. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0d3d4af..0d7a21e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,7 +34,7 @@ jobs: # fixtures. services: phorm: - image: phelger/phorm:2.2.14 + image: phelger/phorm:2.2.15 ports: - 8080:8080 From 7552b9a3bab1205910cf29073fd6ecd5971df55b Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:59:40 +0000 Subject: [PATCH 63/73] Rework the PINT AE extensions Fourteen extensions down to five: transaction type, beneficiary ID, principal ID, credit note reason and goods type, each required by a rule. - The VAT exemption reason goes in cef-vatex instead of its own extension. GOBL doesn't check its values, and gobl.ubl already writes it on the discounts, charges and VAT breakdowns. A new rule (tax combo 07) only takes the four UAE codes, DL8.46.1 to DL8.46.4: Article 46 of the UAE VAT Decree-Law allows no other exempt supplies, though the Schematron doesn't check the list. - The contract value is the contract's description, written for FormatAE only. gobl.ubl already reads it back as the description. - Dropped as optional with no rule, and not on the Ministry of Finance's list of mandatory fields: the customs reference (BTAE-21), batch number (BTAE-24), line purchase order (IBT-183), line despatch advice (IBT-184), remittance scheme (IBT-083-1), billing frequency (IBT-008; a note can carry it) and scheme version (IBT-158-2, BTAE-17-2). Summary invoices now need the ordering period (IBR-138-AE), in two rules. - The item type (GOBL's item key) and the Incoterms (GOBL's ICC extensions) stay mapped, as they are GOBL data. Co-Authored-By: Claude Opus 5.5 --- README.md | 34 +- addon/pint/bill.go | 80 ++--- addon/pint/bill_test.go | 110 +++---- addon/pint/extensions.go | 200 ------------ addon/pint/tax_combo.go | 31 +- addon/pint/tax_combo_test.go | 3 +- ubl/ae.go | 290 ++---------------- ubl/ae_internal_test.go | 259 +--------------- .../pint/ae/invoice-ae-continuous-supply.json | 3 +- .../convert/pint/ae/invoice-ae-exempt.json | 12 +- .../pint/ae/invoice-ae-export-summary.json | 8 +- .../convert/pint/ae/invoice-ae-usd.json | 16 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 13 +- .../ae/out/invoice-ae-continuous-supply.xml | 1 - .../pint/ae/out/invoice-ae-export-summary.xml | 8 - .../convert/pint/ae/out/invoice-ae-usd.xml | 5 +- .../convert/pint/ae/out/invoice-ae.xml | 14 +- .../parse/pint/ae/out/allowance-exempt.json | 8 +- .../parse/pint/ae/out/deemed-supply.json | 7 +- .../parse/pint/ae/out/reverse-charge.json | 7 +- .../pint/ae/out/supply-free-trade-zone.json | 7 +- 21 files changed, 173 insertions(+), 943 deletions(-) diff --git a/README.md b/README.md index b6e8aa2..536e91a 100644 --- a/README.md +++ b/README.md @@ -156,9 +156,8 @@ the trade licence authority (the identity's description) or the passport's issuing country, and the seller's TIN goes under the `TIN` tax scheme. It also writes the transaction type as `cbc:ProfileExecutionID`, with the free trade zone beneficiary and the disclosed agent's principal as the buyer and seller -parties, and the credit note reason as `cac:DiscrepancyResponse`, the billing -frequency in `cac:InvoicePeriod`, the UAE VAT exemption reason of exempt -lines, and each item's type of goods or services subject to the reverse charge +parties, and the credit note reason as `cac:DiscrepancyResponse`, the VAT exemption reason (`cef-vatex`, one of the UAE codes `DL8.46.1` to `DL8.46.4`) of +exempt lines, and each item's type of goods or services subject to the reverse charge as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed `goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and identities labelled `SAC` are written as service accounting codes. The @@ -185,35 +184,24 @@ Without the tag, `exempt` lines are a normal exempt supply (`E`). Anyone reading GOBL data must identify margin scheme lines by the tag together with the `exempt` key, never by the key alone. -It also writes the PINT fields gobl.ubl leaves out: the issue time; the -customs reference number (`peppol-pint-ae-customs-reference`) as -`cac:StatementDocumentReference`; each contract's value -(`peppol-pint-ae-contract-value`); the `IBAN` scheme of the payee account -and the address of its branch; the scheme of the remittance reference -(`peppol-pint-ae-remittance-scheme`); the first due date's amount and date -as the payment terms, which refer to the payment instructions by the ID `1`; -each line's purchase order (`peppol-pint-ae-purchase-order`) and despatch -advice (`peppol-pint-ae-despatch-advice`), with `NA` as the line of either -when there is none; `cbc:TaxIncludedIndicator` as `false`; -the UAE VAT exemption reason of exempt discounts and charges; the tax note -of a line's VAT category as its exemption reason text; each item's batch -number (`peppol-pint-ae-batch-number`) as its lot; and the scheme version -(`peppol-pint-ae-scheme-version`) of the item's classification and service -accounting codes. On import, it reads +It also writes the PINT fields gobl.ubl leaves out: the issue time; each +contract's description, where PINT AE puts the contract value; the `IBAN` +scheme of the payee account and the address of its branch; the first due +date's amount and date as the payment terms, which refer to the payment +instructions by the ID `1`; `cbc:TaxIncludedIndicator` as `false`; and the +tax note of a line's VAT category as its exemption reason text. On import, it reads the invoice UUID, the out-of-scope type codes 480 and 81 back as the `outside-tax-scope` tag, and the identity types, authorities, passport countries and seller TIN back as identity keys and fields, the transaction type back as its extension and -tags, and the credit note reason, billing frequency, line exemption +tags, and the credit note reason, line exemption reasons and item goods types back as their extensions, and the item types and service accounting codes back as item keys and identities, and the `N` category back as the `exempt` key with the `margin-scheme` tag, and the delivery terms back as the `icc-incoterms-2020` extension, and the seller and buyer electronic -addresses as endpoints, and the customs reference, discount and charge -exemption reasons, line exemption reason texts, batch numbers, scheme -versions, contract values, remittance reference schemes and line purchase -orders and despatch advices back as their extensions and tax notes. +addresses as endpoints, and the discount and charge exemption reasons and +line exemption reason texts back as their extensions and tax notes. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 57d7bea..50c024b 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -399,15 +399,22 @@ func billInvoiceRules() *rules.Set { ), rules.When( is.Func("summary invoice", invoiceHasTags(TagSummary)), - rules.Assert("45", "ordering period or billing frequency is required on summary invoices (IBR-138-AE)", - is.Func("has invoice period", invoiceHasInvoicePeriod), + rules.Field("ordering", + rules.Assert("45", "ordering is required on summary invoices (IBR-138-AE)", + is.Present, + ), + rules.Field("period", + rules.Assert("46", "ordering period is required on summary invoices (IBR-138-AE)", + is.Present, + ), + ), ), ), rules.When( is.Func("disclosed agent billing", invoiceHasTags(TagDisclosedAgent)), rules.Field("tax", rules.Field("ext", - rules.Assert("46", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("47", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), @@ -423,7 +430,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("47", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", + rules.Assert("48", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), ), ), @@ -440,11 +447,11 @@ func billInvoiceRules() *rules.Set { is.Func("export", invoiceHasTags(tax.TagExport)), ), rules.Field("delivery", - rules.Assert("48", "delivery is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("49", "delivery is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), rules.Field("receiver", - rules.Assert("49", "delivery receiver is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("50", "delivery receiver is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), rules.Field("addresses", - rules.Assert("50", "delivery address is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("51", "delivery address is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), ), ), ), @@ -456,13 +463,13 @@ func billInvoiceRules() *rules.Set { rules.Field("addresses", rules.Each( rules.Field("street", - rules.Assert("51", "e-commerce delivery address street is required (IBR-142-AE)", is.Present), + rules.Assert("52", "e-commerce delivery address street is required (IBR-142-AE)", is.Present), ), rules.Field("locality", - rules.Assert("52", "e-commerce delivery address city is required (IBR-142-AE)", is.Present), + rules.Assert("53", "e-commerce delivery address city is required (IBR-142-AE)", is.Present), ), rules.Field("region", - rules.Assert("53", "e-commerce delivery address region is required (IBR-142-AE)", is.Present), + rules.Assert("54", "e-commerce delivery address region is required (IBR-142-AE)", is.Present), ), ), ), @@ -482,13 +489,13 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.Func("UAE address", addressIsAE)), rules.Field("street", - rules.Assert("54", "export delivery address street is required (IBR-152-AE)", is.Present), + rules.Assert("55", "export delivery address street is required (IBR-152-AE)", is.Present), ), rules.Field("locality", - rules.Assert("55", "export delivery address city is required (IBR-152-AE)", is.Present), + rules.Assert("56", "export delivery address city is required (IBR-152-AE)", is.Present), ), rules.Field("region", - rules.Assert("56", "export delivery address region is required (IBR-152-AE)", is.Present), + rules.Assert("57", "export delivery address region is required (IBR-152-AE)", is.Present), ), ), ), @@ -507,7 +514,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("57", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("58", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has tax scope or unscoped identity", identitiesScopeIn(org.IdentityScopeTax, cbc.KeyEmpty)), ), ), @@ -523,7 +530,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("58", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("59", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), ), ), @@ -534,12 +541,9 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("59", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("60", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("60", "billing frequency must be from the frequency of billing code list (IBR-005-AE)", - tax.ExtensionHasValidCode(ExtKeyBillingFrequency), - ), rules.Assert("61", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), @@ -547,23 +551,16 @@ func billInvoiceRules() *rules.Set { is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), ), ), - // PINT AE writes the billing frequency where EN writes the VAT - // point date code (BT-8), cac:InvoicePeriod/cbc:DescriptionCode, - // and IBR-005-AE only accepts frequencies there. + // PINT AE uses the element EN writes the VAT point date code + // (BT-8) in, cac:InvoicePeriod/cbc:DescriptionCode, for the + // billing frequency, and IBR-005-AE only accepts frequencies + // there. rules.Field("point", - rules.Assert("63", "tax point must not be set, as its code goes where the billing frequency does (IBR-005-AE)", + rules.Assert("63", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", is.Not(is.Present), ), ), ), - rules.When( - is.Func("billing frequency is Others", invoiceExtIn(ExtKeyBillingFrequency, BillingFrequencyOthers)), - rules.Field("notes", - rules.Assert("64", "a note is required with the billing frequency Others (IBR-160-AE)", - is.Present, - ), - ), - ), // AE document type list // @@ -574,7 +571,7 @@ func billInvoiceRules() *rules.Set { // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", - rules.Assert("65", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("64", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), @@ -596,7 +593,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", - rules.Assert("66", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("65", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency decimals within the PINT precision", currencyHasPINTDecimals), ), ), @@ -604,7 +601,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), rules.Field("currency", - rules.Assert("66", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("65", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -618,7 +615,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("67", "PINT AE tags can only be used on UAE documents", + rules.Assert("66", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -908,19 +905,6 @@ func partyTaxIDIsNotVAT(p *org.Party) bool { return scheme != "" && scheme != tax.CategoryVAT } -// invoiceHasInvoicePeriod reports whether the invoice has what is written as -// cac:InvoicePeriod: an ordering period or a billing frequency. IBR-138-AE's -// text asks for the invoicing period, but its test only checks the element -// is there, so the frequency alone passes. -func invoiceHasInvoicePeriod(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return false - } - return (inv.Ordering != nil && inv.Ordering.Period != nil) || - inv.Tax.GetExt(ExtKeyBillingFrequency) != "" -} - // invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's // lines, discounts and charges is VAT under the profit margin scheme. func invoiceTaxesAreMarginScheme(val any) bool { diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 75ef037..f802c2e 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -7,6 +7,7 @@ import ( "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" @@ -457,7 +458,7 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" @@ -468,7 +469,7 @@ func TestBillDocumentRulesAE(t *testing.T) { faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -694,7 +695,7 @@ func TestBillDocumentRulesAE(t *testing.T) { } func TestBillCurrencyDecimalsRules(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" ae := func(cur currency.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) inv.Currency = cur @@ -983,18 +984,19 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultSummaryOrdering = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" - faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" - faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" - faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-54" - faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1067,16 +1069,13 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, inv)) }) - t.Run("summary invoice needs the ordering period or billing frequency (IBR-138-AE)", func(t *testing.T) { + t.Run("summary invoice needs the ordering period (IBR-138-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagSummary) + assert.Contains(t, aeFaults(t, inv), faultSummaryOrdering) + inv.Ordering = &bill.Ordering{Code: "PO-1"} assert.Contains(t, aeFaults(t, inv), faultSummaryPeriod) start, end := cal.MakeDate(2026, 10, 1), cal.MakeDate(2026, 10, 31) - inv.Ordering = &bill.Ordering{Period: &cal.Period{Start: &start, End: &end}} - assert.Empty(t, aeFaults(t, inv)) - - // The billing frequency alone is written as cac:InvoicePeriod too. - inv = aeDocument(bill.InvoiceTypeStandard, pint.TagSummary) - setExt(inv, pint.ExtKeyBillingFrequency, "MTH") + inv.Ordering.Period = &cal.Period{Start: &start, End: &end} assert.Empty(t, aeFaults(t, inv)) }) @@ -1192,7 +1191,7 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1251,82 +1250,49 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { }) } -func TestBillBillingFrequencyRulesAE(t *testing.T) { - const ( - faultFrequencyCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" - faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" - faultOthersNote = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" - ) - withFrequency := func(code cbc.Code) *bill.Invoice { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBillingFrequency: code})} - return inv - } - - t.Run("frequency must be from the code list (IBR-005-AE)", func(t *testing.T) { - for _, code := range []cbc.Code{"DLY", "WKY", "Q15", "MTH", "Q45", "Q60", "QTR", "YRL", "HYR"} { - assert.Empty(t, aeFaults(t, withFrequency(code)), code) - } - assert.Contains(t, aeFaults(t, withFrequency("FTN")), faultFrequencyCode) - }) - - t.Run("Others needs a note (IBR-160-AE)", func(t *testing.T) { - inv := withFrequency(pint.BillingFrequencyOthers) - assert.Contains(t, aeFaults(t, inv), faultOthersNote) - inv.Notes = []*org.Note{{Text: "Every 3 weeks"}} - assert.Empty(t, aeFaults(t, inv)) - }) - - t.Run("tax point can't be set, as it would take the frequency's place (IBR-005-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Tax = &bill.Tax{Point: tax.PointIssue} - assert.Contains(t, aeFaults(t, inv), faultTaxPoint) - }) - - t.Run("tax point is fine outside the UAE", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) - inv.Tax = &bill.Tax{Point: tax.PointIssue} - require.NoError(t, inv.Calculate()) - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AU.Tax())) - if err != nil { - assert.NotContains(t, err.Error(), faultTaxPoint) - } - }) -} - func TestBillExemptionRulesAE(t *testing.T) { const ( faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" faultDiscountExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" faultChargeExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + faultExemptionCode = "GOBL-PEPPOL-PINT-TAX-COMBO-07" ) exempt := func(code cbc.Code) *tax.Combo { c := lineCombo(tax.KeyExempt) if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) } return c } - t.Run("exempt line needs a UAE exemption reason (IBR-167-AE)", func(t *testing.T) { + t.Run("exempt line needs an exemption reason (IBR-167-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Lines[0].Taxes = tax.Set{exempt("")} assert.Contains(t, aeFaults(t, inv), faultLineExemption) - // IBR-167-AE only checks a code is there, so codes outside the AE - // list are accepted. - for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4", "VATEX-AE-EDU"} { + for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4"} { inv = aeDocument(bill.InvoiceTypeStandard) inv.Lines[0].Taxes = tax.Set{exempt(code)} assert.NotContains(t, aeFaults(t, inv), faultLineExemption, code) } }) + t.Run("exemption reason must be a UAE one", func(t *testing.T) { + for _, code := range []cbc.Code{"DL8.46.5", "VATEX-EU-132"} { + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{exempt(code)} + assert.Contains(t, aeFaults(t, inv), faultExemptionCode, code) + } + inv := aeDocument(bill.InvoiceTypeStandard) + inv.Lines[0].Taxes = tax.Set{exempt("DL8.46.2")} + assert.NotContains(t, aeFaults(t, inv), faultExemptionCode) + }) + t.Run("other categories need no exemption reason", func(t *testing.T) { assert.NotContains(t, aeFaults(t, aeDocument(bill.InvoiceTypeStandard)), faultLineExemption) }) - t.Run("exempt discount needs a UAE exemption reason (IBR-168-AE)", func(t *testing.T) { + t.Run("exempt discount needs an exemption reason (IBR-168-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} inv.Discounts[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyAllowance: "95"}) @@ -1337,7 +1303,7 @@ func TestBillExemptionRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultDiscountExemption) }) - t.Run("exempt charge needs a UAE exemption reason (IBR-169-AE)", func(t *testing.T) { + t.Run("exempt charge needs an exemption reason (IBR-169-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} inv.Charges[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyCharge: "AAT"}) @@ -1466,7 +1432,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { // A line with a UAE exemption reason is a real exempt supply, not a // margin scheme one. inv = margin(pint.TagMarginScheme) - inv.Lines[0].Taxes[0].Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: "DL8.46.1"}) + inv.Lines[0].Taxes[0].Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: "DL8.46.1"}) assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) @@ -1480,7 +1446,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-67" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index afdaded..16f6ea1 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -5,10 +5,8 @@ import ( "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/i18n" "github.com/invopop/gobl/org" - "github.com/invopop/gobl/pay" "github.com/invopop/gobl/pkg/here" "github.com/invopop/gobl/regimes/ae" - "github.com/invopop/gobl/tax" ) // PINT AE extension keys, for the BTAE fields GOBL has no place for. @@ -23,44 +21,15 @@ const ( ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" // ExtKeyCreditNoteReason is the reason for a PINT AE credit note (BTAE-03). ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" - // ExtKeyBillingFrequency is the frequency of billing (IBT-008). - ExtKeyBillingFrequency cbc.Key = "peppol-pint-ae-billing-frequency" - // ExtKeyExemption is the UAE VAT exemption reason of an exempt tax combo - // (IBT-186 on lines, IBT-196 and IBT-198 on allowances and charges). - ExtKeyExemption cbc.Key = "peppol-pint-ae-exemption" // ExtKeyGoodsType is the type of goods or services subject to the reverse // charge mechanism, on the item (BTAE-09). ExtKeyGoodsType cbc.Key = "peppol-pint-ae-goods-type" - // ExtKeyCustomsReference is the customs reference number of an export or - // import (BTAE-21). - ExtKeyCustomsReference cbc.Key = "peppol-pint-ae-customs-reference" - // ExtKeyBatchNumber is the production batch or lot the items come from, - // on the item (BTAE-24). - ExtKeyBatchNumber cbc.Key = "peppol-pint-ae-batch-number" - // ExtKeySchemeVersion is the version of the scheme an item identity's code - // is from, such as an HS or SAC code (IBT-158-2, BTAE-17-2). - ExtKeySchemeVersion cbc.Key = "peppol-pint-ae-scheme-version" - // ExtKeyContractValue is the value of a contract, on its reference - // (BTAE-05). - ExtKeyContractValue cbc.Key = "peppol-pint-ae-contract-value" - // ExtKeyPurchaseOrder is the purchase order a line belongs to (IBT-183). - ExtKeyPurchaseOrder cbc.Key = "peppol-pint-ae-purchase-order" - // ExtKeyDespatchAdvice is the despatch advice a line was sent with - // (IBT-184). - ExtKeyDespatchAdvice cbc.Key = "peppol-pint-ae-despatch-advice" - // ExtKeyRemittanceScheme is the scheme of the payment instructions' - // remittance reference, such as "ABA" (IBT-083-1). - ExtKeyRemittanceScheme cbc.Key = "peppol-pint-ae-remittance-scheme" ) // CreditNoteReasonVolumeDiscount is the credit note reason for a volume // discount, the only one that needs no preceding invoice (IBR-055-AE). const CreditNoteReasonVolumeDiscount cbc.Code = "VD" -// BillingFrequencyOthers is the billing frequency "Others", whose value goes -// in an invoice note (IBR-160-AE). -const BillingFrequencyOthers cbc.Code = "OTH" - // Usages of the PINT AE extensions: offered by the PINT addon under the AE // regime, on the object each one goes on. var ( @@ -69,36 +38,11 @@ var ( Codes: []cbc.Code{ae.CountryCode}, Schemas: []string{bill.ShortSchemaTax}, } - usageAETaxCombo = &cbc.Usage{ - Keys: []cbc.Key{V1}, - Codes: []cbc.Code{ae.CountryCode}, - Schemas: []string{tax.ShortSchemaCombo}, - } usageAEItem = &cbc.Usage{ Keys: []cbc.Key{V1}, Codes: []cbc.Code{ae.CountryCode}, Schemas: []string{org.ShortSchemaItem}, } - usageAEIdentity = &cbc.Usage{ - Keys: []cbc.Key{V1}, - Codes: []cbc.Code{ae.CountryCode}, - Schemas: []string{org.ShortSchemaIdentity}, - } - usageAEDocumentRef = &cbc.Usage{ - Keys: []cbc.Key{V1}, - Codes: []cbc.Code{ae.CountryCode}, - Schemas: []string{org.ShortSchemaDocumentRef}, - } - usageAELine = &cbc.Usage{ - Keys: []cbc.Key{V1}, - Codes: []cbc.Code{ae.CountryCode}, - Schemas: []string{bill.ShortSchemaLine}, - } - usageAEInstructions = &cbc.Usage{ - Keys: []cbc.Key{V1}, - Codes: []cbc.Code{ae.CountryCode}, - Schemas: []string{pay.ShortSchemaInstructions}, - } ) // extensions are the extensions the PINT addon defines. They are only used @@ -207,60 +151,6 @@ var extensions = []*cbc.Definition{ }, }, }, - { - Key: ExtKeyBillingFrequency, - Usage: usageAEInvoiceTax, - Name: i18n.String{ - i18n.EN: "PINT AE: Frequency of Billing", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Frequency of billing (IBT-008), from the frequency of billing code list - (IBR-005-AE). With "OTH" (Others), the frequency is given in an invoice - note (IBR-160-AE). - `), - }, - Sources: []*cbc.Source{ - { - Title: i18n.NewString("PINT AE Frequency of billing codes"), - URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/codelist/FreqBilling/", - }, - }, - Values: []*cbc.Definition{ - {Code: "DLY", Name: i18n.String{i18n.EN: "Daily"}}, - {Code: "WKY", Name: i18n.String{i18n.EN: "Weekly"}}, - {Code: "Q15", Name: i18n.String{i18n.EN: "Once in 15 days"}}, - {Code: "MTH", Name: i18n.String{i18n.EN: "Monthly"}}, - {Code: "Q45", Name: i18n.String{i18n.EN: "Once in 45 days"}}, - {Code: "Q60", Name: i18n.String{i18n.EN: "Once in 60 days"}}, - {Code: "QTR", Name: i18n.String{i18n.EN: "Quarterly"}}, - {Code: "YRL", Name: i18n.String{i18n.EN: "Yearly"}}, - {Code: "HYR", Name: i18n.String{i18n.EN: "Half-Yearly"}}, - {Code: BillingFrequencyOthers, Name: i18n.String{i18n.EN: "Others"}}, - }, - }, - { - Key: ExtKeyExemption, - Usage: usageAETaxCombo, - Name: i18n.String{ - i18n.EN: "PINT AE: VAT Exemption Reason", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Reason a supply is exempt from UAE VAT, such as one of the PINT AE - "Reasons for exemption from tax" codes (DL8.46.1 to DL8.46.4). - Required on exempt lines (IBR-167-AE), discounts (IBR-168-AE) and - charges (IBR-169-AE), where it is written as their exemption reason - code. - `), - }, - Sources: []*cbc.Source{ - { - Title: i18n.NewString("PINT AE Reasons for exemption from tax"), - URL: "https://docs.peppol.eu/poac/ae/pint-ae/trn-invoice/codelist/Aligned-TaxExemptionCodes/", - }, - }, - }, { Key: ExtKeyGoodsType, Usage: usageAEItem, @@ -289,94 +179,4 @@ var extensions = []*cbc.Definition{ {Code: "DL8.48.3.3", Name: i18n.String{i18n.EN: "Pure hydrocarbons"}}, }, }, - { - Key: ExtKeyCustomsReference, - Usage: usageAEInvoiceTax, - Name: i18n.String{ - i18n.EN: "PINT AE: Customs Reference Number", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Customs reference number of an export or import transaction - (BTAE-21). - `), - }, - }, - { - Key: ExtKeyBatchNumber, - Usage: usageAEItem, - Name: i18n.String{ - i18n.EN: "PINT AE: Batch Number", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Production batch or lot the items come from (BTAE-24). - `), - }, - }, - { - Key: ExtKeySchemeVersion, - Usage: usageAEIdentity, - Name: i18n.String{ - i18n.EN: "PINT AE: Scheme Version", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Version of the scheme the code of an item identity is from, for the - item classifications and service accounting codes of an item - (IBT-158-2, BTAE-17-2). - `), - }, - }, - { - Key: ExtKeyContractValue, - Usage: usageAEDocumentRef, - Name: i18n.String{ - i18n.EN: "PINT AE: Contract Value", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Value of a contract, on its reference in the invoice's ordering - details, such as "AED 200000" (BTAE-05). - `), - }, - }, - { - Key: ExtKeyPurchaseOrder, - Usage: usageAELine, - Name: i18n.String{ - i18n.EN: "PINT AE: Line Purchase Order Reference", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Identifier of the purchase order a line belongs to, issued by the - buyer (IBT-183). The line's "order" is the line of that order. - `), - }, - }, - { - Key: ExtKeyDespatchAdvice, - Usage: usageAELine, - Name: i18n.String{ - i18n.EN: "PINT AE: Line Despatch Advice Reference", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Identifier of the despatch advice a line was sent with (IBT-184). - `), - }, - }, - { - Key: ExtKeyRemittanceScheme, - Usage: usageAEInstructions, - Name: i18n.String{ - i18n.EN: "PINT AE: Remittance Reference Scheme", - }, - Desc: i18n.String{ - i18n.EN: here.Doc(` - Scheme of the payment instructions' reference, the remittance - information, such as "ABA" (IBT-083-1). - `), - }, - }, } diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 25df2e3..996912d 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -3,6 +3,7 @@ package pint import ( "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/num" @@ -30,6 +31,17 @@ var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ tax.KeyOutsideScope: en16931.TaxCategoryOutsideScope, }) +// exemptionCodesAE are the UAE VAT exemption reasons PINT AE takes in the +// CEF VATEX extension: the four exempt supplies of Article 46 of the UAE VAT +// Decree-Law (Federal Decree-Law No. 8 of 2017), the only ones the law +// allows. +var exemptionCodesAE = []cbc.Code{ + "DL8.46.1", // certain financial services + "DL8.46.2", // residential buildings + "DL8.46.3", // bare land + "DL8.46.4", // local passenger transport +} + // taxCategoryCodesAUNZ lists the subset of UNTDID 5305 tax category codes // accepted by the A-NZ PINT specification. var taxCategoryCodesAUNZ = []cbc.Code{ @@ -67,7 +79,7 @@ func normalizeTaxCombo(tc *tax.Combo) { // E from their key, as norm reaches them before the invoice, and get it back // once the tag is removed. Discounts and charges are left alone, so the // discount and charge rules 01 and invoice rule 44 reject them (IBR-114-AE, -// IBR-115-AE, IBR-116-AE). Lines with a UAE exemption reason are a real +// IBR-115-AE, IBR-116-AE). Lines with an exemption reason are a real // exempt supply, so they keep E and invoice rule 44 rejects the mixed invoice. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { @@ -78,7 +90,7 @@ func normalizeMarginSchemeAE(inv *bill.Invoice) { continue } for _, c := range l.Taxes { - if c != nil && c.Category == tax.CategoryVAT && c.Key == tax.KeyExempt && !c.Ext.Has(ExtKeyExemption) { + if c != nil && c.Category == tax.CategoryVAT && c.Key == tax.KeyExempt && !c.Ext.Has(cef.ExtKeyVATEX) { c.Ext = c.Ext.Set(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme) } } @@ -167,8 +179,19 @@ func taxComboRules() *rules.Set { rules.When( is.Func("exempt VAT", comboIsExemptVAT), rules.Field("ext", - rules.Assert("06", "exempt VAT needs a UAE VAT exemption reason (IBR-167-AE, IBR-168-AE, IBR-169-AE)", - tax.ExtensionsRequire(ExtKeyExemption), + rules.Assert("06", "exempt VAT needs a VAT exemption reason (IBR-167-AE, IBR-168-AE, IBR-169-AE)", + tax.ExtensionsRequire(cef.ExtKeyVATEX), + ), + ), + ), + + // The UAE VAT law allows no other exemption reasons, though the + // Schematron doesn't check the code list. + rules.When( + is.Func("VAT", comboIsVAT), + rules.Field("ext", + rules.Assert("07", "VAT exemption reason must be a UAE one: DL8.46.1, DL8.46.2, DL8.46.3 or DL8.46.4", + tax.ExtensionsHasCodes(cef.ExtKeyVATEX, exemptionCodesAE...), ), ), ), diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index 136f894..e89fed4 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -6,6 +6,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/l10n" @@ -172,7 +173,7 @@ func TestTaxComboRulesAE(t *testing.T) { } { c := vatCombo(key, cat, nil) if cat == "E" { - c.Ext = c.Ext.Set(pint.ExtKeyExemption, "DL8.46.1") + c.Ext = c.Ext.Set(cef.ExtKeyVATEX, "DL8.46.1") } assert.NoError(t, validateIn(c, ae), "category %s", cat) } diff --git a/ubl/ae.go b/ubl/ae.go index 9bcfe66..4a303f0 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -9,6 +9,7 @@ import ( "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/icc" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" @@ -68,13 +69,10 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error out.Note = aeJoinNotes(out.Note) exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) - exportAEBillingFrequency(out, inv) exportAEIncoterms(out, inv) exportAEDeliveryPartyID(out, inv) - exportAECustomsReference(out, inv) exportAEContractValue(out, inv) exportAEPayment(out, inv) - exportAEChargeExemptions(out, inv) exportAEChargeRates(out) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) @@ -102,12 +100,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAEMarginScheme(inv) importAETransactionType(in, inv) importAECreditNoteReason(in, inv) - importAEBillingFrequency(in, inv) importAEIncoterms(in, inv) importAEDeliveryPartyID(in, inv) - importAECustomsReference(in, inv) - importAEContractValue(in, inv) - importAERemittanceScheme(in, inv) importAEChargeExemptions(in, inv) importAELineExemptions(in.InvoiceLines, inv) importAELineExemptions(in.CreditNoteLines, inv) @@ -115,8 +109,6 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error importAELineGoods(in.CreditNoteLines, inv) importAELineItems(in.InvoiceLines, inv) importAELineItems(in.CreditNoteLines, inv) - importAELineReferences(in.InvoiceLines, inv) - importAELineReferences(in.CreditNoteLines, inv) importAEPartyIdentities(in.AccountingSupplierParty.Party, inv.Supplier, true) importAEPartyIdentities(in.AccountingCustomerParty.Party, inv.Customer, false) importAEPartyEndpoint(in.AccountingSupplierParty.Party, inv.Supplier) @@ -218,29 +210,11 @@ func exportAEIssueTime(out *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAECustomsReference writes the customs reference number as -// cac:StatementDocumentReference/cbc:ID (BTAE-21). -func exportAECustomsReference(out *goblubl.Invoice, inv *bill.Invoice) { - if ref := inv.Tax.GetExt(pint.ExtKeyCustomsReference); ref != "" { - out.StatementDocumentReference = []goblubl.Reference{ - {ID: goblubl.IDType{Value: ref.String()}}, - } - } -} - -// importAECustomsReference reads the first customs reference number back. -func importAECustomsReference(in *goblubl.Invoice, inv *bill.Invoice) { - for _, r := range in.StatementDocumentReference { - if ref := cbc.Code(strings.TrimSpace(r.ID.Value)); ref != "" { - setAEExt(inv, pint.ExtKeyCustomsReference, ref) - return - } - } -} - -// exportAEContractValue writes the value of each contract as -// cac:ContractDocumentReference/cbc:DocumentDescription (BTAE-05), on the -// references gobl.ubl writes in the same order as the invoice's contracts. +// exportAEContractValue writes the description of each contract, where PINT +// AE puts the contract value, as cac:ContractDocumentReference/ +// cbc:DocumentDescription (BTAE-05), on the references gobl.ubl writes in the +// same order as the invoice's contracts. gobl.ubl already reads it back as the +// description. func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Ordering == nil || len(inv.Ordering.Contracts) != len(out.ContractDocumentReference) { return @@ -249,24 +223,7 @@ func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { if c == nil { continue } - if v := c.Ext.Get(pint.ExtKeyContractValue); v != "" { - out.ContractDocumentReference[i].DocumentDescription = v.String() - } - } -} - -// importAEContractValue reads the value of each contract back, which gobl.ubl -// imports as the description of the contract. -func importAEContractValue(in *goblubl.Invoice, inv *bill.Invoice) { - if inv.Ordering == nil || len(inv.Ordering.Contracts) != len(in.ContractDocumentReference) { - return - } - for i, r := range in.ContractDocumentReference { - c := inv.Ordering.Contracts[i] - if v := cbc.Code(strings.TrimSpace(r.DocumentDescription)); c != nil && v != "" { - c.Ext = c.Ext.Set(pint.ExtKeyContractValue, v) - c.Description = "" - } + out.ContractDocumentReference[i].DocumentDescription = c.Description } } @@ -278,9 +235,6 @@ func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { } pm := &out.PaymentMeans[0] if instr := inv.Payment.Instructions; instr != nil { - if scheme := instr.Ext.Get(pint.ExtKeyRemittanceScheme).String(); scheme != "" && pm.PaymentID != nil { - pm.PaymentID.SchemeID = &scheme - } if len(instr.CreditTransfer) > 0 { exportAECreditTransfer(pm.PayeeFinancialAccount, instr.CreditTransfer[0]) } @@ -288,22 +242,6 @@ func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { exportAEPaymentTerms(out, pm, inv) } -// importAERemittanceScheme reads the scheme of the remittance reference back -// (IBT-083-1). -func importAERemittanceScheme(in *goblubl.Invoice, inv *bill.Invoice) { - if len(in.PaymentMeans) == 0 || inv.Payment == nil || inv.Payment.Instructions == nil { - return - } - id := in.PaymentMeans[0].PaymentID - if id == nil || id.SchemeID == nil { - return - } - if scheme := cbc.Code(strings.TrimSpace(*id.SchemeID)); scheme != "" { - instr := inv.Payment.Instructions - instr.Ext = instr.Ext.Set(pint.ExtKeyRemittanceScheme, scheme) - } -} - // exportAECreditTransfer writes the IBAN scheme of the payee account // (IBT-084-1) and the address of its branch (IBT-169 to IBT-175). // gobl.ubl already reads the address back. @@ -377,41 +315,6 @@ func exportAEPaymentTerms(out *goblubl.Invoice, pm *goblubl.PaymentMeans, inv *b out.PaymentTerms.InstallmentDueDate = dd.Date.String() } -// aeChargeTaxes provides the taxes of the invoice's charges and discounts, in -// the order gobl.ubl writes their cac:AllowanceCharge. -func aeChargeTaxes(inv *bill.Invoice) []tax.Set { - sets := make([]tax.Set, 0, len(inv.Charges)+len(inv.Discounts)) - for _, c := range inv.Charges { - sets = append(sets, c.Taxes) - } - for _, d := range inv.Discounts { - sets = append(sets, d.Taxes) - } - return sets -} - -// exportAEChargeExemptions writes the UAE VAT exemption reason of the exempt -// charges and discounts as their cac:TaxCategory/cbc:TaxExemptionReasonCode -// (IBT-196, IBT-198). -func exportAEChargeExemptions(out *goblubl.Invoice, inv *bill.Invoice) { - sets := aeChargeTaxes(inv) - if len(sets) != len(out.AllowanceCharge) { - return - } - for i, set := range sets { - cats := out.AllowanceCharge[i].TaxCategory - if len(cats) != len(set) { - continue - } - for j, c := range set { - if code := c.Ext.Get(pint.ExtKeyExemption); code != "" && c.Category == tax.CategoryVAT { - v := code.String() - cats[j].TaxExemptionReasonCode = &v - } - } - } -} - // exportAEChargeRates writes the rate of the reverse charge allowances and // charges at 5, as PINT AE wants one above 0 (aligned-ibrp-ae-06, // aligned-ibrp-ae-07) and gobl.ubl writes 0. Exempt ones keep the 0 PINT AE @@ -429,8 +332,10 @@ func exportAEChargeRates(out *goblubl.Invoice) { } // importAEChargeExemptions reads the exemption reasons of the charges and -// discounts back onto their VAT combos. gobl.ubl imports the charges and the -// discounts apart, each in the order of the document. +// discounts back onto their VAT combos, from their own cac:TaxCategory: +// gobl.ubl takes them from the VAT breakdown, which only keeps the reasons +// all its charges, discounts and lines share. gobl.ubl imports the charges +// and the discounts apart, each in the order of the document. func importAEChargeExemptions(in *goblubl.Invoice, inv *bill.Invoice) { if len(in.AllowanceCharge) != len(inv.Charges)+len(inv.Discounts) { return @@ -454,7 +359,7 @@ func importAEChargeExemptions(in *goblubl.Invoice, inv *bill.Invoice) { continue } if code := cbc.Code(strings.TrimSpace(*cat.TaxExemptionReasonCode)); code != "" { - c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + c.Ext = c.Ext.Set(cef.ExtKeyVATEX, code) break } } @@ -538,7 +443,7 @@ func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAELineExemption writes the UAE VAT exemption reason of an exempt line +// exportAELineExemption writes the VAT exemption reason of an exempt line // as its cac:ClassifiedTaxCategory/cbc:TaxExemptionReasonCode (IBT-186, // IBR-167-AE), and the text of the invoice's tax note for the line's VAT // category as its cbc:TaxExemptionReason (IBT-185), the same note gobl.ubl @@ -552,7 +457,7 @@ func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line, tx *bill.Tax return } ctc := line.Item.ClassifiedTaxCategory - if code := c.Ext.Get(pint.ExtKeyExemption); code != "" { + if code := c.Ext.Get(cef.ExtKeyVATEX); code != "" { v := code.String() ctc.TaxExemptionReasonCode = &v } @@ -595,7 +500,7 @@ func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { ctc := line.Item.ClassifiedTaxCategory if ctc.TaxExemptionReasonCode != nil { if code := cbc.Code(strings.TrimSpace(*ctc.TaxExemptionReasonCode)); code != "" { - c.Ext = c.Ext.Set(pint.ExtKeyExemption, code) + c.Ext = c.Ext.Set(cef.ExtKeyVATEX, code) } } if ctc.TaxExemptionReason == nil || strings.TrimSpace(*ctc.TaxExemptionReason) == "" { @@ -681,105 +586,7 @@ func exportAELineItemType(line *goblubl.InvoiceLine, l *bill.Line) { } } -// exportAELineSchemeVersions writes the scheme version of the item's -// identities that have one: as @listVersionID on their item classification -// code (IBT-158-2), or as @schemeVersionID on their additional item -// identification (BTAE-17-2), which is where the service accounting codes are -// by now. -// -// TODO: IBT-158-2 is an EN 16931 term (BT-158-2), but its value is held in a -// PINT AE extension and only FormatAE writes it, so other formats drop it on -// export. Move it into gobl.ubl with a generic extension. -func exportAELineSchemeVersions(line *goblubl.InvoiceLine, l *bill.Line) { - if l == nil || l.Item == nil || line.Item == nil { - return - } - for _, id := range l.Item.Identities { - if id == nil || id.Label == "" || id.Ext.Get(pint.ExtKeySchemeVersion) == "" { - continue - } - version := id.Ext.Get(pint.ExtKeySchemeVersion).String() - if line.Item.CommodityClassification != nil { - for _, cc := range *line.Item.CommodityClassification { - if c := cc.ItemClassificationCode; c != nil && c.ListID != nil && *c.ListID == id.Label && c.Value == id.Code.String() { - c.ListVersionID = &version - } - } - } - for _, ai := range line.Item.AdditionalItemIdentification { - if ai.ID != nil && ai.ID.SchemeID != nil && *ai.ID.SchemeID == id.Label && ai.ID.Value == id.Code.String() { - ai.ID.SchemeVersionID = &version - } - } - } -} - -// exportAELineBatch writes the item's batch number as its -// cac:ItemInstance/cac:LotIdentification/cbc:LotNumberID (BTAE-24). -func exportAELineBatch(line *goblubl.InvoiceLine, l *bill.Line) { - if l == nil || l.Item == nil || line.Item == nil { - return - } - if batch := l.Item.Ext.Get(pint.ExtKeyBatchNumber); batch != "" { - line.Item.ItemInstance = []goblubl.ItemInstance{ - {LotIdentification: &goblubl.LotIdentification{LotNumberID: batch.String()}}, - } - } -} - -// aeNoLineID stands for the line of an order or despatch advice when only -// the document is known, as UBL needs a line ID in a line reference. -const aeNoLineID = "NA" - -// exportAELineReferences writes the purchase order of a line as -// cac:OrderLineReference/cac:OrderReference/cbc:ID (IBT-183), next to the -// order line gobl.ubl writes, and its despatch advice as -// cac:DespatchLineReference/cac:DocumentReference/cbc:ID (IBT-184). -func exportAELineReferences(line *goblubl.InvoiceLine, l *bill.Line) { - if l == nil { - return - } - if po := l.Ext.Get(pint.ExtKeyPurchaseOrder); po != "" { - if line.OrderLineReference == nil { - line.OrderLineReference = &goblubl.OrderLineReference{LineID: aeNoLineID} - } - line.OrderLineReference.OrderReference = &goblubl.OrderReference{ID: po.String()} - } - if da := l.Ext.Get(pint.ExtKeyDespatchAdvice); da != "" { - line.DespatchLineReference = &goblubl.LineReference{ - LineID: aeNoLineID, - DocumentReference: &goblubl.Reference{ID: goblubl.IDType{Value: da.String()}}, - } - } -} - -// importAELineReferences reads the purchase order and despatch advice of each -// line back, on the lines gobl.ubl imports in the same order. An order line -// that only stands in for a missing one is dropped. -func importAELineReferences(lines []goblubl.InvoiceLine, inv *bill.Invoice) { - if len(lines) != len(inv.Lines) { - return - } - for i, line := range lines { - l := inv.Lines[i] - if ref := line.OrderLineReference; ref != nil && ref.OrderReference != nil { - if po := cbc.Code(strings.TrimSpace(ref.OrderReference.ID)); po != "" { - l.Ext = l.Ext.Set(pint.ExtKeyPurchaseOrder, po) - if l.Order == aeNoLineID { - l.Order = "" - } - } - } - if ref := line.DespatchLineReference; ref != nil && ref.DocumentReference != nil { - if da := cbc.Code(strings.TrimSpace(ref.DocumentReference.ID.Value)); da != "" { - l.Ext = l.Ext.Set(pint.ExtKeyDespatchAdvice, da) - } - } - } -} - -// importAELineGoods reads the type of goods or services and the batch number -// back onto the items of the invoice's lines, which gobl.ubl imports in the +// importAELineGoods reads the type of goods or services back onto the items of the invoice's lines, which gobl.ubl imports in the // same order. gobl.ubl already reads the GTIN as an identity. func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { @@ -789,15 +596,6 @@ func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if line.Item == nil || inv.Lines[i].Item == nil { continue } - for _, ii := range line.Item.ItemInstance { - if ii.LotIdentification == nil { - continue - } - if batch := cbc.Code(strings.TrimSpace(ii.LotIdentification.LotNumberID)); batch != "" { - inv.Lines[i].Item.Ext = inv.Lines[i].Item.Ext.Set(pint.ExtKeyBatchNumber, batch) - break - } - } if line.Item.CommodityClassification == nil { continue } @@ -813,10 +611,9 @@ func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// importAELineItems reads back what exportAELineSAC, exportAELineItemType and -// exportAELineSchemeVersions write: the service accounting codes as -// identities with their scheme as label, the item type as the item's key, and -// the scheme versions on the identities of their codes. +// importAELineItems reads back what exportAELineSAC and exportAELineItemType +// write: the service accounting codes as identities with their scheme as +// label, and the item type as the item's key. func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return @@ -834,23 +631,11 @@ func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if ai.ID.SchemeID != nil { id.Label = strings.TrimSpace(*ai.ID.SchemeID) } - setAESchemeVersion(id, ai.ID.SchemeVersionID) it.Identities = append(it.Identities, id) } if line.Item.CommodityClassification == nil { continue } - for _, cc := range *line.Item.CommodityClassification { - c := cc.ItemClassificationCode - if c == nil || c.ListID == nil { - continue - } - for _, id := range it.Identities { - if id != nil && id.Label == strings.TrimSpace(*c.ListID) && id.Code.String() == c.Value { - setAESchemeVersion(id, c.ListVersionID) - } - } - } for _, cc := range *line.Item.CommodityClassification { if cc.CommodityCode == nil { continue @@ -863,40 +648,6 @@ func importAELineItems(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// setAESchemeVersion sets the scheme version of an item identity, when there -// is one. -func setAESchemeVersion(id *org.Identity, version *string) { - if version == nil || strings.TrimSpace(*version) == "" { - return - } - id.Ext = id.Ext.Set(pint.ExtKeySchemeVersion, cbc.Code(strings.TrimSpace(*version))) -} - -// exportAEBillingFrequency writes the billing frequency as -// cac:InvoicePeriod/cbc:DescriptionCode (IBT-008), on the period gobl.ubl -// writes from the ordering period, or on its own: IBR-CO-19 accepts a period -// with only a description code. -func exportAEBillingFrequency(out *goblubl.Invoice, inv *bill.Invoice) { - freq := inv.Tax.GetExt(pint.ExtKeyBillingFrequency) - if freq == "" { - return - } - if len(out.InvoicePeriod) == 0 { - out.InvoicePeriod = []goblubl.Period{{}} - } - out.InvoicePeriod[0].DescriptionCode = freq.String() -} - -// importAEBillingFrequency reads the billing frequency back. The frequency -// codes don't overlap the VAT point date codes gobl.ubl reads from the same -// element, so it never sets a tax point from them. -func importAEBillingFrequency(in *goblubl.Invoice, inv *bill.Invoice) { - if len(in.InvoicePeriod) == 0 { - return - } - setAEExt(inv, pint.ExtKeyBillingFrequency, cbc.Code(strings.TrimSpace(in.InvoicePeriod[0].DescriptionCode))) -} - // exportAEIncoterms writes the delivery's Incoterms rule code, from the ICC // Incoterms 2020 or 2010 extension, as cac:Delivery/cac:DeliveryTerms/cbc:ID // (BTAE-22) under the Incoterms scheme. @@ -1033,9 +784,6 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { exportAELineSAC(&lines[i]) exportAELineGoods(&lines[i], inv.Lines[i]) exportAELineItemType(&lines[i], inv.Lines[i]) - exportAELineSchemeVersions(&lines[i], inv.Lines[i]) - exportAELineBatch(&lines[i], inv.Lines[i]) - exportAELineReferences(&lines[i], inv.Lines[i]) } } } diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 3a2a720..e72061c 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -7,6 +7,7 @@ import ( goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/cal" + "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/icc" "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" @@ -613,44 +614,6 @@ func TestAECreditNoteReason(t *testing.T) { }) } -func TestAEBillingFrequency(t *testing.T) { - invoice := func(freq cbc.Code) *bill.Invoice { - return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBillingFrequency: freq})}} - } - - t.Run("writes the frequency on the ordering period", func(t *testing.T) { - out := &goblubl.Invoice{InvoicePeriod: []goblubl.Period{{StartDate: "2025-01-01", EndDate: "2025-01-31"}}} - exportAEBillingFrequency(out, invoice("MTH")) - require.Len(t, out.InvoicePeriod, 1) - assert.Equal(t, "MTH", out.InvoicePeriod[0].DescriptionCode) - assert.Equal(t, "2025-01-01", out.InvoicePeriod[0].StartDate) - }) - - t.Run("writes a period of its own without an ordering period", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEBillingFrequency(out, invoice("QTR")) - require.Len(t, out.InvoicePeriod, 1) - assert.Equal(t, "QTR", out.InvoicePeriod[0].DescriptionCode) - }) - - t.Run("nothing without a frequency", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEBillingFrequency(out, new(bill.Invoice)) - assert.Empty(t, out.InvoicePeriod) - }) - - t.Run("reads the frequency back", func(t *testing.T) { - in := &goblubl.Invoice{InvoicePeriod: []goblubl.Period{{DescriptionCode: " OTH "}}} - inv := new(bill.Invoice) - importAEBillingFrequency(in, inv) - assert.Equal(t, cbc.Code("OTH"), inv.Tax.GetExt(pint.ExtKeyBillingFrequency)) - - inv = new(bill.Invoice) - importAEBillingFrequency(new(goblubl.Invoice), inv) - assert.Nil(t, inv.Tax) - }) -} - func TestAELineExemption(t *testing.T) { ublLine := func() goblubl.InvoiceLine { return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ @@ -660,7 +623,7 @@ func TestAELineExemption(t *testing.T) { goblLine := func(code cbc.Code) *bill.Line { c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) } return &bill.Line{Taxes: tax.Set{c}} } @@ -686,8 +649,8 @@ func TestAELineExemption(t *testing.T) { with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} importAELineExemptions([]goblubl.InvoiceLine{ublLine(), with}, inv) - assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) - assert.Equal(t, cbc.Code("DL8.46.4"), inv.Lines[1].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) + assert.Equal(t, cbc.Code("DL8.46.4"), inv.Lines[1].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) }) t.Run("lines that don't match are skipped", func(t *testing.T) { @@ -696,7 +659,7 @@ func TestAELineExemption(t *testing.T) { with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} importAELineExemptions([]goblubl.InvoiceLine{with}, inv) - assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) }) } @@ -1100,40 +1063,13 @@ func TestExportAEIssueTime(t *testing.T) { assert.Equal(t, "17:31:00", out.IssueTime) } -func TestAECustomsReference(t *testing.T) { - t.Run("writes the customs reference as the statement reference", func(t *testing.T) { - inv := &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyCustomsReference: "EXP010101234"})}} - out := new(goblubl.Invoice) - exportAECustomsReference(out, inv) - require.Len(t, out.StatementDocumentReference, 1) - assert.Equal(t, "EXP010101234", out.StatementDocumentReference[0].ID.Value) - }) - - t.Run("nothing without one", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAECustomsReference(out, &bill.Invoice{}) - assert.Empty(t, out.StatementDocumentReference) - }) - - t.Run("reads the first one back", func(t *testing.T) { - in := &goblubl.Invoice{StatementDocumentReference: []goblubl.Reference{ - {ID: goblubl.IDType{Value: " "}}, - {ID: goblubl.IDType{Value: " EXP010101234 "}}, - {ID: goblubl.IDType{Value: "EXP2"}}, - }} - inv := new(bill.Invoice) - importAECustomsReference(in, inv) - assert.Equal(t, cbc.Code("EXP010101234"), inv.Tax.GetExt(pint.ExtKeyCustomsReference)) - }) -} - func TestExportAEContractValue(t *testing.T) { inv := &bill.Invoice{Ordering: &bill.Ordering{Contracts: []*org.DocumentRef{ - {Code: "CT-1", Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyContractValue: "AED 200000"})}, - {Code: "CT-2", Description: "Framework agreement"}, + {Code: "CT-1", Description: "AED 200000"}, + {Code: "CT-2"}, }}} - t.Run("writes the value of each contract", func(t *testing.T) { + t.Run("writes the description of each contract", func(t *testing.T) { out := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{ {ID: goblubl.IDType{Value: "CT-1"}}, {ID: goblubl.IDType{Value: "CT-2"}}, @@ -1150,21 +1086,6 @@ func TestExportAEContractValue(t *testing.T) { exportAEContractValue(out, &bill.Invoice{}) assert.Empty(t, out.ContractDocumentReference[0].DocumentDescription) }) - - t.Run("reads it back from the description gobl.ubl imports", func(t *testing.T) { - in := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{ - {ID: goblubl.IDType{Value: "CT-1"}, DocumentDescription: " AED 200000 "}, - {ID: goblubl.IDType{Value: "CT-2"}}, - }} - got := &bill.Invoice{Ordering: &bill.Ordering{Contracts: []*org.DocumentRef{ - {Code: "CT-1", Description: "AED 200000"}, - {Code: "CT-2"}, - }}} - importAEContractValue(in, got) - assert.Equal(t, cbc.Code("AED 200000"), got.Ordering.Contracts[0].Ext.Get(pint.ExtKeyContractValue)) - assert.Empty(t, got.Ordering.Contracts[0].Description) - assert.True(t, got.Ordering.Contracts[1].Ext.IsZero()) - }) } func TestExportAEPayment(t *testing.T) { @@ -1242,75 +1163,13 @@ func TestExportAEPayment(t *testing.T) { assert.Nil(t, out.PaymentTerms) }) - t.Run("writes the scheme of the remittance reference and reads it back", func(t *testing.T) { - out := ublInvoice() - out.PaymentMeans[0].PaymentID = &goblubl.IDType{Value: "REM-1"} - inv := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) - inv.Payment.Instructions.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyRemittanceScheme: "ABA"}) - exportAEPayment(out, inv) - assert.Equal(t, "ABA", *out.PaymentMeans[0].PaymentID.SchemeID) - - got := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) - importAERemittanceScheme(out, got) - assert.Equal(t, cbc.Code("ABA"), got.Payment.Instructions.Ext.Get(pint.ExtKeyRemittanceScheme)) - }) - - t.Run("no scheme without one on the reference", func(t *testing.T) { - out := ublInvoice() - out.PaymentMeans[0].PaymentID = &goblubl.IDType{Value: "REM-1"} - got := goblInvoice(&pay.CreditTransfer{IBAN: iban}, nil) - exportAEPayment(out, got) - assert.Nil(t, out.PaymentMeans[0].PaymentID.SchemeID) - importAERemittanceScheme(out, got) - assert.True(t, got.Payment.Instructions.Ext.IsZero()) - }) -} - -func TestAELineReferences(t *testing.T) { - ext := tax.ExtensionsOf(cbc.CodeMap{ - pint.ExtKeyPurchaseOrder: "PO-1", - pint.ExtKeyDespatchAdvice: "DA-1", - }) - - t.Run("writes the purchase order next to the order line", func(t *testing.T) { - line := goblubl.InvoiceLine{OrderLineReference: &goblubl.OrderLineReference{LineID: "3"}} - exportAELineReferences(&line, &bill.Line{Order: "3", Ext: ext}) - assert.Equal(t, "3", line.OrderLineReference.LineID) - assert.Equal(t, "PO-1", line.OrderLineReference.OrderReference.ID) - assert.Equal(t, "NA", line.DespatchLineReference.LineID) - assert.Equal(t, "DA-1", line.DespatchLineReference.DocumentReference.ID.Value) - }) - - t.Run("without an order line, NA stands for it and is dropped on import", func(t *testing.T) { - line := goblubl.InvoiceLine{} - exportAELineReferences(&line, &bill.Line{Ext: ext}) - assert.Equal(t, "NA", line.OrderLineReference.LineID) - - inv := &bill.Invoice{Lines: []*bill.Line{{Order: "NA"}}} - importAELineReferences([]goblubl.InvoiceLine{line}, inv) - assert.Empty(t, inv.Lines[0].Order) - assert.Equal(t, cbc.Code("PO-1"), inv.Lines[0].Ext.Get(pint.ExtKeyPurchaseOrder)) - assert.Equal(t, cbc.Code("DA-1"), inv.Lines[0].Ext.Get(pint.ExtKeyDespatchAdvice)) - }) - - t.Run("nothing without the extensions", func(t *testing.T) { - line := goblubl.InvoiceLine{OrderLineReference: &goblubl.OrderLineReference{LineID: "3"}} - exportAELineReferences(&line, &bill.Line{Order: "3"}) - assert.Nil(t, line.OrderLineReference.OrderReference) - assert.Nil(t, line.DespatchLineReference) - - inv := &bill.Invoice{Lines: []*bill.Line{{Order: "3"}}} - importAELineReferences([]goblubl.InvoiceLine{line}, inv) - assert.Equal(t, cbc.Code("3"), inv.Lines[0].Order) - assert.True(t, inv.Lines[0].Ext.IsZero()) - }) } func TestAEChargeExemptions(t *testing.T) { combo := func(code cbc.Code) tax.Set { c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyExemption: code}) + c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) } return tax.Set{c} } @@ -1318,22 +1177,6 @@ func TestAEChargeExemptions(t *testing.T) { return []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: "E"}, TaxExemptionReasonCode: code}} } - t.Run("writes the reasons of the charges, then the discounts", func(t *testing.T) { - inv := &bill.Invoice{ - Charges: []*bill.Charge{{Taxes: combo("DL8.46.3")}}, - Discounts: []*bill.Discount{{Taxes: combo("")}, {Taxes: combo("DL8.46.1")}}, - } - out := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ - {ChargeIndicator: true, TaxCategory: category(nil)}, - {TaxCategory: category(nil)}, - {TaxCategory: category(nil)}, - }} - exportAEChargeExemptions(out, inv) - assert.Equal(t, "DL8.46.3", *out.AllowanceCharge[0].TaxCategory[0].TaxExemptionReasonCode) - assert.Nil(t, out.AllowanceCharge[1].TaxCategory[0].TaxExemptionReasonCode) - assert.Equal(t, "DL8.46.1", *out.AllowanceCharge[2].TaxCategory[0].TaxExemptionReasonCode) - }) - t.Run("reads them back in the order of the document", func(t *testing.T) { in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ {TaxCategory: category(strPtr(" DL8.46.1 "))}, @@ -1345,21 +1188,19 @@ func TestAEChargeExemptions(t *testing.T) { Discounts: []*bill.Discount{{Taxes: combo("")}, {Taxes: combo("")}}, } importAEChargeExemptions(in, inv) - assert.Equal(t, cbc.Code("DL8.46.3"), inv.Charges[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) - assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) - assert.Empty(t, inv.Discounts[1].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Equal(t, cbc.Code("DL8.46.3"), inv.Charges[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) + assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) + assert.Empty(t, inv.Discounts[1].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) }) t.Run("charges that don't match are skipped", func(t *testing.T) { inv := &bill.Invoice{Discounts: []*bill.Discount{{Taxes: combo("DL8.46.1")}}} - out := new(goblubl.Invoice) - exportAEChargeExemptions(out, inv) in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ {TaxCategory: category(strPtr("DL8.46.2"))}, {TaxCategory: category(strPtr("DL8.46.2"))}, }} importAEChargeExemptions(in, inv) - assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(pint.ExtKeyExemption)) + assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) }) } @@ -1428,77 +1269,3 @@ func TestAELineExemptionReason(t *testing.T) { assert.Equal(t, cbc.Code("E"), inv.Tax.Notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) }) } - -func TestAELineSchemeVersions(t *testing.T) { - version := func(v cbc.Code) tax.Extensions { - return tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeySchemeVersion: v}) - } - hs, sac := pint.IdentityLabelHS, pint.IdentityLabelSAC - - t.Run("writes the versions of the classification and the service accounting code", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{ - CommodityClassification: &[]goblubl.CommodityClassification{ - {ItemClassificationCode: &goblubl.IDType{ListID: &hs, Value: "8471"}}, - {ItemClassificationCode: &goblubl.IDType{ListID: &hs, Value: "8472"}}, - }, - AdditionalItemIdentification: []goblubl.ItemIdentification{ - {ID: &goblubl.IDType{SchemeID: &sac, Value: "998713"}}, - }, - }} - exportAELineSchemeVersions(&line, &bill.Line{Item: &org.Item{Identities: []*org.Identity{ - {Label: hs, Code: "8471", Ext: version("2022")}, - {Label: hs, Code: "8472"}, - {Label: sac, Code: "998713", Ext: version("1.0")}, - }}}) - ccs := *line.Item.CommodityClassification - assert.Equal(t, "2022", *ccs[0].ItemClassificationCode.ListVersionID) - assert.Nil(t, ccs[1].ItemClassificationCode.ListVersionID) - assert.Equal(t, "1.0", *line.Item.AdditionalItemIdentification[0].ID.SchemeVersionID) - }) - - t.Run("reads them back onto the identities", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{ - CommodityClassification: &[]goblubl.CommodityClassification{ - {ItemClassificationCode: &goblubl.IDType{ListID: &hs, ListVersionID: strPtr("2022"), Value: "8471"}}, - }, - AdditionalItemIdentification: []goblubl.ItemIdentification{ - {ID: &goblubl.IDType{SchemeID: &sac, SchemeVersionID: strPtr("1.0"), Value: "998713"}}, - }, - }} - inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{Identities: []*org.Identity{ - {Label: hs, Code: "8471"}, - }}}}} - importAELineItems([]goblubl.InvoiceLine{line}, inv) - ids := inv.Lines[0].Item.Identities - require.Len(t, ids, 2) - assert.Equal(t, cbc.Code("2022"), ids[0].Ext.Get(pint.ExtKeySchemeVersion)) - assert.Equal(t, cbc.Code("1.0"), ids[1].Ext.Get(pint.ExtKeySchemeVersion)) - }) -} - -func TestAELineBatch(t *testing.T) { - t.Run("writes the batch number as the lot of the item", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{}} - exportAELineBatch(&line, &bill.Line{Item: &org.Item{ - Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyBatchNumber: "Lot 1"}), - }}) - require.Len(t, line.Item.ItemInstance, 1) - assert.Equal(t, "Lot 1", line.Item.ItemInstance[0].LotIdentification.LotNumberID) - }) - - t.Run("nothing without one", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{}} - exportAELineBatch(&line, &bill.Line{Item: &org.Item{}}) - assert.Empty(t, line.Item.ItemInstance) - }) - - t.Run("reads it back onto the item", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{ItemInstance: []goblubl.ItemInstance{ - {}, - {LotIdentification: &goblubl.LotIdentification{LotNumberID: " Lot 1 "}}, - }}} - inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}}} - importAELineGoods([]goblubl.InvoiceLine{line}, inv) - assert.Equal(t, cbc.Code("Lot 1"), inv.Lines[0].Item.Ext.Get(pint.ExtKeyBatchNumber)) - }) -} diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index 69f2dac..012aef9 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4949e5919d0ecbf199f4db2735518cf5b19a9d8cb3e1af8ad6f85ad23477c53e" + "val": "37cf6f9be7b9dc5a16180aeb5ce4c633c12b98dce31530259506ccff5f846590" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -27,7 +27,6 @@ "currency": "AED", "tax": { "ext": { - "peppol-pint-ae-billing-frequency": "OTH", "peppol-pint-ae-transaction-type": "00001000", "untdid-document-type": "380" } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index cbc7dc7..41765e6 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7c8153e46a7d5643db38f51697101a8139c522a5f0fb947d35cdc79611a7296c" + "val": "55dac23e9f0a9dca6087b50c0e9e2ea5051bae2faa27fb297be23f70c05aff40" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -151,7 +151,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.1", + "cef-vatex": "DL8.46.1", "untdid-tax-category": "E" } } @@ -173,7 +173,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.2", + "cef-vatex": "DL8.46.2", "untdid-tax-category": "E" } } @@ -191,7 +191,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.1", + "cef-vatex": "DL8.46.1", "untdid-tax-category": "E" } } @@ -264,7 +264,7 @@ { "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.1", + "cef-vatex": "DL8.46.1", "untdid-tax-category": "E" }, "base": "180.00", @@ -273,7 +273,7 @@ { "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.2", + "cef-vatex": "DL8.46.2", "untdid-tax-category": "E" }, "base": "300.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 85fa061..4993ea1 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "15860a41e57e77bdbf8ec0e413f9f0b929a364461d36701a26f50270e3c3cf27" + "val": "861ba9345b6d6c863c71f2d894e2925b4b7e07fbe9e96174e9385f3a6745726a" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -29,7 +29,6 @@ "currency": "AED", "tax": { "ext": { - "peppol-pint-ae-customs-reference": "EXP010101234", "peppol-pint-ae-transaction-type": "00010011", "untdid-document-type": "380" } @@ -117,10 +116,7 @@ "name": "Item Name", "description": "Item Description", "price": "10.00", - "unit": "one", - "ext": { - "peppol-pint-ae-batch-number": "Lot 1" - } + "unit": "one" }, "sum": "1000.00", "taxes": [ diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index b4b54ec..e63fb43 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "bde767b250bf2b3e8b494edae364fe3eee894b6f41463614db9d21e10f2bc2eb" + "val": "d9d0d1ca41657fd627606791eacdb05852ddebe998f2cc4cc5dd1b90452ee8a5" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -120,17 +120,11 @@ "identities": [ { "label": "HS", - "code": "8471", - "ext": { - "peppol-pint-ae-scheme-version": "1.0" - } + "code": "8471" }, { "label": "SAC", - "code": "998713", - "ext": { - "peppol-pint-ae-scheme-version": "1.0" - } + "code": "998713" } ], "description": "Item Description", @@ -201,7 +195,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.3", + "cef-vatex": "DL8.46.3", "untdid-tax-category": "E" } } @@ -299,7 +293,7 @@ { "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.3", + "cef-vatex": "DL8.46.3", "untdid-tax-category": "E" }, "base": "120.00", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index d540a9a..e0799c9 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a3f7cf956a8dc25227ae11efe23cc96474566e24f9d0b51395e5a8294f2efcf1" + "val": "17e56b6dc606745d5477f1751efcf93cddf5d0f45fa8846fd64c8ff17825b1a4" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -127,20 +127,14 @@ } } ], - "total": "1000.00", - "ext": { - "peppol-pint-ae-despatch-advice": "DA-2025-031", - "peppol-pint-ae-purchase-order": "PO-2025-118" - } + "total": "1000.00" } ], "ordering": { "contracts": [ { "code": "CT-2025-014", - "ext": { - "peppol-pint-ae-contract-value": "AED 200000" - } + "description": "AED 200000" } ] }, @@ -174,7 +168,6 @@ } ], "ext": { - "peppol-pint-ae-remittance-scheme": "ABA", "untdid-payment-means": "30" } } diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 5b33604..a9214c4 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -13,7 +13,6 @@ 2025-01-01 2025-01-21 - OTH NA diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index 65c9a78..a1e0098 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -16,9 +16,6 @@ NA - - EXP010101234 - 1357902467 @@ -149,11 +146,6 @@ VAT - - - Lot 1 - - 10.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 4c2fd82..447b4ee 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -124,6 +124,7 @@ 0.00 E + DL8.46.3 VAT @@ -158,11 +159,11 @@ Item Description Item Name - 998713 + 998713 B - 8471 + 8471 S diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 32b080f..9688cc9 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -79,7 +79,7 @@ 1 30 - INV-REM-0042 + INV-REM-0042 AE070331234567890123456 Emirates NBD @@ -129,18 +129,6 @@ 100 1000.00 CS-024 - - NA - - PO-2025-118 - - - - NA - - DA-2025-031 - - Item Description Item Name diff --git a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json index 4b6c121..94f62ea 100644 --- a/ubl/testdata/parse/pint/ae/out/allowance-exempt.json +++ b/ubl/testdata/parse/pint/ae/out/allowance-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "f48f5993b43bdc897ba9fcd15a4295ccbae0a9bafb6ab93b54718dee47016c91" + "val": "8a8dfc7fa80b619fd2e05950066026c27dfb9a7b246e40dc5ef2ef208e6dc1c5" }, "from": "iso6523-actorid-upis::0235:1987654321", "to": "iso6523-actorid-upis::0235:1345678901" @@ -147,7 +147,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.4", + "cef-vatex": "DL8.46.4", "untdid-tax-category": "E" } } @@ -165,7 +165,7 @@ "cat": "VAT", "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.4", + "cef-vatex": "DL8.46.4", "untdid-tax-category": "E" } } @@ -213,7 +213,7 @@ { "key": "exempt", "ext": { - "peppol-pint-ae-exemption": "DL8.46.4", + "cef-vatex": "DL8.46.4", "untdid-tax-category": "E" }, "base": "900.00", diff --git a/ubl/testdata/parse/pint/ae/out/deemed-supply.json b/ubl/testdata/parse/pint/ae/out/deemed-supply.json index 821ea51..c7a2906 100644 --- a/ubl/testdata/parse/pint/ae/out/deemed-supply.json +++ b/ubl/testdata/parse/pint/ae/out/deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "ae580dcdbf90cc53bdab20abbb7e2d3f264c9a867e4688a947a499ae7773e5ad" + "val": "6b9667ceafbfb4aaf3fe7207e313ec06dc13bc9b3963c6a1794e83194f2d7eb0" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:9900000097" @@ -134,10 +134,7 @@ "identities": [ { "label": "HS", - "code": "88098432", - "ext": { - "peppol-pint-ae-scheme-version": "1.0" - } + "code": "88098432" }, { "label": "SAC", diff --git a/ubl/testdata/parse/pint/ae/out/reverse-charge.json b/ubl/testdata/parse/pint/ae/out/reverse-charge.json index 414c9b6..f675d1d 100644 --- a/ubl/testdata/parse/pint/ae/out/reverse-charge.json +++ b/ubl/testdata/parse/pint/ae/out/reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d5bd0299239dc50f49c03c6be1025562f72afecf17f41023bbdfb198d3c2b1ec" + "val": "07fe54e846c66905b22ad743cdc69254c0e8b99c3e3321c9b9648d9d4109dad1" }, "from": "iso6523-actorid-upis::0235:1278906543", "to": "iso6523-actorid-upis::0235:1347809543" @@ -137,10 +137,7 @@ }, { "label": "HS", - "code": "88098432324", - "ext": { - "peppol-pint-ae-scheme-version": "1.0" - } + "code": "88098432324" } ], "description": "Item Description", diff --git a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json index 8861caa..2239177 100644 --- a/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json +++ b/ubl/testdata/parse/pint/ae/out/supply-free-trade-zone.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "806a60879d8335f8fbd46177ba7c24efcdc17b2bcbedea28c9ffdd94ea28677d" + "val": "5a6f8c9c4e0e231e1a56bcabfce971c936a555443c4d345b7f7470c46cdbed06" }, "from": "iso6523-actorid-upis::0235:1246801357", "to": "iso6523-actorid-upis::0235:1789012345" @@ -135,10 +135,7 @@ "identities": [ { "label": "HS", - "code": "112233", - "ext": { - "peppol-pint-ae-scheme-version": "1.0" - } + "code": "112233" } ], "description": "Item Description", From 4784176f03a31583529e79f8852446d798394d92 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 10:31:17 +0000 Subject: [PATCH 64/73] Check the PINT AE round trip on the GOBL invoice - TestRoundTripAE now also compares the imported invoice with the one exported, with the differences UBL can't avoid listed in one place: series joined to the code, currency rounding, the country gobl.ubl gives tax registrations, the gross price PINT AE needs, line charge and discount bases, note keys, and the order of tags and identities. - PINT allows one note on the document and one on each line (ibr-sr-51, ibr-sr-34). Invoices with more are now rejected in every PINT format (invoice rules 13 and 14), instead of FormatAE joining them. - Only the payment due date (IBT-009) is written: FormatAE no longer writes the first due date as a PINT instalment (IBG-33), which the import never read back and the official examples gained on every round trip. Two shared rules, our own limitation rather than PINT rules, reject more than one due date (rule 15) or one for part of the amount due (rule 16). - The later invoice rules are renumbered, 01 to 70 with no gaps. - The convert fixtures drop the Peppol inboxes the EN 16931 addon already copies into endpoints, and the payment terms key nothing needs. - TODOs on the TIN country gobl.ubl adds on import, and on the branch address generic PINT also has (IBG-34). Co-Authored-By: Claude Opus 5.5 --- README.md | 17 +- addon/pint/bill.go | 168 ++++++++++----- addon/pint/bill_test.go | 193 +++++++++++++----- ubl/ae.go | 77 ++----- ubl/ae_internal_test.go | 49 +---- .../convert/bis/credit-note-peppol.json | 16 +- .../convert/bis/credit-note-self-billed.json | 16 +- ubl/testdata/convert/bis/credit-note.json | 16 +- .../convert/bis/invoice-complete.json | 16 +- .../convert/bis/invoice-corrective.json | 16 +- .../convert/bis/invoice-cross-border-b2b.json | 16 +- ubl/testdata/convert/bis/invoice-dk.json | 16 +- .../convert/bis/invoice-intra-comunity.json | 9 +- ubl/testdata/convert/bis/invoice-minimal.json | 16 +- .../convert/bis/invoice-multi-line.json | 16 +- .../convert/bis/invoice-partially-paid.json | 16 +- .../convert/bis/invoice-price-details.json | 16 +- .../bis/invoice-prices-include-vat.json | 16 +- .../convert/bis/invoice-with-charges.json | 16 +- .../bis/invoice-with-contract-ref.json | 16 +- .../convert/bis/invoice-with-delivery.json | 16 +- .../bis/invoice-with-document-discount.json | 16 +- .../convert/bis/invoice-with-item-codes.json | 16 +- .../convert/bis/invoice-with-prepayment.json | 16 +- .../convert/bis/peppol-1-advance.json | 16 +- ubl/testdata/convert/bis/peppol-1.json | 16 +- .../convert/bis/peppol-reverse-charge.json | 16 +- .../convert/bis/self-billed-invoice.json | 16 +- .../pint/ae/credit-note-ae-margin-scheme.json | 17 +- .../pint/ae/credit-note-ae-outside-scope.json | 16 +- .../pint/ae/credit-note-ae-self-billed.json | 16 +- .../ae/credit-note-ae-volume-discount.json | 16 +- .../convert/pint/ae/credit-note-ae.json | 16 +- .../pint/ae/invoice-ae-continuous-supply.json | 17 +- .../pint/ae/invoice-ae-deemed-supply.json | 16 +- .../convert/pint/ae/invoice-ae-exempt.json | 17 +- .../pint/ae/invoice-ae-export-summary.json | 17 +- .../ae/invoice-ae-free-trade-zone-agent.json | 17 +- .../pint/ae/invoice-ae-margin-scheme.json | 17 +- .../pint/ae/invoice-ae-outside-scope.json | 17 +- .../invoice-ae-reverse-charge-allowance.json | 17 +- .../pint/ae/invoice-ae-reverse-charge.json | 17 +- .../pint/ae/invoice-ae-self-billed.json | 17 +- .../pint/ae/invoice-ae-shared-fields.json | 31 +-- .../pint/ae/invoice-ae-tin-passport.json | 17 +- .../convert/pint/ae/invoice-ae-usd.json | 17 +- ubl/testdata/convert/pint/ae/invoice-ae.json | 17 +- .../ae/out/credit-note-ae-margin-scheme.xml | 6 - .../ae/out/invoice-ae-continuous-supply.xml | 6 - .../convert/pint/ae/out/invoice-ae-exempt.xml | 6 - .../pint/ae/out/invoice-ae-export-summary.xml | 6 - .../out/invoice-ae-free-trade-zone-agent.xml | 6 - .../pint/ae/out/invoice-ae-margin-scheme.xml | 6 - .../pint/ae/out/invoice-ae-outside-scope.xml | 6 - .../invoice-ae-reverse-charge-allowance.xml | 6 - .../pint/ae/out/invoice-ae-reverse-charge.xml | 6 - .../pint/ae/out/invoice-ae-self-billed.xml | 6 - .../pint/ae/out/invoice-ae-shared-fields.xml | 10 +- .../pint/ae/out/invoice-ae-tin-passport.xml | 6 - .../convert/pint/ae/out/invoice-ae-usd.xml | 6 - .../convert/pint/ae/out/invoice-ae.xml | 6 - .../convert/pint/aunz/invoice-au.json | 17 +- .../convert/pint/aunz/invoice-nz.json | 17 +- ubl/testdata/convert/pint/invoice-au.json | 17 +- ubl/ubl_test.go | 129 +++++++++++- 65 files changed, 458 insertions(+), 1007 deletions(-) diff --git a/README.md b/README.md index 536e91a..678e199 100644 --- a/README.md +++ b/README.md @@ -163,10 +163,13 @@ as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed identities labelled `SAC` are written as service accounting codes. The delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the delivery terms, and the delivery receiver's UAE TRN, or its TIN without one, -as the delivery party's identification (BTAE-23). Several notes on the -document, or on a line, are joined into one separated by a blank line, as PINT -allows a single note on each (ibr-sr-51, ibr-sr-34), and are imported back as -a single note. +as the delivery party's identification (BTAE-23). PINT allows a single note +on the document and on each line (ibr-sr-51, ibr-sr-34), so the PINT addon +rejects invoices with more, in every PINT format, instead of joining them. +Only the payment due date (IBT-009) is written, so the addon also rejects +more than one due date, or one for part of the amount due. That is a +limitation of this library, not a PINT rule: PINT can carry instalments +(IBG-33). **Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's `margin-scheme` tag, with the `exempt` VAT key on every line: @@ -186,10 +189,8 @@ the `exempt` key, never by the key alone. It also writes the PINT fields gobl.ubl leaves out: the issue time; each contract's description, where PINT AE puts the contract value; the `IBAN` -scheme of the payee account and the address of its branch; the first due -date's amount and date as the payment terms, which refer to the payment -instructions by the ID `1`; `cbc:TaxIncludedIndicator` as `false`; and the -tax note of a line's VAT category as its exemption reason text. On import, it reads +scheme of the payee account and the address of its branch; +`cbc:TaxIncludedIndicator` as `false`; and the tax note of a line's VAT category as its exemption reason text. On import, it reads the invoice UUID, the out-of-scope type codes 480 and 81 back as the `outside-tax-scope` tag, and the identity types, authorities, passport countries and seller TIN back as diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 50c024b..902f877 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -8,6 +8,7 @@ import ( "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" + "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/rules" @@ -103,6 +104,37 @@ func billInvoiceRules() *rules.Set { rules.Assert("12", "payee must differ from the supplier by legal identity, identity or name (ibr-017)", is.Func("payee is not the supplier", payeeIsNotSupplier), ), + // Notes + // + // PINT allows a single note on the document and on each line. Several + // notes are rejected rather than joined, so the user decides how to + // combine their texts and subject codes. + rules.Field("notes", + rules.Assert("13", "invoice can have at most one note (ibr-sr-51)", is.Length(0, 1)), + ), + rules.Field("lines", rules.Each( + rules.Field("notes", + rules.Assert("14", "line can have at most one note (ibr-sr-34)", is.Length(0, 1)), + ), + )), + // Due dates + // + // Not PINT rules but our own limitation: PINT can carry instalments + // (IBG-33) next to the payment due date (IBT-009), but we only write + // the due date, which has no amount. More due dates, or one for part + // of the amount, are rejected rather than lost. + rules.Field("payment", + rules.Field("terms", + rules.Field("due_dates", + rules.Assert("15", "invoice can have at most one due date, as only the payment due date is written (IBT-009)", + is.Length(0, 1), + ), + ), + ), + ), + rules.Assert("16", "due date must be for the whole amount due, as the payment due date has no amount (IBT-009)", + is.Func("due date is for the amount due", dueDatesCoverAmountDue), + ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // AE supplier @@ -113,13 +145,13 @@ func billInvoiceRules() *rules.Set { rules.Field("addresses", rules.Each( rules.Field("street", - rules.Assert("13", "supplier address street is required (IBR-143-AE)", is.Present), + rules.Assert("17", "supplier address street is required (IBR-143-AE)", is.Present), ), rules.Field("locality", - rules.Assert("14", "supplier address city is required (IBR-143-AE)", is.Present), + rules.Assert("18", "supplier address city is required (IBR-143-AE)", is.Present), ), rules.Field("region", - rules.Assert("15", "supplier address region is required (IBR-143-AE)", is.Present), + rules.Assert("19", "supplier address region is required (IBR-143-AE)", is.Present), ), ), ), @@ -128,7 +160,7 @@ func billInvoiceRules() *rules.Set { // 0235:. The party rules check the type of the legal // identities (IBR-173-AE, IBR-181-AE). rules.Field("identities", - rules.Assert("16", "supplier legal identity is required (IBR-150-AE)", + rules.Assert("20", "supplier legal identity is required (IBR-150-AE)", is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), ), ), @@ -139,7 +171,7 @@ func billInvoiceRules() *rules.Set { rules.Field("identities", rules.Each( rules.When( is.Func("tax scope", identityScopeIn(org.IdentityScopeTax)), - rules.Assert("17", "supplier tax scope identity must be a TIN (IBR-148-AE)", + rules.Assert("21", "supplier tax scope identity must be a TIN (IBR-148-AE)", org.IdentityTypeIn(ae.IdentityTypeTIN), ), ), @@ -151,20 +183,20 @@ func billInvoiceRules() *rules.Set { rules.Field("addresses", rules.Each( rules.Field("street", - rules.Assert("18", "customer address street is required (IBR-144-AE)", is.Present), + rules.Assert("22", "customer address street is required (IBR-144-AE)", is.Present), ), rules.Field("locality", - rules.Assert("19", "customer address city is required (IBR-144-AE)", is.Present), + rules.Assert("23", "customer address city is required (IBR-144-AE)", is.Present), ), rules.Field("region", - rules.Assert("20", "customer address region is required (IBR-144-AE)", is.Present), + rules.Assert("24", "customer address region is required (IBR-144-AE)", is.Present), ), ), ), rules.When( is.Func("has UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX", partyHasUAEEndpoint(endpointPattern1or9, false)), rules.Field("identities", - rules.Assert("21", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", + rules.Assert("25", "customer legal identity is required with a UAE Peppol endpoint other than 1XXXXXXXXX or 9XXXXXXXXX (IBR-149-AE)", is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), ), ), @@ -178,20 +210,20 @@ func billInvoiceRules() *rules.Set { // the customer, tax representative, issuer, payee and line sellers. // The supplier's own pass: its tax ID is under VAT, and rule 17 makes // any tax scope identity of it a TIN. Every tax category here is VAT. - rules.Assert("22", "tax registrations must be VAT when the supplier does not have a TIN (IBR-133-AE)", + rules.Assert("26", "tax registrations must be VAT when the supplier does not have a TIN (IBR-133-AE)", is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), ), // AE currency - rules.Assert("23", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("27", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("24", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("28", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("25", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("29", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -202,11 +234,11 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), )), rules.Field("payment", - rules.Assert("26", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("30", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("27", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("31", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -226,11 +258,11 @@ func billInvoiceRules() *rules.Set { is.Func("amount due is positive", invoiceIsDue), rules.Field("payment", rules.Field("terms", - rules.Assert("28", "payment terms are required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("32", "payment terms are required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Present, ), rules.Field("due_dates", - rules.Assert("29", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("33", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Present, ), ), @@ -244,7 +276,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("30", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("34", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -256,7 +288,7 @@ func billInvoiceRules() *rules.Set { invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", rules.Field("identities", - rules.Assert("31", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("35", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), ), ), @@ -266,7 +298,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("32", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("36", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -279,7 +311,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("33", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("37", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -292,7 +324,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", - rules.Assert("34", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + rules.Assert("38", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), @@ -300,7 +332,7 @@ func billInvoiceRules() *rules.Set { ), )), )), - rules.Assert("35", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + rules.Assert("39", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", is.Not(is.Or( is.Func("summary", invoiceHasTags(TagSummary)), is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), @@ -313,7 +345,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("36", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("40", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -327,13 +359,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("37", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("41", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("38", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("42", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -343,7 +375,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("39", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("43", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -351,7 +383,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("40", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("44", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -361,7 +393,7 @@ func billInvoiceRules() *rules.Set { // AE transaction type rules.Field("tax", rules.Field("ext", - rules.Assert("41", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", + rules.Assert("45", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", tax.ExtensionsRequire(ExtKeyTransactionType), tax.ExtensionHasValidCode(ExtKeyTransactionType), ), @@ -371,7 +403,7 @@ func billInvoiceRules() *rules.Set { is.Func("free trade zone", invoiceHasTags(TagFreeTradeZone)), rules.Field("tax", rules.Field("ext", - rules.Assert("42", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("46", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), @@ -383,7 +415,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), rules.Field("customer", - rules.AssertIfPresent("43", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", + rules.AssertIfPresent("47", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpoint(endpointPatternDeemedSupply, true)), ), ), @@ -393,18 +425,18 @@ func billInvoiceRules() *rules.Set { // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceHasTags(TagMarginScheme)), - rules.Assert("44", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", + rules.Assert("48", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), ), ), rules.When( is.Func("summary invoice", invoiceHasTags(TagSummary)), rules.Field("ordering", - rules.Assert("45", "ordering is required on summary invoices (IBR-138-AE)", + rules.Assert("49", "ordering is required on summary invoices (IBR-138-AE)", is.Present, ), rules.Field("period", - rules.Assert("46", "ordering period is required on summary invoices (IBR-138-AE)", + rules.Assert("50", "ordering period is required on summary invoices (IBR-138-AE)", is.Present, ), ), @@ -414,7 +446,7 @@ func billInvoiceRules() *rules.Set { is.Func("disclosed agent billing", invoiceHasTags(TagDisclosedAgent)), rules.Field("tax", rules.Field("ext", - rules.Assert("47", "principal ID is required on disclosed agent billing (IBR-137-AE)", + rules.Assert("51", "principal ID is required on disclosed agent billing (IBR-137-AE)", tax.ExtensionsRequire(ExtKeyPrincipalID), ), ), @@ -430,7 +462,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("48", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", + rules.Assert("52", "supplier TRN or TIN is required on outside scope documents or credit notes related to goods and services (IBR-177-AE)", is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), ), ), @@ -447,11 +479,11 @@ func billInvoiceRules() *rules.Set { is.Func("export", invoiceHasTags(tax.TagExport)), ), rules.Field("delivery", - rules.Assert("49", "delivery is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("53", "delivery is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), rules.Field("receiver", - rules.Assert("50", "delivery receiver is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("54", "delivery receiver is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), rules.Field("addresses", - rules.Assert("51", "delivery address is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), + rules.Assert("55", "delivery address is required on e-commerce supplies and exports (IBR-142-AE, IBR-152-AE)", is.Present), ), ), ), @@ -463,13 +495,13 @@ func billInvoiceRules() *rules.Set { rules.Field("addresses", rules.Each( rules.Field("street", - rules.Assert("52", "e-commerce delivery address street is required (IBR-142-AE)", is.Present), + rules.Assert("56", "e-commerce delivery address street is required (IBR-142-AE)", is.Present), ), rules.Field("locality", - rules.Assert("53", "e-commerce delivery address city is required (IBR-142-AE)", is.Present), + rules.Assert("57", "e-commerce delivery address city is required (IBR-142-AE)", is.Present), ), rules.Field("region", - rules.Assert("54", "e-commerce delivery address region is required (IBR-142-AE)", is.Present), + rules.Assert("58", "e-commerce delivery address region is required (IBR-142-AE)", is.Present), ), ), ), @@ -489,13 +521,13 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.Func("UAE address", addressIsAE)), rules.Field("street", - rules.Assert("55", "export delivery address street is required (IBR-152-AE)", is.Present), + rules.Assert("59", "export delivery address street is required (IBR-152-AE)", is.Present), ), rules.Field("locality", - rules.Assert("56", "export delivery address city is required (IBR-152-AE)", is.Present), + rules.Assert("60", "export delivery address city is required (IBR-152-AE)", is.Present), ), rules.Field("region", - rules.Assert("57", "export delivery address region is required (IBR-152-AE)", is.Present), + rules.Assert("61", "export delivery address region is required (IBR-152-AE)", is.Present), ), ), ), @@ -514,7 +546,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("58", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", + rules.Assert("62", "customer identity or tax registration is required with a UAE Peppol endpoint that is not a TIN, except on exports (IBR-135-AE)", is.Func("has tax scope or unscoped identity", identitiesScopeIn(org.IdentityScopeTax, cbc.KeyEmpty)), ), ), @@ -530,7 +562,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", - rules.Assert("59", "customer tax registration is required with reverse charge (IBR-103-AE)", + rules.Assert("63", "customer tax registration is required with reverse charge (IBR-103-AE)", is.Func("has tax scope identity", identitiesScopeIn(org.IdentityScopeTax)), ), ), @@ -541,13 +573,13 @@ func billInvoiceRules() *rules.Set { // AE tax extensions rules.Field("tax", rules.Field("ext", - rules.Assert("60", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", + rules.Assert("64", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("61", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", + rules.Assert("65", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), - rules.Assert("62", "principal ID must end with 03 (IBR-132-AE)", + rules.Assert("66", "principal ID must end with 03 (IBR-132-AE)", is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), ), ), @@ -556,7 +588,7 @@ func billInvoiceRules() *rules.Set { // billing frequency, and IBR-005-AE only accepts frequencies // there. rules.Field("point", - rules.Assert("63", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", + rules.Assert("67", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", is.Not(is.Present), ), ), @@ -571,7 +603,7 @@ func billInvoiceRules() *rules.Set { // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", - rules.Assert("64", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("68", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), @@ -593,7 +625,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", - rules.Assert("65", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("69", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency decimals within the PINT precision", currencyHasPINTDecimals), ), ), @@ -601,7 +633,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), rules.Field("currency", - rules.Assert("65", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("69", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -615,7 +647,7 @@ func billInvoiceRules() *rules.Set { // addon had tags. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("66", "PINT AE tags can only be used on UAE documents", + rules.Assert("70", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), @@ -815,6 +847,32 @@ func pointDateBeforeIssueDate(val any) bool { return inv.IssueDate.DaysSince(inv.ValueDate.Date) > 0 } +// dueDatesCoverAmountDue reports whether the invoice's due dates are each for +// the whole amount still due, as a percentage of 100% or as that amount, the +// way an imported payment due date comes back. Due dates without either pass. +func dueDatesCoverAmountDue(val any) bool { + inv, ok := val.(*bill.Invoice) + if !ok || inv == nil || inv.Payment == nil || inv.Payment.Terms == nil || inv.Totals == nil { + return true + } + due := inv.Totals.Payable + if inv.Totals.Due != nil { + due = *inv.Totals.Due + } + for _, dd := range inv.Payment.Terms.DueDates { + switch { + case dd == nil: + case dd.Percent != nil: + if !dd.Percent.Equals(num.MakePercentage(1, 0)) { + return false + } + case dd.Amount != nil && !dd.Amount.Equals(due): + return false + } + } + return true +} + // invoiceIsDue reports whether the amount gobl.ubl writes as // cbc:PayableAmount is greater than zero, as IBR-127-AE tests it: the due // total when set, the payable total otherwise. diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index f802c2e..191cf7c 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -232,6 +232,93 @@ func TestBillPartyRules(t *testing.T) { }) } +func TestBillNoteRules(t *testing.T) { + const ( + faultInvoiceNotes = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" + faultLineNotes = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" + ) + faults := func(t *testing.T, inv *bill.Invoice) string { + t.Helper() + err := rules.Validate(inv, tax.AddonContext(pint.V1)) + if err == nil { + return "" + } + return err.Error() + } + note := func(text string) *org.Note { return &org.Note{Text: text} } + + t.Run("one note on the invoice and on each line is fine", func(t *testing.T) { + inv := baseInvoice() + inv.Notes = []*org.Note{note("First")} + inv.Lines = []*bill.Line{{Notes: []*org.Note{note("First")}}} + out := faults(t, inv) + assert.NotContains(t, out, faultInvoiceNotes) + assert.NotContains(t, out, faultLineNotes) + }) + + t.Run("more notes are rejected, not joined (ibr-sr-51, ibr-sr-34)", func(t *testing.T) { + inv := baseInvoice() + inv.Notes = []*org.Note{note("First"), note("Second")} + inv.Lines = []*bill.Line{{Notes: []*org.Note{note("First"), note("Second")}}} + out := faults(t, inv) + assert.Contains(t, out, faultInvoiceNotes) + assert.Contains(t, out, faultLineNotes) + }) +} + +func TestBillDueDateRules(t *testing.T) { + const ( + faultDueDates = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" + faultDueDateWhole = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" + ) + faults := func(t *testing.T, inv *bill.Invoice) string { + t.Helper() + err := rules.Validate(inv, tax.AddonContext(pint.V1)) + if err == nil { + return "" + } + return err.Error() + } + withDueDates := func(dds ...*pay.DueDate) *bill.Invoice { + inv := baseInvoice() + inv.Totals = &bill.Totals{Payable: num.MakeAmount(100000, 2)} + inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{DueDates: dds}} + return inv + } + date := cal.NewDate(2026, 2, 1) + percent := func(p int64) *num.Percentage { v := num.MakePercentage(p, 2); return &v } + amount := func(a int64) *num.Amount { v := num.MakeAmount(a, 2); return &v } + + t.Run("one due date for the whole amount is fine", func(t *testing.T) { + for _, dd := range []*pay.DueDate{ + {Date: date, Percent: percent(100)}, + {Date: date, Amount: amount(100000)}, + {Date: date}, + } { + out := faults(t, withDueDates(dd)) + assert.NotContains(t, out, faultDueDates) + assert.NotContains(t, out, faultDueDateWhole) + } + }) + + t.Run("more due dates are rejected", func(t *testing.T) { + inv := withDueDates(&pay.DueDate{Date: date, Percent: percent(50)}, &pay.DueDate{Date: date, Percent: percent(50)}) + assert.Contains(t, faults(t, inv), faultDueDates) + }) + + t.Run("a due date for part of the amount is rejected", func(t *testing.T) { + assert.Contains(t, faults(t, withDueDates(&pay.DueDate{Date: date, Percent: percent(50)})), faultDueDateWhole) + assert.Contains(t, faults(t, withDueDates(&pay.DueDate{Date: date, Amount: amount(50000)})), faultDueDateWhole) + }) + + t.Run("after advances, the whole amount is what remains due", func(t *testing.T) { + inv := withDueDates(&pay.DueDate{Date: date, Amount: amount(60000)}) + due := num.MakeAmount(60000, 2) + inv.Totals.Due = &due + assert.NotContains(t, faults(t, inv), faultDueDateWhole) + }) +} + func TestBillExemptionNoteRules(t *testing.T) { t.Run("VAT breakdowns outside the scope need no exemption note (BR-O-10 is not in PINT)", func(t *testing.T) { inv := scenarioInvoice(l10n.GB.Tax(), bill.InvoiceTypeStandard) @@ -263,10 +350,10 @@ func usdToAED(amount num.Amount) []*currency.ExchangeRate { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" ) validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) @@ -457,19 +544,19 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" - faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-68" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -695,7 +782,7 @@ func TestBillDocumentRulesAE(t *testing.T) { } func TestBillCurrencyDecimalsRules(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-69" ae := func(cur currency.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) inv.Currency = cur @@ -739,12 +826,12 @@ func TestBillCurrencyDecimalsRules(t *testing.T) { func TestBillAddressRulesAE(t *testing.T) { const ( - faultSupplierStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" - faultSupplierCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" - faultSupplierRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" - faultCustomerStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" - faultCustomerCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" - faultCustomerRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultSupplierStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" + faultSupplierCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-18" + faultSupplierRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-19" + faultCustomerStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + faultCustomerCity = "GOBL-PEPPOL-PINT-BILL-INVOICE-23" + faultCustomerRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-24" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -817,11 +904,11 @@ func aeIdentityDocument() *bill.Invoice { func TestBillIdentityRulesAE(t *testing.T) { const ( - faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" - faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-17" - faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultSupplierLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-20" + faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" + faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" - faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-22" + faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" ) t.Run("trade licences with authorities pass", func(t *testing.T) { @@ -979,24 +1066,24 @@ func TestBillIdentityRulesAE(t *testing.T) { func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultSummaryOrdering = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" - faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" - faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" - faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" - faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" - faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" - faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" - faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" - faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-57" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-58" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" + faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultSummaryOrdering = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" + faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" + faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" + faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" + faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" + faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" + faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" + faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" + faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" + faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" + faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { if inv.Tax == nil { @@ -1113,7 +1200,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") inv.Supplier.TaxID = &tax.Identity{Country: "AE"} out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-30") + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-34") assert.NotContains(t, out, faultSupplierTax) for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { @@ -1188,10 +1275,10 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-60" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { if inv.Tax == nil { @@ -1329,7 +1416,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1446,7 +1533,7 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-70" faults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/ubl/ae.go b/ubl/ae.go index 4a303f0..8062944 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -52,11 +52,6 @@ const accountSchemeIBAN = "IBAN" // which the syntax binding requires and the official examples write. const deliveryTermsSchemeIncoterms = "Incoterms" -// aePaymentMeansID identifies the invoice's payment instructions (IBT-178), so -// that its payment terms can refer to them (IBT-187). GOBL has a single set of -// instructions, so it needs no ID of its own. -const aePaymentMeansID = "1" - // exportAE applies the Peppol PINT AE rules to an exported invoice. func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error { out, ok := doc.(*goblubl.Invoice) @@ -66,7 +61,6 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error } exportAEUUID(out, inv) exportAEIssueTime(out, inv) - out.Note = aeJoinNotes(out.Note) exportAETransactionType(out, inv) exportAECreditNoteReason(out, inv) exportAEIncoterms(out, inv) @@ -228,18 +222,14 @@ func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { } // exportAEPayment completes the payment instructions gobl.ubl writes, which -// are the invoice's only ones, and the payment terms that go with them. +// are the invoice's only ones. func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { if len(out.PaymentMeans) == 0 || inv.Payment == nil { return } - pm := &out.PaymentMeans[0] - if instr := inv.Payment.Instructions; instr != nil { - if len(instr.CreditTransfer) > 0 { - exportAECreditTransfer(pm.PayeeFinancialAccount, instr.CreditTransfer[0]) - } + if instr := inv.Payment.Instructions; instr != nil && len(instr.CreditTransfer) > 0 { + exportAECreditTransfer(out.PaymentMeans[0].PayeeFinancialAccount, instr.CreditTransfer[0]) } - exportAEPaymentTerms(out, pm, inv) } // exportAECreditTransfer writes the IBAN scheme of the payee account @@ -253,9 +243,10 @@ func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfe scheme := accountSchemeIBAN acc.ID.SchemeID = &scheme } - // TODO: gobl.ubl reads the branch address for every UBL format, but only - // FormatAE writes it, so BIS, PINT and A-NZ drop it on export. Move this - // export into gobl.ubl, reusing its address builder, and remove aeAddress. + // TODO: generic PINT has the branch address too (IBG-34), so FormatPINT + // should write it, but it drops it on export, as it did before PINT AE. + // It doesn't belong in gobl.ubl: EN 16931 warns against it (UBL-CR-432), + // and A-NZ doesn't have it. if addr := aeAddress(ct.Branch); addr != nil { if acc.FinancialInstitutionBranch == nil { acc.FinancialInstitutionBranch = new(goblubl.Branch) @@ -287,34 +278,6 @@ func aeAddress(a *org.Address) *goblubl.PostalAddress { return addr } -// exportAEPaymentTerms writes the amount of the first due date and its date -// as the amount and installment due date of the payment terms (IBT-176, -// IBT-177), which refer to the payment instructions by their ID (IBT-187, -// IBT-178). gobl.ubl writes a single cac:PaymentTerms, so later due dates are -// left out, as they are from cbc:DueDate. A due date in another currency has -// no amount to write, as every amount is in the invoice's (IBR-126). -func exportAEPaymentTerms(out *goblubl.Invoice, pm *goblubl.PaymentMeans, inv *bill.Invoice) { - terms := inv.Payment.Terms - if terms == nil || len(terms.DueDates) == 0 { - return - } - dd := terms.DueDates[0] - def := inv.Currency.Def() - if dd == nil || dd.Date == nil || dd.Amount == nil || def == nil || - (dd.Currency != "" && dd.Currency != inv.Currency) { - return - } - if out.PaymentTerms == nil { - out.PaymentTerms = new(goblubl.PaymentTerms) - } - id := aePaymentMeansID - pm.ID = &id - amount := aeAmount(def.Rescale(*dd.Amount), inv.Currency) - out.PaymentTerms.PaymentMeansID = id - out.PaymentTerms.Amount = &amount - out.PaymentTerms.InstallmentDueDate = dd.Date.String() -} - // exportAEChargeRates writes the rate of the reverse charge allowances and // charges at 5, as PINT AE wants one above 0 (aligned-ibrp-ae-06, // aligned-ibrp-ae-07) and gobl.ubl writes 0. Exempt ones keep the 0 PINT AE @@ -788,23 +751,8 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// aeJoinNotes joins the notes into one, separated by a blank line, as PINT -// allows a single note on the document and on each line (ibr-sr-51, -// ibr-sr-34). A joined note is imported back as a single note. -// -// TODO: these are shared PINT rules, and EN 16931 has the line one too -// (UBL-SR-34), so FormatPINT and FormatAUNZ need the same, and FormatBIS on -// its lines. -func aeJoinNotes(notes []string) []string { - if len(notes) < 2 { - return notes - } - return []string{strings.Join(notes, "\n\n")} -} - -// exportAELine completes a line's notes, price details and VAT rate. +// exportAELine completes a line's price details and VAT rate. func exportAELine(line *goblubl.InvoiceLine) { - line.Note = aeJoinNotes(line.Note) exportAEPrice(line) if line.Item != nil && line.Item.ClassifiedTaxCategory != nil { c := line.Item.ClassifiedTaxCategory @@ -821,7 +769,7 @@ func exportAELine(line *goblubl.InvoiceLine) { // document currency check as amounts in the tax currency, which IBR-140-AE // fixes to AED. No test checks their currency, and the official exports in // USD write them in AED too. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-23), they stay in the document currency. +// (GOBL-PEPPOL-PINT-BILL-INVOICE-27), they stay in the document currency. // // GOBL keeps no VAT per line, so it is the line total at the line's rate, // rounded to the document currency, then converted. Exempt lines get no VAT @@ -875,7 +823,7 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { // to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, // IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total // in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-23) with at most 6 decimals (-24). +// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-27) with at most 6 decimals (-28). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return @@ -1057,6 +1005,11 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { // TODO: the BIS gives the seller TIN's scheme no code list, and the official // examples use TIN and TAX. A scheme like TAX is read as a TIN, and written // back as TIN. +// +// TODO: gobl.ubl gives every tax registration it imports the country of the +// party's address, which UBL doesn't carry for the identity, so a TIN +// identity without a country comes back with one (known round-trip +// difference, to be looked at in gobl.ubl). func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { if in == nil || p == nil { return diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index e72061c..2ad87ab 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -1048,12 +1048,6 @@ func TestExportAEExchangeRate(t *testing.T) { }) } -func TestAEJoinNotes(t *testing.T) { - assert.Nil(t, aeJoinNotes(nil)) - assert.Equal(t, []string{"First"}, aeJoinNotes([]string{"First"})) - assert.Equal(t, []string{"First\n\nSecond"}, aeJoinNotes([]string{"First", "Second"})) -} - func TestExportAEIssueTime(t *testing.T) { out := new(goblubl.Invoice) exportAEIssueTime(out, &bill.Invoice{}) @@ -1095,18 +1089,10 @@ func TestExportAEPayment(t *testing.T) { PayeeFinancialAccount: &goblubl.FinancialAccount{ID: &goblubl.IDType{Value: iban.String()}}, }}} } - goblInvoice := func(ct *pay.CreditTransfer, dd *pay.DueDate) *bill.Invoice { - inv := &bill.Invoice{Currency: currency.AED, Payment: &bill.PaymentDetails{ + goblInvoice := func(ct *pay.CreditTransfer) *bill.Invoice { + return &bill.Invoice{Currency: currency.AED, Payment: &bill.PaymentDetails{ Instructions: &pay.Instructions{CreditTransfer: []*pay.CreditTransfer{ct}}, }} - if dd != nil { - inv.Payment.Terms = &pay.Terms{DueDates: []*pay.DueDate{dd}} - } - return inv - } - amount := num.MakeAmount(105000, 2) - dueDate := func() *pay.DueDate { - return &pay.DueDate{Date: cal.NewDate(2025, 2, 6), Amount: &amount} } t.Run("writes the IBAN scheme and the branch address", func(t *testing.T) { @@ -1114,7 +1100,7 @@ func TestExportAEPayment(t *testing.T) { exportAEPayment(out, goblInvoice(&pay.CreditTransfer{ IBAN: iban, Branch: &org.Address{Street: "Baniyas Road", StreetExtra: "Deira", Locality: "Dubai", Region: "DXB", Code: "777", Country: "AE"}, - }, nil)) + })) acc := out.PaymentMeans[0].PayeeFinancialAccount assert.Equal(t, "IBAN", *acc.ID.SchemeID) addr := acc.FinancialInstitutionBranch.Address @@ -1125,44 +1111,21 @@ func TestExportAEPayment(t *testing.T) { assert.Equal(t, "DXB", *addr.CountrySubentity) assert.Equal(t, "777", *addr.PostalZone) assert.Equal(t, "AE", addr.Country.IdentificationCode) - assert.Nil(t, out.PaymentMeans[0].ID, "no terms to refer to the instructions") - assert.Nil(t, out.PaymentTerms) }) t.Run("an account number has no scheme, and no branch no address", func(t *testing.T) { out := ublInvoice() - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{Number: iban}, nil)) + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{Number: iban})) acc := out.PaymentMeans[0].PayeeFinancialAccount assert.Nil(t, acc.ID.SchemeID) assert.Nil(t, acc.FinancialInstitutionBranch) }) - t.Run("writes the first due date as the terms of the instructions", func(t *testing.T) { - out := ublInvoice() - out.PaymentTerms = &goblubl.PaymentTerms{Note: "Net 15 days"} - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dueDate())) - assert.Equal(t, "1", *out.PaymentMeans[0].ID) - assert.Equal(t, "1", out.PaymentTerms.PaymentMeansID) - assert.Equal(t, "Net 15 days", out.PaymentTerms.Note) - assert.Equal(t, aedAmount("1050.00"), *out.PaymentTerms.Amount) - assert.Equal(t, "2025-02-06", out.PaymentTerms.InstallmentDueDate) - }) - - t.Run("no terms for a due date in another currency", func(t *testing.T) { - out := ublInvoice() - dd := dueDate() - dd.Currency = currency.USD - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dd)) - assert.Nil(t, out.PaymentTerms) - assert.Nil(t, out.PaymentMeans[0].ID) - }) - t.Run("nothing without payment instructions", func(t *testing.T) { out := new(goblubl.Invoice) - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban}, dueDate())) - assert.Nil(t, out.PaymentTerms) + exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban})) + assert.Empty(t, out.PaymentMeans) }) - } func TestAEChargeExemptions(t *testing.T) { diff --git a/ubl/testdata/convert/bis/credit-note-peppol.json b/ubl/testdata/convert/bis/credit-note-peppol.json index d948e2a..61000c5 100644 --- a/ubl/testdata/convert/bis/credit-note-peppol.json +++ b/ubl/testdata/convert/bis/credit-note-peppol.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "81f7be576df5db805e97ffbe3117ed8967b09491c0919f6669bd133a8480706c" + "val": "57726d95e56c01b6b3c5eeabe8e17a34b2a1856a39a06b3e9c0e0eb246ee384e" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/credit-note-self-billed.json b/ubl/testdata/convert/bis/credit-note-self-billed.json index 2a5bd98..3badb6f 100644 --- a/ubl/testdata/convert/bis/credit-note-self-billed.json +++ b/ubl/testdata/convert/bis/credit-note-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4fa9ce7f169f32ba37d3fe24d286a1b6cab244a4db2b02818a3bd1cfd1dbcee3" + "val": "cbbcccbeb67eaeba0a9b543a7ebc307d866e9011d7af95eea9127b52c4959202" }, "from": "iso6523-actorid-upis::9930:282741168", "to": "iso6523-actorid-upis::9930:111111125" @@ -48,13 +48,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -86,13 +79,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/credit-note.json b/ubl/testdata/convert/bis/credit-note.json index 040da9e..632ea4c 100644 --- a/ubl/testdata/convert/bis/credit-note.json +++ b/ubl/testdata/convert/bis/credit-note.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "47be08caf0b24abf1b6057bc06385010817d95464cd5442c89762802c67c18d9" + "val": "76e497901a4304efbcff58889240dba1ca0334e9a3f12c6c632bcc044fd587c6" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9920:282741168" @@ -55,13 +55,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -93,13 +86,6 @@ "uri": "iso6523-actorid-upis::9920:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-complete.json b/ubl/testdata/convert/bis/invoice-complete.json index 6315cb7..b6d1dc4 100644 --- a/ubl/testdata/convert/bis/invoice-complete.json +++ b/ubl/testdata/convert/bis/invoice-complete.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d7652cb543305458f46b946db6a8508bc6379d70411ea4802764f34715117c97" + "val": "ec138aa2c08ff725c92a39de917e7b736334a8994f476732a92a7d5ba35b4e1b" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-corrective.json b/ubl/testdata/convert/bis/invoice-corrective.json index 7a2c55b..6d23960 100644 --- a/ubl/testdata/convert/bis/invoice-corrective.json +++ b/ubl/testdata/convert/bis/invoice-corrective.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e93648df4beccf65ecf6066112b694824651e270cd19af64310a42b7378ea3d1" + "val": "21a595b37ad8205ce960a683c78bbc697f8aea93873d8ee3ac1213f00e4e5849" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -54,13 +54,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -92,13 +85,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-cross-border-b2b.json b/ubl/testdata/convert/bis/invoice-cross-border-b2b.json index 8852b5a..523af35 100644 --- a/ubl/testdata/convert/bis/invoice-cross-border-b2b.json +++ b/ubl/testdata/convert/bis/invoice-cross-border-b2b.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3528a064353ffb4bfe14352c43c523bb510fa728339decafdd1ae6e7f96a159f" + "val": "5ea8d870d8795a3656c7e0ddfc5ec3b70118580c8e27b1d6121fb34b4854bb07" }, "from": "iso6523-actorid-upis::9920:B98602642", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9920:B98602642" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "B98602642" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-dk.json b/ubl/testdata/convert/bis/invoice-dk.json index 89c9a4c..321c61a 100644 --- a/ubl/testdata/convert/bis/invoice-dk.json +++ b/ubl/testdata/convert/bis/invoice-dk.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "dd732440a514f0007fc0c730ff6709e1cbaed47e5b830a4564bf20319b913c04" + "val": "4945256620be53d6edb9b1be8d73fbdc996532f92c2358670209ab530e53d07b" }, "from": "iso6523-actorid-upis::0184:10000009", "to": "iso6523-actorid-upis::0088:5790000000005" @@ -56,13 +56,6 @@ "uri": "iso6523-actorid-upis::0184:10000009" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0184", - "code": "10000009" - } - ], "addresses": [ { "street": "Eksempelvej 1", @@ -99,13 +92,6 @@ "uri": "iso6523-actorid-upis::0088:5790000000005" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0088", - "code": "5790000000005" - } - ], "addresses": [ { "street": "Eksempelvej 2", diff --git a/ubl/testdata/convert/bis/invoice-intra-comunity.json b/ubl/testdata/convert/bis/invoice-intra-comunity.json index 24b66ca..cf34de1 100644 --- a/ubl/testdata/convert/bis/invoice-intra-comunity.json +++ b/ubl/testdata/convert/bis/invoice-intra-comunity.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "25f10f037d27ad49f30b4080cc1e575262336ef082f9f231955f4639edee5e24" + "val": "476e99582d2f5d299297fd2b48b807bbc07fbf6ee70265b27647ae690dfc96af" }, "to": "iso6523-actorid-upis::0208:0819258832" }, @@ -82,13 +82,6 @@ "uri": "iso6523-actorid-upis::0208:0819258832" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0208", - "code": "0819258832" - } - ], "addresses": [ { "street": "Bd du Midi 150", diff --git a/ubl/testdata/convert/bis/invoice-minimal.json b/ubl/testdata/convert/bis/invoice-minimal.json index cb2a354..62718e2 100644 --- a/ubl/testdata/convert/bis/invoice-minimal.json +++ b/ubl/testdata/convert/bis/invoice-minimal.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "292af3a691f6742361d4a4fe723175f05d1224efbcdd5499c1654ce327ce3b3d" + "val": "cc93df9ed3717d5ee2b8cd6b7eaf817db492a7f9e3cc304f7b2aae50baf56327" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-multi-line.json b/ubl/testdata/convert/bis/invoice-multi-line.json index 3fadf75..00f92a8 100644 --- a/ubl/testdata/convert/bis/invoice-multi-line.json +++ b/ubl/testdata/convert/bis/invoice-multi-line.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "e2edf8eed651f4ad30ce06df45deb1a124fb60b6884b2b1cd462598c56a9dd00" + "val": "de5d03c7fcb8b1d74f702bcea0dbf09034ca89a0cb1a3762765d5e26e7fa2008" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-partially-paid.json b/ubl/testdata/convert/bis/invoice-partially-paid.json index 6436b93..505d2da 100644 --- a/ubl/testdata/convert/bis/invoice-partially-paid.json +++ b/ubl/testdata/convert/bis/invoice-partially-paid.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5fb03f33493b43085ff84cf283566491005dbee843d621d8df9dcae4936b8bba" + "val": "b711c0a6a2b3c4da793801bb4918fc592a9a18af839bca7f0fd671523d79cde9" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-price-details.json b/ubl/testdata/convert/bis/invoice-price-details.json index 2027be6..1d7621c 100644 --- a/ubl/testdata/convert/bis/invoice-price-details.json +++ b/ubl/testdata/convert/bis/invoice-price-details.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "4df2274560ca98ed6c0c8ef4e1fcff15b77986a8094d622ef7ffcdd697a97b77" + "val": "34fd00a679bfe592e3dc31d6ef847229466e671f8ce450adf708e06e0bc60d2c" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-prices-include-vat.json b/ubl/testdata/convert/bis/invoice-prices-include-vat.json index 2e44903..67fdc36 100644 --- a/ubl/testdata/convert/bis/invoice-prices-include-vat.json +++ b/ubl/testdata/convert/bis/invoice-prices-include-vat.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "bb08f61ec81a0c3296688de8da4e0ed51cbc8e25d459216b36834d5c14f9b2c2" + "val": "aaeaea29a3231d54cd3381443895f7f95c8f0156da53f8c5aa0d1395d280f5cc" }, "from": "iso6523-actorid-upis::0208:0123456749", "to": "iso6523-actorid-upis::0208:0987654394" @@ -40,13 +40,6 @@ "uri": "iso6523-actorid-upis::0208:0123456749" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0208", - "code": "0123456749" - } - ], "addresses": [ { "street": "Sample Street 10", @@ -72,13 +65,6 @@ "uri": "iso6523-actorid-upis::0208:0987654394" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0208", - "code": "0987654394" - } - ], "addresses": [ { "street": "Example Lane 148", diff --git a/ubl/testdata/convert/bis/invoice-with-charges.json b/ubl/testdata/convert/bis/invoice-with-charges.json index 214c0bd..3a1a5ff 100644 --- a/ubl/testdata/convert/bis/invoice-with-charges.json +++ b/ubl/testdata/convert/bis/invoice-with-charges.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "a67fec9739e553627aa07c9c7f708b0e5f17d90251f632d28a352c00359aa3ab" + "val": "f273be5f2805f4647e0af01c74cb900c3d326347d1b4df8b3fe4b253e3b5040e" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-with-contract-ref.json b/ubl/testdata/convert/bis/invoice-with-contract-ref.json index 3ea1dc0..a74171c 100644 --- a/ubl/testdata/convert/bis/invoice-with-contract-ref.json +++ b/ubl/testdata/convert/bis/invoice-with-contract-ref.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "7bca8b821caa2b5e6830d861a96732a45c4bdc572c269e10030d58c6da771060" + "val": "4245914ea91daac211848899d07396973539c9e9013fa8635c4956ddc590a75b" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-with-delivery.json b/ubl/testdata/convert/bis/invoice-with-delivery.json index 287bfdc..21ab092 100644 --- a/ubl/testdata/convert/bis/invoice-with-delivery.json +++ b/ubl/testdata/convert/bis/invoice-with-delivery.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "ad9d96b5a703f667ed25c90d52c21e5eac77716ca1a215265321dfa6f3382f3e" + "val": "b79f7a018e2e6ce3a4aba3d69b62a8fa35445bffb5e4a89a59e172060cf82863" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-with-document-discount.json b/ubl/testdata/convert/bis/invoice-with-document-discount.json index 40b0bbd..e2cbdb1 100644 --- a/ubl/testdata/convert/bis/invoice-with-document-discount.json +++ b/ubl/testdata/convert/bis/invoice-with-document-discount.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "3da312e9ea7a6b63c99be404a324dd106a90b8d57d23c6c9bfd3a4c9a8520744" + "val": "97cdeb5c50eabb2161a9816d8c6ec3b354be58b587eb5226314aaca054f8a9bf" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-with-item-codes.json b/ubl/testdata/convert/bis/invoice-with-item-codes.json index e54e428..ecd2195 100644 --- a/ubl/testdata/convert/bis/invoice-with-item-codes.json +++ b/ubl/testdata/convert/bis/invoice-with-item-codes.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "017cdf49c380dccb8a14601b4daf92cc40de887a8e01cb2c6d9ae4342725910c" + "val": "db4ffaa89a9cff670aef6c38a5a6b1093d554d1e861b1d4b72cdbc1228de3eff" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -83,13 +76,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/invoice-with-prepayment.json b/ubl/testdata/convert/bis/invoice-with-prepayment.json index 2b58bf4..21d3ba2 100644 --- a/ubl/testdata/convert/bis/invoice-with-prepayment.json +++ b/ubl/testdata/convert/bis/invoice-with-prepayment.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "bcef3226c35cc698ef76265018b038a907a57651b2404f6e4ef63abdd4ba4341" + "val": "a4d1f2b2314d3b48ee95f590945bd0349b3811f391cbcefbc4df25d763413ac1" }, "from": "iso6523-actorid-upis::9930:111111125", "to": "iso6523-actorid-upis::9930:282741168" @@ -53,13 +53,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -91,13 +84,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/bis/peppol-1-advance.json b/ubl/testdata/convert/bis/peppol-1-advance.json index 6b2ed0f..3201139 100644 --- a/ubl/testdata/convert/bis/peppol-1-advance.json +++ b/ubl/testdata/convert/bis/peppol-1-advance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5ee520c2f1f01d887280cb3596bfbebe49e5c63507a1be59257305b0bc9ed9d8" + "val": "12d5e96ac105da34a29627ab741e985dab9d6372d06245231507fabb707bc88a" }, "from": "iso6523-actorid-upis::9920:B98602642", "to": "iso6523-actorid-upis::9920:54387763P" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9920:B98602642" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "B98602642" - } - ], "addresses": [ { "num": "42", @@ -84,13 +77,6 @@ "uri": "iso6523-actorid-upis::9920:54387763P" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "54387763P" - } - ], "addresses": [ { "num": "10", diff --git a/ubl/testdata/convert/bis/peppol-1.json b/ubl/testdata/convert/bis/peppol-1.json index 101a711..55a529c 100644 --- a/ubl/testdata/convert/bis/peppol-1.json +++ b/ubl/testdata/convert/bis/peppol-1.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "6ae36799ca32750768cc6fe31180c9c5fce3717a8cfc653c3c4b7fc8f9da0190" + "val": "d264b44712260469e45e78ef9e5df62960312f77afdc73b71bcfe449705db8cd" }, "from": "iso6523-actorid-upis::9920:B98602642", "to": "iso6523-actorid-upis::9920:54387763P" @@ -45,13 +45,6 @@ "uri": "iso6523-actorid-upis::9920:B98602642" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "B98602642" - } - ], "addresses": [ { "num": "42", @@ -84,13 +77,6 @@ "uri": "iso6523-actorid-upis::9920:54387763P" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9920", - "code": "54387763P" - } - ], "addresses": [ { "num": "10", diff --git a/ubl/testdata/convert/bis/peppol-reverse-charge.json b/ubl/testdata/convert/bis/peppol-reverse-charge.json index 275353f..3d0cacd 100644 --- a/ubl/testdata/convert/bis/peppol-reverse-charge.json +++ b/ubl/testdata/convert/bis/peppol-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "919e125441380a4ffee381b9f80d13d148afeb894affd4ee3c8ef69db59f46c4" + "val": "1e53b470c245968389e753b227319747be7b78f0be70750bf4a0eedaf80dd089" }, "from": "iso6523-actorid-upis::9930:de111111125", "to": "iso6523-actorid-upis::9938:lu98765432" @@ -59,13 +59,6 @@ "uri": "iso6523-actorid-upis::9930:de111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "de111111125" - } - ], "addresses": [ { "street": "Example Street 123", @@ -100,13 +93,6 @@ "uri": "iso6523-actorid-upis::9938:lu98765432" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9938", - "code": "lu98765432" - } - ], "addresses": [ { "street": "Example Avenue 456", diff --git a/ubl/testdata/convert/bis/self-billed-invoice.json b/ubl/testdata/convert/bis/self-billed-invoice.json index e1c1c2b..a6100a1 100644 --- a/ubl/testdata/convert/bis/self-billed-invoice.json +++ b/ubl/testdata/convert/bis/self-billed-invoice.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "50e60f6679d65e40b146b99caefc666345eebbf25bbe9958048463ee3e72a8b7" + "val": "9799af533bd10b6320c2f37012afdfc7287c2f6832a49bb2b4847ac51b819c5e" }, "from": "iso6523-actorid-upis::9930:282741168", "to": "iso6523-actorid-upis::9930:111111125" @@ -48,13 +48,6 @@ "uri": "iso6523-actorid-upis::9930:111111125" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "111111125" - } - ], "addresses": [ { "num": "16", @@ -86,13 +79,6 @@ "uri": "iso6523-actorid-upis::9930:282741168" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "9930", - "code": "282741168" - } - ], "addresses": [ { "num": "25", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json index 5b5b874..d3f8d6f 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "35eef84f986a2810ed82e1772d98af5fd1b14b32c0329ea661d24ca64dd0ded5" + "val": "00584c9137b26e2f579e19ada5ee72e101098cbd47ce1dcc94fe1abd1082b157" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -73,13 +73,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -108,13 +101,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -156,7 +142,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json index 5276c74..45f90fc 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "60fa84102f1210245ec1fe632ccd9b43ac603e341c3aeb82def20c8aa4cd9c61" + "val": "27a62f83d1631d564c74d24bd2573a6c73b1747ce8d0edea27e06df3f5c3f0a8" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -62,13 +62,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -97,13 +90,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json index f106365..b3202da 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "40bc2e024dec9695857cd853ca5a52e981d15747a1590fe64bfd4c2d2e6fd80f" + "val": "3ce961ffec96d1ff9a093023168d48f5de4e2aa71fd35c6a61781587ad2f4160" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -62,13 +62,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -97,13 +90,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json index de01d0b..153bc02 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae-volume-discount.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d6ea15e94a76cb4fbb2f76a99b67f85dfe583e23ffe2a1327fc0769b168b2c47" + "val": "f36963d07094d11b804e2de64955e93fcc9a6d5f1c97f265c2eb81c68aa7bc03" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -53,13 +53,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -88,13 +81,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", diff --git a/ubl/testdata/convert/pint/ae/credit-note-ae.json b/ubl/testdata/convert/pint/ae/credit-note-ae.json index bc77d04..231f478 100644 --- a/ubl/testdata/convert/pint/ae/credit-note-ae.json +++ b/ubl/testdata/convert/pint/ae/credit-note-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "8bdd6b94dbe52767ac19841f4fc35610a2b95feb60e9aac4f023dc60a201156f" + "val": "fa1ceef1d3dc511b27fd1718c626267c984915ffecc5f6e1826ed7a9c3452b95" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -59,13 +59,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -94,13 +87,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json index 012aef9..7564aa4 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-continuous-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "37cf6f9be7b9dc5a16180aeb5ce4c633c12b98dce31530259506ccff5f846590" + "val": "c62d8f786fcc7b8d72ab8cd08b2623254b52db6184210d72ef731f68daad304f" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -55,13 +55,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -90,13 +83,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -138,7 +124,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json index 68fe735..69f4cf6 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-deemed-supply.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "2dc8dc4acf91ad6143537cc2ef4fc1e7dd3866128ad3038584fe798ce281e5e8" + "val": "7ddabf80535664ff17da422ad80225ed31987ab147a1b452280149eaa394278e" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:9900000097" @@ -55,13 +55,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -90,13 +83,6 @@ "uri": "iso6523-actorid-upis::0235:9900000097" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "9900000097" - } - ], "addresses": [ { "street": "Corniche Road", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json index 41765e6..eb78d68 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-exempt.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "55dac23e9f0a9dca6087b50c0e9e2ea5051bae2faa27fb297be23f70c05aff40" + "val": "b2690fac7335f0a0f929d514770946f99cc3f2183ba7d5ce3d2ca023df13e0d0" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -62,13 +62,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -97,13 +90,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -220,7 +206,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json index 4993ea1..7afc822 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-export-summary.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "861ba9345b6d6c863c71f2d894e2925b4b7e07fbe9e96174e9385f3a6745726a" + "val": "fe8ab4f6a3d8de93ccb4e71fd3606138f133b8b38277f2ae19b15a41d69e2817" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -57,13 +57,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -92,13 +85,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -140,7 +126,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json index fc976a0..b7775cd 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-free-trade-zone-agent.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "5588c3e14d0ea5da245078293ae567acb56e8a2d2e0a558192e5917181eb0799" + "val": "3adb895a945f2fdb132df86dae69957935674e3d70f66eb6846783f0a221b8bc" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -58,13 +58,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -93,13 +86,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -135,7 +121,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json index 8f69b91..35e27e7 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-margin-scheme.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "193f975acb4d73d89551b498c2dbe98c4678386a49498e542c5466d3aa30917f" + "val": "e752ebb4294935c9d960e0f34bd0991f6557054c78584f6232c28aacaf9fd783" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -65,13 +65,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -100,13 +93,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -148,7 +134,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json index bacf593..3ca496b 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-outside-scope.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "656b11a6945b2cab5eabf9bfc33d8e2dfa2812eb2d2d422ab307db8848e59125" + "val": "5a86a501ea11880882458513af95e640102bbca324bf859ad111529dc95f07f4" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -55,13 +55,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -90,13 +83,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -131,7 +117,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json index 8034694..1fc3ac5 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge-allowance.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "61932740cf37f995b99440ee29acf1df6c4c09f269cacd44fe772db5719bf9d1" + "val": "f326588689945ac91791b0f06751fbd53575269d80153e6240f900d4a601f103" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -52,13 +52,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -87,13 +80,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -171,7 +157,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json index 8abae5e..0e61641 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-reverse-charge.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "30d69d344cf5b9091c763eae12e8deed8c57e0a78384df40ad576e4453ed12e9" + "val": "bac2c8d74e5afa7a689c1e76f0171d3ebef9b399c9413c84ad4df3005b99bcfa" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -52,13 +52,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -87,13 +80,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -144,7 +130,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json index b63b413..49cb6a6 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-self-billed.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "094056c7e0e238df9aa930453507b1e7eac477445a437413351218349ee142d7" + "val": "372f4f2209fca02e9f663e61f5bb38a3c8bce0d6bfbf1c9252131362863fe4ef" }, "from": "iso6523-actorid-upis::0235:1345678906", "to": "iso6523-actorid-upis::0235:1357902467" @@ -55,13 +55,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -90,13 +83,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -132,7 +118,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json index 587ef89..ef0fc60 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-shared-fields.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "c5556348fbbfc482ae579b572ca67c1f574c2c7992fb3a630e5f04163ffa5e8b" + "val": "b14834d8d3931ec9c554408a2f4fe3839b37158ebc0d2725abd6eac142e4f5ea" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -57,13 +57,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -97,13 +90,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -163,13 +149,6 @@ "ext": { "untdid-text-subject": "AAI" } - }, - { - "key": "general", - "text": "Packed on pallets.", - "ext": { - "untdid-text-subject": "AAI" - } } ] }, @@ -269,7 +248,6 @@ ] }, "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-28", @@ -346,13 +324,6 @@ "ext": { "untdid-text-subject": "AAI" } - }, - { - "key": "general", - "text": "Please quote the invoice number when paying.", - "ext": { - "untdid-text-subject": "AAI" - } } ] } diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json index 04790a1..df3f1f4 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-tin-passport.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "459f5560212a0ba47252606e4ed8a9d1fc7a12161388dd6f33e54797d2cbd8f2" + "val": "7508525c45d0ef33f1e4bac693d7dfa3c5fce959cbab9c9277ea87ace10f66a0" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -52,13 +52,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -87,13 +80,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -129,7 +115,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json index e63fb43..2339cba 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae-usd.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae-usd.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "d9d0d1ca41657fd627606791eacdb05852ddebe998f2cc4cc5dd1b90452ee8a5" + "val": "6f2ebc6db3e9e054a4ada49b60eecf64275d2395c63e2903f8747bb67d8a72c7" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -59,13 +59,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -94,13 +87,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -242,7 +228,6 @@ ], "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/invoice-ae.json b/ubl/testdata/convert/pint/ae/invoice-ae.json index e0799c9..20b6d00 100644 --- a/ubl/testdata/convert/pint/ae/invoice-ae.json +++ b/ubl/testdata/convert/pint/ae/invoice-ae.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "17e56b6dc606745d5477f1751efcf93cddf5d0f45fa8846fd64c8ff17825b1a4" + "val": "f8a6c4f1aa1a55b796e919a076c07452d3ceddae5d374d863b998e1ad48cdd6a" }, "from": "iso6523-actorid-upis::0235:1357902467", "to": "iso6523-actorid-upis::0235:1345678906" @@ -53,13 +53,6 @@ "uri": "iso6523-actorid-upis::0235:1357902467" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1357902467" - } - ], "addresses": [ { "street": "Sheikh Zayed Road", @@ -89,13 +82,6 @@ "uri": "iso6523-actorid-upis::0235:1345678906" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0235", - "code": "1345678906" - } - ], "addresses": [ { "street": "Corniche Road", @@ -140,7 +126,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2025-02-06", diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml index 7ff7514..ba45f29 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml @@ -79,7 +79,6 @@ - 1 30 2025-02-06 @@ -87,11 +86,6 @@ Emirates NBD - - 1 - 1000.00 - 2025-02-06 - 0.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index a9214c4..1ba9495 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -76,18 +76,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1050.00 - 2025-02-06 - 50.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index 90352d4..ac6de27 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1561.50 - 2025-02-06 - true Delivery diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index a1e0098..6786d48 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -99,18 +99,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1000.00 - 2025-02-06 - 0.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index 1890cdc..ad923b0 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -85,18 +85,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1050.00 - 2025-02-06 - 50.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 1deb70d..0b71b12 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1000.00 - 2025-02-06 - 0.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index d4c411c..0686bfd 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1000.00 - 2025-02-06 - 0.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index 681c487..dfdbf13 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 975.00 - 2025-02-06 - true Handling diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 487f911..06f0aeb 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1000.00 - 2025-02-06 - 0.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml index 3d58053..a4e873e 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1050.00 - 2025-02-06 - 50.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index e29bef3..666e0ac 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -9,7 +9,7 @@ 17:31:00 2025-02-28 380 - #AAI#Goods remain the property of the seller until paid in full. #AAI#Please quote the invoice number when paying. + #AAI#Goods remain the property of the seller until paid in full. 2025-01-28 AED @@ -135,18 +135,12 @@ - 1 30 AE070331234567890123456 Payee Collections LLC - - 1 - 2182.95 - 2025-02-28 - true ABL @@ -202,7 +196,7 @@ 1 - #AAI#Delivered in two batches. #AAI#Packed on pallets. + #AAI#Delivered in two batches. 10 1900.00 diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index 26cb177..d16bb0d 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -71,18 +71,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1050.00 - 2025-02-06 - 50.00 false diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 447b4ee..30e92c3 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -77,18 +77,12 @@ - 1 30 AE070331234567890123456 Emirates NBD - - 1 - 1769.99 - 2025-02-06 - USD AED diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index 9688cc9..b643d47 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -77,7 +77,6 @@ - 1 30 INV-REM-0042 @@ -98,11 +97,6 @@ - - 1 - 1050.00 - 2025-02-06 - 50.00 false diff --git a/ubl/testdata/convert/pint/aunz/invoice-au.json b/ubl/testdata/convert/pint/aunz/invoice-au.json index fd59888..f5c17b9 100644 --- a/ubl/testdata/convert/pint/aunz/invoice-au.json +++ b/ubl/testdata/convert/pint/aunz/invoice-au.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "87536bed12a6f38cce3d9b4e846708961b72521406fa1666a20f9ea0aa6f6cbb" + "val": "8f1b9eb1f433d8daae3a6d33f43ff99415529cfadc57222df6e5b9149dcfd9f0" }, "from": "iso6523-actorid-upis::0151:51824753556", "to": "iso6523-actorid-upis::0151:53004085616" @@ -47,13 +47,6 @@ "uri": "iso6523-actorid-upis::0151:51824753556" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0151", - "code": "51824753556" - } - ], "addresses": [ { "num": "100", @@ -85,13 +78,6 @@ "uri": "iso6523-actorid-upis::0151:53004085616" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0151", - "code": "53004085616" - } - ], "addresses": [ { "num": "1", @@ -132,7 +118,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2024-06-15", diff --git a/ubl/testdata/convert/pint/aunz/invoice-nz.json b/ubl/testdata/convert/pint/aunz/invoice-nz.json index 0e90cad..6aefe5d 100644 --- a/ubl/testdata/convert/pint/aunz/invoice-nz.json +++ b/ubl/testdata/convert/pint/aunz/invoice-nz.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "582b20df43826dc1267062417ecafa76335fffaf780c051f73a9e36ff0d7d83f" + "val": "f6f20769cf3497c7649a1e1150808a40d2fd9dabc764ca98ad1cd0c78d9050a1" }, "from": "iso6523-actorid-upis::0088:9429044000004", "to": "iso6523-actorid-upis::0088:9429044000011" @@ -47,13 +47,6 @@ "uri": "iso6523-actorid-upis::0088:9429044000004" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0088", - "code": "9429044000004" - } - ], "addresses": [ { "num": "1", @@ -84,13 +77,6 @@ "uri": "iso6523-actorid-upis::0088:9429044000011" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0088", - "code": "9429044000011" - } - ], "addresses": [ { "num": "1010", @@ -130,7 +116,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2024-06-15", diff --git a/ubl/testdata/convert/pint/invoice-au.json b/ubl/testdata/convert/pint/invoice-au.json index fd59888..f5c17b9 100644 --- a/ubl/testdata/convert/pint/invoice-au.json +++ b/ubl/testdata/convert/pint/invoice-au.json @@ -4,7 +4,7 @@ "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", "dig": { "alg": "sha256", - "val": "87536bed12a6f38cce3d9b4e846708961b72521406fa1666a20f9ea0aa6f6cbb" + "val": "8f1b9eb1f433d8daae3a6d33f43ff99415529cfadc57222df6e5b9149dcfd9f0" }, "from": "iso6523-actorid-upis::0151:51824753556", "to": "iso6523-actorid-upis::0151:53004085616" @@ -47,13 +47,6 @@ "uri": "iso6523-actorid-upis::0151:51824753556" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0151", - "code": "51824753556" - } - ], "addresses": [ { "num": "100", @@ -85,13 +78,6 @@ "uri": "iso6523-actorid-upis::0151:53004085616" } ], - "inboxes": [ - { - "key": "peppol", - "scheme": "0151", - "code": "53004085616" - } - ], "addresses": [ { "num": "1", @@ -132,7 +118,6 @@ }, "payment": { "terms": { - "key": "due-date", "due_dates": [ { "date": "2024-06-15", diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index af7ec23..6c48620 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -1,14 +1,18 @@ package ubl_test import ( + "encoding/json" "path/filepath" "regexp" + "slices" + "strings" "testing" "github.com/invopop/gobl.peppol/addon/pint" peppolubl "github.com/invopop/gobl.peppol/ubl" ubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/convert" "github.com/invopop/gobl/l10n" @@ -193,7 +197,8 @@ func TestImportAEFaults(t *testing.T) { // TestRoundTripAE checks that each AE convert example gives the same XML // after an import and a second export, so whatever FormatAE writes it also -// reads back. +// reads back, and that the imported invoice is the one exported, but for the +// known differences roundTripKnownDifferences lists. func TestRoundTripAE(t *testing.T) { examples, err := filepath.Glob(filepath.Join("testdata", "convert", "pint", "ae", "*.json")) require.NoError(t, err) @@ -213,6 +218,20 @@ func TestRoundTripAE(t *testing.T) { require.NoError(t, err) require.NoError(t, out.Calculate()) require.NoError(t, out.Validate()) + + sent, ok := env.Extract().(*bill.Invoice) + require.True(t, ok) + got, ok := out.Extract().(*bill.Invoice) + require.True(t, ok) + want := cloneInvoice(t, sent) + got = cloneInvoice(t, got) + roundTripKnownDifferences(want, got) + wantJSON, err := json.Marshal(want) + require.NoError(t, err) + gotJSON, err := json.Marshal(got) + require.NoError(t, err) + assert.JSONEq(t, string(wantJSON), string(gotJSON)) + doc, err = ubl.ExportInvoice(out, ubl.WithFormat(peppolubl.FormatAE)) require.NoError(t, err) second, err := ubl.Encode(doc) @@ -223,6 +242,114 @@ func TestRoundTripAE(t *testing.T) { } } +// cloneInvoice provides a deep copy of an invoice. +func cloneInvoice(t *testing.T, inv *bill.Invoice) *bill.Invoice { + t.Helper() + data, err := json.Marshal(inv) + require.NoError(t, err) + out := new(bill.Invoice) + require.NoError(t, json.Unmarshal(data, out)) + return out +} + +// roundTripKnownDifferences evens out what a GOBL invoice can't get back from +// its UBL, in the invoice sent (want) or the one imported (got): +// - UBL has a single document number, so the series is joined to the code; +// - gobl.ubl imports invoices with currency rounding, which the amounts +// written already follow; +// - gobl.ubl gives an imported tax registration the party's country; +// - PINT AE needs a gross price on every line, so an item without a list +// price comes back with its price as one, and with the default unit code; +// - the base of a line charge or discount, which GOBL computes, comes back +// set; +// - a note's key isn't written, only the UNTDID text subject code the +// EN 16931 addon gives it; +// - tags and identities come back in the order UBL holds them. +func roundTripKnownDifferences(want, got *bill.Invoice) { + joinSeries := func(series, code cbc.Code) cbc.Code { + if series == "" { + return code + } + return series + "-" + code + } + want.Code = joinSeries(want.Series, want.Code) + want.Series = "" + for _, ref := range want.Preceding { + ref.Code = joinSeries(ref.Series, ref.Code) + ref.Series = "" + } + if want.Tax != nil { + want.Tax.Rounding = tax.RoundingRuleCurrency + } + + for _, pair := range [][2]*org.Party{{want.Supplier, got.Supplier}, {want.Customer, got.Customer}} { + if pair[0] == nil || pair[1] == nil { + continue + } + for _, g := range pair[1].Identities { + for _, w := range pair[0].Identities { + if g.Code == w.Code && w.Country == "" { + g.Country = "" + } + } + } + sortIdentities(pair[0].Identities) + sortIdentities(pair[1].Identities) + } + + for i, gl := range got.Lines { + if i >= len(want.Lines) || gl.Item == nil || want.Lines[i].Item == nil { + continue + } + wi, gi := want.Lines[i].Item, gl.Item + if wi.List == nil && gi.List != nil && gi.Price != nil && gi.List.Equals(*gi.Price) { + gi.List = nil + } + if !wi.Ext.Has(untdid.ExtKeyUnit) && gi.Ext.Get(untdid.ExtKeyUnit) == "C62" { + gi.Ext = gi.Ext.Delete(untdid.ExtKeyUnit) + } + sortIdentities(wi.Identities) + sortIdentities(gi.Identities) + for j, c := range gl.Charges { + if j < len(want.Lines[i].Charges) && want.Lines[i].Charges[j].Base == nil { + c.Base = nil + } + } + for j, d := range gl.Discounts { + if j < len(want.Lines[i].Discounts) && want.Lines[i].Discounts[j].Base == nil { + d.Base = nil + } + } + } + + clearNoteKeys(want.Notes) + for _, l := range want.Lines { + clearNoteKeys(l.Notes) + } + + for _, inv := range []*bill.Invoice{want, got} { + tags := slices.Clone(inv.GetTags()) + slices.Sort(tags) + inv.SetTags(tags...) + } +} + +// clearNoteKeys removes the keys of notes that have a text subject code. +func clearNoteKeys(notes []*org.Note) { + for _, n := range notes { + if n.Ext.Has(untdid.ExtKeyTextSubject) { + n.Key = "" + } + } +} + +// sortIdentities orders identities by code. +func sortIdentities(ids []*org.Identity) { + slices.SortFunc(ids, func(a, b *org.Identity) int { + return strings.Compare(a.Code.String(), b.Code.String()) + }) +} + // TestImportAESellerTIN checks that a seller with a TIN and no TRN, as out of // scope documents allow, keeps the TIN as a tax registration when imported, // instead of getting it as its tax ID. From e1cd26c3a0ef97d3929a2a3fc8aa7326258d36d7 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:21:31 +0000 Subject: [PATCH 65/73] Pin gobl.ubl to the PR head Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index fbd0272..062ce2c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 require ( github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761 + github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index b83e019..4e1e4a0 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 h1:xHvbve38r6TPvd github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761 h1:fRKXWXrItcaYSvYVXzUBCNenGpEVahAI/CF93gBJYwM= -github.com/invopop/gobl.ubl v0.101.1-0.20261118141846-f38e7ae04761/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8 h1:fJdXJeRq8ZgTAFbuGl4lRPHJOOPKVrdYBKzKxnpSA0U= +github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From c6e5789427f558c871ed57ee408f16b14ab22494 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:05:16 +0000 Subject: [PATCH 66/73] Trim the PINT AE comments and tests - Comments: no comments on individual rules except one line for a real quirk, rule set comments say where the rules apply, helpers get one or two lines, self-explanatory constants lose their per-item comments (short end-of-line notes where a value needs one), and no comment cites bare rule numbers or removed behaviour. Notes on why a rule isn't implemented move out of the code. - Tests: tests of removed behaviour, of gobl or EN 16931 rather than this addon, or repeating what the fixtures prove are gone, as is the GOBL-equality half of the round-trip test. ubl/ae_internal_test.go keeps the edge cases and the guards that hold coverage (unchanged: addon 90.6%, ubl 89.8%). - The PINT tax combo rule 01 is back as on main, and the AE rules ignore it, as they check their own category list with N (IBR-139-AE). - The rate on reverse charge and margin scheme taxes comes from the AE regime's standard VAT rate instead of a constant. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 184 +---- addon/pint/bill_line.go | 13 +- addon/pint/bill_line_test.go | 6 - addon/pint/bill_test.go | 292 ++------ addon/pint/extensions.go | 22 +- addon/pint/extensions_test.go | 26 - addon/pint/org_address.go | 6 +- addon/pint/org_identity.go | 43 +- addon/pint/org_identity_test.go | 1 - addon/pint/org_item.go | 31 +- addon/pint/org_item_test.go | 17 - addon/pint/org_party.go | 69 +- addon/pint/org_party_test.go | 14 +- addon/pint/pay.go | 11 +- addon/pint/scenarios.go | 23 +- addon/pint/scenarios_test.go | 10 - addon/pint/tax_combo.go | 57 +- addon/pint/tax_combo_test.go | 38 +- addon/pint/tax_identity.go | 7 +- addon/pint/tax_identity_test.go | 15 +- addon/pint/transaction_type.go | 43 +- addon/pint/transaction_type_test.go | 14 +- ubl/ae.go | 263 +++---- ubl/ae_internal_test.go | 1072 +++------------------------ ubl/ubl.go | 9 +- ubl/ubl_test.go | 131 +--- 26 files changed, 438 insertions(+), 1979 deletions(-) delete mode 100644 addon/pint/extensions_test.go diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 902f877..6b01b7b 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -16,15 +16,10 @@ import ( "github.com/invopop/gobl/tax" ) -// billInvoiceRules enforces the PINT invoice rules shared by every -// jurisdiction, and the PINT AE rules on UAE documents. +// billInvoiceRules validates invoices on PINT documents. func billInvoiceRules() *rules.Set { return rules.For(new(bill.Invoice), - // EN 16931 wants an EU VATEX code or an exemption note for every E, O - // and AE VAT breakdown (BR-E-10, BR-O-10, BR-AE-10). PINT has no such - // rule. PINT AE only asks for the UAE exemption reason on exempt lines, - // discounts and charges (IBR-167-AE, IBR-168-AE, IBR-169-AE), and no - // official example has a reason on a breakdown. + // PINT has no BR-E-10, BR-O-10 or BR-AE-10; PINT AE asks for the UAE reason per line, discount and charge. rules.Ignore("GOBL-EU-EN16931-BILL-INVOICE-08"), // Supplier and customer @@ -46,12 +41,7 @@ func billInvoiceRules() *rules.Set { ), ), // Electronic addresses and customer identification - // - // gobl.ubl writes an email address, from an endpoint or an inbox, as - // cbc:EndpointID with the scheme EM, which is not in PINT's electronic - // address scheme list (ibr-cl-25). We assume no party has both a - // Peppol endpoint and an email address, so any email address is - // rejected. + // gobl.ubl writes emails as EndpointID scheme EM, which PINT doesn't list (ibr-cl-25). rules.Field("supplier", rules.Field("endpoints", rules.Each( rules.Field("uri", @@ -82,8 +72,7 @@ func billInvoiceRules() *rules.Set { rules.AssertIfPresent("09", "customer can have at most one identity besides its first legal one and its tax ones (ibr-sr-16)", is.Func("at most one buyer identifier", partyHasOneIdentification), ), - // EN 16931 allows one tax scope identity (GOBL-EU-EN16931-ORG-PARTY-03), - // so only one with a tax ID code is too many. + // EN 16931 already allows one tax scope identity, so with a tax ID code there must be none. rules.When( org.PartyHasTaxIDCode(), rules.Field("identities", @@ -105,10 +94,6 @@ func billInvoiceRules() *rules.Set { is.Func("payee is not the supplier", payeeIsNotSupplier), ), // Notes - // - // PINT allows a single note on the document and on each line. Several - // notes are rejected rather than joined, so the user decides how to - // combine their texts and subject codes. rules.Field("notes", rules.Assert("13", "invoice can have at most one note (ibr-sr-51)", is.Length(0, 1)), ), @@ -118,11 +103,7 @@ func billInvoiceRules() *rules.Set { ), )), // Due dates - // - // Not PINT rules but our own limitation: PINT can carry instalments - // (IBG-33) next to the payment due date (IBT-009), but we only write - // the due date, which has no amount. More due dates, or one for part - // of the amount, are rejected rather than lost. + // Our own limit, not a PINT rule: only the payment due date (IBT-009) is written, with no amount. rules.Field("payment", rules.Field("terms", rules.Field("due_dates", @@ -138,9 +119,6 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), // AE supplier - // - // The party and address rules ask every UAE address for an emirate - // code as its region (IBR-128-AE). rules.Field("supplier", rules.Field("addresses", rules.Each( @@ -155,19 +133,12 @@ func billInvoiceRules() *rules.Set { ), ), ), - // IBR-150-AE applies to sellers with a 0235 endpoint, which every - // UAE supplier has, as the UAE PASR gives every end user - // 0235:. The party rules check the type of the legal - // identities (IBR-173-AE, IBR-181-AE). + // IBR-150-AE only applies with a 0235 endpoint, which every UAE supplier gets (normalizeSupplierAE). rules.Field("identities", rules.Assert("20", "supplier legal identity is required (IBR-150-AE)", is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), ), ), - // IBR-178-AE needs no rule: EN 16931 allows one tax scope identity - // (GOBL-EU-EN16931-ORG-PARTY-03), which, with the TRN, is the two - // PartyTaxSchemes with one VAT that it accepts. - // The AE regime checks the TIN's format and check digit. rules.Field("identities", rules.Each( rules.When( is.Func("tax scope", identityScopeIn(org.IdentityScopeTax)), @@ -203,13 +174,8 @@ func billInvoiceRules() *rules.Set { ), ), - // AE tax schemes of every party - // - // IBR-133-AE's test runs on every cac:TaxScheme/cbc:ID: a scheme - // other than VAT needs a seller TIN. gobl.ubl writes tax schemes for - // the customer, tax representative, issuer, payee and line sellers. - // The supplier's own pass: its tax ID is under VAT, and rule 17 makes - // any tax scope identity of it a TIN. Every tax category here is VAT. + // AE tax schemes + // IBR-133-AE's test checks every cac:TaxScheme, not only the seller's. rules.Assert("26", "tax registrations must be VAT when the supplier does not have a TIN (IBR-133-AE)", is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), ), @@ -244,10 +210,7 @@ func billInvoiceRules() *rules.Set { ), ), ), - // Self-billed credit notes (261) are exempt too. The rule text only - // names 381 and 81, but the Schematron test also exempts 261, and we - // follow the test. Rule 26 already asks these documents for the - // payment details, and GOBL due dates for their date. + // The IBR-127-AE test also exempts 261, which its text doesn't name; we follow the test. rules.When( is.Not(is.Or( is.Func("document type is 381, 81 or 261", @@ -271,7 +234,7 @@ func billInvoiceRules() *rules.Set { ), ), - // AE document types: all but outside scope (480, 81) + // AE document types rules.When( is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), @@ -282,7 +245,7 @@ func billInvoiceRules() *rules.Set { ), ), - // AE document types: outside scope (480, 81) + // AE outside scope documents rules.When( is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), @@ -341,7 +304,7 @@ func billInvoiceRules() *rules.Set { ), ), - // AE document types: commercial invoice and credit note (380, 381) + // AE commercial invoices and credit notes rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), @@ -350,11 +313,8 @@ func billInvoiceRules() *rules.Set { ), ), - // AE document types: credit notes (381, 81) - // - // IBR-158-AE only names 381, but IBR-055-AE's test fails 81 credit - // notes without a reason too, whether or not they have a preceding - // invoice, so both need one. + // AE credit notes + // IBR-158-AE names only 381, but the IBR-055-AE test also fails 81 without a reason. rules.When( is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), @@ -371,7 +331,6 @@ func billInvoiceRules() *rules.Set { ), ), rules.When( - // A credit note without a reason is reported by the rule above. is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", @@ -409,9 +368,6 @@ func billInvoiceRules() *rules.Set { ), ), ), - // PINT AE BIS 1.5.3 predefines the buyer electronic address of a - // deemed supply. The other predefined endpoints, 9900000098 and - // 9900000099, depend on facts GOBL doesn't know. rules.When( is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), rules.Field("customer", @@ -420,9 +376,6 @@ func billInvoiceRules() *rules.Set { ), ), ), - // With the discount and charge rules 01, a margin scheme invoice can - // have no discounts or charges, as GOBL requires them to have taxes - // (BR-32, BR-37). rules.When( is.Func("margin scheme", invoiceHasTags(TagMarginScheme)), rules.Assert("48", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", @@ -452,9 +405,7 @@ func billInvoiceRules() *rules.Set { ), ), ), - // IBR-177-AE asks for the TRN or the TIN on every document. Rule 30 - // already asks for the TRN except on 480 and 81, so this rule only - // covers those, where the TIN is enough. + // IBR-134-AE already requires the TRN elsewhere, so IBR-177-AE is only checked on 480 and 81. rules.When( is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), @@ -469,10 +420,6 @@ func billInvoiceRules() *rules.Set { ), ), ), - // IBR-142-AE and IBR-152-AE read the delivery address, which - // gobl.ubl writes from the delivery receiver's first address as - // cac:DeliveryLocation/cac:Address. Their tests fail a document - // without one. rules.When( is.Or( is.Func("e-commerce supply", invoiceHasTags(TagECommerce)), @@ -508,10 +455,7 @@ func billInvoiceRules() *rules.Set { ), ), ), - // IBR-152-AE's text says the delivery country should not be AE on - // exports, but its test accepts a delivery address in the UAE, and - // only asks the others for a street, city and region. We follow the - // test. + // IBR-152-AE's text forbids an AE delivery country on exports, but its test accepts one; we follow the test. rules.When( is.Func("export", invoiceHasTags(tax.TagExport)), rules.Field("delivery", @@ -540,9 +484,7 @@ func billInvoiceRules() *rules.Set { rules.Field("customer", rules.When( is.Func("has UAE Peppol endpoint that is not a TIN", partyHasUAEEndpoint(ae.TINPattern, false)), - // gobl.ubl writes the identities without a scope as - // cac:PartyIdentification. The legal one, of which EN 16931 - // allows one, goes to cac:PartyLegalEntity. + // gobl.ubl writes unscoped identities as cac:PartyIdentification. rules.When( is.Not(org.PartyHasTaxIDCode()), rules.Field("identities", @@ -583,10 +525,6 @@ func billInvoiceRules() *rules.Set { is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), ), ), - // PINT AE uses the element EN writes the VAT point date code - // (BT-8) in, cac:InvoicePeriod/cbc:DescriptionCode, for the - // billing frequency, and IBR-005-AE only accepts frequencies - // there. rules.Field("point", rules.Assert("67", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", is.Not(is.Present), @@ -595,12 +533,6 @@ func billInvoiceRules() *rules.Set { ), // AE document type list - // - // PINT AE's list is shorter than EN 16931's: 380 and 480 on invoices, - // 381 and 81 on credit notes, and 389 and 261 for self-billing. The - // other codes the EN 16931 scenarios set, for pro forma, corrective - // and debit note types and the partial, prepayment and factoring - // tags, fail ibr-cl-01. rules.Field("tax", rules.Field("ext", rules.Assert("68", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", @@ -611,17 +543,8 @@ func billInvoiceRules() *rules.Set { ), // Currency decimals - // - // PINT 1.1.4, which PINT AE 1.0.5 builds on, allows as many decimals - // in the document totals as the official precision of the currency - // (ibr-091, ibr-121 to ibr-125): 3 for BHD, IQD, JOD, KWD, LYD, OMR - // and TND, 4 for CLF and UYW, and 2 for the rest. PINT 1.1.3, which - // FormatPINT and FormatAUNZ validate against, allows 2 for every - // currency. gobl.ubl writes the totals with GOBL's decimals for the - // currency, which are more than PINT's for a few, such as MGA and MRU. - // - // TODO: check the other regimes against the precision of the currency - // too once their VESIDs move to PINT 1.1.4. + // PINT AE validates against PINT 1.1.4, which allows each currency's precision; the others use 1.1.3, which allows 2. + // TODO: use the currency precision everywhere once the other VESIDs move to PINT 1.1.4. rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", @@ -640,11 +563,7 @@ func billInvoiceRules() *rules.Set { ), // Tags - // - // The tags the addon defines are for UAE documents, but GOBL can't limit - // an addon's tags to a regime. Other documents can only use the ones - // their regime, another addon or GOBL itself defines too, as before the - // addon had tags. + // GOBL can't limit an addon's tags to a regime, so the PINT AE ones are rejected elsewhere. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), rules.Assert("70", "PINT AE tags can only be used on UAE documents", @@ -654,8 +573,7 @@ func billInvoiceRules() *rules.Set { ) } -// billDiscountRules enforces the PINT AE document level discount rules on UAE -// documents. +// billDiscountRules validates document level discounts on UAE documents. func billDiscountRules() *rules.Set { return rules.For(new(bill.Discount), rules.When( @@ -674,8 +592,7 @@ func billDiscountRules() *rules.Set { ) } -// billChargeRules enforces the PINT AE document level charge rules on UAE -// documents. +// billChargeRules validates document level charges on UAE documents. func billChargeRules() *rules.Set { return rules.For(new(bill.Charge), rules.When( @@ -715,9 +632,8 @@ func invoiceExtIn(key cbc.Key, codes ...cbc.Code) func(any) bool { } } -// invoiceHasNoAETags reports whether the invoice has none of the tags only -// the PINT addon defines. A tag its regime, another addon or GOBL itself -// defines with the same key, such as the Spanish "summary", is not one. +// invoiceHasNoAETags reports whether the invoice has none of the tags only the PINT addon defines. +// Tags that the regime, another addon or GOBL also define don't count. func invoiceHasNoAETags(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -749,9 +665,7 @@ var currencyDecimalsPINT = map[currency.Code]uint32{ currency.CLF: 4, } -// currencyHasPINTDecimals reports whether GOBL's decimals for a currency, -// those gobl.ubl writes the totals with, are no more than its precision in -// PINT 1.1.4 (ibr-091, ibr-121 to ibr-125). A missing or unknown currency fails. +// currencyHasPINTDecimals reports whether GOBL's decimals for the currency fit its PINT 1.1.4 precision. func currencyHasPINTDecimals(val any) bool { code, ok := val.(currency.Code) if !ok { @@ -768,9 +682,7 @@ func currencyHasPINTDecimals(val any) bool { return def.Subunits <= limit } -// currencyHasAtMost2Decimals reports whether GOBL's decimals for a currency, -// those gobl.ubl writes the totals with, are 2 at most, the limit in PINT -// 1.1.3 (ibr-091, ibr-121 to ibr-125). A missing or unknown currency fails. +// currencyHasAtMost2Decimals reports whether GOBL's decimals for the currency are 2 at most (PINT 1.1.3). func currencyHasAtMost2Decimals(val any) bool { code, ok := val.(currency.Code) if !ok { @@ -780,10 +692,7 @@ func currencyHasAtMost2Decimals(val any) bool { return def != nil && def.Subunits <= 2 } -// exchangeRateToAEDHasAtMost6Decimals reports whether the exchange rate from -// the invoice currency to AED has at most 6 decimals, the limit for -// cbc:CalculationRate (IBR-002-AE). It is the only rate written. Invoices -// without it pass: they are in AED, or rule 23 reports them. +// exchangeRateToAEDHasAtMost6Decimals reports whether the rate to AED, if any, has at most 6 decimals. func exchangeRateToAEDHasAtMost6Decimals(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -794,7 +703,7 @@ func exchangeRateToAEDHasAtMost6Decimals(val any) bool { } // invoiceHasReverseChargeLine reports whether any line of the invoice has a -// VAT combo with the reverse charge category AE, the code IBR-103-AE tests. +// VAT combo with the reverse charge category AE. func invoiceHasReverseChargeLine(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -808,10 +717,7 @@ func invoiceHasReverseChargeLine(val any) bool { return false } -// invoiceHasLineComboOtherThanEorO reports whether at least one line has a VAT -// combo whose category is neither exempt (E) nor not subject to VAT (O) -// (IBR-151-AE). Combos of other taxes are ignored, as they carry no VAT -// category. +// invoiceHasLineComboOtherThanEorO reports whether any line has a VAT category other than E or O. func invoiceHasLineComboOtherThanEorO(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -833,9 +739,7 @@ func invoiceHasLineComboOtherThanEorO(val any) bool { return false } -// pointDateBeforeIssueDate reports whether the invoice's value date, written as -// the VAT point date cbc:TaxPointDate, is strictly before the issue date -// (IBR-141-AE). Invoices without a value date pass. +// pointDateBeforeIssueDate reports whether the value date, if any, is before the issue date. func pointDateBeforeIssueDate(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -847,9 +751,8 @@ func pointDateBeforeIssueDate(val any) bool { return inv.IssueDate.DaysSince(inv.ValueDate.Date) > 0 } -// dueDatesCoverAmountDue reports whether the invoice's due dates are each for -// the whole amount still due, as a percentage of 100% or as that amount, the -// way an imported payment due date comes back. Due dates without either pass. +// dueDatesCoverAmountDue reports whether each due date is for the whole amount due, as 100% or as +// that amount. Due dates with neither pass. func dueDatesCoverAmountDue(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil || inv.Payment == nil || inv.Payment.Terms == nil || inv.Totals == nil { @@ -873,9 +776,8 @@ func dueDatesCoverAmountDue(val any) bool { return true } -// invoiceIsDue reports whether the amount gobl.ubl writes as -// cbc:PayableAmount is greater than zero, as IBR-127-AE tests it: the due -// total when set, the payable total otherwise. +// invoiceIsDue reports whether the amount gobl.ubl writes as cbc:PayableAmount, the due total +// when set or the payable total otherwise, is greater than zero. func invoiceIsDue(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil || inv.Totals == nil { @@ -887,15 +789,8 @@ func invoiceIsDue(val any) bool { return inv.Totals.Payable.IsPositive() } -// invoiceNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier -// has a TIN (IBT-032) whenever another party has a tax registration that -// gobl.ubl writes under a tax scheme other than VAT: a tax scope identity -// whose type isn't VAT, or a tax ID from a regime with another scheme, such -// as GST in Australia. PINT AE only allows those when the seller has a TIN -// (IBR-133-AE). The parties are the ones gobl.ubl writes tax schemes for: -// the customer, tax representative, issuer, payee and line sellers. The -// official exports example sends a foreign buyer's tax number as its -// electronic address and legal identifier instead. +// invoiceNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier has a TIN whenever another party +// has a tax registration gobl.ubl writes under a scheme other than VAT. func invoiceNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil { @@ -921,9 +816,7 @@ func invoiceNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { return true } -// partyHasNonVATTaxRegistration reports whether gobl.ubl writes a tax scheme -// other than VAT for the party: its tax ID's, or a tax scope identity's, -// which is the identity type, or LOC without one. +// partyHasNonVATTaxRegistration reports whether gobl.ubl writes a non-VAT tax scheme for the party. func partyHasNonVATTaxRegistration(p *org.Party) bool { if p == nil { return false @@ -939,8 +832,7 @@ func partyHasNonVATTaxRegistration(p *org.Party) bool { return false } -// partyHasTIN reports whether the party has a tax scope identity of the TIN -// type, the seller TIN IBR-133-AE looks for in the seller's tax schemes. +// partyHasTIN reports whether the party has a tax scope identity of the TIN type. func partyHasTIN(p *org.Party) bool { if p == nil { return false diff --git a/addon/pint/bill_line.go b/addon/pint/bill_line.go index d7dc1c5..1c97815 100644 --- a/addon/pint/bill_line.go +++ b/addon/pint/bill_line.go @@ -11,11 +11,10 @@ import ( "github.com/invopop/gobl/tax" ) -// billLineRules enforces the PINT AE line rules on UAE documents. +// billLineRules validates invoice lines on UAE documents. func billLineRules() *rules.Set { return rules.For(new(bill.Line), - // TODO: IBR-145-AE matches ALIGNED-IBRP-050/059-AUNZ (GST). Extend to - // A-NZ after discussing it with colleagues. + // TODO: extend IBR-145-AE to A-NZ (ALIGNED-IBRP-050/059-AUNZ). rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("taxes", @@ -38,8 +37,7 @@ func billLineRules() *rules.Set { ), ), ), - // The IBR-006-AE test checks every goods type, not only those of - // reverse charge lines as its text says. + // The IBR-006-AE test checks every goods type, not only those of reverse charge lines as its text says. rules.Field("item", rules.Field("ext", rules.Assert("04", "type of goods or services must be from the PINT AE code list (IBR-006-AE)", @@ -61,10 +59,7 @@ func billLineRules() *rules.Set { ) } -// lineHasReverseChargeVAT reports whether a line's VAT combo has the reverse -// charge category AE, the code gobl.ubl writes as the line's -// cac:ClassifiedTaxCategory/cbc:ID and IBR-103-AE, IBR-166-AE and IBR-174-AE -// test. +// lineHasReverseChargeVAT reports whether the line's VAT category is AE, reverse charge. func lineHasReverseChargeVAT(val any) bool { l, ok := val.(*bill.Line) if !ok || l == nil { diff --git a/addon/pint/bill_line_test.go b/addon/pint/bill_line_test.go index 39a60f0..5be2eeb 100644 --- a/addon/pint/bill_line_test.go +++ b/addon/pint/bill_line_test.go @@ -87,10 +87,4 @@ func TestBillGoodsTypeRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", nil)), faultGTIN) assert.Contains(t, aeFaults(t, reverseCharge("DL8.48.3.1", gtin("0088"))), faultGTIN) }) - - t.Run("other lines need neither", func(t *testing.T) { - out := aeFaults(t, aeDocument(bill.InvoiceTypeStandard)) - assert.NotContains(t, out, faultGoodsType) - assert.NotContains(t, out, faultGTIN) - }) } diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 191cf7c..3fc663c 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -42,6 +42,17 @@ func baseInvoice() *bill.Invoice { } } +// faults validates the invoice with the PINT addon, in the given contexts too, +// and returns the faults raised, or "" if there are none. +func faults(t *testing.T, inv *bill.Invoice, ctx ...rules.WithContext) string { + t.Helper() + err := rules.Validate(inv, append([]rules.WithContext{tax.AddonContext(pint.V1)}, ctx...)...) + if err == nil { + return "" + } + return err.Error() +} + func TestBillInvoiceRules(t *testing.T) { validate := func(inv *bill.Invoice) error { return rules.Validate(inv, tax.AddonContext(pint.V1)) @@ -111,14 +122,6 @@ func TestBillPartyRules(t *testing.T) { faultPayeeName = "GOBL-PEPPOL-PINT-BILL-INVOICE-11" faultPayeeIsSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-12" ) - faults := func(t *testing.T, inv *bill.Invoice) string { - t.Helper() - err := rules.Validate(inv, tax.AddonContext(pint.V1)) - if err == nil { - return "" - } - return err.Error() - } t.Run("electronic address must not be an email address (IBR-081, IBR-080, ibr-cl-25)", func(t *testing.T) { // An email address is written with the scheme EM, which PINT doesn't @@ -237,14 +240,6 @@ func TestBillNoteRules(t *testing.T) { faultInvoiceNotes = "GOBL-PEPPOL-PINT-BILL-INVOICE-13" faultLineNotes = "GOBL-PEPPOL-PINT-BILL-INVOICE-14" ) - faults := func(t *testing.T, inv *bill.Invoice) string { - t.Helper() - err := rules.Validate(inv, tax.AddonContext(pint.V1)) - if err == nil { - return "" - } - return err.Error() - } note := func(text string) *org.Note { return &org.Note{Text: text} } t.Run("one note on the invoice and on each line is fine", func(t *testing.T) { @@ -271,14 +266,6 @@ func TestBillDueDateRules(t *testing.T) { faultDueDates = "GOBL-PEPPOL-PINT-BILL-INVOICE-15" faultDueDateWhole = "GOBL-PEPPOL-PINT-BILL-INVOICE-16" ) - faults := func(t *testing.T, inv *bill.Invoice) string { - t.Helper() - err := rules.Validate(inv, tax.AddonContext(pint.V1)) - if err == nil { - return "" - } - return err.Error() - } withDueDates := func(dds ...*pay.DueDate) *bill.Invoice { inv := baseInvoice() inv.Totals = &bill.Totals{Payable: num.MakeAmount(100000, 2)} @@ -331,23 +318,6 @@ func TestBillExemptionNoteRules(t *testing.T) { }) } -// aeInvoice is a skeleton UAE invoice in AED with payment instructions, which -// passes the AE invoice rules. Like baseInvoice, it trips unrelated core rules, -// so the tests check for specific fault codes. -func aeInvoice() *bill.Invoice { - inv := baseInvoice() - inv.Type = bill.InvoiceTypeStandard - inv.Currency = currency.AED - inv.Payment = &bill.PaymentDetails{ - Instructions: &pay.Instructions{Key: pay.MeansKeyCreditTransfer}, - } - return inv -} - -func usdToAED(amount num.Amount) []*currency.ExchangeRate { - return []*currency.ExchangeRate{{From: currency.USD, To: currency.AED, Amount: amount}} -} - func TestBillInvoiceRulesAE(t *testing.T) { const ( faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" @@ -355,109 +325,91 @@ func TestBillInvoiceRulesAE(t *testing.T) { faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" ) - validateIn := func(inv *bill.Invoice, regime l10n.TaxCountryCode) string { - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) - if err == nil { - return "" - } - return err.Error() - } - validate := func(inv *bill.Invoice) string { - return validateIn(inv, l10n.AE.Tax()) + inAE := tax.RegimeContext(l10n.AE.Tax()) + standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } + usdToAED := func(amount num.Amount) []*currency.ExchangeRate { + return []*currency.ExchangeRate{{From: currency.USD, To: currency.AED, Amount: amount}} } - t.Run("valid AE invoice raises no AE invoice faults", func(t *testing.T) { - out := validate(aeInvoice()) - assert.NotContains(t, out, faultRate) - assert.NotContains(t, out, faultDecimals) - assert.NotContains(t, out, faultPayment) - assert.NotContains(t, out, faultInstructions) - }) - t.Run("AED invoice needs no exchange rate (IBR-159-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.ExchangeRates = nil - assert.NotContains(t, validate(inv), faultRate) + assert.NotContains(t, faults(t, inv, inAE), faultRate) }) - t.Run("non-AED invoice with a rate to AED is accepted (IBR-159-AE)", func(t *testing.T) { - inv := aeInvoice() + t.Run("non-AED invoice with a rate to AED with 6 decimals is accepted (IBR-159-AE, IBR-002-AE)", func(t *testing.T) { + inv := standard() inv.Currency = currency.USD inv.ExchangeRates = usdToAED(num.MakeAmount(3672500, 6)) - assert.NotContains(t, validate(inv), faultRate) + out := faults(t, inv, inAE) + assert.NotContains(t, out, faultRate) + assert.NotContains(t, out, faultDecimals) }) t.Run("non-AED invoice without a rate is rejected (IBR-159-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Currency = currency.USD - assert.Contains(t, validate(inv), faultRate) + assert.Contains(t, faults(t, inv, inAE), faultRate) }) t.Run("non-AED invoice with a rate to another currency is rejected (IBR-159-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Currency = currency.USD inv.ExchangeRates = []*currency.ExchangeRate{ {From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(92, 2)}, } - assert.Contains(t, validate(inv), faultRate) - }) - - t.Run("exchange rate with 6 decimals is accepted (IBR-002-AE)", func(t *testing.T) { - inv := aeInvoice() - inv.Currency = currency.USD - inv.ExchangeRates = usdToAED(num.MakeAmount(3672500, 6)) - assert.NotContains(t, validate(inv), faultDecimals) + assert.Contains(t, faults(t, inv, inAE), faultRate) }) t.Run("exchange rate with 7 decimals is rejected (IBR-002-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Currency = currency.USD inv.ExchangeRates = usdToAED(num.MakeAmount(36725000, 7)) - assert.Contains(t, validate(inv), faultDecimals) + assert.Contains(t, faults(t, inv, inAE), faultDecimals) }) t.Run("only the rate to AED is checked, as it is the one written (IBR-002-AE)", func(t *testing.T) { toEUR := ¤cy.ExchangeRate{From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(9212345, 7)} - inv := aeInvoice() + inv := standard() inv.Currency = currency.USD inv.ExchangeRates = append(usdToAED(num.MakeAmount(3672500, 6)), toEUR) - assert.NotContains(t, validate(inv), faultDecimals) + assert.NotContains(t, faults(t, inv, inAE), faultDecimals) - inv = aeInvoice() + inv = standard() inv.ExchangeRates = []*currency.ExchangeRate{ {From: currency.AED, To: currency.EUR, Amount: num.MakeAmount(2512345, 7)}, } - assert.NotContains(t, validate(inv), faultDecimals) + assert.NotContains(t, faults(t, inv, inAE), faultDecimals) }) t.Run("invoice without payment is rejected (IBR-191-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Payment = nil - assert.Contains(t, validate(inv), faultPayment) + assert.Contains(t, faults(t, inv, inAE), faultPayment) }) t.Run("invoice with payment but no instructions is rejected (IBR-191-AE)", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Payment = &bill.PaymentDetails{} - out := validate(inv) + out := faults(t, inv, inAE) assert.NotContains(t, out, faultPayment) assert.Contains(t, out, faultInstructions) }) t.Run("credit note without payment is accepted (IBR-191-AE)", func(t *testing.T) { - inv := aeInvoice() - inv.Type = bill.InvoiceTypeCreditNote + inv := aeDocument(bill.InvoiceTypeCreditNote) inv.Payment = nil - assert.NotContains(t, validate(inv), faultPayment) + assert.NotContains(t, faults(t, inv, inAE), faultPayment) }) t.Run("AE invoice rules do not apply outside AE", func(t *testing.T) { - inv := aeInvoice() + inv := standard() inv.Currency = currency.USD inv.ExchangeRates = usdToAED(num.MakeAmount(36725000, 7)) inv.Payment = nil for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { - out := validateIn(inv, regime) + inv.Regime = tax.WithRegime(regime) + out := faults(t, inv, tax.RegimeContext(regime)) assert.NotContains(t, out, faultRate, "regime %s", regime) assert.NotContains(t, out, faultDecimals, "regime %s", regime) assert.NotContains(t, out, faultPayment, "regime %s", regime) @@ -535,11 +487,7 @@ func lineCombo(key cbc.Key) *tax.Combo { func aeFaults(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) - if err == nil { - return "" - } - return err.Error() + return faults(t, inv, tax.RegimeContext(l10n.AE.Tax())) } func TestBillDocumentRulesAE(t *testing.T) { @@ -870,7 +818,6 @@ func TestBillAddressRulesAE(t *testing.T) { inv.Customer.Addresses = nil inv.Customer.TaxID = nil out := aeFaults(t, inv) - assert.Contains(t, out, "BR-10") for _, fault := range []string{faultCustomerStreet, faultCustomerCity, faultCustomerRegion} { assert.NotContains(t, out, fault) } @@ -911,17 +858,13 @@ func TestBillIdentityRulesAE(t *testing.T) { faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" ) - t.Run("trade licences with authorities pass", func(t *testing.T) { - assert.Empty(t, aeFaults(t, aeIdentityDocument())) - }) - t.Run("supplier needs a legal identity (IBR-150-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = nil assert.Contains(t, aeFaults(t, inv), faultSupplierLegalRequired) }) - t.Run("supplier TIN is accepted, before or after the legal identity (IBR-148-AE)", func(t *testing.T) { + t.Run("supplier TIN before the legal identity is accepted (IBR-148-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Supplier.Identities = append([]*org.Identity{ {Type: ae.IdentityTypeTIN, Code: "1234567897"}, @@ -938,14 +881,12 @@ func TestBillIdentityRulesAE(t *testing.T) { } }) - t.Run("the AE regime checks the supplier TIN's format (IBR-148-AE)", func(t *testing.T) { + t.Run("the supplier TIN's format is left to the AE regime (IBR-148-AE)", func(t *testing.T) { for _, code := range []cbc.Code{"2234567890", "123456789"} { inv := aeIdentityDocument() inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Scope: org.IdentityScopeTax, Type: ae.IdentityTypeTIN, Code: code}) - out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-AE-ORG-IDENTITY-01", code) - assert.NotContains(t, out, faultSupplierTIN, code) + assert.NotContains(t, aeFaults(t, inv), faultSupplierTIN, code) } }) @@ -1006,19 +947,6 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) }) - t.Run("customer tax ID under GST needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - // The scheme is set here as these tests don't register the AU regime, - // which gives AU tax IDs the GST scheme. - inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} - withoutTRN(inv) - assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) - - inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - t.Run("supplier TIN from the TRN is enough (IBR-133-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} @@ -1039,11 +967,14 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) }) - t.Run("other parties' tax IDs under GST need a supplier TIN (IBR-133-AE)", func(t *testing.T) { + t.Run("tax IDs under GST need a supplier TIN (IBR-133-AE)", func(t *testing.T) { gst := func() *org.Party { + // The scheme is set here as these tests don't register the AU + // regime, which gives AU tax IDs the GST scheme. return &org.Party{Name: "Party", TaxID: &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST}} } parties := map[string]func(inv *bill.Invoice){ + "customer": func(inv *bill.Invoice) { inv.Customer.TaxID = gst().TaxID }, "tax representative": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Seller: gst()} }, "issuer": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Issuer: gst()} }, "payee": func(inv *bill.Invoice) { inv.Payment.Payee = gst() }, @@ -1100,18 +1031,14 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) require.NoError(t, inv.Calculate()) inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyTransactionType) - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) - require.Error(t, err) - assert.Contains(t, err.Error(), faultTransactionType) + assert.Contains(t, faults(t, inv, tax.RegimeContext(l10n.AE.Tax())), faultTransactionType) }) t.Run("transaction type must be 8 flags (IBR-154-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) require.NoError(t, inv.Calculate()) setExt(inv, pint.ExtKeyTransactionType, "0000002") - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())) - require.Error(t, err) - assert.Contains(t, err.Error(), faultTransactionType) + assert.Contains(t, faults(t, inv, tax.RegimeContext(l10n.AE.Tax())), faultTransactionType) }) t.Run("deemed supplies need no payment instructions or due date (IBR-191-AE, IBR-127-AE)", func(t *testing.T) { @@ -1120,20 +1047,6 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { out := aeFaults(t, inv) assert.NotContains(t, out, faultPaymentInstructions) assert.NotContains(t, out, faultDueDate) - - // PINT has no BR-CO-25, so neither payment nor terms are required. - inv = aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) - inv.Customer.Endpoints = uaeEndpoints("9900000097") - inv.Payment.Terms = nil - assert.Empty(t, aeFaults(t, inv)) - inv.Payment = nil - assert.Empty(t, aeFaults(t, inv)) - - inv = aeDocument(bill.InvoiceTypeStandard) - inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{Notes: "No consideration"}} - out = aeFaults(t, inv) - assert.Contains(t, out, faultPaymentInstructions) - assert.Contains(t, out, faultDueDate) }) t.Run("deemed supply buyer has the predefined endpoint 9900000097 (PINT AE BIS 1.5.3)", func(t *testing.T) { @@ -1328,42 +1241,21 @@ func TestBillCreditNoteReasonRulesAE(t *testing.T) { }) t.Run("reason must be from the code list (IBR-001-AE)", func(t *testing.T) { - for _, code := range []cbc.Code{"DL8.61.1.A", "DL8.61.1.B", "DL8.61.1.C", "DL8.61.1.D", "DL8.61.1.E"} { - inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), code) - assert.Empty(t, aeFaults(t, inv), code) - } - inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), "DL8.61.1.F") + inv := withReason(aeDocument(bill.InvoiceTypeCreditNote), "DL8.61.1.A") + assert.Empty(t, aeFaults(t, inv)) + inv = withReason(aeDocument(bill.InvoiceTypeCreditNote), "DL8.61.1.F") assert.Contains(t, aeFaults(t, inv), faultReasonCode) }) } func TestBillExemptionRulesAE(t *testing.T) { - const ( - faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" - faultDiscountExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" - faultChargeExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" - faultExemptionCode = "GOBL-PEPPOL-PINT-TAX-COMBO-07" - ) + const faultExemptionCode = "GOBL-PEPPOL-PINT-TAX-COMBO-07" exempt := func(code cbc.Code) *tax.Combo { c := lineCombo(tax.KeyExempt) - if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) - } + c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) return c } - t.Run("exempt line needs an exemption reason (IBR-167-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Taxes = tax.Set{exempt("")} - assert.Contains(t, aeFaults(t, inv), faultLineExemption) - - for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4"} { - inv = aeDocument(bill.InvoiceTypeStandard) - inv.Lines[0].Taxes = tax.Set{exempt(code)} - assert.NotContains(t, aeFaults(t, inv), faultLineExemption, code) - } - }) - t.Run("exemption reason must be a UAE one", func(t *testing.T) { for _, code := range []cbc.Code{"DL8.46.5", "VATEX-EU-132"} { inv := aeDocument(bill.InvoiceTypeStandard) @@ -1374,41 +1266,6 @@ func TestBillExemptionRulesAE(t *testing.T) { inv.Lines[0].Taxes = tax.Set{exempt("DL8.46.2")} assert.NotContains(t, aeFaults(t, inv), faultExemptionCode) }) - - t.Run("other categories need no exemption reason", func(t *testing.T) { - assert.NotContains(t, aeFaults(t, aeDocument(bill.InvoiceTypeStandard)), faultLineExemption) - }) - - t.Run("exempt discount needs an exemption reason (IBR-168-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} - inv.Discounts[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyAllowance: "95"}) - assert.Contains(t, aeFaults(t, inv), faultDiscountExemption) - - inv.Discounts[0].Taxes = tax.Set{exempt("DL8.46.4")} - inv.Discounts[0].Ext = tax.Extensions{} - assert.NotContains(t, aeFaults(t, inv), faultDiscountExemption) - }) - - t.Run("exempt charge needs an exemption reason (IBR-169-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{exempt("")}}} - inv.Charges[0].Ext = tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyCharge: "AAT"}) - assert.Contains(t, aeFaults(t, inv), faultChargeExemption) - - inv.Charges[0].Taxes = tax.Set{exempt("DL8.46.4")} - inv.Charges[0].Ext = tax.Extensions{} - assert.NotContains(t, aeFaults(t, inv), faultChargeExemption) - }) - - t.Run("standard rated discounts and charges need no exemption reason", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} - inv.Charges = []*bill.Charge{{Reason: "Handling", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{standardVAT()}}} - out := aeFaults(t, inv) - assert.NotContains(t, out, faultDiscountExemption) - assert.NotContains(t, out, faultChargeExemption) - }) } func TestBillMarginSchemeRulesAE(t *testing.T) { @@ -1445,22 +1302,9 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { c := inv.Lines[0].Taxes[0] assert.Equal(t, pint.TaxCategoryMarginScheme, c.Ext.Get(untdid.ExtKeyTaxCategory)) assert.Nil(t, c.Percent) - assert.True(t, inv.Totals.Tax.IsZero()) - assert.Equal(t, inv.Totals.Sum.String(), inv.Totals.Payable.String()) assert.Equal(t, cbc.Code("00100000"), inv.Tax.GetExt(pint.ExtKeyTransactionType)) }) - t.Run("adds one statement linked to N", func(t *testing.T) { - inv := margin(pint.TagMarginScheme) - require.NoError(t, inv.Calculate()) - notes := statements(inv) - require.Len(t, notes, 1) - assert.Equal(t, pint.TaxCategoryMarginScheme, notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) - - require.NoError(t, inv.Calculate()) - assert.Len(t, statements(inv), 1) - }) - t.Run("an imported statement isn't added again", func(t *testing.T) { inv := margin(pint.TagMarginScheme) inv.Tax = &bill.Tax{Notes: []*tax.Note{{ @@ -1534,14 +1378,10 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { func TestBillTagsOutsideAE(t *testing.T) { const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-70" - faults := func(t *testing.T, inv *bill.Invoice) string { + tagFaults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) - err := rules.Validate(inv, tax.AddonContext(pint.V1), tax.RegimeContext(inv.GetRegime())) - if err == nil { - return "" - } - return err.Error() + return faults(t, inv, tax.RegimeContext(inv.GetRegime())) } aeTags := []cbc.Key{ pint.TagOutsideTaxScope, pint.TagFreeTradeZone, pint.TagDeemedSupply, pint.TagMarginScheme, @@ -1550,32 +1390,26 @@ func TestBillTagsOutsideAE(t *testing.T) { t.Run("UAE documents can use every tag", func(t *testing.T) { inv := scenarioInvoice(l10n.AE.Tax(), bill.InvoiceTypeStandard, aeTags...) - assert.NotContains(t, faults(t, inv), faultTags) + assert.NotContains(t, tagFaults(t, inv), faultTags) }) t.Run("other documents can't use the PINT AE tags", func(t *testing.T) { for _, tag := range aeTags { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tag) if tag == pint.TagMarginScheme { // The UAE regime defines it, so GOBL rejects it first. - assert.ErrorContains(t, inv.Calculate(), "'margin-scheme' undefined") continue } - assert.Contains(t, faults(t, inv), faultTags, tag) + inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tag) + assert.Contains(t, tagFaults(t, inv), faultTags, tag) } }) t.Run("other documents keep the tags GOBL and their regime define", func(t *testing.T) { inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard, tax.TagSelfBilled) - assert.NotContains(t, faults(t, inv), faultTags) + assert.NotContains(t, tagFaults(t, inv), faultTags) // The Spanish regime has its own "summary" tag. inv = scenarioInvoice(l10n.ES.Tax(), bill.InvoiceTypeStandard, pint.TagSummary) - assert.NotContains(t, faults(t, inv), faultTags) - }) - - t.Run("untagged documents pass", func(t *testing.T) { - inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) - assert.NotContains(t, faults(t, inv), faultTags) + assert.NotContains(t, tagFaults(t, inv), faultTags) }) } diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 16f6ea1..349ed9c 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -11,27 +11,17 @@ import ( // PINT AE extension keys, for the BTAE fields GOBL has no place for. const ( - // ExtKeyTransactionType is the PINT AE invoice transaction type (BTAE-02). - ExtKeyTransactionType cbc.Key = "peppol-pint-ae-transaction-type" - // ExtKeyBeneficiaryID is the ID of the beneficiary of a supply in a free - // trade zone (BTAE-01). - ExtKeyBeneficiaryID cbc.Key = "peppol-pint-ae-beneficiary-id" - // ExtKeyPrincipalID is the ID of the principal a disclosed agent bills for - // (BTAE-14). - ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" - // ExtKeyCreditNoteReason is the reason for a PINT AE credit note (BTAE-03). + ExtKeyTransactionType cbc.Key = "peppol-pint-ae-transaction-type" + ExtKeyBeneficiaryID cbc.Key = "peppol-pint-ae-beneficiary-id" // free trade zone beneficiary + ExtKeyPrincipalID cbc.Key = "peppol-pint-ae-principal-id" // principal a disclosed agent bills for ExtKeyCreditNoteReason cbc.Key = "peppol-pint-ae-credit-note-reason" - // ExtKeyGoodsType is the type of goods or services subject to the reverse - // charge mechanism, on the item (BTAE-09). - ExtKeyGoodsType cbc.Key = "peppol-pint-ae-goods-type" + ExtKeyGoodsType cbc.Key = "peppol-pint-ae-goods-type" // goods or services under reverse charge ) -// CreditNoteReasonVolumeDiscount is the credit note reason for a volume -// discount, the only one that needs no preceding invoice (IBR-055-AE). +// CreditNoteReasonVolumeDiscount is the credit note reason for a volume discount. const CreditNoteReasonVolumeDiscount cbc.Code = "VD" -// Usages of the PINT AE extensions: offered by the PINT addon under the AE -// regime, on the object each one goes on. +// Usages of the PINT AE extensions, under the AE regime. var ( usageAEInvoiceTax = &cbc.Usage{ Keys: []cbc.Key{V1}, diff --git a/addon/pint/extensions_test.go b/addon/pint/extensions_test.go deleted file mode 100644 index 5123beb..0000000 --- a/addon/pint/extensions_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package pint_test - -import ( - "testing" - - "github.com/invopop/gobl.peppol/addon/pint" - "github.com/invopop/gobl/cbc" - "github.com/invopop/gobl/regimes/ae" - "github.com/invopop/gobl/rules" - "github.com/invopop/gobl/tax" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestExtensionsUsage(t *testing.T) { - addon := tax.AddonForKey(pint.V1) - require.NotNil(t, addon) - require.NotEmpty(t, addon.Extensions) - for _, ext := range addon.Extensions { - require.NotNil(t, ext.Usage, ext.Key) - assert.Contains(t, ext.Usage.Keys, pint.V1, ext.Key) - assert.Contains(t, ext.Usage.Codes, cbc.Code(ae.CountryCode), ext.Key) - assert.Len(t, ext.Usage.Schemas, 1, ext.Key) - assert.NoError(t, rules.Validate(ext.Usage), ext.Key) - } -} diff --git a/addon/pint/org_address.go b/addon/pint/org_address.go index 99e3b56..ad03b20 100644 --- a/addon/pint/org_address.go +++ b/addon/pint/org_address.go @@ -8,12 +8,10 @@ import ( "github.com/invopop/gobl/tax" ) -// emiratePattern matches the country subdivision codes PINT AE accepts for -// UAE addresses (IBR-128-AE). They are PINT AE's own list, not ISO 3166-2. +// emiratePattern matches the emirate codes PINT AE accepts, its own list rather than ISO 3166-2. const emiratePattern = `^(AUH|DXB|SHJ|UAQ|FUJ|AJM|RAK)$` -// orgAddressRules asks every UAE address of a UAE document for an emirate -// code as its region (IBR-128-AE), written as cbc:CountrySubentity. +// orgAddressRules validates addresses on UAE documents. func orgAddressRules() *rules.Set { return rules.For(new(org.Address), rules.When( diff --git a/addon/pint/org_identity.go b/addon/pint/org_identity.go index 75abcb9..87d58c2 100644 --- a/addon/pint/org_identity.go +++ b/addon/pint/org_identity.go @@ -13,14 +13,8 @@ import ( "github.com/invopop/gobl/tax" ) -// PINT AE legal registration identifier types, written as @schemeAgencyID on -// the seller and buyer cbc:CompanyID (BTAE-15, BTAE-16). The trade licence -// (TL), Emirates ID (EID) and Cabinet Decision (CD) are the AE regime's -// identity types of the same codes; the passport is GOBL's passport key. -const ( - // IdentityTypePassport is a passport. - IdentityTypePassport cbc.Code = "PAS" -) +// IdentityTypePassport is the PINT AE legal registration type of a passport (BTAE-15, BTAE-16). +const IdentityTypePassport cbc.Code = "PAS" // identityTypesAE are the AE regime's identity types that are PINT AE legal // registration identifier types. @@ -30,11 +24,7 @@ var identityTypesAE = []cbc.Code{ ae.IdentityTypeCabinetDecision, } -// orgIdentityRules asks the passports of UAE documents for their issuing -// country and the trade licences for their issuing authority, which are -// written as the @schemeAgencyName of the seller's and buyer's -// cac:PartyLegalEntity/cbc:CompanyID (IBR-012-AE, IBR-010-AE, IBR-172-AE, -// IBR-101-AE). +// orgIdentityRules validates identities on UAE documents. func orgIdentityRules() *rules.Set { return rules.For(new(org.Identity), rules.When( @@ -45,9 +35,7 @@ func orgIdentityRules() *rules.Set { rules.Assert("01", "passport must have the issuing country (IBR-012-AE, IBR-010-AE)", is.Present), ), ), - // IBR-101-AE exempts the buyers with the predefined endpoints - // 9900000098 and 9900000099, but an identity can't see its party's - // endpoint, so their trade licences need the authority too. + // IBR-101-AE exempts the endpoints 9900000098 and 9900000099, but an identity can't see its party's endpoint. rules.When( org.IdentityTypeIn(ae.IdentityTypeTradeLicense), rules.Field("description", @@ -86,12 +74,8 @@ func SetIdentityTypeAE(id *org.Identity, typ cbc.Code) bool { return true } -// normalizeIdentityScopes gives the UAE identities of the supplier and -// customer the scope gobl.ubl needs to write them where PINT AE reads them: -// legal for the trade licence, Emirates ID, passport and Cabinet Decision, -// written as cac:PartyLegalEntity/cbc:CompanyID, and tax for the supplier's -// TIN, written as a cac:PartyTaxScheme. PINT AE has no TIN tax registration -// for the customer, whose TIN stays a plain identity. +// normalizeIdentityScopes scopes the supplier and customer identities where PINT AE reads them: legal +// for the registration types, and tax for the supplier's TIN. func normalizeIdentityScopes(inv *bill.Invoice) { if inv == nil { return @@ -100,10 +84,8 @@ func normalizeIdentityScopes(inv *bill.Invoice) { setIdentityScopes(inv.Customer, org.IdentityScopeLegal) } -// setIdentityScopes gives the party's identities without a scope the one -// they have in PINT AE, when it is one of the given scopes and no other -// identity of the party has it, as EN 16931 allows one identity per scope -// (BT-30, BT-47, BT-31, BT-48). +// setIdentityScopes gives unscoped identities their PINT AE scope, if it's one of scopes and still free, as +// EN 16931 allows one identity per scope. func setIdentityScopes(p *org.Party, scopes ...cbc.Key) { if p == nil { return @@ -137,8 +119,7 @@ func identityScopeAE(id *org.Identity) cbc.Key { return "" } -// IdentitySchemeGTIN is the ISO 6523 scheme of a GTIN, the item standard -// identifier reverse charge lines need (IBR-174-AE). +// IdentitySchemeGTIN is the ISO 6523 scheme of a GTIN. const IdentitySchemeGTIN cbc.Code = "0160" // GTINIdentity returns the first identity with the GTIN scheme, or nil. @@ -151,11 +132,7 @@ func GTINIdentity(ids []*org.Identity) *org.Identity { return nil } -// identityScopeIn returns a predicate that reports whether an identity has -// one of the scopes, the empty one for none. gobl.ubl writes the identity -// with the tax scope as a cac:PartyTaxScheme and the first with the legal -// scope as cac:PartyLegalEntity/cbc:CompanyID, and the rest as -// cac:PartyIdentification. +// identityScopeIn returns a predicate that reports whether an identity has one of the scopes, "" for none. func identityScopeIn(scopes ...cbc.Key) func(any) bool { return func(val any) bool { id, ok := val.(*org.Identity) diff --git a/addon/pint/org_identity_test.go b/addon/pint/org_identity_test.go index 5f2b699..91d84c1 100644 --- a/addon/pint/org_identity_test.go +++ b/addon/pint/org_identity_test.go @@ -36,7 +36,6 @@ func TestIdentityTypeAE(t *testing.T) { func TestSetIdentityTypeAE(t *testing.T) { tests := map[cbc.Code]org.Identity{ "TL": {Type: ae.IdentityTypeTradeLicense}, - "CL": {}, "EID": {Type: ae.IdentityTypeEmiratesID}, "PAS": {Key: org.IdentityKeyPassport}, "CD": {Type: ae.IdentityTypeCabinetDecision}, diff --git a/addon/pint/org_item.go b/addon/pint/org_item.go index 199b64d..44d7c95 100644 --- a/addon/pint/org_item.go +++ b/addon/pint/org_item.go @@ -9,9 +9,7 @@ import ( "github.com/invopop/gobl/tax" ) -// ItemKeyGoodsServices is the item key for an item that is both goods and -// services, PINT AE's item type "B". GOBL's own "goods" and "services" keys -// give the other two types. +// ItemKeyGoodsServices is the item key for PINT AE's item type B, both goods and services. const ItemKeyGoodsServices cbc.Key = "goods-services" // PINT AE item types, written as the item's @@ -22,11 +20,10 @@ const ( ItemTypeGoodsServices cbc.Code = "B" ) -// Labels of the item identities PINT AE uses: the HS item classification -// (IBR-188-AE) and the service accounting code (BTAE-17, IBR-189-AE). +// Labels of the item identities PINT AE uses. const ( - IdentityLabelHS = "HS" - IdentityLabelSAC = "SAC" + IdentityLabelHS = "HS" // HS item classification + IdentityLabelSAC = "SAC" // service accounting code ) // ItemTypeAE returns the PINT AE item type for an item key, or an empty code @@ -57,8 +54,7 @@ func ItemKeyAE(typ cbc.Code) cbc.Key { return "" } -// orgItemRules asks the items of UAE documents for the HS item -// classifications PINT AE needs. +// orgItemRules validates items on UAE documents. func orgItemRules() *rules.Set { return rules.For(new(org.Item), rules.When( @@ -79,11 +75,7 @@ func orgItemRules() *rules.Set { ), ), ), - // gobl.ubl writes identities with a label and no scheme ID as item - // classifications, with the label as their list. FormatAE writes the - // SAC ones as service accounting codes instead (IBR-189-AE). - // IBR-188-AE's text asks for HS on every classification, but its - // test passes when any one is HS. + // IBR-188-AE's text wants every classification to be HS, but its test passes when any one is. rules.Field("identities", rules.Assert("03", "item classifications must include one from the HS list (IBR-188-AE)", is.Func("classifications include HS", identitiesClassifiedWithHS), @@ -101,9 +93,8 @@ func itemKeyIs(key cbc.Key) func(any) bool { } } -// identitiesHaveLabel returns a predicate that reports whether one of the -// identities gobl.ubl writes as item classifications, those with a label and -// no scheme ID, has the label. +// identitiesHaveLabel returns a predicate that reports whether one of the item classifications, +// the identities with a label and no scheme ID, has the label. func identitiesHaveLabel(label string) func(any) bool { return func(val any) bool { ids, ok := val.([]*org.Identity) @@ -119,10 +110,8 @@ func identitiesHaveLabel(label string) func(any) bool { } } -// identitiesClassifiedWithHS reports whether the identities gobl.ubl writes -// as item classifications, those with a label and no scheme ID, include an HS -// one. Items without classifications pass, and the service accounting codes -// don't count as one. +// identitiesClassifiedWithHS reports whether the item classifications, if any, include an HS one. +// SAC codes don't count. func identitiesClassifiedWithHS(val any) bool { ids, ok := val.([]*org.Identity) if !ok { diff --git a/addon/pint/org_item_test.go b/addon/pint/org_item_test.go index 10941af..5a02b0e 100644 --- a/addon/pint/org_item_test.go +++ b/addon/pint/org_item_test.go @@ -12,19 +12,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestItemTypeAE(t *testing.T) { - tests := map[cbc.Key]cbc.Code{ - org.ItemKeyGoods: pint.ItemTypeGoods, - org.ItemKeyServices: pint.ItemTypeServices, - pint.ItemKeyGoodsServices: pint.ItemTypeGoodsServices, - "other": "", - cbc.KeyEmpty: "", - } - for key, want := range tests { - assert.Equal(t, want, pint.ItemTypeAE(key), key) - } -} - func TestItemKeyAE(t *testing.T) { tests := map[cbc.Code]cbc.Key{ "G": org.ItemKeyGoods, @@ -63,10 +50,6 @@ func TestOrgItemRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, item(org.ItemKeyGoods, withScheme)), faultGoodsHS) }) - t.Run("services need no service accounting code", func(t *testing.T) { - assert.Empty(t, aeFaults(t, item(org.ItemKeyServices))) - }) - t.Run("goods and services need an HS classification (IBR-186-AE)", func(t *testing.T) { assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices)), faultGoodsServices) assert.Contains(t, aeFaults(t, item(pint.ItemKeyGoodsServices, sac)), faultGoodsServices) diff --git a/addon/pint/org_party.go b/addon/pint/org_party.go index a817bd1..5691568 100644 --- a/addon/pint/org_party.go +++ b/addon/pint/org_party.go @@ -25,25 +25,14 @@ const endpointSchemeMailto = "mailto" // email addresses. const endpointSchemeEmail cbc.Code = "EM" -// orgPartyRules asks every party of a UAE document with a UAE tax ID for an -// address with an emirate code as its region (IBR-128-AE). gobl.ubl writes -// the country of a party's tax ID over the address's own in -// cac:PostalAddress, and an address with only that country when the party -// has none, so every address of the party is in the UAE there. The address -// rules already check the addresses whose own country is AE. +// orgPartyRules validates parties on UAE documents. // -// It also checks the type of the legal identities of the parties with a UAE -// Peppol endpoint (IBR-173-AE, IBR-181-AE, IBR-180-AE, IBR-183-AE). Every one -// of those tests only fires with a 0235 cbc:EndpointID, so only UAE Peppol -// participants are checked; foreign payees, receivers and factors have none. -// -// TODO: gobl.ubl writes the delivery receiver's address with its own -// country, as cac:DeliveryLocation/cac:Address, so a receiver with a UAE tax -// ID and a foreign address gets an emirate error PINT AE wouldn't give. +// TODO: a delivery receiver with a UAE tax ID and a foreign address gets an emirate error PINT AE wouldn't. func orgPartyRules() *rules.Set { return rules.For(new(org.Party), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), + // gobl.ubl writes a UAE tax ID's country over the address's, so the address counts as UAE. rules.When( is.Func("UAE tax ID", partyHasAETaxID), rules.Field("addresses", @@ -60,10 +49,7 @@ func orgPartyRules() *rules.Set { ), ), ), - // IBR-180-AE and IBR-183-AE exempt the buyers with the predefined - // endpoints 9900000098 and 9900000099. IBR-183-AE also exempts - // other 1XXXXXXXXX endpoints, but IBR-180-AE still asks them for a - // type, and GOBL can only write the four in the list. + // IBR-183-AE also exempts other 1XXXXXXXXX endpoints, but IBR-180-AE still asks them for a type. rules.When( is.Func("has UAE Peppol endpoint other than 9900000098 or 9900000099", partyHasUAEEndpoint(endpointPatternPredefined, false)), rules.Field("identities", rules.Each( @@ -86,22 +72,14 @@ func partyHasAETaxID(val any) bool { return ok && p != nil && p.TaxID != nil && p.TaxID.Code != "" && p.TaxID.Country.Code() == l10n.AE } -// partyHasOneIdentification reports whether gobl.ubl writes at most one -// cac:PartyIdentification for the party, as PINT allows a single buyer -// identifier (ibr-sr-16). gobl.ubl writes every identity there except those -// with the tax scope and the first with the legal scope. +// partyHasOneIdentification reports whether gobl.ubl writes at most one cac:PartyIdentification. func partyHasOneIdentification(val any) bool { p, ok := val.(*org.Party) return ok && p != nil && len(partyIdentifications(p)) <= 1 } -// payeeIsNotSupplier reports whether the invoice's payee differs from the -// supplier, compared as ibr-017 does: on the legal identities gobl.ubl writes -// as cac:PartyLegalEntity/cbc:CompanyID when both have one, else on the -// identities it writes as cac:PartyIdentification when both have any, else on -// the payee's name against the supplier's, regardless of case. Identities -// match on code and the scheme gobl.ubl writes. An invoice without a payee -// passes. +// payeeIsNotSupplier reports whether the payee differs from the supplier by legal identity, else by +// identification, else by name. func payeeIsNotSupplier(val any) bool { inv, ok := val.(*bill.Invoice) if !ok || inv == nil || inv.Payment == nil || inv.Payment.Payee == nil || inv.Supplier == nil { @@ -154,10 +132,7 @@ func identificationScheme(id *org.Identity) cbc.Code { return id.Ext.Get(iso.ExtKeySchemeID) } -// partyEndpointID returns the scheme and code of the party's electronic -// address, chosen as gobl.ubl does for cbc:EndpointID: the first ISO 6523 -// endpoint, or else the first email endpoint, or else the first inbox with an -// email or a scheme. Email addresses have the scheme EM. +// partyEndpointID returns the scheme and code gobl.ubl writes as the party's cbc:EndpointID. func partyEndpointID(p *org.Party) (cbc.Code, string) { if e := p.Endpoint(iso.ActorIDScheme); e != nil { // An ISO 6523 URI reads "iso6523-actorid-upis:::". @@ -185,15 +160,9 @@ func partyEndpointID(p *org.Party) (cbc.Code, string) { // Patterns of the UAE Peppol endpoint codes the PINT AE rules depend on. const ( - // endpointPatternPredefined matches the predefined endpoints 9900000098 - // and 9900000099, which IBR-180-AE and IBR-183-AE exempt. - endpointPatternPredefined = `^99000000(98|99)$` - // endpointPatternDeemedSupply matches the predefined endpoint of the - // buyer of a deemed supply (PINT AE BIS 1.5.3). + endpointPatternPredefined = `^99000000(98|99)$` endpointPatternDeemedSupply = `^9900000097$` - // endpointPattern1or9 matches the codes of 10 digits starting with 1 or - // 9, which need no buyer legal registration identifier (IBR-149-AE). - endpointPattern1or9 = `^[19]\d{9}$` + endpointPattern1or9 = `^[19]\d{9}$` ) // partyHasUAEEndpoint returns a predicate that reports whether the party's @@ -231,15 +200,9 @@ func partyFirstLegalIdentity(val any) *org.Identity { // digits are the TIN. var trnRegexpAE = regexp.MustCompile(ae.TRNPattern) -// normalizeSupplierAE fills in what the supplier's UAE TRN implies, when it -// is missing: the TIN the TRN starts with, as a tax scope identity of the -// TIN type (IBT-032), and the UAE Peppol endpoint, 0235 with the TIN, the -// one the UAE PASR gives every end user. An identity of the TIN type or with -// the tax scope is kept as it is, and the endpoint is only added to a -// supplier with no endpoint or inbox at all. -// -// TODO: the customer's endpoint could be derived from its TRN the same way, -// as every UAE end user is 0235:, but it is not done yet. +// normalizeSupplierAE adds the TIN identity (IBT-032) and 0235: endpoint a UAE supplier's TRN implies, +// unless it already has a TIN or tax identity, or any endpoint or inbox. +// TODO: derive the customer's endpoint from its TRN too. func normalizeSupplierAE(inv *bill.Invoice) { if inv == nil || inv.Supplier == nil { return @@ -265,10 +228,8 @@ func normalizeSupplierAE(inv *bill.Invoice) { } } -// partyTINFromTRN returns the TIN the party's UAE tax ID starts with, when -// the code has the TRN format and the TIN a valid check digit, as the AE -// regime checks them. It returns an empty code otherwise, so an invalid TRN -// gives one error, not a second one on a derived TIN. +// partyTINFromTRN returns the TIN a valid UAE TRN starts with, or "", so an invalid TRN gives one error, +// not a second one on a derived TIN. func partyTINFromTRN(p *org.Party) cbc.Code { if p.TaxID == nil || p.TaxID.Country != l10n.AE.Tax() { return "" diff --git a/addon/pint/org_party_test.go b/addon/pint/org_party_test.go index 27def6f..30c1bc9 100644 --- a/addon/pint/org_party_test.go +++ b/addon/pint/org_party_test.go @@ -48,12 +48,14 @@ func TestNormalizeSupplierAE(t *testing.T) { } }) - t.Run("a Peppol endpoint or inbox is kept", func(t *testing.T) { + t.Run("a Peppol endpoint is kept", func(t *testing.T) { p := trn() p.Endpoints = []*org.Endpoint{{URI: "iso6523-actorid-upis::0088:5790000435975"}} assert.Len(t, normalize(l10n.AE.Tax(), p).Endpoints, 1) + }) - p = trn() + t.Run("an existing Peppol inbox stops the UAE endpoint", func(t *testing.T) { + p := trn() p.Inboxes = []*org.Inbox{{Scheme: "0235", Code: "1234567897"}} assert.Empty(t, normalize(l10n.AE.Tax(), p).Endpoints) }) @@ -131,9 +133,7 @@ func TestOrgPartyRulesAE(t *testing.T) { t.Run("UAE addresses are left to the address rules (IBR-128-AE)", func(t *testing.T) { inv := standard() inv.Supplier.Addresses[0].Region = "Dubai" - out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-ORG-ADDRESS-01") - assert.NotContains(t, out, faultEmirate) + assert.NotContains(t, aeFaults(t, inv), faultEmirate) }) t.Run("other parties are not checked (IBR-128-AE)", func(t *testing.T) { @@ -204,8 +204,6 @@ func TestOrgPartyRulesAE(t *testing.T) { inv.Supplier.Identities[0].Scope = org.IdentityScopeLegal inv.Supplier.Identities = append(inv.Supplier.Identities, &org.Identity{Scope: org.IdentityScopeLegal, Code: "CN-1234567"}) - out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-EU-EN16931-ORG-PARTY-02") - assert.Contains(t, out, faultLegalType) + assert.Contains(t, aeFaults(t, inv), faultLegalType) }) } diff --git a/addon/pint/pay.go b/addon/pint/pay.go index 6d4e881..c79a600 100644 --- a/addon/pint/pay.go +++ b/addon/pint/pay.go @@ -16,9 +16,7 @@ const ( meansCodeSEPACreditTransfer cbc.Code = "58" ) -// payInstructionsRules enforces the payment instruction rules of the -// jurisdictions: A-NZ on Australian and New Zealand documents, and AE on UAE -// documents. +// payInstructionsRules validates payment instructions on A-NZ and UAE documents. func payInstructionsRules() *rules.Set { return rules.For(new(pay.Instructions), rules.When( @@ -31,10 +29,7 @@ func payInstructionsRules() *rules.Set { ), rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - // gobl.ubl only writes the first credit transfer, as - // cac:PayeeFinancialAccount, but every one needs the account. - // Unlike A-NZ, SEPA (58) is not included, as IBR-192-AE only - // checks 30. + // IBR-192-AE checks only 30, not 58. Every credit transfer needs an account, though gobl.ubl writes only the first. rules.When(is.Func("payment means is credit transfer", instructionsMeansIn(meansCodeCreditTransfer)), rules.Field("credit_transfer", rules.Assert("02", "credit transfer is required with the payment means 30 (IBR-192-AE)", is.Present), @@ -51,8 +46,6 @@ func payInstructionsRules() *rules.Set { // creditTransferRules enforces that any credit transfer information provided // on Australian and New Zealand documents carries a payment account identifier. -// AE has no such rule: IBR-192-AE only applies to credit transfer means (30), -// so it is checked from the payment instructions instead. func creditTransferRules() *rules.Set { return rules.For(new(pay.CreditTransfer), rules.When( diff --git a/addon/pint/scenarios.go b/addon/pint/scenarios.go index e90ae7e..34a04c7 100644 --- a/addon/pint/scenarios.go +++ b/addon/pint/scenarios.go @@ -20,16 +20,11 @@ const ( docTypeInvoiceOutsideScope cbc.Code = "480" docTypeCreditNoteGoodsServices cbc.Code = "81" - // UNTDID 1001 codes the EN 16931 scenarios set on standard invoices and - // credit notes, which some PINT AE rules check. - docTypeCommercialInvoice cbc.Code = "380" - docTypeCreditNote cbc.Code = "381" - // docTypeSelfBilledCreditNote is the code the EN 16931 scenarios set on - // self-billed credit notes. + // UNTDID 1001 codes the EN 16931 scenarios set. + docTypeCommercialInvoice cbc.Code = "380" + docTypeCreditNote cbc.Code = "381" docTypeSelfBilledCreditNote cbc.Code = "261" - // docTypeSelfBilledInvoice is the code the EN 16931 scenarios set on - // self-billed invoices. - docTypeSelfBilledInvoice cbc.Code = "389" + docTypeSelfBilledInvoice cbc.Code = "389" ) // docTypesAE are the UNTDID 1001 codes PINT AE accepts: ibr-cl-01's list for @@ -59,10 +54,7 @@ var invoiceTags = &tax.TagSet{ }, transactionTypeTags...), } -// invoiceScenarios set the UNTDID 1001 document type for PINT AE's -// out-of-scope documents. EN 16931's scenarios run first and set 380 or 381 -// from the invoice type; these match afterwards and replace the code, the same -// way EN maps the self-billed tag to 389. +// invoiceScenarios set 480 and 81 on out-of-scope documents, replacing the 380 or 381 that EN 16931 sets first. var invoiceScenarios = &tax.ScenarioSet{ Schema: bill.ShortSchemaInvoice, List: []*tax.Scenario{ @@ -86,9 +78,8 @@ var invoiceScenarios = &tax.ScenarioSet{ }, } -// invoiceIsAE reports whether the scenario document is a UAE invoice. Tags and -// scenarios belong to the addon, which runs for every regime, so the AE-only -// scenarios use it as their filter. +// invoiceIsAE reports whether the scenario document is a UAE invoice, as the addon's scenarios +// apply under every regime. func invoiceIsAE(doc any) bool { inv, ok := doc.(*bill.Invoice) return ok && inv != nil && inv.GetRegime() == l10n.AE.Tax() diff --git a/addon/pint/scenarios_test.go b/addon/pint/scenarios_test.go index b206711..88be581 100644 --- a/addon/pint/scenarios_test.go +++ b/addon/pint/scenarios_test.go @@ -65,16 +65,6 @@ func TestInvoiceScenarios(t *testing.T) { assert.Equal(t, cbc.Code("81"), documentType(t, inv)) }) - t.Run("AE invoice without the tag keeps EN's 380", func(t *testing.T) { - inv := scenarioInvoice(ae, bill.InvoiceTypeStandard) - assert.Equal(t, cbc.Code("380"), documentType(t, inv)) - }) - - t.Run("AE credit note without the tag keeps EN's 381", func(t *testing.T) { - inv := scenarioInvoice(ae, bill.InvoiceTypeCreditNote) - assert.Equal(t, cbc.Code("381"), documentType(t, inv)) - }) - t.Run("a hand-set code is replaced by the scenario", func(t *testing.T) { inv := scenarioInvoice(ae, bill.InvoiceTypeStandard, pint.TagOutsideTaxScope) inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyDocumentType: "380"})} diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index 996912d..fa774d7 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -12,10 +12,7 @@ import ( "github.com/invopop/gobl/tax" ) -// TaxCategoryMarginScheme is the PINT AE VAT category for supplies under the -// profit margin scheme, "Standard rate additional VAT". The official code list -// writes it with a Greek capital Nu (U+039D), but the Schematron tests and -// examples use the Latin N, so we follow them. +// TaxCategoryMarginScheme is the PINT AE margin scheme VAT category. const TaxCategoryMarginScheme cbc.Code = "N" // taxCategoryMap maps GOBL tax keys to the UNTDID 5305 tax category codes that @@ -31,10 +28,7 @@ var taxCategoryMap = tax.ExtensionsOf(cbc.CodeMap{ tax.KeyOutsideScope: en16931.TaxCategoryOutsideScope, }) -// exemptionCodesAE are the UAE VAT exemption reasons PINT AE takes in the -// CEF VATEX extension: the four exempt supplies of Article 46 of the UAE VAT -// Decree-Law (Federal Decree-Law No. 8 of 2017), the only ones the law -// allows. +// exemptionCodesAE are the UAE VAT exemptions of Article 46 of Federal Decree-Law No. 8 of 2017. var exemptionCodesAE = []cbc.Code{ "DL8.46.1", // certain financial services "DL8.46.2", // residential buildings @@ -74,13 +68,8 @@ func normalizeTaxCombo(tc *tax.Combo) { } } -// normalizeMarginSchemeAE gives the PINT AE margin scheme category to the -// exempt VAT lines of a UAE margin scheme invoice. The line combos already have -// E from their key, as norm reaches them before the invoice, and get it back -// once the tag is removed. Discounts and charges are left alone, so the -// discount and charge rules 01 and invoice rule 44 reject them (IBR-114-AE, -// IBR-115-AE, IBR-116-AE). Lines with an exemption reason are a real -// exempt supply, so they keep E and invoice rule 44 rejects the mixed invoice. +// normalizeMarginSchemeAE gives N to the exempt VAT lines without a VATEX code of a UAE margin scheme +// invoice. Discounts, charges and lines with a reason keep E, so the rules reject them. func normalizeMarginSchemeAE(inv *bill.Invoice) { if inv == nil || !inv.HasTags(TagMarginScheme) { return @@ -97,11 +86,8 @@ func normalizeMarginSchemeAE(inv *bill.Invoice) { } } -// normalizeMarginSchemeNoteAE links the regime's margin scheme statement to -// the margin scheme category, so it goes out as the reason on the N VAT -// breakdown. It is a note normalizer because the scenario adds the note after -// the invoice is normalized. The reverse mapping gives the key back to an -// imported statement, so the scenario doesn't add a second one. +// normalizeMarginSchemeNoteAE ties the margin scheme note to N, and keys an imported one so the scenario +// doesn't add a second. It normalizes notes as the scenario adds the note after the invoice is normalized. func normalizeMarginSchemeNoteAE(n *tax.Note) { if n == nil || n.Category != tax.CategoryVAT { return @@ -114,6 +100,7 @@ func normalizeMarginSchemeNoteAE(n *tax.Note) { } } +// taxComboRules validates tax combos on PINT documents. func taxComboRules() *rules.Set { return rules.For(new(tax.Combo), // PINT recognises GST (and other non-VAT schemes) as standard, zero or @@ -121,14 +108,9 @@ func taxComboRules() *rules.Set { // to outside scope must not apply here. rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-05"), - // UAE documents have their own list, with the margin scheme category - // (rule 03). - rules.When( - is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Field("ext", - rules.Assert("01", "invoice line tax category code must be a recognised PINT UNTDID 5305 code", - tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryMap.Values()...), - ), + rules.Field("ext", + rules.Assert("01", "invoice line tax category code must be a recognised PINT UNTDID 5305 code", + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryMap.Values()...), ), ), rules.When( @@ -140,14 +122,11 @@ func taxComboRules() *rules.Set { ), ), - // TODO: A-NZ has the same zero rate rule (05), and asks for a standard - // rate above zero (ALIGNED-IBRP-S-05/06/07). + // TODO: A-NZ has the same zero rate rule (ALIGNED-IBRP-Z-05/06/07) and a positive standard rate (ALIGNED-IBRP-S-05/06/07). rules.When( is.InContext(tax.RegimeIn(regimesAE...)), - // EN 16931 checks VAT category codes against its own list, which has - // no PINT AE margin scheme category (N). Rule 03 checks them against - // the PINT AE list instead. - rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-02"), + // EN 16931's and PINT's category lists have no N; IBR-139-AE checks the PINT AE list instead. + rules.Ignore("GOBL-EU-EN16931-TAX-COMBO-02", "GOBL-PEPPOL-PINT-TAX-COMBO-01"), rules.Field("ext", rules.Assert("03", "tax category code must be an AE UNCL5305 code: E, S, Z, O, AE or N (IBR-139-AE)", tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesAE...), @@ -157,8 +136,6 @@ func taxComboRules() *rules.Set { rules.When( is.Func("tax combo is standard rated", taxComboIsStandard), rules.Field("percent", - // 5.00 also covers the rate above zero ALIGNED-IBRP-S-05/06/07 - // ask for. rules.Assert("04", "tax percentage must be 5.00 (IBR-190-AE, ALIGNED-IBRP-S-05/06/07)", num.Equals(num.MakePercentage(5, 2)), ), @@ -174,8 +151,6 @@ func taxComboRules() *rules.Set { ), ), - // Lines, discounts and charges alike: the margin scheme lines have - // the category N instead of E, so they need none. rules.When( is.Func("exempt VAT", comboIsExemptVAT), rules.Field("ext", @@ -185,8 +160,7 @@ func taxComboRules() *rules.Set { ), ), - // The UAE VAT law allows no other exemption reasons, though the - // Schematron doesn't check the code list. + // The Schematron doesn't check the code list, but UAE VAT law allows no other reasons. rules.When( is.Func("VAT", comboIsVAT), rules.Field("ext", @@ -209,8 +183,7 @@ func taxComboIsZero(val any) bool { return ok && tc != nil && tc.Key == tax.KeyZero } -// taxCategoryCodesOutsideScope are the VAT category codes allowed on 480 and -// 81 documents: exempt (E) and not subject to VAT (O) (IBR-122-AE). +// taxCategoryCodesOutsideScope are the VAT category codes allowed on outside scope documents. var taxCategoryCodesOutsideScope = []cbc.Code{ en16931.TaxCategoryExempt, en16931.TaxCategoryOutsideScope, diff --git a/addon/pint/tax_combo_test.go b/addon/pint/tax_combo_test.go index e89fed4..370540d 100644 --- a/addon/pint/tax_combo_test.go +++ b/addon/pint/tax_combo_test.go @@ -158,7 +158,7 @@ func vatCombo(key cbc.Key, category string, percent *num.Percentage) *tax.Combo } } -func validateIn(tc *tax.Combo, regime l10n.TaxCountryCode) error { +func validateComboIn(tc *tax.Combo, regime l10n.TaxCountryCode) error { return rules.Validate(tc, tax.AddonContext(pint.V1), tax.RegimeContext(regime)) } @@ -175,52 +175,62 @@ func TestTaxComboRulesAE(t *testing.T) { if cat == "E" { c.Ext = c.Ext.Set(cef.ExtKeyVATEX, "DL8.46.1") } - assert.NoError(t, validateIn(c, ae), "category %s", cat) + assert.NoError(t, validateComboIn(c, ae), "category %s", cat) } - assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) - assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) - assert.NoError(t, validateIn(vatCombo(tax.KeyExempt, "N", nil), ae)) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(5, 2)), ae)) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(0, 2)), ae)) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyExempt, "N", nil), ae)) }) t.Run("margin scheme category is rejected outside AE", func(t *testing.T) { for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { - err := validateIn(vatCombo(cbc.KeyEmpty, "N", nil), regime) + err := validateComboIn(vatCombo(cbc.KeyEmpty, "N", nil), regime) assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-01", "regime %s", regime) } }) t.Run("categories outside the AE subset are rejected (IBR-139-AE)", func(t *testing.T) { for _, cat := range []string{"G", "K", "L", "M"} { - err := validateIn(vatCombo(cbc.KeyEmpty, cat, nil), ae) + err := validateComboIn(vatCombo(cbc.KeyEmpty, cat, nil), ae) assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-03", "category %s", cat) } }) t.Run("AE subset does not apply outside AE", func(t *testing.T) { - assert.NoError(t, validateIn(vatCombo(cbc.KeyEmpty, "K", nil), l10n.SG.Tax())) + assert.NoError(t, validateComboIn(vatCombo(cbc.KeyEmpty, "K", nil), l10n.SG.Tax())) }) t.Run("standard rate must be 5% (IBR-190-AE, ALIGNED-IBRP-S-05/06/07)", func(t *testing.T) { for _, rate := range []int64{0, 10} { - err := validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(rate, 2)), ae) + err := validateComboIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(rate, 2)), ae) assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-04", "rate %d", rate) } }) t.Run("5% check compares numbers, not strings", func(t *testing.T) { - assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(50, 3)), ae)) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(50, 3)), ae)) }) t.Run("zero rate must be 0% (ALIGNED-IBRP-Z-05/06/07, IBR-120-AE)", func(t *testing.T) { - err := validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), ae) + err := validateComboIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), ae) assert.ErrorContains(t, err, "GOBL-PEPPOL-PINT-TAX-COMBO-05") }) + t.Run("exempt VAT needs an exemption reason (IBR-167-AE, IBR-168-AE, IBR-169-AE)", func(t *testing.T) { + const faultExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + assert.ErrorContains(t, validateComboIn(vatCombo(tax.KeyExempt, "E", nil), ae), faultExemption) + for _, code := range []cbc.Code{"DL8.46.1", "DL8.46.4"} { + c := vatCombo(tax.KeyExempt, "E", nil) + c.Ext = c.Ext.Set(cef.ExtKeyVATEX, code) + assert.NoError(t, validateComboIn(c, ae), code) + } + }) + t.Run("rate rules do not apply outside AE", func(t *testing.T) { for _, regime := range []l10n.TaxCountryCode{l10n.SG.Tax(), l10n.AU.Tax()} { - assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(0, 2)), regime), regime) - assert.NoError(t, validateIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(10, 2)), regime), regime) - assert.NoError(t, validateIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), regime), regime) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(0, 2)), regime), regime) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyStandard, "S", num.NewPercentage(10, 2)), regime), regime) + assert.NoError(t, validateComboIn(vatCombo(tax.KeyZero, "Z", num.NewPercentage(5, 2)), regime), regime) } }) } diff --git a/addon/pint/tax_identity.go b/addon/pint/tax_identity.go index ddb0566..6b60586 100644 --- a/addon/pint/tax_identity.go +++ b/addon/pint/tax_identity.go @@ -6,13 +6,10 @@ import ( "github.com/invopop/gobl/tax" ) -// taxIdentityRules requires the trailing 03 of a VAT registration on every -// UAE tax identity of a UAE document (IBR-132-AE). The rest of IBR-132-AE's -// format, 15 digits starting with 1, is checked by the AE regime, together -// with the check digit of the TIN they start with. -// vatTRNSuffixPattern is the trailing 03 of a UAE TRN for VAT (IBR-132-AE). +// vatTRNSuffixPattern is the trailing 03 of a UAE TRN for VAT. const vatTRNSuffixPattern = `03$` +// taxIdentityRules validates tax identities on UAE documents. func taxIdentityRules() *rules.Set { return rules.For(new(tax.Identity), rules.When( diff --git a/addon/pint/tax_identity_test.go b/addon/pint/tax_identity_test.go index ccb744b..8b1b859 100644 --- a/addon/pint/tax_identity_test.go +++ b/addon/pint/tax_identity_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/invopop/gobl.peppol/addon/pint" - "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/rules" "github.com/invopop/gobl/tax" @@ -27,18 +26,6 @@ func TestTaxIdentityRulesAE(t *testing.T) { assert.ErrorContains(t, err, faultTRN) }) - t.Run("the rest of the TRN format is left to the AE regime (IBR-132-AE)", func(t *testing.T) { - for name, code := range map[string]cbc.Code{ - "does not start with 1": "200000000000003", - "too short": "10000000000003", - "too long": "1000000000000003", - } { - err := validate(&tax.Identity{Country: "AE", Code: code}) - assert.ErrorContains(t, err, "GOBL-AE-TAX-IDENTITY-01", name) - assert.NotContains(t, err.Error(), faultTRN, name) - } - }) - t.Run("identity without a code is accepted (IBR-132-AE)", func(t *testing.T) { assert.NoError(t, validate(&tax.Identity{Country: "AE"})) }) @@ -51,7 +38,7 @@ func TestTaxIdentityRulesAE(t *testing.T) { }) t.Run("the rule does not apply outside AE", func(t *testing.T) { - err := validateIn(&tax.Identity{Country: "AE", Code: "200000000000003"}, l10n.AU.Tax()) + err := validateIn(&tax.Identity{Country: "AE", Code: "100000001600004"}, l10n.AU.Tax()) if err != nil { assert.NotContains(t, err.Error(), faultTRN) } diff --git a/addon/pint/transaction_type.go b/addon/pint/transaction_type.go index 383b22d..0b388d0 100644 --- a/addon/pint/transaction_type.go +++ b/addon/pint/transaction_type.go @@ -11,28 +11,16 @@ import ( // Invoice tags for the PINT AE transaction type flags (BTAE-02). Exports use // GOBL's own "export" tag. const ( - // TagFreeTradeZone marks a supply of goods or services in a free trade zone. - TagFreeTradeZone cbc.Key = "free-trade-zone" - // TagDeemedSupply marks a supply of goods or services without - // consideration. - TagDeemedSupply cbc.Key = "deemed-supply" - // TagMarginScheme marks a supply of goods under the profit margin scheme. - // The UAE regime defines it, with the statement the invoice must carry. - TagMarginScheme = ae.TagMarginScheme - // TagSummary marks a summary invoice: more than one supply to the same - // person in the same calendar month. - TagSummary cbc.Key = "summary" - // TagContinuousSupply marks a supply made on a recurrent basis. + TagFreeTradeZone cbc.Key = "free-trade-zone" + TagDeemedSupply cbc.Key = "deemed-supply" + TagMarginScheme = ae.TagMarginScheme + TagSummary cbc.Key = "summary" TagContinuousSupply cbc.Key = "continuous-supply" - // TagDisclosedAgent marks a supply an agent who is a registrant makes on - // behalf of a principal. - TagDisclosedAgent cbc.Key = "disclosed-agent" - // TagECommerce marks a supply of goods or services through e-commerce. - TagECommerce cbc.Key = "e-commerce" + TagDisclosedAgent cbc.Key = "disclosed-agent" + TagECommerce cbc.Key = "e-commerce" ) -// transactionTypePattern is the format of the transaction type: 8 flags of -// 0 or 1 (IBR-154-AE). +// transactionTypePattern is the format of the transaction type: 8 flags of 0 or 1. const transactionTypePattern = `^[01]{8}$` // TransactionType is a parsed PINT AE invoice transaction type (BTAE-02). @@ -63,9 +51,8 @@ var transactionTypeFlags = []struct { {tax.TagExport, func(t *TransactionType) *bool { return &t.Export }}, } -// ParseTransactionType reads the flags of a transaction type code. A flag is -// set when its position holds a 1; a missing or malformed code gives no -// flags, as IBR-154-AE checks the format. +// ParseTransactionType reads the flags of a transaction type code: each position holding a 1 sets +// its flag. func ParseTransactionType(code cbc.Code) TransactionType { var t TransactionType s := code.String() @@ -110,11 +97,8 @@ func transactionTypeFromTags(inv *bill.Invoice) TransactionType { return t } -// normalizeTransactionType sets the transaction type of a UAE invoice from its -// flag tags, "00000000" without any. Every PINT AE document needs one -// (IBR-154-AE). The tags are the only source: a code from an earlier -// calculation can't be told apart from one set directly, so keeping it would -// leave the flags of removed tags in place. +// normalizeTransactionType sets the transaction type from the flag tags only: a code from an earlier +// calculation can't be told apart from one set directly. func normalizeTransactionType(inv *bill.Invoice) { if inv == nil { return @@ -164,10 +148,7 @@ var transactionTypeTags = []*cbc.Definition{ }, } -// invoiceHasTags returns a predicate that reports whether an invoice has all -// the tags. The transaction type rules read the flags from the tags, which -// the transaction type is built from (normalizeTransactionType) and the UBL -// import sets from it. +// invoiceHasTags returns a predicate that reports whether an invoice has all the tags. func invoiceHasTags(keys ...cbc.Key) func(any) bool { return func(val any) bool { inv, ok := val.(*bill.Invoice) diff --git a/addon/pint/transaction_type_test.go b/addon/pint/transaction_type_test.go index 4fc071f..5909fc0 100644 --- a/addon/pint/transaction_type_test.go +++ b/addon/pint/transaction_type_test.go @@ -59,10 +59,14 @@ func TestNormalizeTransactionType(t *testing.T) { assert.Equal(t, cbc.Code("00010011"), code(inv)) }) - t.Run("a code set directly is replaced without tags", func(t *testing.T) { + t.Run("a code set directly is replaced by the tags", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard) inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00001000"})} - assert.Equal(t, cbc.Code("00000000"), code(inv)) + assert.Equal(t, cbc.Code("00000000"), code(inv), "without tags") + + inv = aeDocument(bill.InvoiceTypeStandard, pint.TagContinuousSupply) + inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00000000"})} + assert.Equal(t, cbc.Code("00001000"), code(inv), "with tags") }) t.Run("removing the last tag clears its flag", func(t *testing.T) { @@ -72,12 +76,6 @@ func TestNormalizeTransactionType(t *testing.T) { assert.Equal(t, cbc.Code("00000000"), code(inv)) }) - t.Run("tags replace an earlier code", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard, pint.TagContinuousSupply) - inv.Tax = &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyTransactionType: "00000000"})} - assert.Equal(t, cbc.Code("00001000"), code(inv)) - }) - t.Run("only under the AE regime", func(t *testing.T) { inv := scenarioInvoice(l10n.AU.Tax(), bill.InvoiceTypeStandard) require.NoError(t, inv.Calculate()) diff --git a/ubl/ae.go b/ubl/ae.go index 8062944..a52430f 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -36,14 +36,6 @@ const ( // document reference that carries the total with VAT in AED (BTAE-20). const aedTotalDocumentType = "aedtotal-incl-vat" -// aeStandardRate is the rate PINT AE expects on reverse charge and margin -// scheme lines and breakdowns, and on reverse charge allowances and charges. -// GOBL keeps them without a percent, as the invoice charges no VAT, but the -// PINT AE examples and the 5% standard rate (IBR-190-AE) write 5, margin -// scheme lines need a rate (IBR-111-AE), and reverse charge allowances and -// charges one above 0 (aligned-ibrp-ae-06, aligned-ibrp-ae-07). -const aeStandardRate = "5" - // accountSchemeIBAN is the scheme PINT AE gives the ID of an IBAN account // (IBT-084-1), as the official examples do. const accountSchemeIBAN = "IBAN" @@ -67,7 +59,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAEDeliveryPartyID(out, inv) exportAEContractValue(out, inv) exportAEPayment(out, inv) - exportAEChargeRates(out) + exportAEChargeRates(out, aeStandardRate(inv)) exportAELines(out.InvoiceLines, inv) exportAELines(out.CreditNoteLines, inv) for _, p := range goblubl.InvoiceParties(inv, out) { @@ -76,7 +68,7 @@ func exportAE(_ *goblubl.Format, env *gobl.Envelope, doc goblubl.Document) error exportAEPartyIdentities(out.AccountingSupplierParty.Party, inv.Supplier) exportAEPartyIdentities(out.AccountingCustomerParty.Party, inv.Customer) for i := range out.TaxTotal { - exportAETaxTotal(&out.TaxTotal[i]) + exportAETaxTotal(&out.TaxTotal[i], aeStandardRate(inv)) } exportAEExchangeRate(out, inv) return nil @@ -110,10 +102,8 @@ func importAE(_ *goblubl.Format, doc goblubl.Document, env *gobl.Envelope) error return nil } -// importAEOutsideTaxScope reads the PINT AE out-of-scope document types, which -// gobl.ubl does not know and imports as "other": 480 becomes a standard -// invoice and 81 a credit note, both with the outside-tax-scope tag. The PINT -// scenarios then set the type code back when the document is calculated. +// importAEOutsideTaxScope reads 480 and 81, which gobl.ubl imports as "other", as a standard invoice +// and a credit note with the outside-tax-scope tag. func importAEOutsideTaxScope(in *goblubl.Invoice, inv *bill.Invoice) { code := in.InvoiceTypeCode if code == nil { @@ -135,11 +125,8 @@ func importAEOutsideTaxScope(in *goblubl.Invoice, inv *bill.Invoice) { } } -// importAEMarginScheme reads the combos gobl.ubl imports with the N category -// and a 5% rate as exempt, with the margin-scheme tag, the way a user writes a -// margin scheme supply. Without a key, EN 16931 would read them as standard -// rated, which charges VAT the invoice doesn't. The tag normally comes from -// the transaction type, but keeps N on the lines when the flag is missing. +// importAEMarginScheme reads N VAT combos as exempt with the margin-scheme tag, as a user writes them; +// without a key EN 16931 would make them standard rated. func importAEMarginScheme(inv *bill.Invoice) { var sets []tax.Set for _, l := range inv.Lines { @@ -167,17 +154,15 @@ func importAEMarginScheme(inv *bill.Invoice) { } // exportAEUUID writes the invoice's UUID as cbc:UUID, the unique identifier -// number BTAE-07 (IBR-193-AE). +// number (BTAE-07). func exportAEUUID(out *goblubl.Invoice, inv *bill.Invoice) { if !inv.UUID.IsZero() { out.UUID = inv.UUID.String() } } -// exportAETransactionType writes the transaction type as -// cbc:ProfileExecutionID (BTAE-02), and the beneficiary (BTAE-01) and -// principal (BTAE-14) IDs as the only identification of the buyer and seller -// parties, as the PINT AE examples do. +// exportAETransactionType writes the transaction type (BTAE-02), and the beneficiary (BTAE-01) and +// principal (BTAE-14) IDs as the buyer and seller party identifications. func exportAETransactionType(out *goblubl.Invoice, inv *bill.Invoice) { out.ProfileExecutionID = inv.Tax.GetExt(pint.ExtKeyTransactionType).String() if id := inv.Tax.GetExt(pint.ExtKeyBeneficiaryID); id != "" { @@ -204,11 +189,8 @@ func exportAEIssueTime(out *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAEContractValue writes the description of each contract, where PINT -// AE puts the contract value, as cac:ContractDocumentReference/ -// cbc:DocumentDescription (BTAE-05), on the references gobl.ubl writes in the -// same order as the invoice's contracts. gobl.ubl already reads it back as the -// description. +// exportAEContractValue writes each contract's description, PINT AE's contract value (BTAE-05), as its +// cac:ContractDocumentReference/cbc:DocumentDescription. func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Ordering == nil || len(inv.Ordering.Contracts) != len(out.ContractDocumentReference) { return @@ -221,8 +203,7 @@ func exportAEContractValue(out *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAEPayment completes the payment instructions gobl.ubl writes, which -// are the invoice's only ones. +// exportAEPayment completes the payee account gobl.ubl writes from the first credit transfer. func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { if len(out.PaymentMeans) == 0 || inv.Payment == nil { return @@ -232,9 +213,8 @@ func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAECreditTransfer writes the IBAN scheme of the payee account -// (IBT-084-1) and the address of its branch (IBT-169 to IBT-175). -// gobl.ubl already reads the address back. +// exportAECreditTransfer writes the IBAN scheme of the payee account (IBT-084-1) and the address of +// its branch (IBT-169 to IBT-175), which gobl.ubl already reads back. func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfer) { if acc == nil || ct == nil { return @@ -243,10 +223,7 @@ func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfe scheme := accountSchemeIBAN acc.ID.SchemeID = &scheme } - // TODO: generic PINT has the branch address too (IBG-34), so FormatPINT - // should write it, but it drops it on export, as it did before PINT AE. - // It doesn't belong in gobl.ubl: EN 16931 warns against it (UBL-CR-432), - // and A-NZ doesn't have it. + // TODO: FormatPINT should write the branch address too (IBG-34); gobl.ubl can't (UBL-CR-432). if addr := aeAddress(ct.Branch); addr != nil { if acc.FinancialInstitutionBranch == nil { acc.FinancialInstitutionBranch = new(goblubl.Branch) @@ -278,27 +255,21 @@ func aeAddress(a *org.Address) *goblubl.PostalAddress { return addr } -// exportAEChargeRates writes the rate of the reverse charge allowances and -// charges at 5, as PINT AE wants one above 0 (aligned-ibrp-ae-06, -// aligned-ibrp-ae-07) and gobl.ubl writes 0. Exempt ones keep the 0 PINT AE -// wants there (aligned-ibrp-e-06, aligned-ibrp-e-07), and the margin scheme -// isn't allowed on them (IBR-114-AE, IBR-115-AE). -func exportAEChargeRates(out *goblubl.Invoice) { +// exportAEChargeRates writes the standard rate on reverse charge allowances and charges, where gobl.ubl +// writes 0 and PINT AE wants one above 0. +func exportAEChargeRates(out *goblubl.Invoice, standard string) { for _, ac := range out.AllowanceCharge { for _, c := range ac.TaxCategory { if c != nil && c.ID != nil && c.ID.Value == taxCategoryReverseCharge { - rate := aeStandardRate + rate := standard c.Percent = &rate } } } } -// importAEChargeExemptions reads the exemption reasons of the charges and -// discounts back onto their VAT combos, from their own cac:TaxCategory: -// gobl.ubl takes them from the VAT breakdown, which only keeps the reasons -// all its charges, discounts and lines share. gobl.ubl imports the charges -// and the discounts apart, each in the order of the document. +// importAEChargeExemptions reads charge and discount exemption reasons from their own cac:TaxCategory; +// gobl.ubl takes them from the breakdown, which keeps only shared ones. func importAEChargeExemptions(in *goblubl.Invoice, inv *bill.Invoice) { if len(in.AllowanceCharge) != len(inv.Charges)+len(inv.Discounts) { return @@ -336,9 +307,8 @@ func identifiedParty(id cbc.Code) *goblubl.Party { }} } -// importAETransactionType reads back what exportAETransactionType writes. The -// transaction type also sets its flags' tags, so the invoice reads the same -// way a user would write it. +// importAETransactionType reads back what exportAETransactionType writes, and adds the tags of the +// transaction type's flags. func importAETransactionType(in *goblubl.Invoice, inv *bill.Invoice) { code := cbc.Code(strings.TrimSpace(in.ProfileExecutionID)) if code != "" { @@ -395,8 +365,7 @@ func exportAECreditNoteReason(out *goblubl.Invoice, inv *bill.Invoice) { } // importAECreditNoteReason reads the credit note reason back from the first -// cac:DiscrepancyResponse with a code, the only one PINT AE allows -// (ibr-198-ae). +// cac:DiscrepancyResponse with a code, the only one PINT AE allows. func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { for _, r := range in.DiscrepancyResponse { if r.ResponseCode != nil && strings.TrimSpace(r.ResponseCode.Value) != "" { @@ -406,11 +375,8 @@ func importAECreditNoteReason(in *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAELineExemption writes the VAT exemption reason of an exempt line -// as its cac:ClassifiedTaxCategory/cbc:TaxExemptionReasonCode (IBT-186, -// IBR-167-AE), and the text of the invoice's tax note for the line's VAT -// category as its cbc:TaxExemptionReason (IBT-185), the same note gobl.ubl -// writes on the category's VAT breakdown. Standard rated lines have no reason. +// exportAELineExemption writes the line's VATEX code (IBT-186) and, except on standard rated lines, +// its category's tax note as the reason (IBT-185). func exportAELineExemption(line *goblubl.InvoiceLine, l *bill.Line, tx *bill.Tax) { if l == nil || line.Item == nil || line.Item.ClassifiedTaxCategory == nil { return @@ -447,10 +413,8 @@ func aeTaxNote(notes []*tax.Note, c *tax.Combo) *tax.Note { return nil } -// importAELineExemptions reads the line exemption reasons back onto the VAT -// combos of the invoice's lines, which gobl.ubl imports in the same order. A -// reason text becomes the tax note of the line's VAT category, unless the VAT -// breakdown already gave it one. +// importAELineExemptions reads the line VATEX codes back, and a reason text as the category's tax +// note when the breakdown gave none. func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return @@ -481,10 +445,8 @@ func importAELineExemptions(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } } -// exportAELineGoods writes the type of goods or services (BTAE-09) as the -// item's cac:CommodityClassification/cbc:NatureCode, and the item's GTIN as -// its standard identifier (IBR-174-AE): gobl.ubl writes the first identity -// with a scheme there, which may not be the GTIN. +// exportAELineGoods writes the goods type (BTAE-09) as cbc:NatureCode and the GTIN as the standard +// identifier, where gobl.ubl may write another identity. func exportAELineGoods(line *goblubl.InvoiceLine, l *bill.Line) { if l == nil || l.Item == nil || line.Item == nil { return @@ -501,9 +463,8 @@ func exportAELineGoods(line *goblubl.InvoiceLine, l *bill.Line) { } } -// aeCommodityClassification returns the item's first commodity -// classification, adding one if it has none, where the PINT AE item codes go -// alongside the item classification code, as in the official examples. +// aeCommodityClassification returns the item's first commodity classification, adding one if it has +// none. The PINT AE item codes go there with the item classification code, as in the official examples. func aeCommodityClassification(it *goblubl.Item) *goblubl.CommodityClassification { if it.CommodityClassification == nil || len(*it.CommodityClassification) == 0 { it.CommodityClassification = &[]goblubl.CommodityClassification{{}} @@ -511,10 +472,8 @@ func aeCommodityClassification(it *goblubl.Item) *goblubl.CommodityClassificatio return &(*it.CommodityClassification)[0] } -// exportAELineSAC moves the service accounting codes (BTAE-17), which -// gobl.ubl writes as item classifications listed "SAC" since their -// identities have that label, to cac:AdditionalItemIdentification with the -// SAC scheme (IBR-189-AE). +// exportAELineSAC moves the SAC item classifications gobl.ubl writes to cac:AdditionalItemIdentification +// with the SAC scheme (BTAE-17). func exportAELineSAC(line *goblubl.InvoiceLine) { if line.Item == nil || line.Item.CommodityClassification == nil { return @@ -549,8 +508,7 @@ func exportAELineItemType(line *goblubl.InvoiceLine, l *bill.Line) { } } -// importAELineGoods reads the type of goods or services back onto the items of the invoice's lines, which gobl.ubl imports in the -// same order. gobl.ubl already reads the GTIN as an identity. +// importAELineGoods reads the goods type back onto the line items. gobl.ubl already reads the GTIN. func importAELineGoods(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if len(lines) == 0 || len(lines) != len(inv.Lines) { return @@ -655,13 +613,8 @@ func importAEIncoterms(in *goblubl.Invoice, inv *bill.Invoice) { inv.Delivery.Ext = inv.Delivery.Ext.Set(key, code) } -// exportAEDeliveryPartyID writes the delivery receiver's UAE TRN, or its TIN -// when it has no TRN, as cac:DeliveryParty/cac:PartyIdentification/cbc:ID: -// the Deliver to Party ID (BTAE-23) the implementation guide (section 2.3.11) -// asks for when the goods go to someone other than the buyer. The PINT AE -// syntax has the element, the generic PINT one doesn't, but neither the -// syntax nor the semantic model give it a business term, and no rule checks -// it. gobl.ubl writes the delivery party with only its name and contact. +// exportAEDeliveryPartyID writes the receiver's UAE TRN, or else TIN, as the Deliver to Party ID +// (BTAE-23, implementation guide 2.3.11). func exportAEDeliveryPartyID(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Delivery == nil { return @@ -739,8 +692,9 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { if inv.Currency != currency.AED { rate = currency.MatchExchangeRate(inv.ExchangeRates, inv.Currency, currency.AED) } + standard := aeStandardRate(inv) for i := range lines { - exportAELine(&lines[i]) + exportAELine(&lines[i], standard) if len(lines) == len(inv.Lines) { exportAELineAmounts(&lines[i], inv.Lines[i], inv.Currency, rate) exportAELineExemption(&lines[i], inv.Lines[i], inv.Tax) @@ -752,29 +706,16 @@ func exportAELines(lines []goblubl.InvoiceLine, inv *bill.Invoice) { } // exportAELine completes a line's price details and VAT rate. -func exportAELine(line *goblubl.InvoiceLine) { +func exportAELine(line *goblubl.InvoiceLine, standard string) { exportAEPrice(line) if line.Item != nil && line.Item.ClassifiedTaxCategory != nil { c := line.Item.ClassifiedTaxCategory - c.Percent = aeRate(c.ID, c.Percent) + c.Percent = aeRate(c.ID, c.Percent, standard) } } -// exportAELineAmounts writes the line amount payable (BTAE-10) and the line VAT -// amount (BTAE-08) in cac:ItemPriceExtension, which every line needs -// (IBR-194-AE, IBR-104-AE). Both are in AED, as their names and IBR-104-AE -// say, so for invoices in another currency they are converted with the rate -// to AED. The implementation guide (section 3.1.1) asks for AED whatever the -// invoice currency, and IBR-126 leaves cac:ItemPriceExtension out of the -// document currency check as amounts in the tax currency, which IBR-140-AE -// fixes to AED. No test checks their currency, and the official exports in -// USD write them in AED too. Without a rate, which the PINT addon requires -// (GOBL-PEPPOL-PINT-BILL-INVOICE-27), they stay in the document currency. -// -// GOBL keeps no VAT per line, so it is the line total at the line's rate, -// rounded to the document currency, then converted. Exempt lines get no VAT -// amount (IBR-163-AE), and zero rated, reverse charge and margin scheme lines -// a zero one (IBR-165-AE, IBR-162-AE, as the official margin scheme example). +// exportAELineAmounts writes the line amount payable (BTAE-10) and VAT (BTAE-08), in AED as the +// implementation guide (3.1.1) asks. GOBL keeps no VAT per line, so it is the line total at the line's rate. func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.Code, rate *currency.ExchangeRate) { if l == nil || l.Total == nil { return @@ -799,9 +740,8 @@ func exportAELineAmounts(line *goblubl.InvoiceLine, l *bill.Line, cur currency.C line.ItemPriceExtension = ext } -// aeLineVAT provides the VAT charged on a line, and false for exempt lines, -// which must not have one. Only standard rated lines charge VAT: zero rated, -// reverse charge, margin scheme and outside scope lines charge none. +// aeLineVAT provides the VAT charged on a line, which only standard rated lines have, and false for +// exempt lines, which must not have one. func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { zero := num.MakeAmount(0, l.Total.Exp()) if line.Item == nil || line.Item.ClassifiedTaxCategory == nil || line.Item.ClassifiedTaxCategory.ID == nil { @@ -818,12 +758,8 @@ func aeLineVAT(line *goblubl.InvoiceLine, l *bill.Line) (num.Amount, bool) { return zero, true } -// exportAEExchangeRate writes, for invoices not in AED, the exchange rate to -// AED (BTAE-04, IBR-159-AE) as cac:TaxExchangeRate from the document currency -// to the tax currency (IBR-153-AE), and the total with VAT in AED (BTAE-20, -// IBR-175-AE). gobl.ubl already writes the tax currency AED and the VAT total -// in AED (ibt-006, ibt-111) when there is a rate. The PINT addon requires the -// rate (GOBL-PEPPOL-PINT-BILL-INVOICE-27) with at most 6 decimals (-28). +// exportAEExchangeRate writes, for invoices not in AED, the rate to AED (BTAE-04) as cac:TaxExchangeRate +// and the total with VAT in AED (BTAE-20). func exportAEExchangeRate(out *goblubl.Invoice, inv *bill.Invoice) { if inv.Currency == currency.AED { return @@ -854,13 +790,8 @@ func aeAmount(a num.Amount, cur currency.Code) goblubl.Amount { return goblubl.Amount{CurrencyID: &code, Value: a.String()} } -// exportAEPrice adds the price base quantity (ibt-149) and the gross price -// (ibt-148) PINT AE requires on every line (IBR-126-AE). GOBL prices are per -// unit, so the base quantity is 1 in the line's unit. Without a list price, -// gobl.ubl writes no price allowance, so the gross price is the net price with -// a zero discount, written with the decimals of the price as gobl.ubl does for -// a list price. The base quantity also lets IBR-147-AE compute the line net -// amount. +// exportAEPrice adds the base quantity 1 and the gross price PINT AE requires on every line, +// with a zero price discount when gobl.ubl writes none. func exportAEPrice(line *goblubl.InvoiceLine) { price := line.Price if price == nil { @@ -892,13 +823,25 @@ func lineUnitCode(line *goblubl.InvoiceLine) string { return "" } -// aeRate provides the rate PINT AE expects for a line or breakdown VAT -// category. gobl.ubl writes 0 when a combo has no percent, which is right for -// A-NZ but not for AE: exempt must have no rate (aligned-ibrp-e-05, -// IBR-121-AE), and reverse charge and margin scheme must have one -// (aligned-ibrp-ae-05-ae, IBR-119-AE, IBR-111-AE). Document allowances and -// charges are set by exportAEChargeRates. -func aeRate(id *goblubl.IDType, percent *string) *string { +// aeStandardRate provides the AE regime's standard VAT rate on the invoice's tax date, as UBL writes it. +func aeStandardRate(inv *bill.Invoice) string { + date := inv.IssueDate + if inv.ValueDate != nil { + date = *inv.ValueDate + } + rd := tax.RegimeDefFor(l10n.AE).CategoryDef(tax.CategoryVAT).RateDef(tax.KeyStandard, tax.RateGeneral) + if rd == nil { + return "" + } + if v := rd.Value(date, tax.Extensions{}); v != nil { + return v.Percent.StringWithoutSymbol() + } + return "" +} + +// aeRate provides the rate PINT AE expects for a VAT category where gobl.ubl writes 0: none for exempt, +// the standard rate for reverse charge and margin scheme. +func aeRate(id *goblubl.IDType, percent *string, standard string) *string { if id == nil { return percent } @@ -906,16 +849,13 @@ func aeRate(id *goblubl.IDType, percent *string) *string { case taxCategoryExempt: return nil case taxCategoryReverseCharge, taxCategoryMarginScheme: - rate := aeStandardRate + rate := standard return &rate } return percent } -// exportAEPartyTaxID writes a UAE TRN without the AE prefix gobl.ubl adds, -// the bare 15 digits IBR-132-AE checks on the seller, buyer and tax -// representative. Tax IDs from other countries keep their prefix, the usual -// VAT number format. +// exportAEPartyTaxID writes UAE TRNs without the AE prefix gobl.ubl adds. func exportAEPartyTaxID(out *goblubl.Party, tID *tax.Identity) { if out == nil || tID == nil || tID.Code == "" || tID.Country.Code() != l10n.AE { return @@ -939,9 +879,8 @@ func exportAEPartyIdentities(out *goblubl.Party, p *org.Party) { exportAETINIdentification(out) } -// exportAETINIdentification writes the scheme of a TIN identity in -// cac:PartyIdentification as its ISO 6523 ICD, 0235. gobl.ubl writes the -// identity's type, TIN, which is not an ICD (ibr-cl-10). +// exportAETINIdentification writes the scheme of a TIN identity in cac:PartyIdentification as its +// ISO 6523 ICD, 0235, where gobl.ubl writes its type, TIN, which is not an ICD. func exportAETINIdentification(out *goblubl.Party) { for i := range out.PartyIdentification { id := out.PartyIdentification[i].ID @@ -952,14 +891,8 @@ func exportAETINIdentification(out *goblubl.Party) { } } -// exportAELegalIdentity writes the legal registration identifier type of the -// party's legal identity as @schemeAgencyID (BTAE-15, BTAE-16), and, as -// @schemeAgencyName, the issuing country of a passport (BTAE-18, BTAE-19) or -// the issuing authority of a trade licence, taken from its description -// (BTAE-11, BTAE-12; IBR-101-AE, IBR-172-AE). The syntax binding also allows -// an authority on Emirates IDs and Cabinet Decisions, but no rule or text asks -// for one, so none is written. gobl.ubl writes the first legal identity as -// cac:PartyLegalEntity/cbc:CompanyID, so that is the one described here. +// exportAELegalIdentity writes the PINT AE type of the first legal identity as @schemeAgencyID (BTAE-15/16), +// and a passport's country or a trade licence's authority as @schemeAgencyName. func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { if out.PartyLegalEntity == nil || out.PartyLegalEntity.CompanyID == nil { return @@ -995,21 +928,11 @@ func exportAELegalIdentity(out *goblubl.Party, p *org.Party) { } } -// importAEPartyIdentities reads back what exportAEPartyIdentities writes: -// the legal identity's key or type from @schemeAgencyID, with -// @schemeAgencyName as the passport's country or the trade licence's -// description, and a TIN identification from its 0235 scheme. For the -// supplier, it also reads every tax registration that -// is not VAT as a TIN, as PINT AE defines IBT-032 as the seller TIN. -// -// TODO: the BIS gives the seller TIN's scheme no code list, and the official -// examples use TIN and TAX. A scheme like TAX is read as a TIN, and written -// back as TIN. +// importAEPartyIdentities reads back what exportAEPartyIdentities writes, and the supplier's non-VAT +// tax registration as its TIN (IBT-032). // -// TODO: gobl.ubl gives every tax registration it imports the country of the -// party's address, which UBL doesn't carry for the identity, so a TIN -// identity without a country comes back with one (known round-trip -// difference, to be looked at in gobl.ubl). +// TODO: the seller TIN scheme has no code list (examples use TIN and TAX), so any scheme is read as TIN. +// TODO: gobl.ubl gives imported tax registrations the address's country; fix there. func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { if in == nil || p == nil { return @@ -1024,8 +947,6 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { break } } - // A cac:PartyIdentification with the scheme 0235 is a TIN, which export - // writes with that scheme. for _, id := range p.Identities { if id != nil && id.Scope == "" && id.Ext.Get(iso.ExtKeySchemeID) == ae.TINScheme { id.Type = ae.IdentityTypeTIN @@ -1049,10 +970,8 @@ func importAEPartyIdentities(in *goblubl.Party, p *org.Party, supplier bool) { } } -// importAEPartyEndpoint reads the party's electronic address, cbc:EndpointID, -// as an endpoint, which the PINT addon requires on the supplier and customer -// (IBR-080, IBR-081). gobl.ubl imports it as an inbox, which the endpoint -// replaces. +// importAEPartyEndpoint reads cbc:EndpointID as an endpoint, replacing the inbox +// gobl.ubl imports it as. func importAEPartyEndpoint(in *goblubl.Party, p *org.Party) { if in == nil || p == nil || in.EndpointID == nil || in.EndpointID.Value == "" { return @@ -1086,14 +1005,12 @@ func importAELegalIdentity(id *org.Identity, cid *goblubl.IDType) { } } -// exportAETaxTotal fixes the rates of the VAT breakdowns, and merges the ones -// left with the same category and rate. The total with breakdowns, which is -// the one in the document currency, also says its prices don't include VAT -// (IBT-200). -func exportAETaxTotal(tt *goblubl.TaxTotal) { +// exportAETaxTotal fixes the breakdown rates, merges breakdowns left with the same category and rate, +// and says prices exclude VAT (IBT-200). +func exportAETaxTotal(tt *goblubl.TaxTotal, standard string) { for i := range tt.TaxSubtotal { c := &tt.TaxSubtotal[i].TaxCategory - c.Percent = aeRate(c.ID, c.Percent) + c.Percent = aeRate(c.ID, c.Percent, standard) } tt.TaxSubtotal = mergeAETaxSubtotals(tt.TaxSubtotal) if len(tt.TaxSubtotal) > 0 { @@ -1103,12 +1020,8 @@ func exportAETaxTotal(tt *goblubl.TaxTotal) { } } -// mergeAETaxSubtotals merges the VAT breakdowns with the same category and -// rate. GOBL makes a breakdown per exemption code, so two exempt lines with -// different codes give two E breakdowns, but PINT AE wants exactly one per -// category (aligned-ibrp-e-01, o-01, z-01) with the taxable amount of all its -// lines (aligned-ibrp-e-08, o-08, ae-08-ae). Exemption codes and reasons that -// differ are dropped from the merged breakdown; the line keeps its own. +// mergeAETaxSubtotals merges breakdowns with the same category and rate: GOBL makes one per exemption +// code, PINT AE wants one per category. Codes and reasons that differ are dropped. func mergeAETaxSubtotals(subtotals []goblubl.TaxSubtotal) []goblubl.TaxSubtotal { var merged []goblubl.TaxSubtotal for _, st := range subtotals { @@ -1150,9 +1063,7 @@ func sameID(a, b *goblubl.IDType) bool { return a.Value == b.Value } -// samePercent compares two rates by value, so that "0" and "0.0" are the -// same rate and their breakdowns are merged (ALIGNED-IBRP-Z-01 and the other -// one-breakdown-per-category rules). +// samePercent compares rates by value, so "0" and "0.0" match. func samePercent(a, b *string) bool { if a == nil || b == nil { return a == b diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 2ad87ab..b36a978 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -3,23 +3,18 @@ package ubl import ( "testing" - "github.com/invopop/gobl.peppol/addon/pint" goblubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" - "github.com/invopop/gobl/cal" "github.com/invopop/gobl/catalogues/cef" "github.com/invopop/gobl/catalogues/icc" - "github.com/invopop/gobl/catalogues/iso" "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/currency" - "github.com/invopop/gobl/l10n" "github.com/invopop/gobl/num" "github.com/invopop/gobl/org" "github.com/invopop/gobl/pay" "github.com/invopop/gobl/regimes/ae" "github.com/invopop/gobl/tax" - "github.com/invopop/gobl/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,46 +33,7 @@ func aedAmount(v string) goblubl.Amount { return goblubl.Amount{CurrencyID: strPtr("AED"), Value: v} } -func TestExportAEUUID(t *testing.T) { - out := new(goblubl.Invoice) - inv := &bill.Invoice{} - exportAEUUID(out, inv) - assert.Empty(t, out.UUID, "no UUID to write") - - inv.UUID = uuid.MustParse("0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2") - exportAEUUID(out, inv) - assert.Equal(t, "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", out.UUID) -} - -func TestImportAEUUID(t *testing.T) { - inv := new(bill.Invoice) - importAEUUID(&goblubl.Invoice{UUID: " 0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2 "}, inv) - assert.Equal(t, "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", inv.UUID.String()) - - for _, bad := range []string{"", "not-a-uuid"} { - inv = new(bill.Invoice) - importAEUUID(&goblubl.Invoice{UUID: bad}, inv) - assert.True(t, inv.UUID.IsZero(), bad) - } -} - func TestExportAEPrice(t *testing.T) { - t.Run("adds the base quantity and a zero discount on the net price", func(t *testing.T) { - line := &goblubl.InvoiceLine{ - InvoicedQuantity: &goblubl.Quantity{UnitCode: "HUR", Value: "10"}, - Price: &goblubl.Price{PriceAmount: aedAmount("100.00")}, - } - exportAEPrice(line) - require.NotNil(t, line.Price.BaseQuantity) - assert.Equal(t, goblubl.Quantity{UnitCode: "HUR", Value: "1"}, *line.Price.BaseQuantity) - ac := line.Price.AllowanceCharge - require.NotNil(t, ac) - assert.False(t, ac.ChargeIndicator) - assert.Equal(t, "0.00", ac.Amount.Value) - require.NotNil(t, ac.BaseAmount) - assert.Equal(t, "100.00", ac.BaseAmount.Value) - }) - t.Run("writes the zero discount with the decimals of the price", func(t *testing.T) { line := &goblubl.InvoiceLine{ InvoicedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, @@ -87,15 +43,6 @@ func TestExportAEPrice(t *testing.T) { assert.Equal(t, "0.0000", line.Price.AllowanceCharge.Amount.Value) }) - t.Run("uses the credited quantity's unit on credit notes", func(t *testing.T) { - line := &goblubl.InvoiceLine{ - CreditedQuantity: &goblubl.Quantity{UnitCode: "C62", Value: "1"}, - Price: &goblubl.Price{PriceAmount: aedAmount("5.00")}, - } - exportAEPrice(line) - assert.Equal(t, "C62", line.Price.BaseQuantity.UnitCode) - }) - t.Run("keeps a price discount gobl.ubl already wrote", func(t *testing.T) { existing := &goblubl.AllowanceCharge{Amount: aedAmount("20.00"), BaseAmount: &goblubl.Amount{Value: "120.00"}} line := &goblubl.InvoiceLine{ @@ -105,26 +52,20 @@ func TestExportAEPrice(t *testing.T) { exportAEPrice(line) assert.Same(t, existing, line.Price.AllowanceCharge) }) - - t.Run("lines without a price are left alone", func(t *testing.T) { - line := &goblubl.InvoiceLine{} - exportAEPrice(line) - assert.Nil(t, line.Price) - }) } func TestAERate(t *testing.T) { zero := strPtr("0") - assert.Nil(t, aeRate(&goblubl.IDType{Value: "E"}, zero), "exempt has no rate") - rc := aeRate(&goblubl.IDType{Value: "AE"}, zero) + assert.Nil(t, aeRate(&goblubl.IDType{Value: "E"}, zero, "5"), "exempt has no rate") + rc := aeRate(&goblubl.IDType{Value: "AE"}, zero, "5") require.NotNil(t, rc) - assert.Equal(t, "5", *rc, "reverse charge is written at 5") - ms := aeRate(&goblubl.IDType{Value: "N"}, zero) + assert.Equal(t, "5", *rc, "reverse charge is written at the standard rate") + ms := aeRate(&goblubl.IDType{Value: "N"}, zero, "5") require.NotNil(t, ms) - assert.Equal(t, "5", *ms, "margin scheme is written at 5") - assert.Equal(t, strPtr("5"), aeRate(&goblubl.IDType{Value: "S"}, strPtr("5")), "standard keeps its rate") - assert.Nil(t, aeRate(&goblubl.IDType{Value: "O"}, nil), "outside scope keeps no rate") - assert.Equal(t, zero, aeRate(nil, zero), "no category, no change") + assert.Equal(t, "5", *ms, "margin scheme is written at the standard rate") + assert.Equal(t, strPtr("5"), aeRate(&goblubl.IDType{Value: "S"}, strPtr("5"), "5"), "standard keeps its rate") + assert.Nil(t, aeRate(&goblubl.IDType{Value: "O"}, nil, "5"), "outside scope keeps no rate") + assert.Equal(t, zero, aeRate(nil, zero, "5"), "no category, no change") } func TestMergeAETaxSubtotals(t *testing.T) { @@ -171,163 +112,6 @@ func TestMergeAETaxSubtotals(t *testing.T) { }) } -func TestExportAETaxTotal(t *testing.T) { - tt := &goblubl.TaxTotal{TaxSubtotal: []goblubl.TaxSubtotal{ - {TaxableAmount: aedAmount("100.00"), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("AE", strPtr("0"))}, - {TaxableAmount: aedAmount("50.00"), TaxAmount: aedAmount("0.00"), TaxCategory: aeCategory("E", strPtr("0"))}, - }} - exportAETaxTotal(tt) - require.Len(t, tt.TaxSubtotal, 2) - assert.Equal(t, strPtr("5"), tt.TaxSubtotal[0].TaxCategory.Percent) - assert.Nil(t, tt.TaxSubtotal[1].TaxCategory.Percent) - require.NotNil(t, tt.TaxIncludedIndicator) - assert.False(t, *tt.TaxIncludedIndicator) - - // The VAT total in AED has no breakdowns, and no indicator. - aed := &goblubl.TaxTotal{TaxAmount: aedAmount("5.00")} - exportAETaxTotal(aed) - assert.Nil(t, aed.TaxIncludedIndicator) -} - -func TestExportAEPartyTaxID(t *testing.T) { - party := func(companyID string) *goblubl.Party { - return &goblubl.Party{PartyTaxScheme: []goblubl.PartyTaxScheme{{ - CompanyID: &goblubl.IDType{Value: companyID}, - TaxScheme: &goblubl.TaxScheme{ID: goblubl.IDType{Value: "VAT"}}, - }}} - } - - t.Run("writes a UAE TRN without its prefix", func(t *testing.T) { - out := party("AE100000001600003") - exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000001600003"}) - assert.Equal(t, "100000001600003", out.PartyTaxScheme[0].CompanyID.Value) - }) - - t.Run("keeps the prefix of other countries' VAT numbers", func(t *testing.T) { - out := party("DE111111125") - exportAEPartyTaxID(out, &tax.Identity{Country: "DE", Code: "111111125"}) - assert.Equal(t, "DE111111125", out.PartyTaxScheme[0].CompanyID.Value) - }) - - t.Run("leaves other tax registrations alone", func(t *testing.T) { - out := party("1234567897") - exportAEPartyTaxID(out, &tax.Identity{Country: "AE", Code: "100000001600003"}) - assert.Equal(t, "1234567897", out.PartyTaxScheme[0].CompanyID.Value) - }) - - t.Run("parties without a tax ID are skipped", func(t *testing.T) { - out := party("AE100000001600003") - exportAEPartyTaxID(out, nil) - assert.Equal(t, "AE100000001600003", out.PartyTaxScheme[0].CompanyID.Value) - }) -} - -func TestExportAEPartyIdentities(t *testing.T) { - // export builds the UBL party the way gobl.ubl does, then adds the AE - // details. - export := func(p *org.Party) *goblubl.Party { - out := goblubl.NewParty(p) - exportAEPartyIdentities(out, p) - return out - } - legal := func(typ cbc.Code, code string) *org.Identity { - return &org.Identity{Type: typ, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} - } - passport := func(code string) *org.Identity { - return &org.Identity{Key: org.IdentityKeyPassport, Scope: org.IdentityScopeLegal, Code: cbc.Code(code)} - } - - t.Run("trade licence gets TL and its authority", func(t *testing.T) { - id := legal(ae.IdentityTypeTradeLicense, "112345678900003") - id.Description = "Trade License issuing Authority" - cid := export(&org.Party{Name: "Seller", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID - assert.Equal(t, "112345678900003", cid.Value) - assert.Equal(t, "TL", *cid.SchemeAgencyID) - assert.Equal(t, "Trade License issuing Authority", *cid.SchemeAgencyName) - }) - - t.Run("passport gets PAS and its issuing country", func(t *testing.T) { - id := passport("P1234567890") - id.Country = "IN" - cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID - assert.Equal(t, "PAS", *cid.SchemeAgencyID) - assert.Equal(t, "IN", *cid.SchemeAgencyName) - }) - - t.Run("Emirates ID and Cabinet Decision get their type only", func(t *testing.T) { - for _, typ := range []cbc.Code{ae.IdentityTypeEmiratesID, ae.IdentityTypeCabinetDecision} { - id := legal(typ, "784199012345671") - id.Description = "not an authority" - cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID - assert.Equal(t, typ.String(), *cid.SchemeAgencyID, typ) - assert.Nil(t, cid.SchemeAgencyName, typ) - } - }) - - t.Run("passport ignores the description", func(t *testing.T) { - id := passport("P1234567890") - id.Description = "not a country" - cid := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{id}}).PartyLegalEntity.CompanyID - assert.Nil(t, cid.SchemeAgencyName) - }) - - t.Run("legal identity without a PINT AE type is left alone", func(t *testing.T) { - cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ - {Scope: org.IdentityScopeLegal, Code: "CN-1234567"}, - }}).PartyLegalEntity.CompanyID - assert.Nil(t, cid.SchemeAgencyID) - assert.Nil(t, cid.SchemeAgencyName) - }) - - t.Run("the first legal identity is described, after a tax one", func(t *testing.T) { - cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ - {Type: ae.IdentityTypeTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, - legal(ae.IdentityTypeEmiratesID, "784199012345671"), - legal(ae.IdentityTypeCabinetDecision, "CD-1"), - }}).PartyLegalEntity.CompanyID - assert.Equal(t, "784199012345671", cid.Value) - assert.Equal(t, "EID", *cid.SchemeAgencyID) - }) - - t.Run("TIN is written under the TIN scheme, next to the VAT TRN", func(t *testing.T) { - out := export(&org.Party{ - Name: "Seller", - TaxID: &tax.Identity{Country: "AE", Code: "100000001600003"}, - Identities: []*org.Identity{ - {Type: ae.IdentityTypeTIN, Scope: org.IdentityScopeTax, Code: "1234567897"}, - }, - }) - require.Len(t, out.PartyTaxScheme, 2) - assert.Equal(t, "VAT", out.PartyTaxScheme[0].TaxScheme.ID.Value) - assert.Equal(t, "1234567897", out.PartyTaxScheme[1].CompanyID.Value) - assert.Equal(t, "TIN", out.PartyTaxScheme[1].TaxScheme.ID.Value) - }) - - t.Run("other tax identities keep the scheme gobl.ubl gives them", func(t *testing.T) { - out := export(&org.Party{Name: "Seller", Identities: []*org.Identity{ - {Scope: org.IdentityScopeTax, Code: "1234567897"}, - }}) - require.Len(t, out.PartyTaxScheme, 1) - assert.Equal(t, goblubl.TaxSchemeTaxRegistration, out.PartyTaxScheme[0].TaxScheme.ID.Value) - }) - - t.Run("a TIN identification has the scheme 0235", func(t *testing.T) { - out := export(&org.Party{Name: "Buyer", Identities: []*org.Identity{ - {Type: ae.IdentityTypeTIN, Code: "1234567897"}, - }}) - require.Len(t, out.PartyIdentification, 1) - assert.Equal(t, "1234567897", out.PartyIdentification[0].ID.Value) - assert.Equal(t, "0235", *out.PartyIdentification[0].ID.SchemeID) - }) - - t.Run("nil parties are skipped", func(t *testing.T) { - assert.NotPanics(t, func() { - exportAEPartyIdentities(nil, &org.Party{}) - exportAEPartyIdentities(&goblubl.Party{}, nil) - }) - }) -} - func TestImportAEPartyIdentities(t *testing.T) { companyID := func(agencyID, agencyName string) *goblubl.Party { cid := &goblubl.IDType{Value: "112345678900003"} @@ -347,46 +131,6 @@ func TestImportAEPartyIdentities(t *testing.T) { return p } - t.Run("trade licence with its authority", func(t *testing.T) { - id := imported(companyID("TL", "Trade License issuing Authority"), false).Identities[0] - assert.Equal(t, ae.IdentityTypeTradeLicense, id.Type) - assert.Equal(t, "Trade License issuing Authority", id.Description) - }) - - t.Run("an identification with the scheme 0235 is a TIN", func(t *testing.T) { - scheme := "0235" - in := &goblubl.Party{PartyIdentification: []goblubl.Identification{ - {ID: &goblubl.IDType{Value: "1234567897", SchemeID: &scheme}}, - }} - id := imported(in, false).Identities[0] - assert.Equal(t, ae.IdentityTypeTIN, id.Type) - assert.False(t, id.Ext.Has(iso.ExtKeySchemeID)) - }) - - t.Run("passport with its issuing country", func(t *testing.T) { - id := imported(companyID("PAS", "IN"), false).Identities[0] - assert.Equal(t, org.IdentityKeyPassport, id.Key) - assert.Equal(t, l10n.ISOCountryCode("IN"), id.Country) - assert.Empty(t, id.Description) - }) - - t.Run("Emirates ID and Cabinet Decision, without an authority", func(t *testing.T) { - for _, typ := range []cbc.Code{ae.IdentityTypeEmiratesID, ae.IdentityTypeCabinetDecision} { - id := imported(companyID(typ.String(), "Some Authority"), false).Identities[0] - assert.Equal(t, typ, id.Type, typ) - assert.Empty(t, id.Description, typ) - } - }) - - t.Run("unknown or missing types are left alone", func(t *testing.T) { - for _, typ := range []string{"XYZ", "CL", ""} { - id := imported(companyID(typ, "Some Authority"), false).Identities[0] - assert.Empty(t, id.Key, typ) - assert.Empty(t, id.Type, typ) - assert.Empty(t, id.Description, typ) - } - }) - t.Run("supplier non-VAT tax registration is the TIN", func(t *testing.T) { in := companyID("TL", "Authority") in.PartyTaxScheme = []goblubl.PartyTaxScheme{ @@ -407,6 +151,15 @@ func TestImportAEPartyIdentities(t *testing.T) { assert.Equal(t, ae.IdentityTypeTIN, p.Identities[1].Type) }) + t.Run("unknown or missing types are left alone", func(t *testing.T) { + for _, typ := range []string{"XYZ", ""} { + id := imported(companyID(typ, "Some Authority"), false).Identities[0] + assert.Empty(t, id.Key, typ) + assert.Empty(t, id.Type, typ) + assert.Empty(t, id.Description, typ) + } + }) + t.Run("nil parties are skipped", func(t *testing.T) { assert.NotPanics(t, func() { importAEPartyIdentities(nil, &org.Party{}, true) @@ -415,20 +168,36 @@ func TestImportAEPartyIdentities(t *testing.T) { }) } -func TestImportAEPartyEndpoint(t *testing.T) { - t.Run("the electronic address replaces the inbox gobl.ubl imports", func(t *testing.T) { - in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: "0235", Value: "1357902467"}} - p := &org.Party{Inboxes: []*org.Inbox{ - {Scheme: "0235", Code: "1357902467"}, - {Key: "other", Code: "ABC"}, - }} - importAEPartyEndpoint(in, p) - require.Len(t, p.Endpoints, 1) - assert.Equal(t, cbc.URI("iso6523-actorid-upis::0235:1357902467"), p.Endpoints[0].URI) - require.Len(t, p.Inboxes, 1) - assert.Equal(t, cbc.Code("ABC"), p.Inboxes[0].Code) +func TestExportAEPartyIdentities(t *testing.T) { + export := func(p *org.Party) *goblubl.Party { + out := goblubl.NewParty(p) + exportAEPartyIdentities(out, p) + return out + } + + t.Run("legal identity without a PINT AE type is left alone", func(t *testing.T) { + cid := export(&org.Party{Name: "Party", Identities: []*org.Identity{ + {Scope: org.IdentityScopeLegal, Code: "CN-1234567"}, + }}).PartyLegalEntity.CompanyID + assert.Nil(t, cid.SchemeAgencyID) + assert.Nil(t, cid.SchemeAgencyName) + }) + + t.Run("parties without a company ID are left alone", func(t *testing.T) { + out := export(&org.Party{Name: "Party"}) + require.NotNil(t, out.PartyLegalEntity) + assert.Nil(t, out.PartyLegalEntity.CompanyID) + }) + + t.Run("nil parties are skipped", func(t *testing.T) { + assert.NotPanics(t, func() { + exportAEPartyIdentities(nil, &org.Party{}) + exportAEPartyIdentities(&goblubl.Party{}, nil) + }) }) +} +func TestImportAEPartyEndpoint(t *testing.T) { t.Run("an email address is read as a mailto endpoint", func(t *testing.T) { in := &goblubl.Party{EndpointID: &goblubl.EndpointID{SchemeID: goblubl.SchemeIDEmail, Value: "billing@example.ae"}} p := &org.Party{Inboxes: []*org.Inbox{{Email: "billing@example.ae"}}} @@ -442,124 +211,10 @@ func TestImportAEPartyEndpoint(t *testing.T) { p := &org.Party{} importAEPartyEndpoint(&goblubl.Party{}, p) assert.Empty(t, p.Endpoints) - assert.NotPanics(t, func() { - importAEPartyEndpoint(nil, p) - importAEPartyEndpoint(&goblubl.Party{}, nil) - }) - }) -} - -func TestImportAEMarginScheme(t *testing.T) { - combo := func(category cbc.Code) *tax.Combo { - five := num.MakePercentage(5, 2) - return &tax.Combo{ - Category: tax.CategoryVAT, - Percent: &five, - Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), - } - } - inv := &bill.Invoice{ - Lines: []*bill.Line{{Taxes: tax.Set{combo("N")}}, {Taxes: tax.Set{combo("S")}}}, - Discounts: []*bill.Discount{{Taxes: tax.Set{combo("N")}}}, - } - importAEMarginScheme(inv) - - ms := inv.Lines[0].Taxes[0] - assert.Equal(t, tax.KeyExempt, ms.Key) - assert.Nil(t, ms.Percent, "margin scheme lines charge no VAT") - assert.Equal(t, tax.KeyExempt, inv.Discounts[0].Taxes[0].Key) - assert.True(t, inv.HasTags(pint.TagMarginScheme), "the tag keeps N on the lines") - - other := inv.Lines[1].Taxes[0] - assert.Empty(t, other.Key, "other categories are left to EN 16931") - assert.NotNil(t, other.Percent) - - inv = &bill.Invoice{Lines: []*bill.Line{{Taxes: tax.Set{combo("S")}}}} - importAEMarginScheme(inv) - assert.False(t, inv.HasTags(pint.TagMarginScheme)) -} - -func TestImportAEOutsideScope(t *testing.T) { - importCode := func(invoiceCode, creditNoteCode string) *bill.Invoice { - in := new(goblubl.Invoice) - if invoiceCode != "" { - in.InvoiceTypeCode = &goblubl.IDType{Value: invoiceCode} - } - if creditNoteCode != "" { - in.CreditNoteTypeCode = &goblubl.IDType{Value: creditNoteCode} - } - inv := &bill.Invoice{Type: bill.InvoiceTypeOther} - importAEOutsideTaxScope(in, inv) - return inv - } - - inv := importCode("480", "") - assert.Equal(t, bill.InvoiceTypeStandard, inv.Type) - assert.True(t, inv.HasTags(pint.TagOutsideTaxScope)) - - inv = importCode("", "81") - assert.Equal(t, bill.InvoiceTypeCreditNote, inv.Type) - assert.True(t, inv.HasTags(pint.TagOutsideTaxScope)) - - inv = importCode("380", "") - assert.Equal(t, bill.InvoiceTypeOther, inv.Type, "other codes are left to gobl.ubl") - assert.False(t, inv.HasTags(pint.TagOutsideTaxScope)) - - t.Run("does not add the tag twice", func(t *testing.T) { - in := &goblubl.Invoice{InvoiceTypeCode: &goblubl.IDType{Value: "480"}} - inv := &bill.Invoice{Tags: tax.WithTags(pint.TagOutsideTaxScope)} - importAEOutsideTaxScope(in, inv) - assert.Equal(t, []cbc.Key{pint.TagOutsideTaxScope}, inv.Tags.List) - }) -} - -func TestExportAETransactionType(t *testing.T) { - invoice := func(ext cbc.CodeMap) *bill.Invoice { - return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(ext)}} - } - - t.Run("writes the code and the beneficiary and principal IDs", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAETransactionType(out, invoice(cbc.CodeMap{ - pint.ExtKeyTransactionType: "10000100", - pint.ExtKeyBeneficiaryID: "189098765401003", - pint.ExtKeyPrincipalID: "155667745601003", - })) - assert.Equal(t, "10000100", out.ProfileExecutionID) - assert.Equal(t, "189098765401003", out.BuyerCustomerParty.Party.PartyIdentification[0].ID.Value) - assert.Equal(t, "155667745601003", out.SellerSupplierParty.Party.PartyIdentification[0].ID.Value) - }) - - t.Run("writes no parties without IDs", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAETransactionType(out, invoice(cbc.CodeMap{pint.ExtKeyTransactionType: "00000000"})) - assert.Equal(t, "00000000", out.ProfileExecutionID) - assert.Nil(t, out.BuyerCustomerParty) - assert.Nil(t, out.SellerSupplierParty) - }) - - t.Run("invoices without tax details are skipped", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAETransactionType(out, new(bill.Invoice)) - assert.Empty(t, out.ProfileExecutionID) }) } func TestImportAETransactionType(t *testing.T) { - t.Run("reads the code as extension and tags, with the IDs", func(t *testing.T) { - in := &goblubl.Invoice{ - ProfileExecutionID: " 10000101 ", - BuyerCustomerParty: &goblubl.CustomerParty{Party: identifiedParty("189098765401003")}, - SellerSupplierParty: &goblubl.SupplierParty{Party: identifiedParty("155667745601003")}, - } - inv := new(bill.Invoice) - importAETransactionType(in, inv) - assert.Equal(t, cbc.Code("10000101"), inv.Tax.GetExt(pint.ExtKeyTransactionType)) - assert.Equal(t, cbc.Code("189098765401003"), inv.Tax.GetExt(pint.ExtKeyBeneficiaryID)) - assert.Equal(t, cbc.Code("155667745601003"), inv.Tax.GetExt(pint.ExtKeyPrincipalID)) - assert.Equal(t, []cbc.Key{pint.TagFreeTradeZone, pint.TagDisclosedAgent, tax.TagExport}, inv.Tags.List) - }) - t.Run("existing tags are not repeated", func(t *testing.T) { inv := &bill.Invoice{Tags: tax.WithTags(tax.TagExport)} importAETransactionType(&goblubl.Invoice{ProfileExecutionID: "00000001"}, inv) @@ -574,314 +229,12 @@ func TestImportAETransactionType(t *testing.T) { }) } -func TestAECreditNoteReason(t *testing.T) { - invoice := func(reason cbc.Code) *bill.Invoice { - return &bill.Invoice{Tax: &bill.Tax{Ext: tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyCreditNoteReason: reason})}} - } - creditNote := func() *goblubl.Invoice { - return &goblubl.Invoice{CreditNoteTypeCode: &goblubl.IDType{Value: "381"}} - } - - t.Run("writes the reason on credit notes", func(t *testing.T) { - out := creditNote() - exportAECreditNoteReason(out, invoice("VD")) - require.Len(t, out.DiscrepancyResponse, 1) - assert.Equal(t, "VD", out.DiscrepancyResponse[0].ResponseCode.Value) - }) - - t.Run("never on invoices, which UBL doesn't allow it on", func(t *testing.T) { - out := &goblubl.Invoice{InvoiceTypeCode: &goblubl.IDType{Value: "380"}} - exportAECreditNoteReason(out, invoice("VD")) - assert.Empty(t, out.DiscrepancyResponse) - }) - - t.Run("nothing without a reason", func(t *testing.T) { - out := creditNote() - exportAECreditNoteReason(out, new(bill.Invoice)) - assert.Empty(t, out.DiscrepancyResponse) - }) - - t.Run("reads the first reason back", func(t *testing.T) { - in := creditNote() - in.DiscrepancyResponse = []goblubl.Response{ - {}, - {ResponseCode: &goblubl.IDType{Value: " VD "}}, - {ResponseCode: &goblubl.IDType{Value: "DL8.61.1.E"}}, - } - inv := new(bill.Invoice) - importAECreditNoteReason(in, inv) - assert.Equal(t, cbc.Code("VD"), inv.Tax.GetExt(pint.ExtKeyCreditNoteReason)) - }) -} - -func TestAELineExemption(t *testing.T) { - ublLine := func() goblubl.InvoiceLine { - return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ - ID: &goblubl.IDType{Value: "E"}, - }}} - } - goblLine := func(code cbc.Code) *bill.Line { - c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} - if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) - } - return &bill.Line{Taxes: tax.Set{c}} - } - - t.Run("writes the exemption reason on the line", func(t *testing.T) { - line := ublLine() - exportAELineExemption(&line, goblLine("DL8.46.2"), nil) - require.NotNil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) - assert.Equal(t, "DL8.46.2", *line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) - }) - - t.Run("nothing without a reason", func(t *testing.T) { - line := ublLine() - exportAELineExemption(&line, goblLine(""), nil) - assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) - exportAELineExemption(&line, nil, nil) - assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReasonCode) - }) - - t.Run("reads the reasons back onto the line combos", func(t *testing.T) { - code := " DL8.46.4 " - with := ublLine() - with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code - inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} - importAELineExemptions([]goblubl.InvoiceLine{ublLine(), with}, inv) - assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - assert.Equal(t, cbc.Code("DL8.46.4"), inv.Lines[1].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - }) - - t.Run("lines that don't match are skipped", func(t *testing.T) { - code := "DL8.46.4" - with := ublLine() - with.Item.ClassifiedTaxCategory.TaxExemptionReasonCode = &code - inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} - importAELineExemptions([]goblubl.InvoiceLine{with}, inv) - assert.Empty(t, inv.Lines[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - }) -} - -func TestAELineGoods(t *testing.T) { - gtin := func(scheme cbc.Code, code cbc.Code) *org.Identity { - return &org.Identity{Code: code, Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: scheme})} - } - goblLine := func(goodsType cbc.Code, ids ...*org.Identity) *bill.Line { - it := &org.Item{Name: "Gold bars", Identities: ids} - if goodsType != "" { - it.Ext = tax.ExtensionsOf(cbc.CodeMap{pint.ExtKeyGoodsType: goodsType}) - } - return &bill.Line{Item: it} - } - - t.Run("writes the goods type as the nature code", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{}} - exportAELineGoods(&line, goblLine("DL8.48.8.1")) - require.NotNil(t, line.Item.CommodityClassification) - require.Len(t, *line.Item.CommodityClassification, 1) - assert.Equal(t, "DL8.48.8.1", *(*line.Item.CommodityClassification)[0].NatureCode) - }) - - t.Run("on the first classification when there is one", func(t *testing.T) { - list := "HS" - line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ - {ItemClassificationCode: &goblubl.IDType{Value: "7108", ListID: &list}}, - }}} - exportAELineGoods(&line, goblLine("DL8.48.8.1")) - require.Len(t, *line.Item.CommodityClassification, 1) - cc := (*line.Item.CommodityClassification)[0] - assert.Equal(t, "DL8.48.8.1", *cc.NatureCode) - assert.Equal(t, "7108", cc.ItemClassificationCode.Value) - }) - - t.Run("writes the GTIN as the standard identifier", func(t *testing.T) { - other := "0088" - line := goblubl.InvoiceLine{Item: &goblubl.Item{StandardItemIdentification: &goblubl.ItemIdentification{ - ID: &goblubl.IDType{SchemeID: &other, Value: "5410000000000"}, - }}} - exportAELineGoods(&line, goblLine("", gtin("0088", "5410000000000"), gtin("0160", "4006381333931"))) - id := line.Item.StandardItemIdentification.ID - assert.Equal(t, "0160", *id.SchemeID) - assert.Equal(t, "4006381333931", id.Value) - }) - - t.Run("nothing without a goods type or GTIN", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{}} - exportAELineGoods(&line, goblLine("")) - assert.Nil(t, line.Item.CommodityClassification) - assert.Nil(t, line.Item.StandardItemIdentification) - exportAELineGoods(&line, nil) - assert.Nil(t, line.Item.CommodityClassification) - }) - - t.Run("reads the goods type back onto the items", func(t *testing.T) { - code := " DL8.48.3.2 " - with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{NatureCode: &code}}}} - without := goblubl.InvoiceLine{Item: &goblubl.Item{}} - inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} - importAELineGoods([]goblubl.InvoiceLine{without, with}, inv) - assert.Empty(t, inv.Lines[0].Item.Ext.Get(pint.ExtKeyGoodsType)) - assert.Equal(t, cbc.Code("DL8.48.3.2"), inv.Lines[1].Item.Ext.Get(pint.ExtKeyGoodsType)) - }) - - t.Run("lines that don't match are skipped", func(t *testing.T) { - code := "DL8.48.3.2" - with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{NatureCode: &code}}}} - inv := &bill.Invoice{Lines: []*bill.Line{goblLine(""), goblLine("")}} - importAELineGoods([]goblubl.InvoiceLine{with}, inv) - assert.Empty(t, inv.Lines[0].Item.Ext.Get(pint.ExtKeyGoodsType)) - }) -} - -func TestAELineItems(t *testing.T) { - list := func(v string) *string { return &v } - classification := func(listID, code string) goblubl.CommodityClassification { - return goblubl.CommodityClassification{ItemClassificationCode: &goblubl.IDType{Value: code, ListID: list(listID)}} - } - - t.Run("moves the service accounting codes to additional identifiers", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ - classification("HS", "8471"), classification("SAC", "998713"), - }}} - exportAELineSAC(&line) - require.Len(t, *line.Item.CommodityClassification, 1) - assert.Equal(t, "8471", (*line.Item.CommodityClassification)[0].ItemClassificationCode.Value) - require.Len(t, line.Item.AdditionalItemIdentification, 1) - id := line.Item.AdditionalItemIdentification[0].ID - assert.Equal(t, "SAC", *id.SchemeID) - assert.Equal(t, "998713", id.Value) - }) - - t.Run("no classifications left when all were SAC", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ - classification("SAC", "998713"), - }}} - exportAELineSAC(&line) - assert.Nil(t, line.Item.CommodityClassification) - assert.Len(t, line.Item.AdditionalItemIdentification, 1) - }) - - t.Run("writes the item type on the first classification", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{ - classification("HS", "8471"), - }}} - exportAELineItemType(&line, &bill.Line{Item: &org.Item{Key: pint.ItemKeyGoodsServices}}) - cc := (*line.Item.CommodityClassification)[0] - assert.Equal(t, "B", *cc.CommodityCode) - assert.Equal(t, "8471", cc.ItemClassificationCode.Value) - }) - - t.Run("nothing for items without an AE type", func(t *testing.T) { - line := goblubl.InvoiceLine{Item: &goblubl.Item{}} - exportAELineItemType(&line, &bill.Line{Item: &org.Item{Key: "other"}}) - assert.Nil(t, line.Item.CommodityClassification) - exportAELineItemType(&line, nil) - assert.Nil(t, line.Item.CommodityClassification) - }) - - t.Run("reads the item type and service accounting codes back", func(t *testing.T) { - with := goblubl.InvoiceLine{Item: &goblubl.Item{ - AdditionalItemIdentification: []goblubl.ItemIdentification{{ID: &goblubl.IDType{SchemeID: list("SAC"), Value: " 998713 "}}}, - CommodityClassification: &[]goblubl.CommodityClassification{{CommodityCode: list("S")}}, - }} - inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}, {Item: &org.Item{}}}} - importAELineItems([]goblubl.InvoiceLine{{Item: &goblubl.Item{}}, with}, inv) - assert.Empty(t, inv.Lines[0].Item.Key) - assert.Empty(t, inv.Lines[0].Item.Identities) - assert.Equal(t, org.ItemKeyServices, inv.Lines[1].Item.Key) - require.Len(t, inv.Lines[1].Item.Identities, 1) - assert.Equal(t, "SAC", inv.Lines[1].Item.Identities[0].Label) - assert.Equal(t, cbc.Code("998713"), inv.Lines[1].Item.Identities[0].Code) - }) - - t.Run("lines that don't match are skipped", func(t *testing.T) { - with := goblubl.InvoiceLine{Item: &goblubl.Item{CommodityClassification: &[]goblubl.CommodityClassification{{CommodityCode: list("G")}}}} - inv := &bill.Invoice{Lines: []*bill.Line{{Item: &org.Item{}}, {Item: &org.Item{}}}} - importAELineItems([]goblubl.InvoiceLine{with}, inv) - assert.Empty(t, inv.Lines[0].Item.Key) - }) -} - -func TestAEDeliveryPartyID(t *testing.T) { - delivery := func(r *org.Party) *bill.Invoice { - return &bill.Invoice{Delivery: &bill.DeliveryDetails{Receiver: r}} - } - partyID := func(out *goblubl.Invoice) string { - require.Len(t, out.Delivery, 1) - require.NotNil(t, out.Delivery[0].DeliveryParty) - require.Len(t, out.Delivery[0].DeliveryParty.PartyIdentification, 1) - return out.Delivery[0].DeliveryParty.PartyIdentification[0].ID.Value - } - - t.Run("writes the receiver's TRN", func(t *testing.T) { - out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: &goblubl.Party{PartyName: &goblubl.PartyName{Name: "Warehouse"}}}}} - exportAEDeliveryPartyID(out, delivery(&org.Party{ - Name: "Warehouse", - TaxID: &tax.Identity{Country: "AE", Code: "155667745601003"}, - Identities: []*org.Identity{{Type: ae.IdentityTypeTIN, Code: "1345678906"}}, - })) - assert.Equal(t, "155667745601003", partyID(out)) - assert.Equal(t, "Warehouse", out.Delivery[0].DeliveryParty.PartyName.Name) - }) - - t.Run("or its TIN without a TRN", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEDeliveryPartyID(out, delivery(&org.Party{ - Identities: []*org.Identity{{Type: ae.IdentityTypeTIN, Code: "1345678906"}}, - })) - assert.Equal(t, "1345678906", partyID(out)) - }) - - t.Run("nothing without a UAE tax ID or TIN", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEDeliveryPartyID(out, delivery(&org.Party{Name: "Warehouse", TaxID: &tax.Identity{Country: "GB", Code: "123456789"}})) - exportAEDeliveryPartyID(out, delivery(nil)) - exportAEDeliveryPartyID(out, &bill.Invoice{}) - assert.Empty(t, out.Delivery) - }) - - t.Run("reads a TRN back as the receiver's tax ID", func(t *testing.T) { - in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: identifiedParty(" 155667745601003 ")}}} - inv := delivery(&org.Party{Name: "Warehouse"}) - importAEDeliveryPartyID(in, inv) - r := inv.Delivery.Receiver - assert.Equal(t, "Warehouse", r.Name) - require.NotNil(t, r.TaxID) - assert.Equal(t, l10n.TaxCountryCode("AE"), r.TaxID.Country) - assert.Equal(t, cbc.Code("155667745601003"), r.TaxID.Code) - assert.Empty(t, r.Identities) - }) - - t.Run("and anything else as a TIN, on a new receiver", func(t *testing.T) { - in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: identifiedParty("1345678906")}}} - inv := new(bill.Invoice) - importAEDeliveryPartyID(in, inv) - require.NotNil(t, inv.Delivery) - r := inv.Delivery.Receiver - require.NotNil(t, r) - assert.Nil(t, r.TaxID) - require.Len(t, r.Identities, 1) - assert.Equal(t, ae.IdentityTypeTIN, r.Identities[0].Type) - assert.Equal(t, cbc.Code("1345678906"), r.Identities[0].Code) - }) - - t.Run("nothing to read without an ID", func(t *testing.T) { - inv := new(bill.Invoice) - importAEDeliveryPartyID(&goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: &goblubl.Party{}}}}, inv) - importAEDeliveryPartyID(new(goblubl.Invoice), inv) - assert.Nil(t, inv.Delivery) - }) -} - func TestAEIncoterms(t *testing.T) { - delivery := func(key cbc.Key, code cbc.Code) *bill.Invoice { - return &bill.Invoice{Delivery: &bill.DeliveryDetails{Ext: tax.ExtensionsOf(cbc.CodeMap{key: code})}} - } - t.Run("writes the Incoterms as the delivery terms", func(t *testing.T) { out := new(goblubl.Invoice) - exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) + exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{ + Ext: tax.ExtensionsOf(cbc.CodeMap{icc.ExtKeyIncoterms2020: "CIF"}), + }}) require.Len(t, out.Delivery, 1) require.Len(t, out.Delivery[0].DeliveryTerms, 1) id := out.Delivery[0].DeliveryTerms[0].ID @@ -890,28 +243,6 @@ func TestAEIncoterms(t *testing.T) { assert.Equal(t, "Incoterms", *id.SchemeID) }) - t.Run("also from the 2010 edition", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2010, "DAT")) - assert.Equal(t, "DAT", out.Delivery[0].DeliveryTerms[0].ID.Value) - }) - - t.Run("on the delivery gobl.ubl wrote", func(t *testing.T) { - out := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryLocation: &goblubl.Location{ID: &goblubl.IDType{Value: "5790000436101"}}}}} - exportAEIncoterms(out, delivery(icc.ExtKeyIncoterms2020, "CIF")) - require.Len(t, out.Delivery, 1) - assert.Equal(t, "CIF", out.Delivery[0].DeliveryTerms[0].ID.Value) - assert.Equal(t, "5790000436101", out.Delivery[0].DeliveryLocation.ID.Value) - }) - - t.Run("nothing without Incoterms", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEIncoterms(out, &bill.Invoice{Delivery: &bill.DeliveryDetails{}}) - assert.Empty(t, out.Delivery) - exportAEIncoterms(out, &bill.Invoice{}) - assert.Empty(t, out.Delivery) - }) - t.Run("reads the Incoterms back as the 2020 edition", func(t *testing.T) { in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryTerms: []goblubl.DeliveryTerms{{ID: goblubl.IDType{Value: " CIF "}}}}}} inv := new(bill.Invoice) @@ -950,17 +281,6 @@ func TestExportAELineAmounts(t *testing.T) { return &bill.Line{Total: &a, Taxes: tax.Set{{Category: tax.CategoryVAT, Key: key, Percent: percent}}} } - t.Run("standard rated line gets its VAT and the total with VAT", func(t *testing.T) { - out := line("S") - exportAELineAmounts(out, goblLine("10486.00", tax.KeyStandard, num.NewPercentage(5, 2)), currency.AED, nil) - ext := out.ItemPriceExtension - require.NotNil(t, ext) - assert.Equal(t, "11010.30", ext.Amount.Value) - assert.Equal(t, "AED", *ext.Amount.CurrencyID) - require.Len(t, ext.TaxTotal, 1) - assert.Equal(t, "524.30", ext.TaxTotal[0].TaxAmount.Value) - }) - t.Run("line VAT is rounded to the currency", func(t *testing.T) { out := line("S") exportAELineAmounts(out, goblLine("99.99", tax.KeyStandard, num.NewPercentage(5, 2)), currency.USD, nil) @@ -979,256 +299,110 @@ func TestExportAELineAmounts(t *testing.T) { assert.Equal(t, "18.36", ext.TaxTotal[0].TaxAmount.Value, "5.00 USD") assert.Equal(t, "385.61", ext.Amount.Value, "99.99 USD is 367.25 AED, plus the VAT") }) - - t.Run("zero rated and reverse charge lines get a zero VAT amount", func(t *testing.T) { - for _, c := range []struct { - category string - key cbc.Key - }{{"Z", tax.KeyZero}, {"AE", tax.KeyReverseCharge}} { - out := line(c.category) - exportAELineAmounts(out, goblLine("200.00", c.key, nil), currency.AED, nil) - ext := out.ItemPriceExtension - assert.Equal(t, "200.00", ext.Amount.Value, c.category) - require.Len(t, ext.TaxTotal, 1, c.category) - assert.Equal(t, "0.00", ext.TaxTotal[0].TaxAmount.Value, c.category) - } - }) - - t.Run("exempt lines get no VAT amount", func(t *testing.T) { - out := line("E") - exportAELineAmounts(out, goblLine("120.00", tax.KeyExempt, nil), currency.AED, nil) - assert.Equal(t, "120.00", out.ItemPriceExtension.Amount.Value) - assert.Empty(t, out.ItemPriceExtension.TaxTotal) - }) - - t.Run("lines without a total are left alone", func(t *testing.T) { - out := line("S") - exportAELineAmounts(out, &bill.Line{}, currency.AED, nil) - assert.Nil(t, out.ItemPriceExtension) - }) } -func TestExportAEExchangeRate(t *testing.T) { - invoice := func(cur currency.Code, rates ...*currency.ExchangeRate) *bill.Invoice { - return &bill.Invoice{ - Currency: cur, - ExchangeRates: rates, - Totals: &bill.Totals{TotalWithTax: num.MakeAmount(24875000, 2)}, - } +func TestAELineExemptionReason(t *testing.T) { + ublLine := func(category string, reason *string) goblubl.InvoiceLine { + return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ + ID: &goblubl.IDType{Value: category}, TaxExemptionReason: reason, + }}} + } + goblLine := func(category cbc.Code) *bill.Line { + return &bill.Line{Taxes: tax.Set{{ + Category: tax.CategoryVAT, + Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), + }}} } - t.Run("writes the rate and the AED total with VAT", func(t *testing.T) { - out := new(goblubl.Invoice) - inv := invoice(currency.USD, ¤cy.ExchangeRate{From: currency.USD, To: currency.AED, Amount: num.MakeAmount(367285, 5)}) - exportAEExchangeRate(out, inv) - require.NotNil(t, out.TaxExchangeRate) - assert.Equal(t, "USD", *out.TaxExchangeRate.SourceCurrencyCode) - assert.Equal(t, "AED", *out.TaxExchangeRate.TargetCurrencyCode) - assert.Equal(t, "3.67285", *out.TaxExchangeRate.CalculationRate) - require.Len(t, out.AdditionalDocumentReference, 1) - ref := out.AdditionalDocumentReference[0] - assert.Equal(t, "AED", ref.ID.Value) - assert.Equal(t, "aedtotal-incl-vat", ref.DocumentTypeCode) - assert.Equal(t, "913621.44", ref.DocumentDescription, "the Exports.xml example: 248750 USD at 3.67285") + t.Run("reads the text back as a tax note, once per category", func(t *testing.T) { + inv := &bill.Invoice{Lines: []*bill.Line{goblLine("E"), goblLine("E"), goblLine("O")}} + importAELineExemptions([]goblubl.InvoiceLine{ + ublLine("E", strPtr(" Exempt supply ")), + ublLine("E", strPtr("Another text")), + ublLine("O", strPtr(" ")), + }, inv) + require.Len(t, inv.Tax.Notes, 1) + assert.Equal(t, "Exempt supply", inv.Tax.Notes[0].Text) + assert.Equal(t, cbc.Code("E"), inv.Tax.Notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) }) +} - t.Run("AED invoices need neither", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEExchangeRate(out, invoice(currency.AED)) - assert.Nil(t, out.TaxExchangeRate) - assert.Empty(t, out.AdditionalDocumentReference) +func TestExportAELines(t *testing.T) { + t.Run("lines without an item, price or total are left alone", func(t *testing.T) { + lines := []goblubl.InvoiceLine{{}} + exportAELines(lines, &bill.Invoice{Currency: currency.AED, Lines: []*bill.Line{{}}}) + assert.Equal(t, goblubl.InvoiceLine{}, lines[0]) }) +} +func TestExportAEExchangeRate(t *testing.T) { t.Run("invoices without a rate to AED are left to the PINT addon", func(t *testing.T) { out := new(goblubl.Invoice) - inv := invoice(currency.USD, ¤cy.ExchangeRate{From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(92, 2)}) - exportAEExchangeRate(out, inv) + exportAEExchangeRate(out, &bill.Invoice{ + Currency: currency.USD, + ExchangeRates: []*currency.ExchangeRate{{From: currency.USD, To: currency.EUR, Amount: num.MakeAmount(92, 2)}}, + }) assert.Nil(t, out.TaxExchangeRate) assert.Empty(t, out.AdditionalDocumentReference) }) } -func TestExportAEIssueTime(t *testing.T) { - out := new(goblubl.Invoice) - exportAEIssueTime(out, &bill.Invoice{}) - assert.Empty(t, out.IssueTime) - - exportAEIssueTime(out, &bill.Invoice{IssueTime: cal.NewTime(17, 31, 0)}) - assert.Equal(t, "17:31:00", out.IssueTime) -} - -func TestExportAEContractValue(t *testing.T) { - inv := &bill.Invoice{Ordering: &bill.Ordering{Contracts: []*org.DocumentRef{ - {Code: "CT-1", Description: "AED 200000"}, - {Code: "CT-2"}, - }}} - - t.Run("writes the description of each contract", func(t *testing.T) { - out := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{ - {ID: goblubl.IDType{Value: "CT-1"}}, - {ID: goblubl.IDType{Value: "CT-2"}}, - }} - exportAEContractValue(out, inv) - assert.Equal(t, "AED 200000", out.ContractDocumentReference[0].DocumentDescription) - assert.Empty(t, out.ContractDocumentReference[1].DocumentDescription) - }) - - t.Run("references that don't match are skipped", func(t *testing.T) { - out := &goblubl.Invoice{ContractDocumentReference: []goblubl.Reference{{ID: goblubl.IDType{Value: "CT-1"}}}} - exportAEContractValue(out, inv) - assert.Empty(t, out.ContractDocumentReference[0].DocumentDescription) - exportAEContractValue(out, &bill.Invoice{}) - assert.Empty(t, out.ContractDocumentReference[0].DocumentDescription) - }) -} - -func TestExportAEPayment(t *testing.T) { - iban := cbc.Code("AE070331234567890123456") - ublInvoice := func() *goblubl.Invoice { - return &goblubl.Invoice{PaymentMeans: []goblubl.PaymentMeans{{ - PayeeFinancialAccount: &goblubl.FinancialAccount{ID: &goblubl.IDType{Value: iban.String()}}, - }}} - } - goblInvoice := func(ct *pay.CreditTransfer) *bill.Invoice { - return &bill.Invoice{Currency: currency.AED, Payment: &bill.PaymentDetails{ - Instructions: &pay.Instructions{CreditTransfer: []*pay.CreditTransfer{ct}}, - }} - } - - t.Run("writes the IBAN scheme and the branch address", func(t *testing.T) { - out := ublInvoice() - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{ - IBAN: iban, - Branch: &org.Address{Street: "Baniyas Road", StreetExtra: "Deira", Locality: "Dubai", Region: "DXB", Code: "777", Country: "AE"}, - })) - acc := out.PaymentMeans[0].PayeeFinancialAccount - assert.Equal(t, "IBAN", *acc.ID.SchemeID) - addr := acc.FinancialInstitutionBranch.Address - require.NotNil(t, addr) - assert.Equal(t, "Baniyas Road", *addr.StreetName) - assert.Equal(t, "Deira", *addr.AdditionalStreetName) - assert.Equal(t, "Dubai", *addr.CityName) - assert.Equal(t, "DXB", *addr.CountrySubentity) - assert.Equal(t, "777", *addr.PostalZone) - assert.Equal(t, "AE", addr.Country.IdentificationCode) - }) - - t.Run("an account number has no scheme, and no branch no address", func(t *testing.T) { - out := ublInvoice() - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{Number: iban})) - acc := out.PaymentMeans[0].PayeeFinancialAccount - assert.Nil(t, acc.ID.SchemeID) - assert.Nil(t, acc.FinancialInstitutionBranch) - }) - - t.Run("nothing without payment instructions", func(t *testing.T) { - out := new(goblubl.Invoice) - exportAEPayment(out, goblInvoice(&pay.CreditTransfer{IBAN: iban})) - assert.Empty(t, out.PaymentMeans) +func TestExportAECreditTransfer(t *testing.T) { + t.Run("writes the branch address on a new branch", func(t *testing.T) { + acc := &goblubl.FinancialAccount{ID: &goblubl.IDType{Value: "AE070331234567890123456"}} + exportAECreditTransfer(acc, &pay.CreditTransfer{ + IBAN: "AE070331234567890123456", + Branch: &org.Address{Street: "Baniyas Road", Locality: "Dubai", Region: "DXB", Country: "AE"}, + }) + require.NotNil(t, acc.FinancialInstitutionBranch) + require.NotNil(t, acc.FinancialInstitutionBranch.Address) + assert.Equal(t, "Dubai", *acc.FinancialInstitutionBranch.Address.CityName) }) } -func TestAEChargeExemptions(t *testing.T) { - combo := func(code cbc.Code) tax.Set { - c := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt} - if code != "" { - c.Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: code}) - } - return tax.Set{c} - } - category := func(code *string) []*goblubl.TaxCategory { - return []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: "E"}, TaxExemptionReasonCode: code}} - } - - t.Run("reads them back in the order of the document", func(t *testing.T) { - in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ - {TaxCategory: category(strPtr(" DL8.46.1 "))}, - {ChargeIndicator: true, TaxCategory: category(strPtr("DL8.46.3"))}, - {TaxCategory: category(nil)}, - }} - inv := &bill.Invoice{ - Charges: []*bill.Charge{{Taxes: combo("")}}, - Discounts: []*bill.Discount{{Taxes: combo("")}, {Taxes: combo("")}}, - } - importAEChargeExemptions(in, inv) - assert.Equal(t, cbc.Code("DL8.46.3"), inv.Charges[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - assert.Empty(t, inv.Discounts[1].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) - }) - +func TestImportAEChargeExemptions(t *testing.T) { t.Run("charges that don't match are skipped", func(t *testing.T) { - inv := &bill.Invoice{Discounts: []*bill.Discount{{Taxes: combo("DL8.46.1")}}} - in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ - {TaxCategory: category(strPtr("DL8.46.2"))}, - {TaxCategory: category(strPtr("DL8.46.2"))}, - }} + exempt := &tax.Combo{Category: tax.CategoryVAT, Key: tax.KeyExempt, Ext: tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: "DL8.46.1"})} + inv := &bill.Invoice{Discounts: []*bill.Discount{{Taxes: tax.Set{exempt}}}} + category := []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: "E"}, TaxExemptionReasonCode: strPtr("DL8.46.2")}} + in := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{{TaxCategory: category}, {TaxCategory: category}}} importAEChargeExemptions(in, inv) assert.Equal(t, cbc.Code("DL8.46.1"), inv.Discounts[0].Taxes[0].Ext.Get(cef.ExtKeyVATEX)) }) } -func TestExportAEChargeRates(t *testing.T) { - category := func(id string) []*goblubl.TaxCategory { - return []*goblubl.TaxCategory{{ID: &goblubl.IDType{Value: id}, Percent: strPtr("0")}} - } - out := &goblubl.Invoice{AllowanceCharge: []goblubl.AllowanceCharge{ - {ChargeIndicator: true, TaxCategory: category("AE")}, - {TaxCategory: category("AE")}, - {TaxCategory: category("E")}, - }} - exportAEChargeRates(out) - assert.Equal(t, "5", *out.AllowanceCharge[0].TaxCategory[0].Percent, "reverse charge charge (aligned-ibrp-ae-07)") - assert.Equal(t, "5", *out.AllowanceCharge[1].TaxCategory[0].Percent, "reverse charge allowance (aligned-ibrp-ae-06)") - assert.Equal(t, "0", *out.AllowanceCharge[2].TaxCategory[0].Percent, "exempt keeps 0 (aligned-ibrp-e-06)") -} - -func TestAELineExemptionReason(t *testing.T) { - ublLine := func(category string, reason *string) goblubl.InvoiceLine { - return goblubl.InvoiceLine{Item: &goblubl.Item{ClassifiedTaxCategory: &goblubl.ClassifiedTaxCategory{ - ID: &goblubl.IDType{Value: category}, TaxExemptionReason: reason, - }}} - } - goblLine := func(category cbc.Code) *bill.Line { - return &bill.Line{Taxes: tax.Set{{ - Category: tax.CategoryVAT, - Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), - }}} - } - note := func(category cbc.Code, text string) *tax.Note { - return &tax.Note{ - Category: tax.CategoryVAT, - Text: text, - Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: category}), - } +func TestAEDeliveryPartyID(t *testing.T) { + delivery := func(r *org.Party) *bill.Invoice { + return &bill.Invoice{Delivery: &bill.DeliveryDetails{Receiver: r}} } - t.Run("writes the tax note of the line's category", func(t *testing.T) { - tx := &bill.Tax{Notes: []*tax.Note{note("O", "Out of scope"), note("E", "Exempt supply")}} - line := ublLine("E", nil) - exportAELineExemption(&line, goblLine("E"), tx) - require.NotNil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) - assert.Equal(t, "Exempt supply", *line.Item.ClassifiedTaxCategory.TaxExemptionReason) + t.Run("writes the receiver's TIN without a TRN", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEDeliveryPartyID(out, delivery(&org.Party{ + Identities: []*org.Identity{{Type: ae.IdentityTypeTIN, Code: "1345678906"}}, + })) + require.Len(t, out.Delivery, 1) + require.NotNil(t, out.Delivery[0].DeliveryParty) + require.Len(t, out.Delivery[0].DeliveryParty.PartyIdentification, 1) + assert.Equal(t, "1345678906", out.Delivery[0].DeliveryParty.PartyIdentification[0].ID.Value) }) - t.Run("nothing on standard rated lines or without a note", func(t *testing.T) { - tx := &bill.Tax{Notes: []*tax.Note{note("S", "Standard"), note("O", "Out of scope")}} - line := ublLine("S", nil) - exportAELineExemption(&line, goblLine("S"), tx) - assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) - line = ublLine("E", nil) - exportAELineExemption(&line, goblLine("E"), tx) - assert.Nil(t, line.Item.ClassifiedTaxCategory.TaxExemptionReason) + t.Run("nothing without a receiver", func(t *testing.T) { + out := new(goblubl.Invoice) + exportAEDeliveryPartyID(out, delivery(nil)) + assert.Empty(t, out.Delivery) }) - t.Run("reads the text back as a tax note, once per category", func(t *testing.T) { - inv := &bill.Invoice{Lines: []*bill.Line{goblLine("E"), goblLine("E"), goblLine("O")}} - importAELineExemptions([]goblubl.InvoiceLine{ - ublLine("E", strPtr(" Exempt supply ")), - ublLine("E", strPtr("Another text")), - ublLine("O", strPtr(" ")), - }, inv) - require.Len(t, inv.Tax.Notes, 1) - assert.Equal(t, "Exempt supply", inv.Tax.Notes[0].Text) - assert.Equal(t, cbc.Code("E"), inv.Tax.Notes[0].Ext.Get(untdid.ExtKeyTaxCategory)) + t.Run("reads anything but a TRN as a TIN, on a new receiver", func(t *testing.T) { + in := &goblubl.Invoice{Delivery: []*goblubl.Delivery{{DeliveryParty: identifiedParty("1345678906")}}} + inv := new(bill.Invoice) + importAEDeliveryPartyID(in, inv) + require.NotNil(t, inv.Delivery) + r := inv.Delivery.Receiver + require.NotNil(t, r) + assert.Nil(t, r.TaxID) + require.Len(t, r.Identities, 1) + assert.Equal(t, ae.IdentityTypeTIN, r.Identities[0].Type) + assert.Equal(t, cbc.Code("1345678906"), r.Identities[0].Code) }) } diff --git a/ubl/ubl.go b/ubl/ubl.go index dfaca8e..15801af 100644 --- a/ubl/ubl.go +++ b/ubl/ubl.go @@ -138,9 +138,8 @@ var SpecificationAUNZSelfBilling = goblubl.Specification{ Applies: isSelfBilled, } -// FormatAE defines the Peppol PINT AE format, for UAE e-invoicing. Invoices -// are written with PINT AE Billing, and self-billed invoices with PINT AE -// Self-Billing. The exported document is adjusted to the AE rules by exportAE. +// FormatAE defines the Peppol PINT AE format. Invoices are written with +// PINT AE Billing, and self-billed invoices with PINT AE Self-Billing. var FormatAE = goblubl.Format{ Key: KeyAE, Name: i18n.NewString("UBL Peppol PINT AE 1"), @@ -158,9 +157,7 @@ var FormatAE = goblubl.Format{ SpecificationAESelfBilling, }, ExportFuncs: []goblubl.ExportFunc{exportAE}, - // importPINT is left out: it makes a tax registration that isn't VAT the - // tax ID, which is right for GST, but in PINT AE that one is the seller's - // TIN. gobl.ubl already reads the VAT one as the tax ID. + // No importPINT: it reads a non-VAT tax registration as the tax ID, which in PINT AE is the seller's TIN. ImportFuncs: []goblubl.ImportFunc{importAE}, Match: matchCustomization("urn:peppol:pint:billing-1@ae-1", "urn:peppol:pint:selfbilling-1@ae-1"), } diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index 6c48620..e200c81 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -1,18 +1,14 @@ package ubl_test import ( - "encoding/json" "path/filepath" "regexp" - "slices" - "strings" "testing" "github.com/invopop/gobl.peppol/addon/pint" peppolubl "github.com/invopop/gobl.peppol/ubl" ubl "github.com/invopop/gobl.ubl" "github.com/invopop/gobl/bill" - "github.com/invopop/gobl/catalogues/untdid" "github.com/invopop/gobl/cbc" "github.com/invopop/gobl/convert" "github.com/invopop/gobl/l10n" @@ -85,7 +81,7 @@ func TestDetectPINTFallback(t *testing.T) { f = ubl.FindFormat(peppolubl.SpecificationAUNZSelfBilling.CustomizationID, peppolubl.SpecificationAUNZSelfBilling.ProfileID) require.NotNil(t, f) assert.Equal(t, peppolubl.KeyAUNZ, f.Key) - // AE has its own format now, so the fallback no longer claims it. + // AE has its own format, so the fallback doesn't claim it. f = ubl.FindFormat(peppolubl.FormatPINT.CustomizationID+"@ae-1", peppolubl.FormatPINT.ProfileID) require.NotNil(t, f) assert.Equal(t, peppolubl.KeyAE, f.Key) @@ -197,8 +193,7 @@ func TestImportAEFaults(t *testing.T) { // TestRoundTripAE checks that each AE convert example gives the same XML // after an import and a second export, so whatever FormatAE writes it also -// reads back, and that the imported invoice is the one exported, but for the -// known differences roundTripKnownDifferences lists. +// reads back. func TestRoundTripAE(t *testing.T) { examples, err := filepath.Glob(filepath.Join("testdata", "convert", "pint", "ae", "*.json")) require.NoError(t, err) @@ -218,20 +213,6 @@ func TestRoundTripAE(t *testing.T) { require.NoError(t, err) require.NoError(t, out.Calculate()) require.NoError(t, out.Validate()) - - sent, ok := env.Extract().(*bill.Invoice) - require.True(t, ok) - got, ok := out.Extract().(*bill.Invoice) - require.True(t, ok) - want := cloneInvoice(t, sent) - got = cloneInvoice(t, got) - roundTripKnownDifferences(want, got) - wantJSON, err := json.Marshal(want) - require.NoError(t, err) - gotJSON, err := json.Marshal(got) - require.NoError(t, err) - assert.JSONEq(t, string(wantJSON), string(gotJSON)) - doc, err = ubl.ExportInvoice(out, ubl.WithFormat(peppolubl.FormatAE)) require.NoError(t, err) second, err := ubl.Encode(doc) @@ -242,114 +223,6 @@ func TestRoundTripAE(t *testing.T) { } } -// cloneInvoice provides a deep copy of an invoice. -func cloneInvoice(t *testing.T, inv *bill.Invoice) *bill.Invoice { - t.Helper() - data, err := json.Marshal(inv) - require.NoError(t, err) - out := new(bill.Invoice) - require.NoError(t, json.Unmarshal(data, out)) - return out -} - -// roundTripKnownDifferences evens out what a GOBL invoice can't get back from -// its UBL, in the invoice sent (want) or the one imported (got): -// - UBL has a single document number, so the series is joined to the code; -// - gobl.ubl imports invoices with currency rounding, which the amounts -// written already follow; -// - gobl.ubl gives an imported tax registration the party's country; -// - PINT AE needs a gross price on every line, so an item without a list -// price comes back with its price as one, and with the default unit code; -// - the base of a line charge or discount, which GOBL computes, comes back -// set; -// - a note's key isn't written, only the UNTDID text subject code the -// EN 16931 addon gives it; -// - tags and identities come back in the order UBL holds them. -func roundTripKnownDifferences(want, got *bill.Invoice) { - joinSeries := func(series, code cbc.Code) cbc.Code { - if series == "" { - return code - } - return series + "-" + code - } - want.Code = joinSeries(want.Series, want.Code) - want.Series = "" - for _, ref := range want.Preceding { - ref.Code = joinSeries(ref.Series, ref.Code) - ref.Series = "" - } - if want.Tax != nil { - want.Tax.Rounding = tax.RoundingRuleCurrency - } - - for _, pair := range [][2]*org.Party{{want.Supplier, got.Supplier}, {want.Customer, got.Customer}} { - if pair[0] == nil || pair[1] == nil { - continue - } - for _, g := range pair[1].Identities { - for _, w := range pair[0].Identities { - if g.Code == w.Code && w.Country == "" { - g.Country = "" - } - } - } - sortIdentities(pair[0].Identities) - sortIdentities(pair[1].Identities) - } - - for i, gl := range got.Lines { - if i >= len(want.Lines) || gl.Item == nil || want.Lines[i].Item == nil { - continue - } - wi, gi := want.Lines[i].Item, gl.Item - if wi.List == nil && gi.List != nil && gi.Price != nil && gi.List.Equals(*gi.Price) { - gi.List = nil - } - if !wi.Ext.Has(untdid.ExtKeyUnit) && gi.Ext.Get(untdid.ExtKeyUnit) == "C62" { - gi.Ext = gi.Ext.Delete(untdid.ExtKeyUnit) - } - sortIdentities(wi.Identities) - sortIdentities(gi.Identities) - for j, c := range gl.Charges { - if j < len(want.Lines[i].Charges) && want.Lines[i].Charges[j].Base == nil { - c.Base = nil - } - } - for j, d := range gl.Discounts { - if j < len(want.Lines[i].Discounts) && want.Lines[i].Discounts[j].Base == nil { - d.Base = nil - } - } - } - - clearNoteKeys(want.Notes) - for _, l := range want.Lines { - clearNoteKeys(l.Notes) - } - - for _, inv := range []*bill.Invoice{want, got} { - tags := slices.Clone(inv.GetTags()) - slices.Sort(tags) - inv.SetTags(tags...) - } -} - -// clearNoteKeys removes the keys of notes that have a text subject code. -func clearNoteKeys(notes []*org.Note) { - for _, n := range notes { - if n.Ext.Has(untdid.ExtKeyTextSubject) { - n.Key = "" - } - } -} - -// sortIdentities orders identities by code. -func sortIdentities(ids []*org.Identity) { - slices.SortFunc(ids, func(a, b *org.Identity) int { - return strings.Compare(a.Code.String(), b.Code.String()) - }) -} - // TestImportAESellerTIN checks that a seller with a TIN and no TRN, as out of // scope documents allow, keeps the TIN as a tax registration when imported, // instead of getting it as its tax ID. From 2e2eb44b06bafbff28db4b7167b9f056f2dcbe0c Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:07:08 +0000 Subject: [PATCH 67/73] Pin gobl and gobl.ubl to the PR heads Co-Authored-By: Claude Opus 5.5 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 062ce2c..3b9c58b 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/invopop/gobl.peppol go 1.25.0 require ( - github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 + github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff github.com/invopop/gobl.cii v0.84.0 - github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8 + github.com/invopop/gobl.ubl v0.101.1-0.20261119140955-d1772f886d59 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 4e1e4a0..6043492 100644 --- a/go.sum +++ b/go.sum @@ -22,12 +22,12 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43 h1:xHvbve38r6TPvdquEJ0lJwPlqIU/6XCBJdACDTX1E+k= -github.com/invopop/gobl v0.512.1-0.20261118194003-0061d2660d43/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= +github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff h1:eCXKA1mnojbc+8GkVgCJNIAzmH5EGhDw4RucCD84oIU= +github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.84.0 h1:ivFkWl6GU/7PRl8/8Z87AL4WhhRq6MUtkk2nB9+7g4c= github.com/invopop/gobl.cii v0.84.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8 h1:fJdXJeRq8ZgTAFbuGl4lRPHJOOPKVrdYBKzKxnpSA0U= -github.com/invopop/gobl.ubl v0.101.1-0.20261119111541-f5b47b323ab8/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.101.1-0.20261119140955-d1772f886d59 h1:1UyZSrf0p62PTC4zgLMBv/xj4/F4K685wLHqD7b/iWg= +github.com/invopop/gobl.ubl v0.101.1-0.20261119140955-d1772f886d59/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From 227ed46dee89332251e739abaa7b17a9b7a6a463 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:40:14 +0000 Subject: [PATCH 68/73] Stop writing the IBAN scheme on the payee account The scheme (IBT-084-1) is optional and no PINT AE rule checks it, and gobl.ubl keeps the account ID a plain string again. Co-Authored-By: Claude Opus 5.5 --- ubl/ae.go | 12 ++---------- ubl/ae_internal_test.go | 2 +- .../pint/ae/out/credit-note-ae-margin-scheme.xml | 2 +- .../pint/ae/out/credit-note-ae-outside-scope.xml | 2 +- .../pint/ae/out/credit-note-ae-self-billed.xml | 2 +- .../pint/ae/out/credit-note-ae-volume-discount.xml | 2 +- ubl/testdata/convert/pint/ae/out/credit-note-ae.xml | 2 +- .../pint/ae/out/invoice-ae-continuous-supply.xml | 2 +- .../convert/pint/ae/out/invoice-ae-exempt.xml | 2 +- .../pint/ae/out/invoice-ae-export-summary.xml | 2 +- .../pint/ae/out/invoice-ae-free-trade-zone-agent.xml | 2 +- .../convert/pint/ae/out/invoice-ae-margin-scheme.xml | 2 +- .../convert/pint/ae/out/invoice-ae-outside-scope.xml | 2 +- .../ae/out/invoice-ae-reverse-charge-allowance.xml | 2 +- .../pint/ae/out/invoice-ae-reverse-charge.xml | 2 +- .../convert/pint/ae/out/invoice-ae-self-billed.xml | 2 +- .../convert/pint/ae/out/invoice-ae-shared-fields.xml | 2 +- .../convert/pint/ae/out/invoice-ae-tin-passport.xml | 2 +- ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml | 2 +- ubl/testdata/convert/pint/ae/out/invoice-ae.xml | 2 +- 20 files changed, 21 insertions(+), 29 deletions(-) diff --git a/ubl/ae.go b/ubl/ae.go index 61548c4..f9a2a1a 100644 --- a/ubl/ae.go +++ b/ubl/ae.go @@ -35,10 +35,6 @@ const ( // document reference that carries the total with VAT in AED (BTAE-20). const aedTotalDocumentType = "aedtotal-incl-vat" -// accountSchemeIBAN is the scheme PINT AE gives the ID of an IBAN account -// (IBT-084-1), as the official examples do. -const accountSchemeIBAN = "IBAN" - // deliveryTermsSchemeIncoterms is the scheme of the Incoterms code (BTAE-22), // which the syntax binding requires and the official examples write. const deliveryTermsSchemeIncoterms = "Incoterms" @@ -210,16 +206,12 @@ func exportAEPayment(out *goblubl.Invoice, inv *bill.Invoice) { } } -// exportAECreditTransfer writes the IBAN scheme of the payee account (IBT-084-1) and the address of -// its branch (IBT-169 to IBT-175), which gobl.ubl already reads back. +// exportAECreditTransfer writes the address of the payee account's branch (IBG-34), which gobl.ubl +// already reads back. func exportAECreditTransfer(acc *goblubl.FinancialAccount, ct *pay.CreditTransfer) { if acc == nil || ct == nil { return } - if acc.ID != nil && ct.IBAN != "" && acc.ID.Value == ct.IBAN.String() { - scheme := accountSchemeIBAN - acc.ID.SchemeID = &scheme - } // TODO: FormatPINT should write the branch address too (IBG-34); gobl.ubl can't (UBL-CR-432). if addr := aeAddress(ct.Branch); addr != nil { if acc.FinancialInstitutionBranch == nil { diff --git a/ubl/ae_internal_test.go b/ubl/ae_internal_test.go index 159dc29..0bf7f98 100644 --- a/ubl/ae_internal_test.go +++ b/ubl/ae_internal_test.go @@ -332,7 +332,7 @@ func TestExportAEExchangeRate(t *testing.T) { func TestExportAECreditTransfer(t *testing.T) { t.Run("writes the branch address on a new branch", func(t *testing.T) { - acc := &goblubl.FinancialAccount{ID: &goblubl.IDType{Value: "AE070331234567890123456"}} + acc := &goblubl.FinancialAccount{ID: strPtr("AE070331234567890123456")} exportAECreditTransfer(acc, &pay.CreditTransfer{ IBAN: "AE070331234567890123456", Branch: &org.Address{Street: "Baniyas Road", Locality: "Dubai", Region: "DXB", Country: "AE"}, diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml index ba45f29..aa01b8a 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-margin-scheme.xml @@ -82,7 +82,7 @@ 30 2025-02-06 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml index 631bbb7..7223372 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-outside-scope.xml @@ -81,7 +81,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml index ae851c5..288f397 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-self-billed.xml @@ -81,7 +81,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml index aec76af..c4468cf 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae-volume-discount.xml @@ -75,7 +75,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml index ede7d6a..8dfc2c8 100644 --- a/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/credit-note-ae.xml @@ -81,7 +81,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml index 1ba9495..ae03699 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-continuous-supply.xml @@ -78,7 +78,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml index ac6de27..961ae56 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-exempt.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml index 6786d48..f00ab55 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-export-summary.xml @@ -101,7 +101,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml index ad923b0..a57411b 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-free-trade-zone-agent.xml @@ -87,7 +87,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml index 0b71b12..d4f2c0c 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-margin-scheme.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml index 0686bfd..5da7023 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-outside-scope.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml index dfdbf13..012f90f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge-allowance.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml index 06f0aeb..856082f 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-reverse-charge.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml index a4e873e..cf1ac3a 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-self-billed.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml index 666e0ac..7328af5 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-shared-fields.xml @@ -137,7 +137,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Payee Collections LLC diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml index d16bb0d..4d60928 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-tin-passport.xml @@ -73,7 +73,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml index 30e92c3..0e10400 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae-usd.xml @@ -79,7 +79,7 @@ 30 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD diff --git a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml index b643d47..793eb39 100644 --- a/ubl/testdata/convert/pint/ae/out/invoice-ae.xml +++ b/ubl/testdata/convert/pint/ae/out/invoice-ae.xml @@ -80,7 +80,7 @@ 30 INV-REM-0042 - AE070331234567890123456 + AE070331234567890123456 Emirates NBD EBILAEAD From 33d4602d603ee117d390852f6a0e902bbb1cb5a8 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:42:36 +0000 Subject: [PATCH 69/73] Shorten the PINT AE README Co-Authored-By: Claude Opus 5.5 --- README.md | 112 +++++++++--------------------------------------------- 1 file changed, 17 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 678e199..78b61ed 100644 --- a/README.md +++ b/README.md @@ -54,46 +54,24 @@ $addons: See the [`examples`](./examples) directory for complete invoices. -### PINT - -Documents with the PINT addon, in any regime: - -- Have supplier and customer electronic addresses, and no email address as - an endpoint or inbox. gobl.ubl writes an email address as `cbc:EndpointID` - with the scheme `EM`, which PINT does not accept, so a party can't have one - next to its Peppol endpoint either. -- Have at most one customer identity written as `cac:PartyIdentification` - (any identity other than the tax ones and the first legal one, including a - UAE customer's TIN), and at most one customer tax registration (the tax ID - or a `tax` identity). -- Give the payee a name, and a payee that differs from the supplier in its - legal identity, identity or name. - ### PINT AE -UAE documents with the PINT addon follow the PINT AE rules: - -- They can only be invoices and credit notes, without the `partial`, - `prepayment` or `factoring` tags, as PINT AE has no document type for - anything else. Documents out of scope of VAT take the `outside-tax-scope` - tag, which sets the document type to 480 on invoices and 81 on credit notes. -- Trade licences carry their issuing authority in the description, and - passports their issuing country. -- The supplier's and customer's UAE identities without a scope get the one - PINT AE reads them from: `legal` for the first trade licence, Emirates ID, - passport or Cabinet Decision of a party that has no legal identity yet, and - `tax` for the supplier's TIN. -- A supplier with a UAE TRN gets the TIN it starts with as a `tax` identity, - and the UAE Peppol endpoint `0235:`, when it has neither. -- The PINT AE transaction type comes from the tags `free-trade-zone`, +UAE documents with the PINT addon are modelled as usual in GOBL, plus: + +- **Transaction type** (BTAE-02): set from the tags `free-trade-zone`, `deemed-supply`, `margin-scheme`, `summary`, `continuous-supply`, `disclosed-agent`, `e-commerce` and `export`. -- PINT AE predefines three customer endpoints: `0235:9900000097` on deemed - supplies, which the addon checks, and `0235:9900000099` for exports to a - receiver not on Peppol and `0235:9900000098` for a buyer not subject to UAE - e-invoicing, which the user sets. -- Supplies under the profit margin scheme take the AE regime's - `margin-scheme` tag; see [Conversion](#conversion) for how they are written. +- **Out of scope documents**: the `outside-tax-scope` tag (type codes 480 + and 81). +- **Profit margin scheme**: the AE regime's `margin-scheme` tag with the + `exempt` VAT key on every line; the lines are written in category `N`. +- **Exemption reasons**: `cef-vatex` on exempt VAT combos, with the UAE codes + `DL8.46.1` to `DL8.46.4`. +- **Deemed supplies** go to the predefined endpoint `0235:9900000097`. + +PINT allows one note on the document and one per line, and only the payment +due date (IBT-009) is written, so invoices with more notes, more than one due +date or a due date for part of the amount are rejected. ## Layout @@ -144,65 +122,9 @@ and `urn:peppol:bis:selfbilling`. Documents carrying either are imported with `FormatAUNZ`. `FormatAE` does the same with `SpecificationAESelfBilling` (`urn:peppol:pint:selfbilling-1@ae-1`). -`FormatAE` also adjusts the output to the PINT AE rules: it writes the invoice -UUID, the price base quantity and gross price, the UAE TRN without its country -prefix, the standard rate on reverse charge lines, breakdowns, allowances and -charges, no rate on exempt lines and breakdowns, one VAT breakdown per -category, and each line's amount with VAT and VAT amount in AED. For invoices not in AED, it also writes the exchange rate to -AED and the total with VAT in AED, and converts the line amounts with that -rate. The seller and buyer legal identities get their PINT AE type (`TL`, -`EID`, `PAS` or `CD`, from the AE regime's identity keys and `passport`), with -the trade licence authority (the identity's description) or the passport's -issuing country, and the seller's TIN goes under the `TIN` tax scheme. It also -writes the transaction type as `cbc:ProfileExecutionID`, with the free trade -zone beneficiary and the disclosed agent's principal as the buyer and seller -parties, and the credit note reason as `cac:DiscrepancyResponse`, the VAT exemption reason (`cef-vatex`, one of the UAE codes `DL8.46.1` to `DL8.46.4`) of -exempt lines, and each item's type of goods or services subject to the reverse charge -as its `cbc:NatureCode`, with its GTIN as the standard identifier. Items keyed -`goods`, `services` or `goods-services` get the item type `G`, `S` or `B`, and -identities labelled `SAC` are written as service accounting codes. The -delivery's ICC Incoterms (`icc-incoterms-2020` or `-2010`) are written as the -delivery terms, and the delivery receiver's UAE TRN, or its TIN without one, -as the delivery party's identification (BTAE-23). PINT allows a single note -on the document and on each line (ibr-sr-51, ibr-sr-34), so the PINT addon -rejects invoices with more, in every PINT format, instead of joining them. -Only the payment due date (IBT-009) is written, so the addon also rejects -more than one due date, or one for part of the amount due. That is a -limitation of this library, not a PINT rule: PINT can carry instalments -(IBG-33). - -**Profit margin scheme.** A UAE supply under the profit margin scheme takes the AE regime's -`margin-scheme` tag, with the `exempt` VAT key on every line: - -- Issue one invoice per margin scheme sale, with no other VAT treatments and - no document-level discounts or charges (IBR-116-AE). -- The lines go out in the `N` category at the standard rate, with no VAT - amount. -- The statement that VAT is charged under the scheme, which the regime's - scenario adds as a VAT note, goes out as the VAT exemption reason text of - the `N` breakdown and lines. -- The margin VAT is reported in the VAT return, not on the invoice. - -Without the tag, `exempt` lines are a normal exempt supply (`E`). Anyone -reading GOBL data must identify margin scheme lines by the tag together with -the `exempt` key, never by the key alone. - -It also writes the PINT fields gobl.ubl leaves out: the issue time; each -contract's description, where PINT AE puts the contract value; the `IBAN` -scheme of the payee account and the address of its branch; -`cbc:TaxIncludedIndicator` as `false`; and the tax note of a line's VAT category as its exemption reason text. On import, it reads -the invoice UUID, the out-of-scope type codes 480 and 81 back as the -`outside-tax-scope` tag, and -the identity types, authorities, passport countries and seller TIN back as -identity keys and fields, the transaction type back as its extension and -tags, and the credit note reason, line exemption -reasons and item goods types back as their extensions, and the item -types and service accounting codes back as item keys and identities, and -the `N` category back as the `exempt` key with the `margin-scheme` tag, and -the delivery terms back -as the `icc-incoterms-2020` extension, and the seller and buyer electronic -addresses as endpoints, and the discount and charge exemption reasons and -line exemption reason texts back as their extensions and tax notes. +`FormatAE` also writes the PINT AE fields and adjustments the rules ask for +(such as the invoice UUID, the transaction type, line amounts with VAT in AED +and the exchange rate to AED) and reads them back. Each one's Peppol document type identifier is `urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##::2.1`, From d37e97f78939e1f0b145f06bf2a043ead738d56f Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:43:55 +0000 Subject: [PATCH 70/73] Pin gobl.ubl to the PR head Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index eded373..b6847ed 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 require ( github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff github.com/invopop/gobl.cii v0.85.0 - github.com/invopop/gobl.ubl v0.102.1-0.20261119151845-2ad1ca4239a0 + github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index c9d6755..ee5b291 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff h1:eCXKA1mnojbc+8 github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.85.0 h1:EbVISpzaBdOlnGxh/M0JMNUMMl0xbSRmi/DTez5YH+o= github.com/invopop/gobl.cii v0.85.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.102.1-0.20261119151845-2ad1ca4239a0 h1:OqZnt1Nyec0PFBBboH1HQbpDRWN/CAxXZq2Sury0lbc= -github.com/invopop/gobl.ubl v0.102.1-0.20261119151845-2ad1ca4239a0/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e h1:5h/ne812LMgU2xSzjxEtwiHe+z/ZbXf18T1aktbMApA= +github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From a52d92b6f151d055be5067432a2c0b2e90a3d8e3 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:51:07 +0000 Subject: [PATCH 71/73] Pin gobl.ubl to the PR head Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b6847ed..68ebb7a 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.25.0 require ( github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff github.com/invopop/gobl.cii v0.85.0 - github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e + github.com/invopop/gobl.ubl v0.103.1-0.20261119164756-14cbfffcf2c2 github.com/invopop/phorm v0.1.5 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index ee5b291..1620daf 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff h1:eCXKA1mnojbc+8 github.com/invopop/gobl v0.512.1-0.20261119150448-a26856f0b5ff/go.mod h1:7xBxkslYmW2MdNvanWiVPUYIvR3Se+2dKLYA6Tg+A40= github.com/invopop/gobl.cii v0.85.0 h1:EbVISpzaBdOlnGxh/M0JMNUMMl0xbSRmi/DTez5YH+o= github.com/invopop/gobl.cii v0.85.0/go.mod h1:YQZ5XlHyEFPerP9TgCXAr1Bb7YIlkjssQIKY0P/2R50= -github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e h1:5h/ne812LMgU2xSzjxEtwiHe+z/ZbXf18T1aktbMApA= -github.com/invopop/gobl.ubl v0.102.1-0.20261119163852-20f695d14f8e/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= +github.com/invopop/gobl.ubl v0.103.1-0.20261119164756-14cbfffcf2c2 h1:Bg8ZOe2FIj0cAcoULSqanHOSWtLtQL8fncS2qO1bklc= +github.com/invopop/gobl.ubl v0.103.1-0.20261119164756-14cbfffcf2c2/go.mod h1:11heZ+/Zl3EtK5JpjKZULu1Co2+aer9yw427qzHqukY= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/phorm v0.1.5 h1:qzhDJgo1YaRFTRknD58cLbuTp5UAV/PhQTD9FFK0LIM= From 619f0c3cd5d186616cc19fc63033f21ad2e51478 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:51:07 +0000 Subject: [PATCH 72/73] Import the rest of the official PINT AE examples gobl.ubl v0.103.0 reads issue times with a time zone (#190), so the official PINT AE 1.0.5 examples that have one can be imported. They are added as parse fixtures, with their goldens, and give only the faults of their made-up data: TRNs that fail the check digit and placeholder email addresses. None of the PINT addon's rules fails on any of them. Co-Authored-By: Claude Opus 5.5 --- .../parse/pint/ae/allowance-outside-scope.xml | 156 ++++ .../parse/pint/ae/allowance-zero-rated.xml | 159 ++++ ubl/testdata/parse/pint/ae/charge-exempt.xml | 156 ++++ .../parse/pint/ae/charge-outside-scope.xml | 156 ++++ .../parse/pint/ae/charge-reverse-charge.xml | 165 ++++ .../parse/pint/ae/charge-zero-rated.xml | 159 ++++ .../parse/pint/ae/commercial-invoice.xml | 140 +++ .../parse/pint/ae/continuous-supplies.xml | 239 ++++++ .../pint/ae/credit-note-disclosed-agent.xml | 256 ++++++ .../parse/pint/ae/credit-note-standard.xml | 249 ++++++ .../pint/ae/credit-note-volume-discount.xml | 248 ++++++ .../parse/pint/ae/disclosed-agent-billing.xml | 178 ++++ ubl/testdata/parse/pint/ae/e-commerce.xml | 258 ++++++ .../pint/ae/exports-predefined-endpoint.xml | 199 +++++ ubl/testdata/parse/pint/ae/exports.xml | 199 +++++ .../pint/ae/out/allowance-outside-scope.json | 247 ++++++ .../pint/ae/out/allowance-zero-rated.json | 247 ++++++ .../parse/pint/ae/out/charge-exempt.json | 250 ++++++ .../pint/ae/out/charge-outside-scope.json | 247 ++++++ .../pint/ae/out/charge-reverse-charge.json | 253 ++++++ .../parse/pint/ae/out/charge-zero-rated.json | 247 ++++++ .../parse/pint/ae/out/commercial-invoice.json | 224 +++++ .../pint/ae/out/continuous-supplies.json | 329 +++++++ .../ae/out/credit-note-disclosed-agent.json | 347 ++++++++ .../pint/ae/out/credit-note-standard.json | 343 ++++++++ .../ae/out/credit-note-volume-discount.json | 337 ++++++++ .../pint/ae/out/disclosed-agent-billing.json | 274 ++++++ .../parse/pint/ae/out/e-commerce.json | 360 ++++++++ .../ae/out/exports-predefined-endpoint.json | 258 ++++++ ubl/testdata/parse/pint/ae/out/exports.json | 256 ++++++ .../ae/out/standard-invoice-extensive.json | 812 ++++++++++++++++++ .../standard-invoice-predefined-endpoint.json | 367 ++++++++ .../pint/ae/out/standard-tax-invoice.json | 367 ++++++++ .../parse/pint/ae/out/summary-invoice.json | 401 +++++++++ .../parse/pint/ae/out/zero-rated.json | 226 +++++ .../pint/ae/standard-invoice-extensive.xml | 687 +++++++++++++++ .../standard-invoice-predefined-endpoint.xml | 264 ++++++ .../parse/pint/ae/standard-tax-invoice.xml | 264 ++++++ .../parse/pint/ae/summary-invoice.xml | 316 +++++++ ubl/testdata/parse/pint/ae/zero-rated.xml | 138 +++ ubl/ubl_test.go | 44 +- 41 files changed, 11010 insertions(+), 12 deletions(-) create mode 100644 ubl/testdata/parse/pint/ae/allowance-outside-scope.xml create mode 100644 ubl/testdata/parse/pint/ae/allowance-zero-rated.xml create mode 100644 ubl/testdata/parse/pint/ae/charge-exempt.xml create mode 100644 ubl/testdata/parse/pint/ae/charge-outside-scope.xml create mode 100644 ubl/testdata/parse/pint/ae/charge-reverse-charge.xml create mode 100644 ubl/testdata/parse/pint/ae/charge-zero-rated.xml create mode 100644 ubl/testdata/parse/pint/ae/commercial-invoice.xml create mode 100644 ubl/testdata/parse/pint/ae/continuous-supplies.xml create mode 100644 ubl/testdata/parse/pint/ae/credit-note-disclosed-agent.xml create mode 100644 ubl/testdata/parse/pint/ae/credit-note-standard.xml create mode 100644 ubl/testdata/parse/pint/ae/credit-note-volume-discount.xml create mode 100644 ubl/testdata/parse/pint/ae/disclosed-agent-billing.xml create mode 100644 ubl/testdata/parse/pint/ae/e-commerce.xml create mode 100644 ubl/testdata/parse/pint/ae/exports-predefined-endpoint.xml create mode 100644 ubl/testdata/parse/pint/ae/exports.xml create mode 100644 ubl/testdata/parse/pint/ae/out/allowance-outside-scope.json create mode 100644 ubl/testdata/parse/pint/ae/out/allowance-zero-rated.json create mode 100644 ubl/testdata/parse/pint/ae/out/charge-exempt.json create mode 100644 ubl/testdata/parse/pint/ae/out/charge-outside-scope.json create mode 100644 ubl/testdata/parse/pint/ae/out/charge-reverse-charge.json create mode 100644 ubl/testdata/parse/pint/ae/out/charge-zero-rated.json create mode 100644 ubl/testdata/parse/pint/ae/out/commercial-invoice.json create mode 100644 ubl/testdata/parse/pint/ae/out/continuous-supplies.json create mode 100644 ubl/testdata/parse/pint/ae/out/credit-note-disclosed-agent.json create mode 100644 ubl/testdata/parse/pint/ae/out/credit-note-standard.json create mode 100644 ubl/testdata/parse/pint/ae/out/credit-note-volume-discount.json create mode 100644 ubl/testdata/parse/pint/ae/out/disclosed-agent-billing.json create mode 100644 ubl/testdata/parse/pint/ae/out/e-commerce.json create mode 100644 ubl/testdata/parse/pint/ae/out/exports-predefined-endpoint.json create mode 100644 ubl/testdata/parse/pint/ae/out/exports.json create mode 100644 ubl/testdata/parse/pint/ae/out/standard-invoice-extensive.json create mode 100644 ubl/testdata/parse/pint/ae/out/standard-invoice-predefined-endpoint.json create mode 100644 ubl/testdata/parse/pint/ae/out/standard-tax-invoice.json create mode 100644 ubl/testdata/parse/pint/ae/out/summary-invoice.json create mode 100644 ubl/testdata/parse/pint/ae/out/zero-rated.json create mode 100644 ubl/testdata/parse/pint/ae/standard-invoice-extensive.xml create mode 100644 ubl/testdata/parse/pint/ae/standard-invoice-predefined-endpoint.xml create mode 100644 ubl/testdata/parse/pint/ae/standard-tax-invoice.xml create mode 100644 ubl/testdata/parse/pint/ae/summary-invoice.xml create mode 100644 ubl/testdata/parse/pint/ae/zero-rated.xml diff --git a/ubl/testdata/parse/pint/ae/allowance-outside-scope.xml b/ubl/testdata/parse/pint/ae/allowance-outside-scope.xml new file mode 100644 index 0000000..cf32dca --- /dev/null +++ b/ubl/testdata/parse/pint/ae/allowance-outside-scope.xml @@ -0,0 +1,156 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-ALLOW-O-01 + a1b2c3d4-e5f6-7890-abcd-500000000005 + 2025-03-15 + 2025-03-30 + 480 + Not subject to VAT invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + false + 95 + Discount + 100 + + O + + VAT + + + + + 0 + false + + 900 + 0 + + O + + VAT + + + + + + 1000 + 900 + 900 + 100 + 900 + + + 1 + 10 + 1000 + + Services not subject to VAT + Out of Scope Services + + O + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/allowance-zero-rated.xml b/ubl/testdata/parse/pint/ae/allowance-zero-rated.xml new file mode 100644 index 0000000..1d61d26 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/allowance-zero-rated.xml @@ -0,0 +1,159 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-ALLOW-Z-01 + a1b2c3d4-e5f6-7890-abcd-700000000007 + 2025-03-15 + 2025-03-30 + 380 + Zero rated supply invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + false + 95 + Discount + 100 + + Z + 0 + + VAT + + + + + 0 + false + + 900 + 0 + + Z + 0 + + VAT + + + + + + 1000 + 900 + 900 + 100 + 900 + + + 1 + 10 + 1000 + + Zero rated goods for export + Zero Rated Goods + + Z + 0 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/charge-exempt.xml b/ubl/testdata/parse/pint/ae/charge-exempt.xml new file mode 100644 index 0000000..9a6e7f1 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/charge-exempt.xml @@ -0,0 +1,156 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CHARGE-E-01 + a1b2c3d4-e5f6-7890-abcd-400000000004 + 2025-03-15 + 2025-03-30 + 480 + Exempt supply invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + true + AAT + Handling fee + 200 + + E + 0 + DL8.46.4 + + VAT + + + + + 0 + false + + 1200 + 0 + + E + + VAT + + + + + + 1000 + 1200 + 1200 + 200 + 1200 + + + 1 + 10 + 1000 + + Local passenger transport services exempt from VAT + Local Passenger Transport + + E + DL8.46.4 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/charge-outside-scope.xml b/ubl/testdata/parse/pint/ae/charge-outside-scope.xml new file mode 100644 index 0000000..a2f102a --- /dev/null +++ b/ubl/testdata/parse/pint/ae/charge-outside-scope.xml @@ -0,0 +1,156 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CHARGE-O-01 + a1b2c3d4-e5f6-7890-abcd-600000000006 + 2025-03-15 + 2025-03-30 + 480 + Not subject to VAT invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + true + AAT + Handling fee + 200 + + O + + VAT + + + + + 0 + false + + 1200 + 0 + + O + + VAT + + + + + + 1000 + 1200 + 1200 + 200 + 1200 + + + 1 + 10 + 1000 + + Services not subject to VAT + Out of Scope Services + + O + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0.00 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/charge-reverse-charge.xml b/ubl/testdata/parse/pint/ae/charge-reverse-charge.xml new file mode 100644 index 0000000..29e9d42 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/charge-reverse-charge.xml @@ -0,0 +1,165 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CHARGE-AE-01 + a1b2c3d4-e5f6-7890-abcd-200000000002 + 2025-03-15 + 2025-03-30 + 380 + Tax invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + true + AAT + Rush Delivery + 200 + + AE + 5 + + VAT + + + + + 0 + false + + 1200 + 0 + + AE + 5 + + VAT + + + + + + 1000 + 1200 + 1200 + 200 + 1200 + + + 1 + 10 + 1000 + + Consulting services subject to reverse charge + Consulting Services + + 9876543210 + + + DL8.48.3.1 + + + AE + 5 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/charge-zero-rated.xml b/ubl/testdata/parse/pint/ae/charge-zero-rated.xml new file mode 100644 index 0000000..ffb0c3c --- /dev/null +++ b/ubl/testdata/parse/pint/ae/charge-zero-rated.xml @@ -0,0 +1,159 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CHARGE-Z-01 + a1b2c3d4-e5f6-7890-abcd-800000000008 + 2025-03-15 + 2025-03-30 + 380 + Zero rated supply invoice + 2025-03-10 + AED + + + 1987654321 + + Seller Trade Name + + + Al Maktoum Road + Dubai + DXB + + AE + + + + 198765432102003 + + VAT + + + + Seller Legal Name + 112345678900003 + Merchant + + + Contact Name + +971501234567 + seller@example.ae + + + + + + 1345678901 + + Buyer Trade Name + + + Khalifa Street + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Buyer Contact + +971502345678 + buyer@example.ae + + + + + 30 + + AE070331234567890123456 + current account + + ABORAEADXXX + + + + + Net 15 days + + + true + AAT + Rush Delivery + 200 + + Z + 0 + + VAT + + + + + 0 + false + + 1200 + 0 + + Z + 0 + + VAT + + + + + + 1000 + 1200 + 1200 + 200 + 1200 + + + 1 + 10 + 1000 + + Zero rated goods for export + Zero Rated Goods + + Z + 0 + + VAT + + + + + 100 + 1 + + false + 0 + 100 + + + + 1000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/commercial-invoice.xml b/ubl/testdata/parse/pint/ae/commercial-invoice.xml new file mode 100644 index 0000000..b642330 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/commercial-invoice.xml @@ -0,0 +1,140 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-CI-001Test + 19e2c9a3-b000-4fb0-9bd5-a9c4ebda2358 + 2025-02-07 + 17:38:00+04:00 + 2025-02-07 + 480 + AED + + + 1987654321 + + Seller Trade Name + + + Street Name + Sharjah + SHJ + + AE + + + + 198765432112303 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email address + + + + + + 1345678901 + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email Address + + + + + + Payee Ltd. + + + CN12389045678121 + + + + 10 + + + Cash payment + + + 0 + false + + 150000 + 0 + + O + + VAT + + + + + + 150000 + 150000 + 150000 + 150000 + + + 1 + 1000 + 150000 + + Item Description + Item Name + + O + + VAT + + + + + 150 + 1 + + false + 1 + 151 + + + + 150000 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/continuous-supplies.xml b/ubl/testdata/parse/pint/ae/continuous-supplies.xml new file mode 100644 index 0000000..cd30bda --- /dev/null +++ b/ubl/testdata/parse/pint/ae/continuous-supplies.xml @@ -0,0 +1,239 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00001000 + AE-001CS-TEST + 2175fae7-7dc2-4aea-b78b-d358f8863919 + 2025-02-07 + 2025-03-07 + 380 + Tax invoice + 2025-01-30 + AED + + 2025-01-31 + 2025-02-07 + MTH + + + ZXC-CS-03 + AED 1000000 + + + Cabbills + + + https://www.site.ae/cabbills.pdf + + + + + All signed cab bills + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + + 1987654321 + + Supplier Trade Name + + + Street Name + Dubai + DXB + + AE + + + + 132654987101003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email Address + + + + + + 1456789456 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 145678945601003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email Address + + + + + 30 + + AE0000000001 + current account + + 236000 + + + + + 1 month + + + true + ABU + Polyethylene wrap packing + 1.5 + 75 + 5000 + + S + 5 + + VAT + + + + + 253.75 + false + + 5075 + 253.75 + + S + 5 + + VAT + + + + + 727.5 + 0 + + E + + VAT + + + + + + 5727.50 + 5802.5 + 6056.25 + 75 + 0.75 + 6057 + + + 1 + 10 + 5000 + + 2025-01-31 + 2025-02-07 + + + 250 + + + Item Description + Item Name + + G + 23424 + + + S + 5 + + VAT + + + + + 500 + 1 + + false + 0 + 500 + + + + 5250 + + 250 + + + + + 2 + 1455 + 727.5 + + 2025-01-31 + 2025-02-07 + + + Item Description + Item Name + + E + DL8.46.4 + Local passenger transport + + VAT + + + + + 0.5 + 1 + + false + 0 + 0.5 + + + + 727.5 + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/credit-note-disclosed-agent.xml b/ubl/testdata/parse/pint/ae/credit-note-disclosed-agent.xml new file mode 100644 index 0000000..6ac2625 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/credit-note-disclosed-agent.xml @@ -0,0 +1,256 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000100 + AE001-CN-TEST + 9330196c-74e7-4da2-bb72-b290e3b86556 + 2025-02-07 + 15:55:00+04:00 + 381 + Tax Credit invoice + AED + Regular sales + PO-AE-220 + + 2025-01-31 + 2025-02-07 + + + DL8.61.1.E + + + PO-AE-220 + Salesorder-2122 + + + + Sample-02 + 2025-02-07 + + + + Memo-1000 + + + PO-AE-220 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + PO-AE-220 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Sarjah + SHJ + + AE + + + + 198765432102003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email address + + + + + + 1345678901 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email address + + + + + + Payee Party Name + + + 1122334455 + + + + + + 155667745601003 + + + + + Will be adjusted against next invoice + + + false + 100 + Special Rebate + 2.5 + 262.15 + 10486 + + S + 5 + + VAT + + + + + true + AAT + Rush Delivery + 4 + 419.44 + 10486 + + S + 5 + + VAT + + + + + 532.16 + false + + 10643.29 + 532.1645 + + S + 5 + + VAT + + + + + + 10486 + 10643.29 + 11175.45 + 262.15 + 419.44 + 0.05 + 11175.5 + + + 1 + All items + 2000 + 10486 + + 2025-01-31 + 2025-01-31 + + + 1 + + PO-AE-220 + + + + false + 95 + Discount + 3 + 294 + 9800 + + + true + AAC + Technical Modification + 10 + 980 + 9800 + + + Item Description + Item Name + + Buyer Item Identification + + + Seller Item Identification + + + AE + + + G + 11223355 + + + S + 5 + + VAT + + + + Additional Item Property Name + Additional Item Property Value + + + + 4.9 + 1 + + false + 0.1 + 5 + + + + 11010.3 + + 524.3 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/credit-note-standard.xml b/ubl/testdata/parse/pint/ae/credit-note-standard.xml new file mode 100644 index 0000000..fdcfe5b --- /dev/null +++ b/ubl/testdata/parse/pint/ae/credit-note-standard.xml @@ -0,0 +1,249 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE001-CN-TEST + f1c9d83d-e31f-43fc-919f-10b961f599e7 + 2025-02-07 + 15:55:00+04:00 + 381 + Tax Credit invoice + AED + Regular sales + PO-AE-220 + + 2025-01-31 + 2025-02-07 + + + DL8.61.1.E + + + PO-AE-220 + Salesorder-2122 + + + + Sample-02 + 2025-02-07 + + + + Memo-1000 + + + PO-AE-220 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + PO-AE-220 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Sarjah + SHJ + + AE + + + + 198765432102003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email address + + + + + + 1345678901 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email address + + + + + + Payee Party Name + + + 1122334455 + + + + Will be adjusted against next invoice + + + false + 100 + Special Rebate + 2.5 + 262.15 + 10486 + + S + 5 + + VAT + + + + + true + AAT + Rush Delivery + 4 + 419.44 + 10486 + + S + 5 + + VAT + + + + + 532.16 + false + + 10643.29 + 532.1645 + + S + 5 + + VAT + + + + + + 10486 + 10643.29 + 11175.45 + 262.15 + 419.44 + 0.05 + 11175.5 + + + 1 + All items + 2000 + 10486 + + 2025-01-31 + 2025-01-31 + + + 1 + + PO-AE-220 + + + + false + 95 + Discount + 3 + 294 + 9800 + + + true + AAC + Technical Modification + 10 + 980 + 9800 + + + Item Description + Item Name + + Buyer Item Identification + + + Seller Item Identification + + + AE + + + G + 11223355 + + + S + 5 + + VAT + + + + Additional Item Property Name + Additional Item Property Value + + + + 4.9 + 1 + + false + 0.1 + 5 + + + + 11010.3 + + 524.3 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/credit-note-volume-discount.xml b/ubl/testdata/parse/pint/ae/credit-note-volume-discount.xml new file mode 100644 index 0000000..47503ef --- /dev/null +++ b/ubl/testdata/parse/pint/ae/credit-note-volume-discount.xml @@ -0,0 +1,248 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE001-CN-VD + a2b3c4d5-e6f7-8901-abcd-ef1234567890 + 2025-02-07 + 15:55:00+04:00 + 381 + Volume discount credit note - VD reason, no BillingReference required per ibr-055-ae + AED + Regular sales + PO-AE-220 + + 2025-01-31 + 2025-02-07 + + + VD + Volume discount + + + PO-AE-220 + Salesorder-2122 + + + Memo-1000 + + + PO-AE-220 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + PO-AE-220 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Sarjah + SHJ + + AE + + + + 198765432102003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email address + + + + + + 1345678901 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email address + + + + + + Payee Party Name + + + 1122334455 + + + + Will be adjusted against next invoice + + + false + 100 + Special Rebate + 2.5 + 262.15 + 10486 + + S + 5 + + VAT + + + + + true + AAT + Rush Delivery + 4 + 419.44 + 10486 + + S + 5 + + VAT + + + + + 532.16 + false + + 10643.29 + 532.1645 + + S + 5 + + VAT + + + + + + 10486 + 10643.29 + 11175.45 + 262.15 + 419.44 + 0.05 + 11175.5 + + + 1 + All items + 2000 + 10486 + + 2025-01-31 + 2025-01-31 + + + 1 + + PO-AE-220 + + + + VD + Volume discount + + + false + 95 + Discount + 3 + 294 + 9800 + + + true + AAC + Technical Modification + 10 + 980 + 9800 + + + Item Description + Item Name + + Buyer Item Identification + + + Seller Item Identification + + + AE + + + G + 11223355 + + + S + 5 + + VAT + + + + Additional Item Property Name + Additional Item Property Value + + + + 4.9 + 1 + + false + 0.1 + 5 + + + + 11010.3 + + 524.3 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/disclosed-agent-billing.xml b/ubl/testdata/parse/pint/ae/disclosed-agent-billing.xml new file mode 100644 index 0000000..7a6e941 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/disclosed-agent-billing.xml @@ -0,0 +1,178 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000100 + AE-01DAB-TEST + 01506abf-d824-4548-af5e-539b284b4203 + 2025-02-07 + 15:08:00+04:00 + 2025-02-07 + 380 + Tax invoice + AED + + + 1239874562 + + Street Name + Sharjah + SHJ + + AE + + + + 124680135701003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Telephone Number + Email Address + + + + + + 1456789456 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 145678945601003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact number + email address + + + + + + + 155667745601003 + + + + + 30 + + AE0000000001 + current account + + 236000 + + + + + cash payment + + + false + 100 + Special Rebate + 5 + 49.97 + 999.375 + + S + 5 + + VAT + + + + + 47.47 + false + + 949.405 + 47.47025 + + S + 5 + + VAT + + + + + + 999.38 + 949.41 + 996.88 + 49.97 + 996.88 + + + 1 + Inspect the goods + 50 + 999.375 + + true + AAC + Technical Modification + 2.5 + 24.375 + 975 + + + Item Description + Item Name + + G + 889900 + + + S + 5 + + VAT + + + + + 19.5 + 1 + + false + 0.5 + 20 + + + + 1049.3438 + + 49.9688 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/e-commerce.xml b/ubl/testdata/parse/pint/ae/e-commerce.xml new file mode 100644 index 0000000..3d6baff --- /dev/null +++ b/ubl/testdata/parse/pint/ae/e-commerce.xml @@ -0,0 +1,258 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000010 + AE-001-E-Commerce-TEST + 0401431a-3b05-442e-95bd-2d12c2cb2296 + 2025-02-11 + 11:35:10+04:00 + 2025-02-11 + 380 + Tax invoice + AED + + DR-INV-001 + + + https://www.site.ae/invoices.pdf + + + + + DR-INV-02 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + + 112345678900003 + + Supplier Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address line + + + AE + + + + 112345678900003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Contact Email address + + + + + + 112345679000003 + + Buyer Trade Name + + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address Line + + + AE + + + + 112345679000003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Contact Email address + + + + + + 132345679670003 + + + Payee Party Name + + + 112345679350001 + + + + 2025-02-11 + + 112345679000003 + + Street Name + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Address line 3 + + + AE + + + + + + Delivery Party Name + + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + Instant Payment + + + false + 95 + Discount + 5 + 5 + 100 + + S + 5 + + VAT + + + + + true + AAC + Technical Modification + 2.5 + 2.5 + 100 + + S + 5 + + VAT + + + + + 5 + false + + 100 + 5 + + S + 5 + + VAT + + + + + + 102.5 + 100 + 105 + 5 + 2.5 + 0 + 0 + 105 + + + 1 + Please check the invoice + 1 + 102.5 + + false + 95 + Discount + 2.5 + 2.5 + 100 + + + true + AAC + Technical Modification + 5 + 5 + 100 + + + Item Description + Item Name + + G + 11223355 + + + S + 5 + 100 + + VAT + + + + + 100 + 1 + + false + 1 + 101 + + + + 107.625 + + 5.125 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/exports-predefined-endpoint.xml b/ubl/testdata/parse/pint/ae/exports-predefined-endpoint.xml new file mode 100644 index 0000000..368ac7b --- /dev/null +++ b/ubl/testdata/parse/pint/ae/exports-predefined-endpoint.xml @@ -0,0 +1,199 @@ + + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000001 + AE-001-Exports-TEST + 42fd81e6-27cd-422e-b93e-760f6c47c82d + 2025-02-07 + 17:31:00+04:00 + 2025-02-22 + 380 + Tax invoice + 2025-01-31 + USD + AED + + EXP-09 + EC-24-25-1001 + + + EXP010101234 + + + AED + aedtotal-incl-vat + 913621.44 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Dubai + DXB + + AE + + + + 132654987101003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email Address + + + + + + 9900000099 + + Buyer Legal Name + + + Street Name + Additional Street Name + Perth + Postal code + WA + + AU + + + + Export Traders + CN0102000001123 + + + Contact Name + Email Address + + + + + + + mm + 333 + 333 + + US + + + + + CIF + + + + 1 + + + within 1 month + + + USD + AED + 3.67285 + + + 0 + false + + 248750 + 0 + + Z + 0 + + VAT + + + + + + 0 + + + 248750 + 248750 + 248750 + 248750 + + + 1 + 5000 + 248750 + + 0 + + + Item Description + Item Name + + G + 22334455 + + + Z + 0 + + VAT + + + + + Lot 1 + + + + + 49.75 + 1 + + false + 0.25 + 50 + + + + 913621.44 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/exports.xml b/ubl/testdata/parse/pint/ae/exports.xml new file mode 100644 index 0000000..2458b5d --- /dev/null +++ b/ubl/testdata/parse/pint/ae/exports.xml @@ -0,0 +1,199 @@ + + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000001 + AE-001-Exports-TEST + 42fd81e6-27cd-422e-b93e-760f6c47c82d + 2025-02-07 + 17:31:00+04:00 + 2025-02-22 + 380 + Tax invoice + 2025-01-31 + USD + AED + + EXP-09 + EC-24-25-1001 + + + EXP010101234 + + + AED + aedtotal-incl-vat + 913621.44 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Dubai + DXB + + AE + + + + 132654987101003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email Address + + + + + + 51824753556 + + Buyer Legal Name + + + Street Name + Additional Street Name + Perth + Postal code + WA + + AU + + + + Export company + CN0102000001123 + + + Contact Name + Email Address + + + + + + + mm + 333 + 333 + + US + + + + + CIF + + + + 1 + + + within 1 month + + + USD + AED + 3.67285 + + + 0 + false + + 248750 + 0 + + Z + 0 + + VAT + + + + + + 0 + + + 248750 + 248750 + 248750 + 248750 + + + 1 + 5000 + 248750 + + 0 + + + Item Description + Item Name + + G + 22334455 + + + Z + 0 + + VAT + + + + + Lot 1 + + + + + 49.75 + 1 + + false + 0.25 + 50 + + + + 913621.44 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/allowance-outside-scope.json b/ubl/testdata/parse/pint/ae/out/allowance-outside-scope.json new file mode 100644 index 0000000..e6b27d1 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/allowance-outside-scope.json @@ -0,0 +1,247 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "cd397fe17b94104ac1a366be43bcad2ea6d2e499c06f7082419ef769a4ba8a2e" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-tax-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-ALLOW-O-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Out of Scope Services", + "description": "Services not subject to VAT", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "total": "1000.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Discount", + "amount": "100.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "900.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "discount": "100.00", + "total": "900.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + }, + "base": "900.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "900.00", + "payable": "900.00" + }, + "notes": [ + { + "text": "Not subject to VAT invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/allowance-zero-rated.json b/ubl/testdata/parse/pint/ae/out/allowance-zero-rated.json new file mode 100644 index 0000000..8f4f5d2 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/allowance-zero-rated.json @@ -0,0 +1,247 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "d8a710af97e31ce240532a5212976bad855710317b1a198a2a04dd09ca779dca" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-ALLOW-Z-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Zero Rated Goods", + "description": "Zero rated goods for export", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "1000.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Discount", + "amount": "100.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "900.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "discount": "100.00", + "total": "900.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "900.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "900.00", + "payable": "900.00" + }, + "notes": [ + { + "text": "Zero rated supply invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/charge-exempt.json b/ubl/testdata/parse/pint/ae/out/charge-exempt.json new file mode 100644 index 0000000..58791eb --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/charge-exempt.json @@ -0,0 +1,250 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "3a4b2089f13b033d2e412a698f6307c0f3b3af59f9910b65f6e83e408aa25284" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-tax-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-CHARGE-E-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Local Passenger Transport", + "description": "Local passenger transport services exempt from VAT", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.4", + "untdid-tax-category": "E" + } + } + ], + "total": "1000.00" + } + ], + "charges": [ + { + "i": 1, + "reason": "Handling fee", + "amount": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.4", + "untdid-tax-category": "E" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1200.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "charge": "200.00", + "total": "1200.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.4", + "untdid-tax-category": "E" + }, + "base": "1200.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1200.00", + "payable": "1200.00" + }, + "notes": [ + { + "text": "Exempt supply invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/charge-outside-scope.json b/ubl/testdata/parse/pint/ae/out/charge-outside-scope.json new file mode 100644 index 0000000..96d0632 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/charge-outside-scope.json @@ -0,0 +1,247 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "254e32977d29359a0af08bcb5d4895c1c04b8b16327d1e3d508b473691052585" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-tax-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-CHARGE-O-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Out of Scope Services", + "description": "Services not subject to VAT", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "total": "1000.00" + } + ], + "charges": [ + { + "i": 1, + "reason": "Handling fee", + "amount": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1200.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "charge": "200.00", + "total": "1200.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + }, + "base": "1200.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1200.00", + "payable": "1200.00" + }, + "notes": [ + { + "text": "Not subject to VAT invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/charge-reverse-charge.json b/ubl/testdata/parse/pint/ae/out/charge-reverse-charge.json new file mode 100644 index 0000000..5ea1709 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/charge-reverse-charge.json @@ -0,0 +1,253 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "7a5747643d912a1839bcb4bc085a40fb28cd3b149671d442f45849ef93fd5930" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-CHARGE-AE-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Consulting Services", + "identities": [ + { + "code": "9876543210", + "ext": { + "iso-scheme-id": "0160" + } + } + ], + "description": "Consulting services subject to reverse charge", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1", + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "total": "1000.00" + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1200.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "charge": "200.00", + "total": "1200.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + }, + "base": "1200.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1200.00", + "payable": "1200.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/charge-zero-rated.json b/ubl/testdata/parse/pint/ae/out/charge-zero-rated.json new file mode 100644 index 0000000..8ca5820 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/charge-zero-rated.json @@ -0,0 +1,247 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "240c9b62483cc6edefe4dfde65b14e826655c321ec8dce030c370397d000ce62" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-CHARGE-Z-01", + "issue_date": "2025-03-15", + "value_date": "2025-03-10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Seller Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Al Maktoum Road", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "seller@example.ae" + } + ], + "telephones": [ + { + "num": "+971501234567" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Buyer Contact" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Khalifa Street", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "buyer@example.ae" + } + ], + "telephones": [ + { + "num": "+971502345678" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "item": { + "name": "Zero Rated Goods", + "description": "Zero rated goods for export", + "list": "100", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1000.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "1000.00" + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "200.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-30", + "amount": "1200.00", + "percent": "100%" + } + ], + "notes": "Net 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE070331234567890123456", + "bic": "ABORAEADXXX", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "1000.00", + "charge": "200.00", + "total": "1200.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "1200.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "1200.00", + "payable": "1200.00" + }, + "notes": [ + { + "text": "Zero rated supply invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/commercial-invoice.json b/ubl/testdata/parse/pint/ae/out/commercial-invoice.json new file mode 100644 index 0000000..3818273 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/commercial-invoice.json @@ -0,0 +1,224 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "2392799f45b29fb36053d68ee66e7fcacdc57be7870d31e0eb953f768ff89c46" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "outside-tax-scope" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-CI-001Test", + "issue_date": "2025-02-07", + "issue_time": "17:38:00", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "480" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432112303" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "1000", + "item": { + "name": "Item Name", + "description": "Item Description", + "list": "151", + "discount": "1", + "price": "150.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "150000.00", + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "total": "150000.00" + } + ], + "payment": { + "payee": { + "name": "Payee Ltd.", + "identities": [ + { + "scope": "legal", + "code": "CN12389045678121" + } + ] + }, + "terms": { + "due_dates": [ + { + "date": "2025-02-07", + "amount": "150000.00", + "percent": "100%" + } + ], + "notes": "Cash payment" + }, + "instructions": { + "key": "cash", + "detail": "In cash", + "ext": { + "untdid-payment-means": "10" + } + } + }, + "totals": { + "sum": "150000.00", + "total": "150000.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + }, + "base": "150000.00", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "150000.00", + "payable": "150000.00" + } + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/continuous-supplies.json b/ubl/testdata/parse/pint/ae/out/continuous-supplies.json new file mode 100644 index 0000000..dbb954d --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/continuous-supplies.json @@ -0,0 +1,329 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "18ae894b9ae4571e0fec36d6d642627716b5246cc12427d22178c49f12b3eec2" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1456789456" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "continuous-supply" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001CS-TEST", + "issue_date": "2025-02-07", + "value_date": "2025-01-30", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00001000", + "untdid-document-type": "380" + }, + "notes": [ + { + "cat": "VAT", + "key": "exempt", + "text": "Local passenger transport", + "ext": { + "untdid-tax-category": "E" + } + } + ] + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "132654987101003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "145678945601003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1456789456" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1456789456" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "10", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "23424" + } + ], + "description": "Item Description", + "list": "500", + "price": "500.00", + "ext": { + "untdid-unit": "TIP" + } + }, + "sum": "5000.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "5000.00" + }, + { + "i": 2, + "quantity": "1455", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "item": { + "name": "Item Name", + "description": "Item Description", + "list": "0.5", + "price": "0.50", + "ext": { + "untdid-unit": "LN" + } + }, + "sum": "727.50", + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.4", + "untdid-tax-category": "E" + } + } + ], + "total": "727.50" + } + ], + "charges": [ + { + "i": 1, + "reason": "Polyethylene wrap packing", + "base": "5000", + "percent": "1.5%", + "amount": "75", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "ABU" + } + } + ], + "ordering": { + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "contracts": [ + { + "code": "ZXC-CS-03", + "description": "AED 1000000" + } + ] + }, + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-03-07", + "amount": "6057.00", + "percent": "100%" + } + ], + "notes": "1 month" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "5727.50", + "charge": "75.00", + "total": "5802.50", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "5075.00", + "percent": "5%", + "amount": "253.75" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.4", + "untdid-tax-category": "E" + }, + "base": "727.50", + "amount": "0.00" + } + ], + "amount": "253.75" + } + ], + "sum": "253.75" + }, + "tax": "253.75", + "total_with_tax": "6056.25", + "rounding": "0.75", + "payable": "6057.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "Cabbills", + "url": "https://www.site.ae/cabbills.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/credit-note-disclosed-agent.json b/ubl/testdata/parse/pint/ae/out/credit-note-disclosed-agent.json new file mode 100644 index 0000000..6017439 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/credit-note-disclosed-agent.json @@ -0,0 +1,347 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "4a9f733ae204bb7102065c952458b4015cf2ef728c1ee46799b7af3c464cd67e" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "disclosed-agent" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "code": "AE001-CN-TEST", + "issue_date": "2025-02-07", + "issue_time": "15:55:00", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-02-07", + "code": "Sample-02" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-principal-id": "155667745601003", + "peppol-pint-ae-transaction-type": "00000100", + "untdid-document-type": "381" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sarjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2000", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "order": "1", + "item": { + "ref": "Seller Item Identification", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "Buyer Item Identification" + }, + { + "label": "HS", + "code": "11223355" + } + ], + "attributes": [ + { + "label": "Additional Item Property Name", + "text": "Additional Item Property Value" + } + ], + "description": "Item Description", + "list": "5", + "discount": "0.1", + "price": "4.90", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "9800.00", + "discounts": [ + { + "reason": "Discount", + "base": "9800.00", + "percent": "3%", + "amount": "294.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "9800.00", + "percent": "10%", + "amount": "980.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "10486.00", + "notes": [ + { + "text": "All items" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "262.15", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "419.44", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "ordering": { + "code": "PO-AE-220", + "cost": "Regular sales", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "purchases": [ + { + "code": "PO-AE-220" + } + ], + "sales": [ + { + "code": "Salesorder-2122" + } + ], + "despatch": [ + { + "code": "Memo-1000" + } + ], + "tender": [ + { + "code": "PO-AE-220" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Party Name", + "identities": [ + { + "scope": "legal", + "code": "1122334455" + } + ] + }, + "terms": { + "notes": "Will be adjusted against next invoice" + } + }, + "totals": { + "sum": "10486.00", + "discount": "262.15", + "charge": "419.44", + "total": "10643.29", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10643.29", + "percent": "5%", + "amount": "532.16" + } + ], + "amount": "532.16" + } + ], + "sum": "532.16" + }, + "tax": "532.16", + "total_with_tax": "11175.45", + "rounding": "0.05", + "payable": "11175.50" + }, + "notes": [ + { + "text": "Tax Credit invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/credit-note-standard.json b/ubl/testdata/parse/pint/ae/out/credit-note-standard.json new file mode 100644 index 0000000..24fe7b7 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/credit-note-standard.json @@ -0,0 +1,343 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "fc66967c942a5fbb70adf5b67dcf6cb4356062a97590c19cb176000ac1c056a3" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "code": "AE001-CN-TEST", + "issue_date": "2025-02-07", + "issue_time": "15:55:00", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-02-07", + "code": "Sample-02" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-credit-note-reason": "DL8.61.1.E", + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "381" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sarjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2000", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "order": "1", + "item": { + "ref": "Seller Item Identification", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "Buyer Item Identification" + }, + { + "label": "HS", + "code": "11223355" + } + ], + "attributes": [ + { + "label": "Additional Item Property Name", + "text": "Additional Item Property Value" + } + ], + "description": "Item Description", + "list": "5", + "discount": "0.1", + "price": "4.90", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "9800.00", + "discounts": [ + { + "reason": "Discount", + "base": "9800.00", + "percent": "3%", + "amount": "294.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "9800.00", + "percent": "10%", + "amount": "980.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "10486.00", + "notes": [ + { + "text": "All items" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "262.15", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "419.44", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "ordering": { + "code": "PO-AE-220", + "cost": "Regular sales", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "purchases": [ + { + "code": "PO-AE-220" + } + ], + "sales": [ + { + "code": "Salesorder-2122" + } + ], + "despatch": [ + { + "code": "Memo-1000" + } + ], + "tender": [ + { + "code": "PO-AE-220" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Party Name", + "identities": [ + { + "scope": "legal", + "code": "1122334455" + } + ] + }, + "terms": { + "notes": "Will be adjusted against next invoice" + } + }, + "totals": { + "sum": "10486.00", + "discount": "262.15", + "charge": "419.44", + "total": "10643.29", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10643.29", + "percent": "5%", + "amount": "532.16" + } + ], + "amount": "532.16" + } + ], + "sum": "532.16" + }, + "tax": "532.16", + "total_with_tax": "11175.45", + "rounding": "0.05", + "payable": "11175.50" + }, + "notes": [ + { + "text": "Tax Credit invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/credit-note-volume-discount.json b/ubl/testdata/parse/pint/ae/out/credit-note-volume-discount.json new file mode 100644 index 0000000..9d3de03 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/credit-note-volume-discount.json @@ -0,0 +1,337 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "9b3ac2b9ada6a768dcc49bd2da94154cc86a98c5f5670e2c241e5d448315b888" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "credit-note", + "code": "AE001-CN-VD", + "issue_date": "2025-02-07", + "issue_time": "15:55:00", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-credit-note-reason": "VD", + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "381" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sarjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2000", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "order": "1", + "item": { + "ref": "Seller Item Identification", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "Buyer Item Identification" + }, + { + "label": "HS", + "code": "11223355" + } + ], + "attributes": [ + { + "label": "Additional Item Property Name", + "text": "Additional Item Property Value" + } + ], + "description": "Item Description", + "list": "5", + "discount": "0.1", + "price": "4.90", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "9800.00", + "discounts": [ + { + "reason": "Discount", + "base": "9800.00", + "percent": "3%", + "amount": "294.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "9800.00", + "percent": "10%", + "amount": "980.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "10486.00", + "notes": [ + { + "text": "All items" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "262.15", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "419.44", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "ordering": { + "code": "PO-AE-220", + "cost": "Regular sales", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "purchases": [ + { + "code": "PO-AE-220" + } + ], + "sales": [ + { + "code": "Salesorder-2122" + } + ], + "despatch": [ + { + "code": "Memo-1000" + } + ], + "tender": [ + { + "code": "PO-AE-220" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Party Name", + "identities": [ + { + "scope": "legal", + "code": "1122334455" + } + ] + }, + "terms": { + "notes": "Will be adjusted against next invoice" + } + }, + "totals": { + "sum": "10486.00", + "discount": "262.15", + "charge": "419.44", + "total": "10643.29", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10643.29", + "percent": "5%", + "amount": "532.16" + } + ], + "amount": "532.16" + } + ], + "sum": "532.16" + }, + "tax": "532.16", + "total_with_tax": "11175.45", + "rounding": "0.05", + "payable": "11175.50" + }, + "notes": [ + { + "text": "Volume discount credit note - VD reason, no BillingReference required per ibr-055-ae" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/disclosed-agent-billing.json b/ubl/testdata/parse/pint/ae/out/disclosed-agent-billing.json new file mode 100644 index 0000000..370cf1f --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/disclosed-agent-billing.json @@ -0,0 +1,274 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "a12b3f0f36099606ff5bab463e55d90ca9aa8c6dcffb12ec3ee6559bd12c64ba" + }, + "from": "iso6523-actorid-upis::0235:1239874562", + "to": "iso6523-actorid-upis::0235:1456789456" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "disclosed-agent", + "bypass" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-01DAB-TEST", + "issue_date": "2025-02-07", + "issue_time": "15:08:00", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-principal-id": "155667745601003", + "peppol-pint-ae-transaction-type": "00000100", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "tax_id": { + "country": "AE", + "code": "124680135701003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1239874562" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1239874562" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Telephone Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "145678945601003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1456789456" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1456789456" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "email address" + } + ], + "telephones": [ + { + "num": "Contact number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "50", + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "889900" + } + ], + "description": "Item Description", + "list": "20", + "discount": "0.5", + "price": "19.50", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "975.00", + "charges": [ + { + "reason": "Technical Modification", + "amount": "24.38", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "999.375", + "notes": [ + { + "text": "Inspect the goods" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "base": "999.375", + "percent": "5%", + "amount": "49.97", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-07", + "amount": "996.88", + "percent": "100%" + } + ], + "notes": "cash payment" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "999.38", + "discount": "49.97", + "total": "949.41", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "ext": { + "untdid-tax-category": "S" + }, + "base": "949.405", + "percent": "5%", + "amount": "47.47025" + } + ], + "amount": "47.47025" + } + ], + "sum": "47.47025" + }, + "tax": "47.47", + "total_with_tax": "996.88", + "payable": "996.88" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/e-commerce.json b/ubl/testdata/parse/pint/ae/out/e-commerce.json new file mode 100644 index 0000000..8e1db29 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/e-commerce.json @@ -0,0 +1,360 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "b0523c01e5d7bdceaca8bfac980a250585e86e8340bf1d95bea22a6b94d257f3" + }, + "from": "iso6523-actorid-upis::0235:112345678900003", + "to": "iso6523-actorid-upis::0235:112345679000003" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "e-commerce" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001-E-Commerce-TEST", + "issue_date": "2025-02-11", + "issue_time": "11:35:10", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000010", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "112345678900003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345678900003" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345678900003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "112345679000003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345679000003" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345679000003" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Contact Email address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "1", + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "11223355" + } + ], + "description": "Item Description", + "list": "101", + "discount": "1", + "price": "100.00", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "100.00", + "discounts": [ + { + "reason": "Discount", + "amount": "2.50", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "100.00", + "percent": "5%", + "amount": "5.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "102.50", + "notes": [ + { + "text": "Please check the invoice" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Discount", + "base": "100", + "percent": "5%", + "amount": "5", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Technical Modification", + "amount": "2.50", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAC" + } + } + ], + "payment": { + "payee": { + "name": "Payee Party Name", + "identities": [ + { + "scope": "legal", + "code": "112345679350001" + }, + { + "code": "132345679670003", + "ext": { + "iso-scheme-id": "0066" + } + } + ] + }, + "advances": [ + { + "description": "Prepaid Amount", + "amount": "0.00" + } + ], + "terms": { + "due_dates": [ + { + "date": "2025-02-11", + "amount": "105.00", + "percent": "100%" + } + ], + "notes": "Instant Payment" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "delivery": { + "receiver": { + "name": "Delivery Party Name", + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ] + }, + "identities": [ + { + "code": "112345679000003", + "ext": { + "iso-scheme-id": "0066" + } + } + ], + "date": "2025-02-11" + }, + "totals": { + "sum": "102.50", + "discount": "5.00", + "charge": "2.50", + "total": "100.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "100.00", + "percent": "5%", + "amount": "5.00" + } + ], + "amount": "5.00" + } + ], + "sum": "5.00" + }, + "tax": "5.00", + "total_with_tax": "105.00", + "payable": "105.00", + "advance": "0.00", + "due": "105.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "DR-INV-001", + "url": "https://www.site.ae/invoices.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/exports-predefined-endpoint.json b/ubl/testdata/parse/pint/ae/out/exports-predefined-endpoint.json new file mode 100644 index 0000000..b22bd03 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/exports-predefined-endpoint.json @@ -0,0 +1,258 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "84651eddb0685a11952e2b2f47f135e0ab7d74f81212dee15c4ff7a1341cefcc" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:9900000099" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "export" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001-Exports-TEST", + "issue_date": "2025-02-07", + "issue_time": "17:31:00", + "value_date": "2025-01-31", + "currency": "USD", + "exchange_rates": [ + { + "from": "USD", + "to": "AED", + "amount": "3.67285" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000001", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "132654987101003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Export Traders", + "alias": "Buyer Legal Name", + "identities": [ + { + "scope": "legal", + "country": "AU", + "key": "passport", + "code": "CN0102000001123" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:9900000099" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "9900000099" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Perth", + "region": "WA", + "code": "Postal code", + "country": "AU" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "5000", + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "22334455" + } + ], + "description": "Item Description", + "list": "50", + "discount": "0.25", + "price": "49.75", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "248750.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "248750.00" + } + ], + "ordering": { + "purchases": [ + { + "code": "EXP-09" + } + ], + "sales": [ + { + "code": "EC-24-25-1001" + } + ] + }, + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-22", + "amount": "248750.00", + "percent": "100%" + } + ], + "notes": "within 1 month" + }, + "instructions": { + "key": "any", + "detail": "Instrument Not Defined", + "ext": { + "untdid-payment-means": "1" + } + } + }, + "delivery": { + "receiver": { + "addresses": [ + { + "street": "mm", + "locality": "333", + "region": "333", + "country": "US" + } + ] + }, + "ext": { + "icc-incoterms-2020": "CIF" + } + }, + "totals": { + "sum": "248750.00", + "total": "248750.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "248750.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "248750.00", + "payable": "248750.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/exports.json b/ubl/testdata/parse/pint/ae/out/exports.json new file mode 100644 index 0000000..44579df --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/exports.json @@ -0,0 +1,256 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "a96d36e1938fca0986fde4eb332a99f27f739237b4d5d58f936788170d1244f4" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0151:51824753556" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "export" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001-Exports-TEST", + "issue_date": "2025-02-07", + "issue_time": "17:31:00", + "value_date": "2025-01-31", + "currency": "USD", + "exchange_rates": [ + { + "from": "USD", + "to": "AED", + "amount": "3.67285" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000001", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "132654987101003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Export company", + "alias": "Buyer Legal Name", + "identities": [ + { + "scope": "legal", + "code": "CN0102000001123" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0151:51824753556" + } + ], + "inboxes": [ + { + "scheme": "0151", + "code": "51824753556" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Perth", + "region": "WA", + "code": "Postal code", + "country": "AU" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "5000", + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "22334455" + } + ], + "description": "Item Description", + "list": "50", + "discount": "0.25", + "price": "49.75", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "248750.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "248750.00" + } + ], + "ordering": { + "purchases": [ + { + "code": "EXP-09" + } + ], + "sales": [ + { + "code": "EC-24-25-1001" + } + ] + }, + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-22", + "amount": "248750.00", + "percent": "100%" + } + ], + "notes": "within 1 month" + }, + "instructions": { + "key": "any", + "detail": "Instrument Not Defined", + "ext": { + "untdid-payment-means": "1" + } + } + }, + "delivery": { + "receiver": { + "addresses": [ + { + "street": "mm", + "locality": "333", + "region": "333", + "country": "US" + } + ] + }, + "ext": { + "icc-incoterms-2020": "CIF" + } + }, + "totals": { + "sum": "248750.00", + "total": "248750.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "248750.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "248750.00", + "payable": "248750.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice-extensive.json b/ubl/testdata/parse/pint/ae/out/standard-invoice-extensive.json new file mode 100644 index 0000000..b3dbd94 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice-extensive.json @@ -0,0 +1,812 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "ba4aa4653e5217dee968b65a60673e18e2d14243b866772a83703d748c03c531" + }, + "from": "iso6523-actorid-upis::0235:112345678900003", + "to": "iso6523-actorid-upis::0235:112345679000003" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "free-trade-zone", + "continuous-supply", + "e-commerce" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "INV-001/2025", + "issue_date": "2025-01-30", + "issue_time": "18:24:10", + "value_date": "2025-01-29", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-01-30", + "code": "INV-1001/2022" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-beneficiary-id": "189098765401003", + "peppol-pint-ae-transaction-type": "10001010", + "untdid-document-type": "380" + }, + "notes": [ + { + "cat": "VAT", + "key": "exempt", + "text": "Supply of residential units (lease or sale)", + "ext": { + "untdid-tax-category": "E" + } + } + ] + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "112345678900003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contct Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345678900003" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345678900003" + } + ], + "addresses": [ + { + "street": "Al Bateen Street", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer Legal Name", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "112345679000003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:112345679000003" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "112345679000003" + } + ], + "addresses": [ + { + "street": "Khalifa street", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "5", + "period": { + "start": "2025-01-30", + "end": "2025-01-30" + }, + "order": "st-nar-1", + "cost": "ABC-001", + "item": { + "ref": "art-p-001", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "art-to-001" + }, + { + "code": "04012345123456", + "ext": { + "iso-scheme-id": "0160" + } + }, + { + "label": "HS", + "code": "88098432324" + } + ], + "attributes": [ + { + "label": "colour", + "text": "red" + } + ], + "description": "Item Description", + "list": "1000", + "price": "1000.00", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "5000.00", + "discounts": [ + { + "reason": "Discount", + "base": "5000.00", + "percent": "1%", + "amount": "50.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "amount": "10.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "4960.00", + "notes": [ + { + "text": "Please check the invoice" + } + ] + }, + { + "i": 2, + "quantity": "10", + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "1101" + } + ], + "description": "Item Description", + "list": "2000", + "discount": "20", + "price": "1980.00", + "per": "5", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "3960.00", + "discounts": [ + { + "reason": "Discount", + "base": "4000.00", + "percent": "2%", + "amount": "80.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Special Construction", + "amount": "20.00", + "ext": { + "untdid-charge": "AAV" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.2", + "untdid-tax-category": "E" + } + } + ], + "total": "3900.00" + }, + { + "i": 3, + "quantity": "15", + "period": { + "start": "2025-01-30", + "end": "2025-01-30" + }, + "order": "st-nar-1", + "cost": "CS-024", + "item": { + "ref": "art-p-001", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "art-to-001" + }, + { + "label": "HS", + "code": "3450" + } + ], + "attributes": [ + { + "label": "Item Additional Name", + "text": "Item Additional Value" + } + ], + "description": "Item Description", + "list": "3000", + "discount": "30", + "price": "2970.00", + "per": "10", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "4455.00", + "discounts": [ + { + "reason": "Discount", + "amount": "135.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "amount": "112.50", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + } + } + ], + "total": "4432.50", + "notes": [ + { + "text": "Please check the invoice" + } + ] + }, + { + "i": 4, + "quantity": "20", + "period": { + "start": "2025-01-30", + "end": "2025-01-30" + }, + "order": "st-nar-1", + "cost": "CS-024", + "item": { + "ref": "art-p-001", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "art-to-001" + }, + { + "code": "04012345123456", + "ext": { + "iso-scheme-id": "0160" + } + }, + { + "label": "HS", + "code": "5000" + } + ], + "attributes": [ + { + "label": "Item Additional Name", + "text": "Item Additional Value" + } + ], + "description": "Item Description", + "list": "158.4", + "price": "158.40", + "unit": "piece", + "origin": "AE", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1", + "untdid-unit": "H87" + } + }, + "sum": "3168.00", + "discounts": [ + { + "reason": "Discount", + "base": "3200.00", + "percent": "4%", + "amount": "128.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "total": "3040.00", + "notes": [ + { + "text": "Please check the invoice" + } + ] + }, + { + "i": 5, + "quantity": "25", + "period": { + "start": "2025-01-30", + "end": "2025-01-30" + }, + "order": "st-nar-1", + "cost": "CS-024", + "item": { + "ref": "art-p-001", + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "art-to-001" + }, + { + "code": "04012345123456", + "ext": { + "iso-scheme-id": "0160" + } + }, + { + "label": "HS", + "code": "8680" + } + ], + "attributes": [ + { + "label": "Item Additional Name", + "text": "Item Additional Value" + } + ], + "description": "Item Description", + "list": "5000", + "discount": "50", + "price": "4950.00", + "per": "50", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "2475.00", + "discounts": [ + { + "reason": "Discount", + "amount": "625.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "2500.00", + "percent": "5%", + "amount": "125.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "1975.00", + "notes": [ + { + "text": "Please check the invoice" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Discount", + "amount": "273.75", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + }, + { + "i": 2, + "reason": "Discount", + "amount": "2451.25", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Technical Modification", + "base": "1975", + "percent": "4%", + "amount": "79", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAC" + } + } + ], + "ordering": { + "code": "BR-001/23", + "cost": "4025:123:4343", + "period": { + "start": "2025-01-30", + "end": "2025-01-30" + }, + "seller": { + "name": "Seller Tax Representative Party Name", + "tax_id": { + "country": "AE", + "code": "123349792700003" + }, + "addresses": [ + { + "street": "Al Bateen Street", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zonw", + "country": "AE" + } + ] + }, + "projects": [ + { + "code": "BR-001/23" + } + ], + "contracts": [ + { + "code": "BR-001/23", + "description": "AED200000" + } + ], + "purchases": [ + { + "code": "PO-001/23" + } + ], + "sales": [ + { + "code": "SO-001/23" + } + ], + "receiving": [ + { + "code": "RAR-001/23" + } + ], + "despatch": [ + { + "code": "DAR-001/23" + } + ], + "tender": [ + { + "code": "LR-001/23" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Party Name", + "identities": [ + { + "scope": "legal", + "code": "112345679350001" + }, + { + "code": "132345679670003", + "ext": { + "iso-scheme-id": "0060" + } + } + ] + }, + "advances": [ + { + "description": "Prepaid Amount", + "amount": "10000.00" + } + ], + "terms": { + "due_dates": [ + { + "date": "2025-02-13", + "amount": "5777.50", + "percent": "100%" + } + ], + "notes": "15 days" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "direct_debit": { + "ref": "2025-01-30" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "delivery": { + "receiver": { + "name": "Delivery Party Name", + "addresses": [ + { + "street": "Khalifa street", + "street_extra": "Additional Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "code": "Postal Zone", + "country": "AE" + } + ] + }, + "identities": [ + { + "code": "112345679000003", + "ext": { + "iso-scheme-id": "0060" + } + } + ], + "date": "2025-01-30" + }, + "totals": { + "sum": "18307.50", + "discount": "2725.00", + "charge": "79.00", + "total": "15661.50", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "2314.00", + "percent": "5%", + "amount": "115.70" + }, + { + "key": "exempt", + "ext": { + "cef-vatex": "DL8.46.2", + "untdid-tax-category": "E" + }, + "base": "3900.00", + "amount": "0.00" + }, + { + "key": "outside-scope", + "ext": { + "untdid-tax-category": "O" + }, + "base": "4432.50", + "amount": "0.00" + }, + { + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + }, + "base": "3040.00", + "amount": "0.00" + }, + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "1975.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "115.70" + } + ], + "sum": "115.70" + }, + "tax": "115.70", + "total_with_tax": "15777.20", + "rounding": "0.30", + "payable": "15777.50", + "advance": "10000.00", + "due": "5777.50" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "DR-INV-001", + "description": "Invoice is enclosed", + "url": "https://www.site.ae/invoices.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/standard-invoice-predefined-endpoint.json b/ubl/testdata/parse/pint/ae/out/standard-invoice-predefined-endpoint.json new file mode 100644 index 0000000..2923c04 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/standard-invoice-predefined-endpoint.json @@ -0,0 +1,367 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "b4e2414132dad1ac1db0607b2e83887dc61d75e69e44f43c2bd20cd4c6def416" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:9900000098" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-01TEST", + "issue_date": "2025-02-06", + "issue_time": "07:54:00", + "value_date": "2025-01-30", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-02-06", + "code": "INV-234-2025" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Party Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Telephone number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Noor Electronics", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:9900000098" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "9900000098" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Telephone number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2000", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "order": "1", + "item": { + "ref": "Sales Goods", + "name": "Item Name", + "identities": [ + { + "code": "Purchase goods" + } + ], + "attributes": [ + { + "label": "Item details", + "text": "Item Value" + } + ], + "description": "Item Description", + "list": "5", + "discount": "0.1", + "price": "4.90", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "9800.00", + "discounts": [ + { + "reason": "Discount", + "base": "9800.00", + "percent": "3%", + "amount": "294.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "9800.00", + "percent": "10%", + "amount": "980.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "10486.00", + "notes": [ + { + "text": "All items" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "262.15", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "419.44", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "ordering": { + "code": "PO-AE-220", + "cost": "Regular sales", + "period": { + "start": "2025-01-31", + "end": "2025-02-06" + }, + "projects": [ + { + "code": "Regular work" + } + ], + "purchases": [ + { + "code": "PO-AE-220" + } + ], + "sales": [ + { + "code": "Salesorder-2122" + } + ], + "despatch": [ + { + "code": "Memo-1000" + } + ], + "tender": [ + { + "code": "PO-AE-220" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Name", + "identities": [ + { + "scope": "legal", + "code": "1122334455" + } + ] + }, + "terms": { + "due_dates": [ + { + "date": "2025-02-13", + "amount": "11175.50", + "percent": "100%" + } + ], + "notes": "Within a week" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "10486.00", + "discount": "262.15", + "charge": "419.44", + "total": "10643.29", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10643.29", + "percent": "5%", + "amount": "532.16" + } + ], + "amount": "532.16" + } + ], + "sum": "532.16" + }, + "tax": "532.16", + "total_with_tax": "11175.45", + "rounding": "0.05", + "payable": "11175.50" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "PO-AE-220", + "url": "https://www.site.ae/PO-AE-220.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/standard-tax-invoice.json b/ubl/testdata/parse/pint/ae/out/standard-tax-invoice.json new file mode 100644 index 0000000..02490d9 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/standard-tax-invoice.json @@ -0,0 +1,367 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "952e40c78cd37443b101d808906a144cb6947959fd74b212384bdcf58eb85bf4" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1345678901" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-01TEST", + "issue_date": "2025-02-06", + "issue_time": "07:54:00", + "value_date": "2025-01-30", + "currency": "AED", + "preceding": [ + { + "issue_date": "2025-02-06", + "code": "INV-234-2025" + } + ], + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Party Trade Name", + "tax_id": { + "country": "AE", + "code": "198765432102003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Telephone number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Noor Electronics", + "alias": "Buyer Trade Name", + "tax_id": { + "country": "AE", + "code": "134567890123003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1345678901" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1345678901" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email address" + } + ], + "telephones": [ + { + "num": "Telephone number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "2000", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "order": "1", + "item": { + "ref": "Sales Goods", + "name": "Item Name", + "identities": [ + { + "code": "Purchase goods" + } + ], + "attributes": [ + { + "label": "Item details", + "text": "Item Value" + } + ], + "description": "Item Description", + "list": "5", + "discount": "0.1", + "price": "4.90", + "unit": "piece", + "origin": "AE", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "9800.00", + "discounts": [ + { + "reason": "Discount", + "base": "9800.00", + "percent": "3%", + "amount": "294.00", + "ext": { + "untdid-allowance": "95" + } + } + ], + "charges": [ + { + "reason": "Technical Modification", + "base": "9800.00", + "percent": "10%", + "amount": "980.00", + "ext": { + "untdid-charge": "AAC" + } + } + ], + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "10486.00", + "notes": [ + { + "text": "All items" + } + ] + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special Rebate", + "amount": "262.15", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "charges": [ + { + "i": 1, + "reason": "Rush Delivery", + "amount": "419.44", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-charge": "AAT" + } + } + ], + "ordering": { + "code": "PO-AE-220", + "cost": "Regular sales", + "period": { + "start": "2025-01-31", + "end": "2025-02-06" + }, + "projects": [ + { + "code": "Regular work" + } + ], + "purchases": [ + { + "code": "PO-AE-220" + } + ], + "sales": [ + { + "code": "Salesorder-2122" + } + ], + "despatch": [ + { + "code": "Memo-1000" + } + ], + "tender": [ + { + "code": "PO-AE-220" + } + ] + }, + "payment": { + "payee": { + "name": "Payee Name", + "identities": [ + { + "scope": "legal", + "code": "1122334455" + } + ] + }, + "terms": { + "due_dates": [ + { + "date": "2025-02-13", + "amount": "11175.50", + "percent": "100%" + } + ], + "notes": "Within a week" + }, + "instructions": { + "key": "any", + "detail": "Debit Card", + "card": { + "last4": "1234", + "holder": "Card Holder Name" + }, + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "10486.00", + "discount": "262.15", + "charge": "419.44", + "total": "10643.29", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10643.29", + "percent": "5%", + "amount": "532.16" + } + ], + "amount": "532.16" + } + ], + "sum": "532.16" + }, + "tax": "532.16", + "total_with_tax": "11175.45", + "rounding": "0.05", + "payable": "11175.50" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "PO-AE-220", + "url": "https://www.site.ae/PO-AE-220.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/summary-invoice.json b/ubl/testdata/parse/pint/ae/out/summary-invoice.json new file mode 100644 index 0000000..108725f --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/summary-invoice.json @@ -0,0 +1,401 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "99dd606346f0374228082b5337f66b552acb6412d281fe9abae98c8bac8c3712" + }, + "from": "iso6523-actorid-upis::0235:1278906543", + "to": "iso6523-actorid-upis::0235:1347809543" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "$tags": [ + "summary" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-010TEST", + "issue_date": "2025-02-07", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00010000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Supplier Trade Name", + "tax_id": { + "country": "AE", + "code": "127890654301003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1278906543" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1278906543" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Abu Dhabi", + "region": "AUH", + "country": "AE" + } + ], + "emails": [ + { + "addr": "emailAddress" + } + ], + "telephones": [ + { + "num": "Contact number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Noor Electronics", + "tax_id": { + "country": "AE", + "code": "134780954301003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1347809543" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1347809543" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Sharjah", + "region": "SHJ", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Emailaddress" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "100", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "11223344" + } + ], + "description": "Item Description", + "list": "15", + "discount": "0.75", + "price": "14.25", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "1425.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "1425.00" + }, + { + "i": 2, + "quantity": "150", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "224455" + } + ], + "description": "Item Description", + "list": "25", + "discount": "1.25", + "price": "23.75", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "3562.50", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "3562.50" + }, + { + "i": 3, + "quantity": "200", + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + }, + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "label": "HS", + "code": "123456" + } + ], + "description": "Item Description", + "list": "30", + "discount": "1.5", + "price": "28.50", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "5700.00", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "total": "5700.00" + }, + { + "i": 4, + "quantity": "30", + "period": { + "start": "2025-01-31", + "end": "2025-01-31" + }, + "item": { + "key": "goods", + "name": "Item Name", + "identities": [ + { + "code": "34092834029", + "ext": { + "iso-scheme-id": "0160" + } + }, + { + "label": "HS", + "code": "88098432324" + } + ], + "description": "Item Description", + "list": "100", + "discount": "1", + "price": "99.00", + "unit": "kl", + "ext": { + "peppol-pint-ae-goods-type": "DL8.48.3.1", + "untdid-unit": "K6" + } + }, + "sum": "2970.00", + "taxes": [ + { + "cat": "VAT", + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + } + } + ], + "total": "2970.00" + } + ], + "discounts": [ + { + "i": 1, + "reason": "Special rebate", + "amount": "80.16", + "taxes": [ + { + "cat": "VAT", + "key": "standard", + "percent": "5%", + "ext": { + "untdid-tax-category": "S" + } + } + ], + "ext": { + "untdid-allowance": "100" + } + } + ], + "ordering": { + "period": { + "start": "2025-01-31", + "end": "2025-02-07" + } + }, + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-21", + "amount": "14108.00", + "percent": "100%" + } + ], + "notes": "Within 15 days" + }, + "instructions": { + "key": "credit-transfer", + "detail": "Credit transfer", + "credit_transfer": [ + { + "iban": "AE0000000001", + "bic": "236000", + "name": "current account" + } + ], + "ext": { + "untdid-payment-means": "30" + } + } + }, + "totals": { + "sum": "13657.50", + "discount": "80.16", + "total": "13577.34", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "ext": { + "untdid-tax-category": "S" + }, + "base": "10607.34", + "percent": "5%", + "amount": "530.37" + }, + { + "key": "reverse-charge", + "ext": { + "untdid-tax-category": "AE" + }, + "base": "2970.00", + "amount": "0.00" + } + ], + "amount": "530.37" + } + ], + "sum": "530.37" + }, + "tax": "530.37", + "total_with_tax": "14107.71", + "rounding": "0.29", + "payable": "14108.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ], + "attachments": [ + { + "code": "DC", + "url": "https://www.site.ae/deliverychallans.pdf" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/out/zero-rated.json b/ubl/testdata/parse/pint/ae/out/zero-rated.json new file mode 100644 index 0000000..e0c8d1f --- /dev/null +++ b/ubl/testdata/parse/pint/ae/out/zero-rated.json @@ -0,0 +1,226 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "dig": { + "alg": "sha256", + "val": "62f2c887df133158832a40fbaea30939c121caac7f0365a23e75485007efaace" + }, + "from": "iso6523-actorid-upis::0235:1987654321", + "to": "iso6523-actorid-upis::0235:1347809543" + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "AE", + "$addons": [ + "eu-en16931-v2017", + "peppol-pint-v1" + ], + "uuid": "0195ce71-dc9c-72c8-bf2c-9890a4a9f0a2", + "type": "standard", + "code": "AE-001-ZeroRated-TEST", + "issue_date": "2025-02-07", + "issue_time": "17:31:00", + "value_date": "2025-01-31", + "currency": "AED", + "tax": { + "rounding": "currency", + "ext": { + "peppol-pint-ae-transaction-type": "00000000", + "untdid-document-type": "380" + } + }, + "supplier": { + "name": "Supplier Legal Name", + "alias": "Seller Trade Name", + "tax_id": { + "country": "AE", + "code": "132654987101003" + }, + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345678900003", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1987654321" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1987654321" + } + ], + "addresses": [ + { + "street": "Street Name", + "locality": "Dubai", + "region": "DXB", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ], + "telephones": [ + { + "num": "Contact Number" + } + ], + "registration": { + "other": "Merchant" + } + }, + "customer": { + "name": "Buyer legal Name", + "alias": "Buyer Legal Name", + "identities": [ + { + "scope": "legal", + "type": "TL", + "code": "112345679000001", + "description": "Trade License issuing Authority" + } + ], + "people": [ + { + "name": { + "given": "Contact Name" + } + } + ], + "endpoints": [ + { + "uri": "iso6523-actorid-upis::0235:1347809543" + } + ], + "inboxes": [ + { + "scheme": "0235", + "code": "1347809543" + } + ], + "addresses": [ + { + "street": "Street Name", + "street_extra": "Additional Street Name", + "locality": "Dubai", + "region": "DXB", + "code": "Postal code", + "country": "AE" + } + ], + "emails": [ + { + "addr": "Email Address" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "5000", + "item": { + "name": "Item Name", + "description": "Item Description", + "list": "50", + "discount": "0.25", + "price": "49.75", + "unit": "piece", + "ext": { + "untdid-unit": "H87" + } + }, + "sum": "248750.00", + "taxes": [ + { + "cat": "VAT", + "key": "zero", + "percent": "0%", + "ext": { + "untdid-tax-category": "Z" + } + } + ], + "total": "248750.00" + } + ], + "ordering": { + "purchases": [ + { + "code": "EXP-09" + } + ], + "sales": [ + { + "code": "EC-24-25-1001" + } + ] + }, + "payment": { + "terms": { + "due_dates": [ + { + "date": "2025-02-22", + "amount": "248750.00", + "percent": "100%" + } + ], + "notes": "within 15 days" + }, + "instructions": { + "key": "any", + "detail": "Instrument Not Defined", + "ext": { + "untdid-payment-means": "1" + } + } + }, + "totals": { + "sum": "248750.00", + "total": "248750.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "zero", + "ext": { + "untdid-tax-category": "Z" + }, + "base": "248750.00", + "percent": "0%", + "amount": "0.00" + } + ], + "amount": "0.00" + } + ], + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "248750.00", + "payable": "248750.00" + }, + "notes": [ + { + "text": "Tax invoice" + } + ] + } +} \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/standard-invoice-extensive.xml b/ubl/testdata/parse/pint/ae/standard-invoice-extensive.xml new file mode 100644 index 0000000..83d4017 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/standard-invoice-extensive.xml @@ -0,0 +1,687 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 10001010 + INV-001/2025 + 4b6000ca-0128-4bdc-99a6-406f2909247f + 2025-01-30 + 18:24:10+04:00 + 2025-02-13 + 380 + Tax invoice + 2025-01-29 + AED + 4025:123:4343 + BR-001/23 + + 2025-01-30 + 2025-01-30 + OTH + + + PO-001/23 + SO-001/23 + + + + INV-1001/2022 + 2025-01-30 + + + + DAR-001/23 + + + RAR-001/23 + + + LR-001/23 + + + BR-001/23 + AED200000 + + + DR-INV-001 + Invoice is enclosed + + + https://www.site.ae/invoices.pdf + + + + + DR-INV-02 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + BR-001/23 + + + + 112345678900003 + + Supplier Trade Name + + + Al Bateen Street + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address line + + + AE + + + + 112345678900003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contct Name + Contact Number + Email Address + + + + + + 112345679000003 + + Buyer Trade Name + + + Khalifa street + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Additional Address Line + + + AE + + + + 112345679000003 + + VAT + + + + Buyer Legal Name + 112345679000001 + + + Contact Name + Contact Number + Email Address + + + + + + 132345679670003 + + + Payee Party Name + + + 112345679350001 + + + + + + 189098765401003 + + + + + + Seller Tax Representative Party Name + + + Al Bateen Street + Additional Street Name + Abu Dhabi + Postal Zonw + AUH + + Address line + + + AE + + + + 123349792700003 + + VAT + + + + + 2025-01-30 + + 112345679000003 + + Khalifa street + Additional Street Name + Abu Dhabi + Postal Zone + AUH + + Text + + + AE + + + + + + Delivery Party Name + + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + AE0000000001 + current account + + 236000 + + + + 2025-01-30 + + + + 15 days + + + false + 95 + Discount + 1.5 + 273.75 + 18250 + + S + 5 + + VAT + + + + + false + 95 + Discount + 50 + 2451.25 + 4902.5 + + S + 5 + + VAT + + + + + true + AAC + Technical Modification + 4 + 79 + 1975 + + S + 5 + + VAT + + + + + 115.70 + false + + 2314 + 115.70 + + S + 5 + + VAT + + + + + 3900 + 0 + + E + + VAT + + + + + 4432.50 + 0 + + O + + VAT + + + + + 3040 + 0 + + AE + 5 + + VAT + + + + + 1975 + 0 + + Z + 0 + + VAT + + + + + + 18307.50 + 15661.50 + 15777.20 + 2725 + 79 + 10000 + 0.30 + 5777.50 + + + 1 + Please check the invoice + 5 + 4960 + ABC-001 + + 2025-01-30 + 2025-01-30 + + + st-nar-1 + + PO-001/23 + + + + false + 95 + Discount + 1 + 50 + 5000 + + + true + AAC + Technical Modification + 10 + + + Item Description + Item Name + + art-to-001 + + + art-p-001 + + + 04012345123456 + + + AE + + + G + 88098432324 + + + S + 5 + + VAT + + + + colour + red + + + + 1000 + 1 + + false + 0 + 1000 + + + + 5208 + + 248 + + + + + 2 + 10 + 3900 + + false + 95 + Discount + 2 + 80 + 4000 + + + true + AAV + Special Construction + 20 + + + Item Description + Item Name + + AE + + + G + 1101 + + + E + DL8.46.2 + Supply of residential units (lease or sale) + + VAT + + + + + 1980 + 5 + + false + 20 + 2000 + + + + 3900 + + + + 3 + Please check the invoice + 15 + 4432.50 + CS-024 + + 2025-01-30 + 2025-01-30 + + + st-nar-1 + + PO-001/23 + + + + false + 95 + Discount + 135 + + + true + AAC + Technical Modification + 2.5 + 112.5 + 4500 + + + Item Description + Item Name + + art-to-001 + + + art-p-001 + + + AE + + + G + 3450 + + + O + + VAT + + + + Item Additional Name + Item Additional Value + + + + 2970 + 10 + + false + 30 + 3000 + + + + 4432.50 + + 0 + + + + + 4 + Please check the invoice + 20 + 3040 + CS-024 + + 2025-01-30 + 2025-01-30 + + + st-nar-1 + + PO-001/23 + + + + false + 95 + Discount + 4 + 128 + 3200 + + + Item Description + Item Name + + art-to-001 + + + art-p-001 + + + 04012345123456 + + + AE + + + DL8.48.3.1 + G + 5000 + + + AE + 5 + + VAT + + + + Item Additional Name + Item Additional Value + + + + 158.4 + 1 + + false + 0 + 158.4 + + + + 3040 + + 0 + + + + + 5 + Please check the invoice + 25 + 1975 + CS-024 + + 2025-01-30 + 2025-01-30 + + + st-nar-1 + + PO-001/23 + + + + false + 95 + Discount + 625 + + + true + AAC + Technical Modification + 5 + 125 + 2500 + + + Item Description + Item Name + + art-to-001 + + + art-p-001 + + + 04012345123456 + + + AE + + + G + 8680 + + + Z + 0 + + VAT + + + + Item Additional Name + Item Additional Value + + + + 4950 + 50 + + false + 50 + 5000 + + + + 1975 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/standard-invoice-predefined-endpoint.xml b/ubl/testdata/parse/pint/ae/standard-invoice-predefined-endpoint.xml new file mode 100644 index 0000000..7b45fb8 --- /dev/null +++ b/ubl/testdata/parse/pint/ae/standard-invoice-predefined-endpoint.xml @@ -0,0 +1,264 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-01TEST + f12f329f-6430-4399-b661-7c5cd9c3a9e6 + 2025-02-06 + 07:54:00+04:00 + 2025-02-13 + 380 + Tax invoice + 2025-01-30 + AED + Regular sales + PO-AE-220 + + 2025-01-31 + 2025-02-06 + + + PO-AE-220 + Salesorder-2122 + + + + INV-234-2025 + 2025-02-06 + + + + Memo-1000 + + + PO-AE-220 + + + PO-AE-220 + + + https://www.site.ae/PO-AE-220.pdf + + + + + PO-AE-220 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + Regular work + + + + 1987654321 + + Party Trade Name + + + Street Name + Sharjah + SHJ + + AE + + + + 198765432102003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Telephone number + Email address + + + + + + 9900000098 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Noor Electronics + 112345679000001 + + + Contact Name + Telephone number + Email address + + + + + + Payee Name + + + 1122334455 + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + Within a week + + + false + 100 + Special Rebate + 2.5 + 262.15 + 10486 + + S + 5 + + VAT + + + + + true + AAT + Rush Delivery + 4 + 419.44 + 10486 + + S + 5 + + VAT + + + + + 532.16 + false + + 10643.29 + 532.1645 + + S + 5 + + VAT + + + + + + 10486 + 10643.29 + 11175.45 + 262.15 + 419.44 + 0.05 + 11175.5 + + + 1 + All items + 2000 + 10486 + + 2025-01-31 + 2025-01-31 + + + 1 + + PO-AE-220 + + + + false + 95 + Discount + 3 + 294 + 9800 + + + true + AAC + Technical Modification + 10 + 980 + 9800 + + + Item Description + Item Name + + Purchase goods + + + Sales Goods + + + AE + + + S + 5 + + VAT + + + + Item details + Item Value + + + + 4.9 + 1 + + false + 0.1 + 5 + + + + 11010.3 + + 524.3 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/standard-tax-invoice.xml b/ubl/testdata/parse/pint/ae/standard-tax-invoice.xml new file mode 100644 index 0000000..0d850bf --- /dev/null +++ b/ubl/testdata/parse/pint/ae/standard-tax-invoice.xml @@ -0,0 +1,264 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-01TEST + f12f329f-6430-4399-b661-7c5cd9c3a9e6 + 2025-02-06 + 07:54:00+04:00 + 2025-02-13 + 380 + Tax invoice + 2025-01-30 + AED + Regular sales + PO-AE-220 + + 2025-01-31 + 2025-02-06 + + + PO-AE-220 + Salesorder-2122 + + + + INV-234-2025 + 2025-02-06 + + + + Memo-1000 + + + PO-AE-220 + + + PO-AE-220 + + + https://www.site.ae/PO-AE-220.pdf + + + + + PO-AE-220 + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + Regular work + + + + 1987654321 + + Party Trade Name + + + Street Name + Sharjah + SHJ + + AE + + + + 198765432102003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Telephone number + Email address + + + + + + 1345678901 + + Buyer Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 134567890123003 + + VAT + + + + Noor Electronics + 112345679000001 + + + Contact Name + Telephone number + Email address + + + + + + Payee Name + + + 1122334455 + + + + 55 + + XXXXXXXXXXXX1234 + VISA + Card Holder Name + + + + Within a week + + + false + 100 + Special Rebate + 2.5 + 262.15 + 10486 + + S + 5 + + VAT + + + + + true + AAT + Rush Delivery + 4 + 419.44 + 10486 + + S + 5 + + VAT + + + + + 532.16 + false + + 10643.29 + 532.1645 + + S + 5 + + VAT + + + + + + 10486 + 10643.29 + 11175.45 + 262.15 + 419.44 + 0.05 + 11175.5 + + + 1 + All items + 2000 + 10486 + + 2025-01-31 + 2025-01-31 + + + 1 + + PO-AE-220 + + + + false + 95 + Discount + 3 + 294 + 9800 + + + true + AAC + Technical Modification + 10 + 980 + 9800 + + + Item Description + Item Name + + Purchase goods + + + Sales Goods + + + AE + + + S + 5 + + VAT + + + + Item details + Item Value + + + + 4.9 + 1 + + false + 0.1 + 5 + + + + 11010.3 + + 524.3 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/summary-invoice.xml b/ubl/testdata/parse/pint/ae/summary-invoice.xml new file mode 100644 index 0000000..bf6353d --- /dev/null +++ b/ubl/testdata/parse/pint/ae/summary-invoice.xml @@ -0,0 +1,316 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00010000 + AE-010TEST + 108f8b54-9d31-461f-b9be-1de67837f4d4 + 2025-02-07 + 2025-02-21 + 380 + Tax invoice + AED + + 2025-01-31 + 2025-02-07 + + + DC + + + https://www.site.ae/deliverychallans.pdf + + + + + Delivery Challans + + JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCA1OTUgODQyXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA1IDAgUiA+PiA+PiAvQ29udGVudHMgNCAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL0xlbmd0aCA0OCA+PgpzdHJlYW0KQlQgL0YxIDE0IFRmIDcyIDc3MCBUZCAoU2FtcGxlIGF0dGFjaG1lbnQpIFRqIEVUCmVuZHN0cmVhbQplbmRvYmoKNSAwIG9iago8PCAvVHlwZSAvRm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9IZWx2ZXRpY2EgPj4KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDU4IDAwMDAwIG4gCjAwMDAwMDAxMTUgMDAwMDAgbiAKMDAwMDAwMDI0MSAwMDAwMCBuIAowMDAwMDAwMzM5IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgNiAvUm9vdCAxIDAgUiA+PgpzdGFydHhyZWYKNDA5CiUlRU9GCg== + + + + + 1278906543 + + Supplier Trade Name + + + Street Name + Abu Dhabi + AUH + + AE + + + + 127890654301003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact number + emailAddress + + + + + + 1347809543 + + Street Name + Sharjah + SHJ + + AE + + + + 134780954301003 + + VAT + + + + Noor Electronics + 112345679000001 + + + Contact Name + Contact Number + Emailaddress + + + + + 30 + + AE0000000001 + current account + + 236000 + + + + + Within 15 days + + + false + 100 + Special rebate + 0.75 + 80.16 + 10687.5 + + S + 5 + + VAT + + + + + 530.37 + false + + 10607.34 + 530.367 + + S + 5 + + VAT + + + + + 2970 + 0 + + AE + 5 + + VAT + + + + + + 13657.5 + 13577.34 + 14107.71 + 80.16 + 0.29 + 14108 + + + 1 + 100 + 1425 + + 2025-01-31 + 2025-02-07 + + + Item Description + Item Name + + G + 11223344 + + + S + 5 + + VAT + + + + + 14.25 + 1 + + false + 0.75 + 15 + + + + 1496.25 + + 71.25 + + + + + 2 + 150 + 3562.5 + + 2025-01-31 + 2025-02-07 + + + Item Description + Item Name + + G + 224455 + + + S + 5 + + VAT + + + + + 23.75 + 1 + + false + 1.25 + 25 + + + + 3740.625 + + 178.125 + + + + + 3 + 200 + 5700 + + 2025-01-31 + 2025-02-07 + + + Item Description + Item Name + + G + 123456 + + + S + 5 + + VAT + + + + + 28.5 + 1 + + false + 1.5 + 30 + + + + 5985 + + 285 + + + + + 4 + 30 + 2970 + + 2025-01-31 + 2025-01-31 + + + Item Description + Item Name + + 34092834029 + + + DL8.48.3.1 + G + 88098432324 + + + AE + 5 + + VAT + + + + + 99 + 1 + + false + 1 + 100 + + + + 2970 + + 0 + + + + \ No newline at end of file diff --git a/ubl/testdata/parse/pint/ae/zero-rated.xml b/ubl/testdata/parse/pint/ae/zero-rated.xml new file mode 100644 index 0000000..daf4dfb --- /dev/null +++ b/ubl/testdata/parse/pint/ae/zero-rated.xml @@ -0,0 +1,138 @@ + + + urn:peppol:pint:billing-1@ae-1 + urn:peppol:bis:billing + 00000000 + AE-001-ZeroRated-TEST + 65a5426a-b9ee-4190-9db7-1ada969b3eb2 + 2025-02-07 + 17:31:00+04:00 + 2025-02-22 + 380 + Tax invoice + 2025-01-31 + AED + + EXP-09 + EC-24-25-1001 + + + + 1987654321 + + Seller Trade Name + + + Street Name + Dubai + DXB + + AE + + + + 132654987101003 + + VAT + + + + Supplier Legal Name + 112345678900003 + Merchant + + + Contact Name + Contact Number + Email Address + + + + + + 1347809543 + + Buyer Legal Name + + + Street Name + Additional Street Name + Dubai + Postal code + DXB + + AE + + + + Buyer legal Name + 112345679000001 + + + Contact Name + Email Address + + + + + 1 + + + within 15 days + + + 0 + false + + 248750 + 0 + + Z + 0 + + VAT + + + + + + 248750 + 248750 + 248750 + 248750 + + + 1 + 5000 + 248750 + + Item Description + Item Name + + Z + 0 + + VAT + + + + + 49.75 + 1 + + false + 0.25 + 50 + + + + 248750 + + 0 + + + + \ No newline at end of file diff --git a/ubl/ubl_test.go b/ubl/ubl_test.go index e200c81..acd778a 100644 --- a/ubl/ubl_test.go +++ b/ubl/ubl_test.go @@ -152,18 +152,38 @@ func TestDetectAndImportAE(t *testing.T) { // import. margin-scheme-credit-note.xml is the official margin scheme // example turned into a credit note, as there is no official one. var importFaultsAE = map[string][]string{ - "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "allowance-reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, - "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, - "seller-trn-tin-identifiers.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, - "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, - "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "allowance-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "allowance-outside-scope.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "allowance-reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "allowance-zero-rated.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "buyer-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "charge-exempt.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "charge-outside-scope.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "charge-reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "charge-zero-rated.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "commercial-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "continuous-supplies.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "credit-note-disclosed-agent.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "credit-note-standard.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "credit-note-volume-discount.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "deemed-supply.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "disclosed-agent-billing.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "e-commerce.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "exports-predefined-endpoint.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "exports.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "margin-scheme-credit-note.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "margin-scheme.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "reverse-charge.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "seller-pas-identifier.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "seller-tin-identifier.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "seller-trn-tin-identifiers.xml": {"GOBL-AE-ORG-IDENTITY-02", "GOBL-AE-TAX-IDENTITY-02"}, + "standard-invoice-extensive.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "standard-invoice-predefined-endpoint.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "standard-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02"}, + "standard-tax-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "summary-invoice.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "supply-free-trade-zone.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, + "zero-rated.xml": {"GOBL-AE-TAX-IDENTITY-02", "GOBL-ORG-EMAIL-02"}, } // faultCodePattern matches the fault codes in a validation error. From ece95808cc4d5e434580af5cc8ab2b28516a53e3 Mon Sep 17 00:00:00 2001 From: Miguel Alvarez <157546624+miguelalvarezd@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:48:58 +0000 Subject: [PATCH 73/73] Drop PINT AE rules our output can't fail and simplify helpers - Drop the transaction type rule (IBR-154-AE): the normalizer always builds it from the tags. - Drop the IBR-133-AE rule and its helpers: with the other supplier rules and the normalizer, the supplier always has a TIN. - Drop the discount and charge rule sets (IBR-114/115-AE): only lines get N. - Check the margin scheme on the lines' categories, and reject discounts and charges on margin scheme invoices, without helpers. - Check the principal ID's 03 ending with the extension's pattern. - Remove the VAT guards on UAE tax combos (the AE regime only has VAT) and check the exemption reason on the extensions directly. - Test the tax point rule (IBR-005-AE). - Renumber the invoice rules in file order. Co-Authored-By: Claude Opus 5.5 --- addon/pint/bill.go | 263 ++++++++------------------------------- addon/pint/bill_test.go | 196 ++++++++--------------------- addon/pint/extensions.go | 5 +- addon/pint/pint.go | 2 - addon/pint/tax_combo.go | 40 ++---- 5 files changed, 112 insertions(+), 394 deletions(-) diff --git a/addon/pint/bill.go b/addon/pint/bill.go index 6b01b7b..99f5891 100644 --- a/addon/pint/bill.go +++ b/addon/pint/bill.go @@ -1,8 +1,6 @@ package pint import ( - "regexp" - "github.com/invopop/gobl/addons/eu/en16931" "github.com/invopop/gobl/bill" "github.com/invopop/gobl/catalogues/untdid" @@ -174,22 +172,16 @@ func billInvoiceRules() *rules.Set { ), ), - // AE tax schemes - // IBR-133-AE's test checks every cac:TaxScheme, not only the seller's. - rules.Assert("26", "tax registrations must be VAT when the supplier does not have a TIN (IBR-133-AE)", - is.Func("non-VAT tax registrations with supplier TIN", invoiceNonVATTaxRegistrationsHaveSupplierTIN), - ), - // AE currency - rules.Assert("27", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", + rules.Assert("26", "exchange_rates must have a rate from the invoice currency to AED (IBR-159-AE)", currency.CanConvertTo(currency.AED), ), - rules.Assert("28", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", + rules.Assert("27", "exchange rate to AED must have at most 6 decimals (IBR-002-AE)", is.Func("AED rate has at most 6 decimals", exchangeRateToAEDHasAtMost6Decimals), ), // AE VAT point date - rules.Assert("29", "VAT point date must be before the invoice issue date (IBR-141-AE)", + rules.Assert("28", "VAT point date must be before the invoice issue date (IBR-141-AE)", is.Func("VAT point date before issue date", pointDateBeforeIssueDate), ), @@ -200,11 +192,11 @@ func billInvoiceRules() *rules.Set { is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), )), rules.Field("payment", - rules.Assert("30", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("29", "payment details required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), rules.Field("instructions", - rules.Assert("31", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", + rules.Assert("30", "payment instructions required, except on credit notes and deemed supplies (IBR-191-AE)", is.Present, ), ), @@ -221,11 +213,11 @@ func billInvoiceRules() *rules.Set { is.Func("amount due is positive", invoiceIsDue), rules.Field("payment", rules.Field("terms", - rules.Assert("32", "payment terms are required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("31", "payment terms are required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Present, ), rules.Field("due_dates", - rules.Assert("33", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", + rules.Assert("32", "payment due date is required when the amount due is positive, except on credit notes and deemed supplies (IBR-127-AE)", is.Present, ), ), @@ -239,7 +231,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("document type is invoice outside scope or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices))), rules.Field("supplier", - rules.Assert("34", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", + rules.Assert("33", "supplier tax ID code is required, except on outside scope documents (IBR-134-AE)", org.PartyHasTaxIDCode(), ), ), @@ -251,51 +243,42 @@ func billInvoiceRules() *rules.Set { invoiceExtIn(untdid.ExtKeyDocumentType, docTypeInvoiceOutsideScope, docTypeCreditNoteGoodsServices)), rules.Field("customer", rules.Field("identities", - rules.Assert("35", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", + rules.Assert("34", "customer legal identity is required on outside scope documents or credit notes related to goods and services (IBR-136-AE)", is.Func("has legal scope identity", identitiesScopeIn(org.IdentityScopeLegal)), ), ), ), rules.Field("lines", rules.Each( rules.Field("taxes", rules.Each( - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("36", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), - tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), - ), + rules.Field("ext", + rules.Assert("35", "line VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), ), )), )), rules.Field("discounts", rules.Each( rules.Field("taxes", rules.Each( - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("37", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), - tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), - ), + rules.Field("ext", + rules.Assert("36", "discount VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), ), )), )), rules.Field("charges", rules.Each( rules.Field("taxes", rules.Each( - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("38", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", - tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), - tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), - ), + rules.Field("ext", + rules.Assert("37", "charge VAT category code must be E or O on outside scope documents or credit notes related to goods and services (IBR-122-AE)", + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, taxCategoryCodesOutsideScope...), ), ), )), )), - rules.Assert("39", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", + rules.Assert("38", "transaction type cannot be summary, deemed supply or margin scheme on outside scope documents or credit notes related to goods and services (IBR-157-AE)", is.Not(is.Or( is.Func("summary", invoiceHasTags(TagSummary)), is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), @@ -308,7 +291,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("document type is 380 or 381", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCommercialInvoice, docTypeCreditNote)), - rules.Assert("40", "at least one line combo must be something other than E or O (IBR-151-AE)", + rules.Assert("39", "at least one line combo must be something other than E or O (IBR-151-AE)", is.Func("has at least one line combo other than E or O", invoiceHasLineComboOtherThanEorO), ), ), @@ -319,13 +302,13 @@ func billInvoiceRules() *rules.Set { is.Func("document type is credit note or credit note related to goods and services", invoiceExtIn(untdid.ExtKeyDocumentType, docTypeCreditNote, docTypeCreditNoteGoodsServices)), rules.Field("value_date", - rules.Assert("41", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", + rules.Assert("40", "VAT point date must not be there on credit notes or credit notes related to goods and services (IBR-124-AE)", is.Not(is.Present), ), ), rules.Field("tax", rules.Field("ext", - rules.Assert("42", "credit note reason is required (IBR-158-AE, IBR-055-AE)", + rules.Assert("41", "credit note reason is required (IBR-158-AE, IBR-055-AE)", tax.ExtensionsRequire(ExtKeyCreditNoteReason), ), ), @@ -334,7 +317,7 @@ func billInvoiceRules() *rules.Set { is.Not(is.Func("credit note reason is missing or volume discount", invoiceExtIn(ExtKeyCreditNoteReason, cbc.CodeEmpty, CreditNoteReasonVolumeDiscount))), rules.Field("preceding", - rules.Assert("43", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", + rules.Assert("42", "preceding invoice is required on credit notes, except for volume discounts (IBR-055-AE)", is.Present, ), ), @@ -342,7 +325,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("credit note reason is volume discount", invoiceExtIn(ExtKeyCreditNoteReason, CreditNoteReasonVolumeDiscount)), rules.Field("preceding", - rules.Assert("44", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", + rules.Assert("43", "preceding invoice must not be there on volume discount credit notes (IBR-055-AE)", is.Not(is.Present), ), ), @@ -350,19 +333,11 @@ func billInvoiceRules() *rules.Set { ), // AE transaction type - rules.Field("tax", - rules.Field("ext", - rules.Assert("45", "transaction type is required, as 8 flags of 0 or 1 (IBR-154-AE)", - tax.ExtensionsRequire(ExtKeyTransactionType), - tax.ExtensionHasValidCode(ExtKeyTransactionType), - ), - ), - ), rules.When( is.Func("free trade zone", invoiceHasTags(TagFreeTradeZone)), rules.Field("tax", rules.Field("ext", - rules.Assert("46", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", + rules.Assert("44", "beneficiary ID is required on free trade zone supplies (IBR-007-AE)", tax.ExtensionsRequire(ExtKeyBeneficiaryID), ), ), @@ -371,15 +346,28 @@ func billInvoiceRules() *rules.Set { rules.When( is.Func("deemed supply", invoiceHasTags(TagDeemedSupply)), rules.Field("customer", - rules.AssertIfPresent("47", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", + rules.AssertIfPresent("45", "customer electronic address must be the predefined endpoint 0235:9900000097 on deemed supplies (PINT AE BIS 1.5.3, IBT-049)", is.Func("has UAE Peppol endpoint 9900000097", partyHasUAEEndpoint(endpointPatternDeemedSupply, true)), ), ), ), rules.When( is.Func("margin scheme", invoiceHasTags(TagMarginScheme)), - rules.Assert("48", "margin scheme invoice must only have exempt lines without a UAE exemption reason, mapped to the margin scheme category N, and no other VAT treatments (IBR-116-AE)", - is.Func("only margin scheme VAT", invoiceTaxesAreMarginScheme), + rules.Field("lines", rules.Each( + rules.Field("taxes", rules.Each( + rules.Field("ext", + rules.Assert("46", "margin scheme invoice lines must be exempt without a UAE exemption reason, mapped to the margin scheme category N (IBR-116-AE)", + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), + ), + ), + )), + )), + // Discounts and charges need a VAT category (BR-32, BR-37), and it can't be N (IBR-114-AE, IBR-115-AE). + rules.Field("discounts", + rules.Assert("47", "margin scheme invoice can't have discounts (IBR-116-AE)", is.Empty), + ), + rules.Field("charges", + rules.Assert("48", "margin scheme invoice can't have charges (IBR-116-AE)", is.Empty), ), ), rules.When( @@ -518,15 +506,12 @@ func billInvoiceRules() *rules.Set { rules.Assert("64", "credit note reason must be from the Reasons for credit note code list (IBR-001-AE)", tax.ExtensionHasValidCode(ExtKeyCreditNoteReason), ), - rules.Assert("65", "principal ID must be a TRN of 15 digits starting with 1 (IBR-132-AE)", + rules.Assert("65", "principal ID must be a TRN of 15 digits starting with 1 and ending with 03 (IBR-132-AE)", tax.ExtensionHasValidCode(ExtKeyPrincipalID), ), - rules.Assert("66", "principal ID must end with 03 (IBR-132-AE)", - is.Func("principal ID ends with 03", extensionMatches(ExtKeyPrincipalID, vatTRNSuffixPattern)), - ), ), rules.Field("point", - rules.Assert("67", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", + rules.Assert("66", "tax point must not be set, as PINT AE uses its element for the billing frequency (IBR-005-AE)", is.Not(is.Present), ), ), @@ -535,7 +520,7 @@ func billInvoiceRules() *rules.Set { // AE document type list rules.Field("tax", rules.Field("ext", - rules.Assert("68", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", + rules.Assert("67", "document type must be 380, 480, 381, 81, 389 or 261 (ibr-cl-01)", tax.ExtensionsHasCodes(untdid.ExtKeyDocumentType, docTypesAE...), ), ), @@ -548,7 +533,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.InContext(tax.RegimeIn(regimesAE...)), rules.Field("currency", - rules.Assert("69", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("68", "currency must not have more decimals than PINT allows for it (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency decimals within the PINT precision", currencyHasPINTDecimals), ), ), @@ -556,7 +541,7 @@ func billInvoiceRules() *rules.Set { rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), rules.Field("currency", - rules.Assert("69", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", + rules.Assert("68", "currency must have at most 2 decimals (ibr-091, ibr-121, ibr-122, ibr-123, ibr-124, ibr-125)", is.Func("currency has at most 2 decimals", currencyHasAtMost2Decimals), ), ), @@ -566,62 +551,13 @@ func billInvoiceRules() *rules.Set { // GOBL can't limit an addon's tags to a regime, so the PINT AE ones are rejected elsewhere. rules.When( is.Not(is.InContext(tax.RegimeIn(regimesAE...))), - rules.Assert("70", "PINT AE tags can only be used on UAE documents", + rules.Assert("69", "PINT AE tags can only be used on UAE documents", is.Func("has no PINT AE tags", invoiceHasNoAETags), ), ), ) } -// billDiscountRules validates document level discounts on UAE documents. -func billDiscountRules() *rules.Set { - return rules.For(new(bill.Discount), - rules.When( - is.InContext(tax.RegimeIn(regimesAE...)), - rules.Field("taxes", rules.Each( - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("01", "discount VAT category cannot be margin scheme (IBR-115-AE)", - tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), - ), - ), - ), - )), - ), - ) -} - -// billChargeRules validates document level charges on UAE documents. -func billChargeRules() *rules.Set { - return rules.For(new(bill.Charge), - rules.When( - is.InContext(tax.RegimeIn(regimesAE...)), - rules.Field("taxes", rules.Each( - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("01", "charge VAT category cannot be margin scheme (IBR-114-AE)", - tax.ExtensionsExcludeCodes(untdid.ExtKeyTaxCategory, TaxCategoryMarginScheme), - ), - ), - ), - )), - ), - ) -} - -// extensionMatches returns a predicate that reports whether the extension -// for the key, if there, matches the pattern. -func extensionMatches(key cbc.Key, pattern string) func(any) bool { - re := regexp.MustCompile(pattern) - return func(val any) bool { - ext, _ := tax.ExtensionsFromValue(val) - code := ext.Get(key) - return code == "" || re.MatchString(code.String()) - } -} - // invoiceExtIn returns a predicate that reports whether the invoice's tax // extension for the key is one of the codes. A missing extension is the empty // code. @@ -788,102 +724,3 @@ func invoiceIsDue(val any) bool { } return inv.Totals.Payable.IsPositive() } - -// invoiceNonVATTaxRegistrationsHaveSupplierTIN reports whether the supplier has a TIN whenever another party -// has a tax registration gobl.ubl writes under a scheme other than VAT. -func invoiceNonVATTaxRegistrationsHaveSupplierTIN(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return false - } - parties := []*org.Party{inv.Customer} - if inv.Ordering != nil { - parties = append(parties, inv.Ordering.Seller, inv.Ordering.Issuer) - } - if inv.Payment != nil { - parties = append(parties, inv.Payment.Payee) - } - for _, l := range inv.Lines { - if l != nil { - parties = append(parties, l.Seller) - } - } - for _, p := range parties { - if partyHasNonVATTaxRegistration(p) { - return partyHasTIN(inv.Supplier) - } - } - return true -} - -// partyHasNonVATTaxRegistration reports whether gobl.ubl writes a non-VAT tax scheme for the party. -func partyHasNonVATTaxRegistration(p *org.Party) bool { - if p == nil { - return false - } - if partyTaxIDIsNotVAT(p) { - return true - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeTax && id.Type != tax.CategoryVAT { - return true - } - } - return false -} - -// partyHasTIN reports whether the party has a tax scope identity of the TIN type. -func partyHasTIN(p *org.Party) bool { - if p == nil { - return false - } - for _, id := range p.Identities { - if id != nil && id.Scope == org.IdentityScopeTax && id.Type == ae.IdentityTypeTIN { - return true - } - } - return false -} - -// partyTaxIDIsNotVAT reports whether the party has a tax ID code whose scheme -// is not VAT. gobl.ubl writes a tax ID without a scheme under VAT. -func partyTaxIDIsNotVAT(p *org.Party) bool { - if p.TaxID == nil || p.TaxID.Code == "" { - return false - } - scheme := p.TaxID.GetScheme() - return scheme != "" && scheme != tax.CategoryVAT -} - -// invoiceTaxesAreMarginScheme reports whether every tax combo of an invoice's -// lines, discounts and charges is VAT under the profit margin scheme. -func invoiceTaxesAreMarginScheme(val any) bool { - inv, ok := val.(*bill.Invoice) - if !ok || inv == nil { - return false - } - var sets []tax.Set - for _, l := range inv.Lines { - if l != nil { - sets = append(sets, l.Taxes) - } - } - for _, d := range inv.Discounts { - if d != nil { - sets = append(sets, d.Taxes) - } - } - for _, c := range inv.Charges { - if c != nil { - sets = append(sets, c.Taxes) - } - } - for _, set := range sets { - for _, c := range set { - if !comboIsMarginScheme(c) { - return false - } - } - } - return true -} diff --git a/addon/pint/bill_test.go b/addon/pint/bill_test.go index 3fc663c..2fb60fb 100644 --- a/addon/pint/bill_test.go +++ b/addon/pint/bill_test.go @@ -320,10 +320,10 @@ func TestBillExemptionNoteRules(t *testing.T) { func TestBillInvoiceRulesAE(t *testing.T) { const ( - faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" - faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultRate = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" + faultDecimals = "GOBL-PEPPOL-PINT-BILL-INVOICE-27" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" ) inAE := tax.RegimeContext(l10n.AE.Tax()) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } @@ -492,19 +492,20 @@ func aeFaults(t *testing.T, inv *bill.Invoice) string { func TestBillDocumentRulesAE(t *testing.T) { const ( - faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultSellerTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" faultReverseCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-63" - faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" - faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" - faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" - faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" - faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" - faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" - faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" - faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" - faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-68" + faultBuyerLegalID = "GOBL-PEPPOL-PINT-BILL-INVOICE-34" + faultLineCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-35" + faultDiscountCat = "GOBL-PEPPOL-PINT-BILL-INVOICE-36" + faultChargeCategory = "GOBL-PEPPOL-PINT-BILL-INVOICE-37" + faultOnlyExempt = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultCreditPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-40" + faultPointDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-28" + faultTaxPoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" + faultPayment = "GOBL-PEPPOL-PINT-BILL-INVOICE-29" + faultDueTerms = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultDocumentType = "GOBL-PEPPOL-PINT-BILL-INVOICE-67" ) standard := func() *bill.Invoice { return aeDocument(bill.InvoiceTypeStandard) } outsideScope := func() *bill.Invoice { @@ -652,6 +653,12 @@ func TestBillDocumentRulesAE(t *testing.T) { } }) + t.Run("tax point is rejected, as its element holds the billing frequency (IBR-005-AE)", func(t *testing.T) { + inv := standard() + inv.Tax = &bill.Tax{Point: tax.PointDelivery} + assert.Contains(t, aeFaults(t, inv), faultTaxPoint) + }) + t.Run("due date is required when an amount is due (IBR-127-AE)", func(t *testing.T) { inv := standard() inv.Payment.Terms.DueDates = nil @@ -730,7 +737,7 @@ func TestBillDocumentRulesAE(t *testing.T) { } func TestBillCurrencyDecimalsRules(t *testing.T) { - const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-69" + const fault = "GOBL-PEPPOL-PINT-BILL-INVOICE-68" ae := func(cur currency.Code) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard) inv.Currency = cur @@ -832,12 +839,6 @@ func tradeLicense(code string) *org.Identity { return &org.Identity{Type: ae.IdentityTypeTradeLicense, Code: cbc.Code(code), Description: "Dubai Economy and Tourism"} } -// withoutTRN removes the supplier's TRN, from which the supplier gets its -// TIN. -func withoutTRN(inv *bill.Invoice) { - inv.Supplier.TaxID = &tax.Identity{Country: "AE"} -} - // aeIdentityDocument returns a valid UAE invoice whose parties have UAE Peppol // endpoints and trade licences, the case the legal registration rules apply to. func aeIdentityDocument() *bill.Invoice { @@ -855,7 +856,6 @@ func TestBillIdentityRulesAE(t *testing.T) { faultSupplierTIN = "GOBL-PEPPOL-PINT-BILL-INVOICE-21" faultCustomerLegalRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-25" faultCustomerTaxCount = "GOBL-PEPPOL-PINT-BILL-INVOICE-10" - faultTaxSupplier = "GOBL-PEPPOL-PINT-BILL-INVOICE-26" ) t.Run("supplier needs a legal identity (IBR-150-AE)", func(t *testing.T) { @@ -924,96 +924,33 @@ func TestBillIdentityRulesAE(t *testing.T) { assert.Contains(t, aeFaults(t, inv), faultCustomerTaxCount) }) - t.Run("customer TIN without a scope is a plain identity (ibr-104, IBR-179-AE, IBR-133-AE)", func(t *testing.T) { + t.Run("customer TIN without a scope is a plain identity (ibr-104, IBR-179-AE)", func(t *testing.T) { inv := aeIdentityDocument() inv.Customer.Identities = append(inv.Customer.Identities, &org.Identity{Type: ae.IdentityTypeTIN, Code: "1345678906"}) out := aeFaults(t, inv) assert.Empty(t, inv.Customer.Identities[1].Scope) assert.NotContains(t, out, faultCustomerTaxCount) - assert.NotContains(t, out, faultTaxSupplier) - }) - - t.Run("customer tax identity needs a supplier TIN (IBR-133-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - withoutTRN(inv) - inv.Customer.TaxID = nil - inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Scope: org.IdentityScopeTax, Code: "1345678906"}) - assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) - - inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - - t.Run("supplier TIN from the TRN is enough (IBR-133-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.TaxID = &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST} - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - - t.Run("customer tax ID under VAT needs no supplier TIN", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.TaxID = &tax.Identity{Country: "DE", Code: "111111125"} - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - - t.Run("customer tax identity under VAT needs no supplier TIN (IBR-133-AE)", func(t *testing.T) { - inv := aeIdentityDocument() - inv.Customer.TaxID = nil - inv.Customer.Identities = append(inv.Customer.Identities, - &org.Identity{Scope: org.IdentityScopeTax, Type: tax.CategoryVAT, Code: "1345678906"}) - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - - t.Run("tax IDs under GST need a supplier TIN (IBR-133-AE)", func(t *testing.T) { - gst := func() *org.Party { - // The scheme is set here as these tests don't register the AU - // regime, which gives AU tax IDs the GST scheme. - return &org.Party{Name: "Party", TaxID: &tax.Identity{Country: "AU", Code: "51824753556", Scheme: tax.CategoryGST}} - } - parties := map[string]func(inv *bill.Invoice){ - "customer": func(inv *bill.Invoice) { inv.Customer.TaxID = gst().TaxID }, - "tax representative": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Seller: gst()} }, - "issuer": func(inv *bill.Invoice) { inv.Ordering = &bill.Ordering{Issuer: gst()} }, - "payee": func(inv *bill.Invoice) { inv.Payment.Payee = gst() }, - "line seller": func(inv *bill.Invoice) { inv.Lines[0].Seller = gst() }, - } - for name, set := range parties { - t.Run(name, func(t *testing.T) { - inv := aeIdentityDocument() - set(inv) - withoutTRN(inv) - assert.Contains(t, aeFaults(t, inv), faultTaxSupplier) - - inv.Supplier.Identities = append(inv.Supplier.Identities, - &org.Identity{Type: ae.IdentityTypeTIN, Code: "1234567897"}) - assert.NotContains(t, aeFaults(t, inv), faultTaxSupplier) - }) - } }) } func TestBillTransactionTypeRulesAE(t *testing.T) { const ( - faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-31" - faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-33" - faultTransactionType = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" - faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" - faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultPaymentInstructions = "GOBL-PEPPOL-PINT-BILL-INVOICE-30" + faultDueDate = "GOBL-PEPPOL-PINT-BILL-INVOICE-32" + faultBeneficiary = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultDeemedEndpoint = "GOBL-PEPPOL-PINT-BILL-INVOICE-45" faultSummaryOrdering = "GOBL-PEPPOL-PINT-BILL-INVOICE-49" faultSummaryPeriod = "GOBL-PEPPOL-PINT-BILL-INVOICE-50" faultPrincipal = "GOBL-PEPPOL-PINT-BILL-INVOICE-51" faultPrincipalTRN = "GOBL-PEPPOL-PINT-BILL-INVOICE-65" - faultPrincipalVAT = "GOBL-PEPPOL-PINT-BILL-INVOICE-66" faultSupplierTax = "GOBL-PEPPOL-PINT-BILL-INVOICE-52" faultDelivery = "GOBL-PEPPOL-PINT-BILL-INVOICE-53" faultDeliveryAddress = "GOBL-PEPPOL-PINT-BILL-INVOICE-55" faultECommerceStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-56" faultExportStreet = "GOBL-PEPPOL-PINT-BILL-INVOICE-59" faultExportRegion = "GOBL-PEPPOL-PINT-BILL-INVOICE-61" - faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-39" + faultOutsideScopeFlags = "GOBL-PEPPOL-PINT-BILL-INVOICE-38" faultCustomerIdentifier = "GOBL-PEPPOL-PINT-BILL-INVOICE-62" ) setExt := func(inv *bill.Invoice, key cbc.Key, code cbc.Code) { @@ -1027,20 +964,6 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { } foreign := &org.Address{Street: "Baker Street 221B", Locality: "London", Region: "Greater London", Country: "GB"} - t.Run("transaction type is required (IBR-154-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - require.NoError(t, inv.Calculate()) - inv.Tax.Ext = inv.Tax.Ext.Delete(pint.ExtKeyTransactionType) - assert.Contains(t, faults(t, inv, tax.RegimeContext(l10n.AE.Tax())), faultTransactionType) - }) - - t.Run("transaction type must be 8 flags (IBR-154-AE)", func(t *testing.T) { - inv := aeDocument(bill.InvoiceTypeStandard) - require.NoError(t, inv.Calculate()) - setExt(inv, pint.ExtKeyTransactionType, "0000002") - assert.Contains(t, faults(t, inv, tax.RegimeContext(l10n.AE.Tax())), faultTransactionType) - }) - t.Run("deemed supplies need no payment instructions or due date (IBR-191-AE, IBR-127-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDeemedSupply) inv.Payment = &bill.PaymentDetails{Terms: &pay.Terms{Notes: "No consideration"}} @@ -1086,18 +1009,16 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { assert.Empty(t, aeFaults(t, inv)) }) - t.Run("principal ID must be a TRN (IBR-132-AE)", func(t *testing.T) { - for _, code := range []cbc.Code{"255667745601003", "15566774560100", "1556677456010A3"} { + t.Run("principal ID must be a TRN ending with 03 (IBR-132-AE)", func(t *testing.T) { + for _, code := range []cbc.Code{"255667745601003", "15566774560100", "1556677456010A3", "155667745601004"} { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) setExt(inv, pint.ExtKeyPrincipalID, code) assert.Contains(t, aeFaults(t, inv), faultPrincipalTRN, code) } inv := aeDocument(bill.InvoiceTypeStandard, pint.TagDisclosedAgent) - setExt(inv, pint.ExtKeyPrincipalID, "155667745601004") - out := aeFaults(t, inv) - assert.NotContains(t, out, faultPrincipalTRN) - assert.Contains(t, out, faultPrincipalVAT) + setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") + assert.NotContains(t, aeFaults(t, inv), faultPrincipalTRN) // It is checked without the disclosed agent tag too, as it is // written whenever it is there. @@ -1113,7 +1034,7 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { setExt(inv, pint.ExtKeyPrincipalID, "155667745601003") inv.Supplier.TaxID = &tax.Identity{Country: "AE"} out := aeFaults(t, inv) - assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-34") + assert.Contains(t, out, "GOBL-PEPPOL-PINT-BILL-INVOICE-33") assert.NotContains(t, out, faultSupplierTax) for _, typ := range []cbc.Key{bill.InvoiceTypeStandard, bill.InvoiceTypeCreditNote} { @@ -1188,9 +1109,9 @@ func TestBillTransactionTypeRulesAE(t *testing.T) { func TestBillCreditNoteReasonRulesAE(t *testing.T) { const ( - faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" - faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" - faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-44" + faultReasonRequired = "GOBL-PEPPOL-PINT-BILL-INVOICE-41" + faultPrecedingMissing = "GOBL-PEPPOL-PINT-BILL-INVOICE-42" + faultPrecedingVD = "GOBL-PEPPOL-PINT-BILL-INVOICE-43" faultReasonCode = "GOBL-PEPPOL-PINT-BILL-INVOICE-64" ) withReason := func(inv *bill.Invoice, code cbc.Code) *bill.Invoice { @@ -1270,10 +1191,10 @@ func TestBillExemptionRulesAE(t *testing.T) { func TestBillMarginSchemeRulesAE(t *testing.T) { const ( - faultDiscount = "GOBL-PEPPOL-PINT-BILL-DISCOUNT-01" - faultCharge = "GOBL-PEPPOL-PINT-BILL-CHARGE-01" - faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" - faultOnlyMargin = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" + faultLineExemption = "GOBL-PEPPOL-PINT-TAX-COMBO-06" + faultMarginLine = "GOBL-PEPPOL-PINT-BILL-INVOICE-46" + faultMarginDiscount = "GOBL-PEPPOL-PINT-BILL-INVOICE-47" + faultMarginCharge = "GOBL-PEPPOL-PINT-BILL-INVOICE-48" ) margin := func(tags ...cbc.Key) *bill.Invoice { inv := aeDocument(bill.InvoiceTypeStandard, tags...) @@ -1289,12 +1210,6 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { } return notes } - marginCombo := func() *tax.Combo { - return &tax.Combo{ - Category: tax.CategoryVAT, - Ext: tax.ExtensionsOf(cbc.CodeMap{untdid.ExtKeyTaxCategory: pint.TaxCategoryMarginScheme}), - } - } t.Run("exempt lines are N without VAT", func(t *testing.T) { inv := margin(pint.TagMarginScheme) @@ -1333,24 +1248,9 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) }) - t.Run("discounts and charges can't be margin scheme (IBR-115-AE, IBR-114-AE)", func(t *testing.T) { - // The normalizers only give N to lines, so only a category set - // directly gets here. - ctx := []rules.WithContext{tax.AddonContext(pint.V1), tax.RegimeContext(l10n.AE.Tax())} - d := &bill.Discount{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{marginCombo()}} - assert.ErrorContains(t, rules.Validate(d, ctx...), faultDiscount) - c := &bill.Charge{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{marginCombo()}} - assert.ErrorContains(t, rules.Validate(c, ctx...), faultCharge) - - inv := aeDocument(bill.InvoiceTypeStandard) - inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(tax.KeyStandard)}}} - out := aeFaults(t, inv) - assert.NotContains(t, out, faultDiscount) - }) - t.Run("margin scheme invoices only have exempt lines (IBR-116-AE)", func(t *testing.T) { inv := aeDocument(bill.InvoiceTypeStandard, pint.TagMarginScheme) - assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + assert.Contains(t, aeFaults(t, inv), faultMarginLine) inv = margin(pint.TagMarginScheme) inv.Lines = append(inv.Lines, &bill.Line{ @@ -1358,26 +1258,28 @@ func TestBillMarginSchemeRulesAE(t *testing.T) { Item: &org.Item{Name: "Watch strap", Description: "Leather strap", Price: num.NewAmount(1000, 2)}, Taxes: tax.Set{standardVAT()}, }) - assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + assert.Contains(t, aeFaults(t, inv), faultMarginLine) // A line with a UAE exemption reason is a real exempt supply, not a // margin scheme one. inv = margin(pint.TagMarginScheme) inv.Lines[0].Taxes[0].Ext = tax.ExtensionsOf(cbc.CodeMap{cef.ExtKeyVATEX: "DL8.46.1"}) - assert.Contains(t, aeFaults(t, inv), faultOnlyMargin) + assert.Contains(t, aeFaults(t, inv), faultMarginLine) assert.Equal(t, cbc.Code("E"), inv.Lines[0].Taxes[0].Ext.Get(untdid.ExtKeyTaxCategory)) for _, key := range []cbc.Key{tax.KeyExempt, tax.KeyStandard} { inv = margin(pint.TagMarginScheme) inv.Discounts = []*bill.Discount{{Reason: "Loyalty", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(key)}}} inv.Charges = []*bill.Charge{{Reason: "Delivery", Amount: num.MakeAmount(100, 2), Taxes: tax.Set{lineCombo(key)}}} - assert.Contains(t, aeFaults(t, inv), faultOnlyMargin, key) + out := aeFaults(t, inv) + assert.Contains(t, out, faultMarginDiscount, key) + assert.Contains(t, out, faultMarginCharge, key) } }) } func TestBillTagsOutsideAE(t *testing.T) { - const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-70" + const faultTags = "GOBL-PEPPOL-PINT-BILL-INVOICE-69" tagFaults := func(t *testing.T, inv *bill.Invoice) string { t.Helper() require.NoError(t, inv.Calculate()) diff --git a/addon/pint/extensions.go b/addon/pint/extensions.go index 349ed9c..510dde6 100644 --- a/addon/pint/extensions.go +++ b/addon/pint/extensions.go @@ -21,6 +21,9 @@ const ( // CreditNoteReasonVolumeDiscount is the credit note reason for a volume discount. const CreditNoteReasonVolumeDiscount cbc.Code = "VD" +// principalIDPattern is a UAE TRN ending with 03, as PINT AE asks of the principal ID (IBR-132-AE). +const principalIDPattern = `^1\d{12}03$` + // Usages of the PINT AE extensions, under the AE regime. var ( usageAEInvoiceTax = &cbc.Usage{ @@ -92,7 +95,7 @@ var extensions = []*cbc.Definition{ and ending with 03 (IBR-132-AE). `), }, - Pattern: ae.TRNPattern, + Pattern: principalIDPattern, }, { Key: ExtKeyCreditNoteReason, diff --git a/addon/pint/pint.go b/addon/pint/pint.go index dd896e1..f53a63d 100644 --- a/addon/pint/pint.go +++ b/addon/pint/pint.go @@ -38,8 +38,6 @@ func init() { rules.GOBL.Add(Namespace), is.InContext(tax.AddonIn(V1)), billInvoiceRules(), - billDiscountRules(), - billChargeRules(), billLineRules(), taxComboRules(), taxCategoryTotalRules(), diff --git a/addon/pint/tax_combo.go b/addon/pint/tax_combo.go index fa774d7..513aae1 100644 --- a/addon/pint/tax_combo.go +++ b/addon/pint/tax_combo.go @@ -151,9 +151,12 @@ func taxComboRules() *rules.Set { ), ), - rules.When( - is.Func("exempt VAT", comboIsExemptVAT), - rules.Field("ext", + rules.Field("ext", + rules.When( + is.AllOf( + tax.ExtensionsRequire(untdid.ExtKeyTaxCategory), + tax.ExtensionsHasCodes(untdid.ExtKeyTaxCategory, en16931.TaxCategoryExempt), + ), rules.Assert("06", "exempt VAT needs a VAT exemption reason (IBR-167-AE, IBR-168-AE, IBR-169-AE)", tax.ExtensionsRequire(cef.ExtKeyVATEX), ), @@ -161,12 +164,9 @@ func taxComboRules() *rules.Set { ), // The Schematron doesn't check the code list, but UAE VAT law allows no other reasons. - rules.When( - is.Func("VAT", comboIsVAT), - rules.Field("ext", - rules.Assert("07", "VAT exemption reason must be a UAE one: DL8.46.1, DL8.46.2, DL8.46.3 or DL8.46.4", - tax.ExtensionsHasCodes(cef.ExtKeyVATEX, exemptionCodesAE...), - ), + rules.Field("ext", + rules.Assert("07", "VAT exemption reason must be a UAE one: DL8.46.1, DL8.46.2, DL8.46.3 or DL8.46.4", + tax.ExtensionsHasCodes(cef.ExtKeyVATEX, exemptionCodesAE...), ), ), ), @@ -188,25 +188,3 @@ var taxCategoryCodesOutsideScope = []cbc.Code{ en16931.TaxCategoryExempt, en16931.TaxCategoryOutsideScope, } - -// comboIsVAT reports whether a tax combo is VAT. -func comboIsVAT(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && c.Category == tax.CategoryVAT -} - -// comboIsExemptVAT reports whether a tax combo is VAT with the exempt -// category code E. -func comboIsExemptVAT(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && c.Category == tax.CategoryVAT && - c.Ext.Get(untdid.ExtKeyTaxCategory) == en16931.TaxCategoryExempt -} - -// comboIsMarginScheme reports whether a tax combo is VAT under the profit -// margin scheme. -func comboIsMarginScheme(val any) bool { - c, ok := val.(*tax.Combo) - return ok && c != nil && c.Category == tax.CategoryVAT && - c.Ext.Get(untdid.ExtKeyTaxCategory) == TaxCategoryMarginScheme -}