Skip to content

Commit

Permalink
Merge branch 'main' into addon-verifactu
Browse files Browse the repository at this point in the history
  • Loading branch information
apardods authored Dec 3, 2024
2 parents 8cb512e + 6d09561 commit 2c7873a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 65 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- `es-verifactu-v1`: added initial Spain VeriFactu addon.

## [v0.206.1] - 2024-11-28

### Fixed

- `org`: Party validation now working with regimes when defined.

## [v0.206.0] - 2024-11-26

### Added
Expand Down
11 changes: 3 additions & 8 deletions examples/gr/invoice-b2c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tax:
supplier:
tax_id:
country: "EL"
code: "728089281"
code: "177472438"
name: "Ελληνικά Τρόφιμα Α.Ε."
emails:
- addr: "[email protected]"
Expand All @@ -33,15 +33,10 @@ lines:
taxes:
- cat: VAT
rate: standard
- quantity: 1
item:
name: "Cleaning"
price: "8.44"
taxes:
- cat: VAT
rate: reduced

payment:
instructions:
key: card
advances:
- key: card
percent: "100%"
Expand Down
11 changes: 7 additions & 4 deletions examples/gr/invoice-el-el.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $tags:
supplier:
tax_id:
country: "EL"
code: "728089281"
code: "177472438"
name: "Ελληνικά Τρόφιμα Α.Ε."
emails:
- addr: "[email protected]"
Expand Down Expand Up @@ -42,19 +42,22 @@ lines:
name: "Υπηρεσίες Ανάπτυξης"
price: "90.00"
unit: "h"
ext:
"gr-mydata-income-cat": "category1_3"
"gr-mydata-income-type": "E3_561_001"
discounts:
- percent: "10%"
reason: "Ειδική Έκπτωση"
taxes:
- cat: VAT
rate: standard
ext:
"gr-mydata-income-cat": "category1_1"
"gr-mydata-income-type": "E3_106"
- quantity: 1
item:
name: "Tax exempt item"
price: "100.00"
ext:
"gr-mydata-income-cat": "category1_3"
"gr-mydata-income-type": "E3_561_001"
taxes:
- cat: VAT
rate: exempt
Expand Down
2 changes: 1 addition & 1 deletion examples/gr/invoice-islands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $tags:
supplier:
tax_id:
country: "EL"
code: "728089281"
code: "177472438"
name: "Ελληνικά Τρόφιμα Α.Ε."
emails:
- addr: "[email protected]"
Expand Down
59 changes: 18 additions & 41 deletions examples/gr/out/invoice-b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "7b1f15e3697d8d68d22caa0557078fc772e90ddcff058712f0cbab0013e5c08f"
"val": "e0933613d76459243623c7f1c78dc0665214e06f6649113b7ccd4530e04d1948"
}
},
"doc": {
Expand All @@ -31,7 +31,7 @@
"name": "Ελληνικά Τρόφιμα Α.Ε.",
"tax_id": {
"country": "EL",
"code": "728089281"
"code": "177472438"
},
"addresses": [
{
Expand Down Expand Up @@ -69,26 +69,6 @@
}
],
"total": "8.44"
},
{
"i": 2,
"quantity": "1",
"item": {
"name": "Cleaning",
"price": "8.44"
},
"sum": "8.44",
"taxes": [
{
"cat": "VAT",
"rate": "reduced",
"percent": "13%",
"ext": {
"gr-mydata-vat-rate": "2"
}
}
],
"total": "8.44"
}
],
"payment": {
Expand All @@ -97,16 +77,22 @@
"key": "card",
"description": "Prepaid amount",
"percent": "100%",
"amount": "20.01",
"amount": "10.47",
"ext": {
"gr-mydata-payment-means": "7"
}
}
]
],
"instructions": {
"key": "card",
"ext": {
"gr-mydata-payment-means": "7"
}
}
},
"totals": {
"sum": "16.88",
"total": "16.88",
"sum": "8.44",
"total": "8.44",
"taxes": {
"categories": [
{
Expand All @@ -120,26 +106,17 @@
"base": "8.44",
"percent": "24%",
"amount": "2.03"
},
{
"key": "reduced",
"ext": {
"gr-mydata-vat-rate": "2"
},
"base": "8.44",
"percent": "13%",
"amount": "1.10"
}
],
"amount": "3.13"
"amount": "2.03"
}
],
"sum": "3.13"
"sum": "2.03"
},
"tax": "3.13",
"total_with_tax": "20.01",
"payable": "20.01",
"advance": "20.01",
"tax": "2.03",
"total_with_tax": "10.47",
"payable": "10.47",
"advance": "10.47",
"due": "0.00"
}
}
Expand Down
20 changes: 12 additions & 8 deletions examples/gr/out/invoice-el-el.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "0adb783cf39fd01962abbc45755da8a3cf16b16f5a3d0fec3eba7edd68a1bc66"
"val": "2946cc07a733a1eaa682226ace3b321077e8f97033642042a67b75c0cf98ffbf"
}
},
"doc": {
Expand All @@ -31,7 +31,7 @@
"name": "Ελληνικά Τρόφιμα Α.Ε.",
"tax_id": {
"country": "EL",
"code": "728089281"
"code": "177472438"
},
"addresses": [
{
Expand Down Expand Up @@ -76,7 +76,11 @@
"item": {
"name": "Υπηρεσίες Ανάπτυξης",
"price": "90.00",
"unit": "h"
"unit": "h",
"ext": {
"gr-mydata-income-cat": "category1_3",
"gr-mydata-income-type": "E3_561_001"
}
},
"sum": "1800.00",
"discounts": [
Expand All @@ -92,8 +96,6 @@
"rate": "standard",
"percent": "24%",
"ext": {
"gr-mydata-income-cat": "category1_1",
"gr-mydata-income-type": "E3_106",
"gr-mydata-vat-rate": "1"
}
}
Expand All @@ -105,7 +107,11 @@
"quantity": "1",
"item": {
"name": "Tax exempt item",
"price": "100.00"
"price": "100.00",
"ext": {
"gr-mydata-income-cat": "category1_3",
"gr-mydata-income-type": "E3_561_001"
}
},
"sum": "100.00",
"taxes": [
Expand Down Expand Up @@ -140,8 +146,6 @@
{
"key": "standard",
"ext": {
"gr-mydata-income-cat": "category1_1",
"gr-mydata-income-type": "E3_106",
"gr-mydata-vat-rate": "1"
},
"base": "1620.00",
Expand Down
4 changes: 2 additions & 2 deletions examples/gr/out/invoice-islands.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "dda9cc633ac5050877271cc1bd6631bd95b1190a4e4b26a69725d86e4f2a6d55"
"val": "24b8131e19c332262a8d8afe0bddfaadc7213f841d377fdcfeca8526641cddba"
}
},
"doc": {
Expand All @@ -31,7 +31,7 @@
"name": "Ελληνικά Τρόφιμα Α.Ε.",
"tax_id": {
"country": "EL",
"code": "728089281"
"code": "177472438"
},
"addresses": [
{
Expand Down
10 changes: 10 additions & 0 deletions org/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func (p *Party) Validate() error {

// ValidateWithContext is used to check the party's data meets minimum expectations.
func (p *Party) ValidateWithContext(ctx context.Context) error {
ctx = p.ValidationContext(ctx)
return tax.ValidateStructWithContext(ctx, p,
validation.Field(&p.Regime),
validation.Field(&p.Name),
validation.Field(&p.TaxID),
validation.Field(&p.Identities),
Expand All @@ -109,6 +111,14 @@ func (p *Party) ValidateWithContext(ctx context.Context) error {
)
}

// ValidationContext returns a context with the regime's validation rules.
func (p *Party) ValidationContext(ctx context.Context) context.Context {
if r := p.RegimeDef(); r != nil {
ctx = r.WithContext(ctx)
}
return ctx
}

// JSONSchemaExtend adds extra details to the schema.
func (Party) JSONSchemaExtend(js *jsonschema.Schema) {
js.Extras = map[string]any{
Expand Down
33 changes: 33 additions & 0 deletions org/party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,36 @@ func TestPartyAddressNill(t *testing.T) {
party.Normalize(nil)
assert.NoError(t, party.Validate())
}

func TestPartyValidation(t *testing.T) {
t.Run("with regime", func(t *testing.T) {
party := org.Party{
Regime: tax.WithRegime("DE"),
Name: "Invopop",
Identities: []*org.Identity{
{
Key: "de-tax-number",
Code: "123 456 78901",
},
},
}
require.NoError(t, party.Calculate())
assert.NoError(t, party.Validate())
assert.Equal(t, "DE", party.GetRegime().String())
})
t.Run("with regime and bad code", func(t *testing.T) {
party := org.Party{
Regime: tax.WithRegime("DE"),
Name: "Invopop",
Identities: []*org.Identity{
{
Key: "de-tax-number",
Code: "1231312423432422",
},
},
}
require.NoError(t, party.Calculate())
err := party.Validate()
assert.ErrorContains(t, err, "identities: (0: (code: must be in a valid format.).).")
})
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type Version string

// VERSION is the current version of the GOBL library.
const VERSION Version = "v0.206.0"
const VERSION Version = "v0.206.1"

// Semver parses and returns semver
func (v Version) Semver() *semver.Version {
Expand Down

0 comments on commit 2c7873a

Please sign in to comment.