Skip to content

Commit

Permalink
Final proposal for EN16931 addon and catalogues with XRechnung
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Oct 25, 2024
1 parent f52229d commit e80e161
Show file tree
Hide file tree
Showing 71 changed files with 3,448 additions and 874 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to GOBL will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). See also the [GOBL versions](https://docs.gobl.org/overview/versions) documentation site for more details.

## [Unreleased]

### Added

- New "tax catalogues" used for defining extensions for specific standards.
- `eu-en16931-v2017`: addon for underlying support of the EN16931 semantic specifications.
- `de-xrechnung-v3`: addon with extra normalization for XRechnung specification in Germany.

### Removed

- `pay`: UNTDID 4461 mappings from payment means table, now provided by catalogues

## [v0.203.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
_ "github.com/invopop/gobl/addons/de/xrechnung"
_ "github.com/invopop/gobl/addons/es/facturae"
_ "github.com/invopop/gobl/addons/es/tbai"
_ "github.com/invopop/gobl/addons/eu/en16931"
_ "github.com/invopop/gobl/addons/gr/mydata"
_ "github.com/invopop/gobl/addons/it/sdi"
_ "github.com/invopop/gobl/addons/mx/cfdi"
Expand Down
169 changes: 0 additions & 169 deletions addons/de/xrechnung/extensions.go

This file was deleted.

58 changes: 14 additions & 44 deletions addons/de/xrechnung/instructions.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,47 @@
package xrechnung

import (
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/pay"
"github.com/invopop/validation"
)

// Payment keys for XRechnung SEPA direct debit and credit transfer
const (
KeyPaymentMeansSEPACreditTransfer cbc.Key = "sepa-credit-transfer"
KeyPaymentMeansSEPADirectDebit cbc.Key = "sepa-direct-debit"
)

var validPaymentKeys = []cbc.Key{
pay.MeansKeyCash,
pay.MeansKeyCheque,
pay.MeansKeyCreditTransfer,
pay.MeansKeyCard,
pay.MeansKeyDirectDebit,
pay.MeansKeyOther,
KeyPaymentMeansSEPACreditTransfer,
KeyPaymentMeansSEPADirectDebit,
}

// ValidatePaymentInstructions validates the payment instructions according to the XRechnung standard
func validatePaymentInstructions(value interface{}) error {
instr, ok := value.(*pay.Instructions)
if !ok || instr == nil {
return nil
}

Check warning on line 13 in addons/de/xrechnung/instructions.go

View check run for this annotation

Codecov / codecov/patch

addons/de/xrechnung/instructions.go#L12-L13

Added lines #L12 - L13 were not covered by tests
return validation.ValidateStruct(instr,
validation.Field(&instr.Key,
validation.Required,
validation.By(validatePaymentKey),
validation.Skip,
),
// BR-DE-23
validation.Field(&instr.CreditTransfer,
validation.When(instr.Key == KeyPaymentMeansSEPACreditTransfer,
validation.When(
instr.Key.Has(pay.MeansKeyCreditTransfer),
validation.Required,
validation.Each(validation.By(validateCreditTransfer)),
),
validation.Skip,
),
// BR-DE-24
validation.Field(&instr.Card,
validation.When(instr.Key == pay.MeansKeyCard,
validation.When(
instr.Key.Has(pay.MeansKeyCard),
validation.Required,
),
validation.Skip,
),
// BR-DE-25
validation.Field(&instr.DirectDebit,
validation.When(instr.Key == KeyPaymentMeansSEPADirectDebit || instr.Key == pay.MeansKeyDirectDebit,
validation.When(
instr.Key.Has(pay.MeansKeyDirectDebit),
validation.Required,
validation.By(validateDirectDebit),
validation.By(validateInstructionsDirectDebit),
validation.Skip,
),
),
)
}

func validatePaymentKey(value interface{}) error {
t, ok := value.(cbc.Key)
if !ok {
return validation.NewError("invalid_key", "invalid payment key")
}
if !t.In(validPaymentKeys...) {
return validation.NewError("invalid", "invalid payment key")
}
return nil
}

func validateDirectDebit(value interface{}) error {
func validateInstructionsDirectDebit(value interface{}) error {
dd, ok := value.(*pay.DirectDebit)
if !ok || dd == nil {
return nil
Expand All @@ -95,13 +64,14 @@ func validateDirectDebit(value interface{}) error {

// BR-DE-19
func validateCreditTransfer(value interface{}) error {
creditTransfer, _ := value.(*pay.CreditTransfer)
if creditTransfer == nil {
ct, ok := value.(*pay.CreditTransfer)
if ct == nil || !ok {
return nil
}

Check warning on line 70 in addons/de/xrechnung/instructions.go

View check run for this annotation

Codecov / codecov/patch

addons/de/xrechnung/instructions.go#L69-L70

Added lines #L69 - L70 were not covered by tests
return validation.ValidateStruct(creditTransfer,
validation.Field(&creditTransfer.Number,
validation.When(creditTransfer.IBAN == "",
return validation.ValidateStruct(ct,
validation.Field(&ct.Number,
validation.When(
ct.IBAN == "",
validation.Required,
),
),
Expand Down
Loading

0 comments on commit e80e161

Please sign in to comment.