Skip to content

Commit

Permalink
Merge pull request #4 from invopop/address-fix
Browse files Browse the repository at this point in the history
Update Address LineOne & Update PartyIdentification
  • Loading branch information
apardods authored Nov 20, 2024
2 parents b8e2580 + 4d44b98 commit 3ee5eb2
Show file tree
Hide file tree
Showing 32 changed files with 230 additions and 172 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
jobs:
lint:
name: golangci-lint
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
id: go

- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ There are certain assumptions and lost information in the conversion from UBL to
3. Fields ProfileID (BT-23) and CustomizationID (BT-24) in UBL are not supported and lost in the conversion.
4. The AccountingCost (BT-19, BT-133) fields are added as notes.
5. Payment advances do not include their own tax rate, they use the global tax rate of the invoice.
6. Identification fields that use ISO/IEC 6523 codes are currently not directly mapped to their [codelist](https://docs.peppol.eu/poacc/billing/3.0/codelist/ICD/), with their reference code being mapped to the Label.
7. The field AdditionalItemProperty (BG-32) is currently not supported in GOBL and lost in the conversion.


## Development
Expand Down
4 changes: 2 additions & 2 deletions document/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CustomerParty struct {
// Party represents a party involved in a transaction
type Party struct {
EndpointID *EndpointID `xml:"cbc:EndpointID"`
PartyIdentification []Identification `xml:"cac:PartyIdentification"`
PartyIdentification *Identification `xml:"cac:PartyIdentification"`
PartyName *PartyName `xml:"cac:PartyName"`
PostalAddress *PostalAddress `xml:"cac:PostalAddress"`
PartyTaxScheme []PartyTaxScheme `xml:"cac:PartyTaxScheme"`
Expand All @@ -29,7 +29,7 @@ type EndpointID struct {

// Identification represents an identification
type Identification struct {
ID IDType `xml:"cbc:ID"`
ID *IDType `xml:"cbc:ID"`
}

// PartyName represents the name of a party
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
toolchain go1.22.1

require (
github.com/invopop/gobl v0.205.0
github.com/invopop/gobl v0.205.1
github.com/joho/godotenv v1.5.1
// github.com/lestrrat-go/libxml2 v0.0.0-20240521004304-a75c203ac627
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ 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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/gobl v0.205.0 h1:NkwtCTBNVdcvZKebFOcYUt/FH5GGS9G9JH6eFSmtGpg=
github.com/invopop/gobl v0.205.0/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/gobl v0.205.1 h1:khW63/Hu2lzU+IpRN2RF71cfUttCizL0HHAmeakWHyE=
github.com/invopop/gobl v0.205.1/go.mod h1:DmPohPel8b3ta4nDKnXRNzWQlB89cN74e0/WwPUEZUU=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/validation v0.8.0 h1:e5hXHGnONHImgJdonIpNbctg1hlWy1ncaHoVIQ0JWuw=
Expand Down
13 changes: 13 additions & 0 deletions internal/gtou/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/invopop/gobl.ubl/document"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/catalogues/untdid"
"github.com/invopop/gobl/num"
)
Expand Down Expand Up @@ -99,6 +100,18 @@ func (c *Converter) newLines(inv *bill.Invoice) error {
}
}

if len(l.Item.Identities) > 0 {
for _, id := range l.Item.Identities {
s := id.Ext[iso.ExtKeySchemeID].String()
it.StandardItemIdentification = &document.ItemIdentification{
ID: &document.IDType{
SchemeID: &s,
Value: id.Code.String(),
},
}
}
}

invLine.Item = it

if l.Item.Price != (num.Amount{}) {
Expand Down
2 changes: 2 additions & 0 deletions internal/gtou/lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestNewLines(t *testing.T) {
assert.False(t, doc.InvoiceLine[0].AllowanceCharge[1].ChargeIndicator)
assert.Equal(t, "Damage", *doc.InvoiceLine[0].AllowanceCharge[1].AllowanceChargeReason)
assert.Equal(t, "12.00", doc.InvoiceLine[0].AllowanceCharge[1].Amount.Value)
assert.Equal(t, "0088", *doc.InvoiceLine[0].Item.StandardItemIdentification.ID.SchemeID)
assert.Equal(t, "1234567890128", doc.InvoiceLine[0].Item.StandardItemIdentification.ID.Value)

})

Expand Down
29 changes: 19 additions & 10 deletions internal/gtou/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"

"github.com/invopop/gobl.ubl/document"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/org"
)
Expand Down Expand Up @@ -58,6 +59,20 @@ func (c *Converter) newParty(party *org.Party) document.Party {
Name: party.Alias,
}
}

if len(party.Identities) > 0 {
for _, id := range party.Identities {
if id.Ext != nil {
s := id.Ext[iso.ExtKeySchemeID].String()
p.PartyIdentification = &document.Identification{
ID: &document.IDType{
SchemeID: &s,
Value: id.Code.String(),
},
}
}
}
}
return p
}

Expand All @@ -71,19 +86,13 @@ func newAddress(addresses []*org.Address) *document.PostalAddress {
addr := &document.PostalAddress{}

if a.Street != "" {
addr.StreetName = &a.Street
}

if a.Number != "" {
addr.AddressLine = []document.AddressLine{
{
Line: a.Number,
},
}
l := a.LineOne()
addr.StreetName = &l
}

if a.StreetExtra != "" {
addr.AdditionalStreetName = &a.StreetExtra
l := a.LineTwo()
addr.AdditionalStreetName = &l
}

if a.Locality != "" {
Expand Down
9 changes: 5 additions & 4 deletions internal/gtou/party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func TestNewParty(t *testing.T) {
assert.Equal(t, "+49100200300", *doc.AccountingSupplierParty.Party.Contact.Telephone)
assert.Equal(t, "[email protected]", *doc.AccountingSupplierParty.Party.Contact.ElectronicMail)

assert.Equal(t, "16", doc.AccountingSupplierParty.Party.PostalAddress.AddressLine[0].Line)
assert.Equal(t, "Dietmar-Hopp-Allee", *doc.AccountingSupplierParty.Party.PostalAddress.StreetName)
assert.Equal(t, "Dietmar-Hopp-Allee 16", *doc.AccountingSupplierParty.Party.PostalAddress.StreetName)
assert.Equal(t, "Walldorf", *doc.AccountingSupplierParty.Party.PostalAddress.CityName)
assert.Equal(t, "69190", *doc.AccountingSupplierParty.Party.PostalAddress.PostalZone)
assert.Equal(t, "DE", doc.AccountingSupplierParty.Party.PostalAddress.Country.IdentificationCode)
Expand All @@ -27,11 +26,13 @@ func TestNewParty(t *testing.T) {
assert.Equal(t, "Sample Consumer", *doc.AccountingCustomerParty.Party.PartyLegalEntity.RegistrationName)
assert.Equal(t, "[email protected]", *doc.AccountingCustomerParty.Party.Contact.ElectronicMail)

assert.Equal(t, "25", doc.AccountingCustomerParty.Party.PostalAddress.AddressLine[0].Line)
assert.Equal(t, "Werner-Heisenberg-Allee", *doc.AccountingCustomerParty.Party.PostalAddress.StreetName)
assert.Equal(t, "Werner-Heisenberg-Allee 25", *doc.AccountingCustomerParty.Party.PostalAddress.StreetName)
assert.Equal(t, "München", *doc.AccountingCustomerParty.Party.PostalAddress.CityName)
assert.Equal(t, "80939", *doc.AccountingCustomerParty.Party.PostalAddress.PostalZone)
assert.Equal(t, "DE", doc.AccountingCustomerParty.Party.PostalAddress.Country.IdentificationCode)

assert.Equal(t, "0088", *doc.AccountingCustomerParty.Party.PartyIdentification.ID.SchemeID)
assert.Equal(t, "1234567890128", doc.AccountingCustomerParty.Party.PartyIdentification.ID.Value)
})

}
17 changes: 13 additions & 4 deletions internal/utog/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/invopop/gobl.ubl/document"
"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/num"
Expand Down Expand Up @@ -135,11 +136,19 @@ func (c *Converter) getIdentities(docLine *document.InvoiceLine) []*org.Identity
}
}

if docLine.Item.StandardItemIdentification != nil && docLine.Item.StandardItemIdentification.ID != nil {
id := getIdentity(docLine.Item.StandardItemIdentification.ID)
if id != nil {
ids = append(ids, id)
if docLine.Item.StandardItemIdentification != nil &&
docLine.Item.StandardItemIdentification.ID != nil &&
docLine.Item.StandardItemIdentification.ID.SchemeID != nil {
s := *docLine.Item.StandardItemIdentification.ID.SchemeID
id := &org.Identity{
Ext: tax.Extensions{
iso.ExtKeySchemeID: tax.ExtValue(s),
},
Code: cbc.Code(docLine.Item.StandardItemIdentification.ID.Value),
}

ids = append(ids, id)

}

if docLine.Item.CommodityClassification != nil && len(*docLine.Item.CommodityClassification) > 0 {
Expand Down
3 changes: 2 additions & 1 deletion internal/utog/lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"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"
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestGetLines(t *testing.T) {

assert.Len(t, line.Item.Identities, 3)
assert.Equal(t, cbc.Code("1234567890128"), line.Item.Identities[0].Code)
assert.Equal(t, "0088", line.Item.Identities[0].Label)
assert.Equal(t, "0088", line.Item.Identities[0].Ext[iso.ExtKeySchemeID].String())
assert.Equal(t, cbc.Code("12344321"), line.Item.Identities[1].Code)
assert.Equal(t, "ZZZ", line.Item.Identities[1].Label)
assert.Equal(t, cbc.Code("65434568"), line.Item.Identities[2].Code)
Expand Down
24 changes: 14 additions & 10 deletions internal/utog/party.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utog

import (
"github.com/invopop/gobl.ubl/document"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
Expand Down Expand Up @@ -91,17 +92,20 @@ func (c *Converter) getParty(party *document.Party) *org.Party {
}
}

if party.PartyIdentification != nil {
for _, id := range party.PartyIdentification {
identity := getIdentity(&id.ID)
if identity == nil {
continue
}
if p.Identities == nil {
p.Identities = make([]*org.Identity, 0)
}
p.Identities = append(p.Identities, identity)
if party.PartyIdentification != nil &&
party.PartyIdentification.ID != nil &&
party.PartyIdentification.ID.SchemeID != nil {
s := *party.PartyIdentification.ID.SchemeID
identity := &org.Identity{
Ext: tax.Extensions{
iso.ExtKeySchemeID: tax.ExtValue(s),
},
Code: cbc.Code(party.PartyIdentification.ID.Value),
}
if p.Identities == nil {
p.Identities = make([]*org.Identity, 0)
}
p.Identities = append(p.Identities, identity)
}

return p
Expand Down
7 changes: 4 additions & 3 deletions internal/utog/party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/l10n"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestGetParty(t *testing.T) {
require.Len(t, seller.Identities, 2)
assert.Equal(t, "CompanyID", seller.Identities[0].Label)
assert.Equal(t, cbc.Code("123456789"), seller.Identities[0].Code)
assert.Equal(t, "0088", seller.Identities[1].Label)
assert.Equal(t, "0088", seller.Identities[1].Ext[iso.ExtKeySchemeID].String())
assert.Equal(t, cbc.Code("1238764941386"), seller.Identities[1].Code)

assert.Equal(t, "Main street 34", seller.Addresses[0].Street)
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestGetParty(t *testing.T) {
require.Len(t, customer.Identities, 2)
assert.Equal(t, "CompanyID", customer.Identities[0].Label)
assert.Equal(t, cbc.Code("987654321"), customer.Identities[0].Code)
assert.Equal(t, "0088", customer.Identities[1].Label)
assert.Equal(t, "0088", customer.Identities[1].Ext[iso.ExtKeySchemeID].String())
assert.Equal(t, cbc.Code("3456789012098"), customer.Identities[1].Code)

assert.Equal(t, "John Doe", customer.People[0].Name.Given)
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestGetParty(t *testing.T) {
require.Len(t, supplier.Identities, 2)
assert.Equal(t, "CompanyID", supplier.Identities[0].Label)
assert.Equal(t, cbc.Code("DK16356706"), supplier.Identities[0].Code)
assert.Equal(t, "0088", supplier.Identities[1].Label)
assert.Equal(t, "0088", supplier.Identities[1].Ext[iso.ExtKeySchemeID].String())
assert.Equal(t, cbc.Code("1238764941386"), supplier.Identities[1].Code)

customer := inv.Customer
Expand Down
3 changes: 2 additions & 1 deletion internal/utog/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/cbc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -26,7 +27,7 @@ func TestGetPayment(t *testing.T) {
require.Len(t, payment.Payee.Identities, 2)
assert.Equal(t, "CompanyID", payment.Payee.Identities[0].Label)
assert.Equal(t, cbc.Code("989823401"), payment.Payee.Identities[0].Code)
assert.Equal(t, "0088", payment.Payee.Identities[1].Label)
assert.Equal(t, "0088", payment.Payee.Identities[1].Ext[iso.ExtKeySchemeID].String())
assert.Equal(t, cbc.Code("2298740918237"), payment.Payee.Identities[1].Code)
assert.Equal(t, "2 % discount if paid within 2 days\n Penalty percentage 10% from due date", payment.Terms.Notes)
})
Expand Down
8 changes: 8 additions & 0 deletions test/data/gtou/invoice-de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
{
"addr": "[email protected]"
}
],
"identities": [
{
"code": "1234567890128",
"ext": {
"iso-scheme-id": "0088"
}
}
]
},
"lines": [
Expand Down
10 changes: 9 additions & 1 deletion test/data/gtou/invoice-without-buyers-tax-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@
"item": {
"name": "Development services",
"price": "90.00",
"unit": "h"
"unit": "h",
"identities": [
{
"code": "1234567890128",
"ext": {
"iso-scheme-id": "0088"
}
}
]
},
"sum": "1800.00",
"taxes": [
Expand Down
10 changes: 2 additions & 8 deletions test/data/gtou/out/correction-invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PostalAddress>
<cbc:StreetName>Dietmar-Hopp-Allee</cbc:StreetName>
<cbc:StreetName>Dietmar-Hopp-Allee 16</cbc:StreetName>
<cbc:CityName>Walldorf</cbc:CityName>
<cbc:PostalZone>69190</cbc:PostalZone>
<cac:AddressLine>
<cbc:Line>16</cbc:Line>
</cac:AddressLine>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
Expand All @@ -40,12 +37,9 @@
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PostalAddress>
<cbc:StreetName>Werner-Heisenberg-Allee</cbc:StreetName>
<cbc:StreetName>Werner-Heisenberg-Allee 25</cbc:StreetName>
<cbc:CityName>München</cbc:CityName>
<cbc:PostalZone>80939</cbc:PostalZone>
<cac:AddressLine>
<cbc:Line>25</cbc:Line>
</cac:AddressLine>
<cac:Country>
<cbc:IdentificationCode>DE</cbc:IdentificationCode>
</cac:Country>
Expand Down
Loading

0 comments on commit 3ee5eb2

Please sign in to comment.