forked from invopop/gobl.fatturapa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.go
43 lines (38 loc) · 891 Bytes
/
address.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package fatturapa
import (
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
)
const (
foreignCAP = "00000"
)
// address from IndirizzoType
type address struct {
Indirizzo string // Street
NumeroCivico string `xml:",omitempty"` // Number
CAP string // Post Code
Comune string // Locality
Provincia string `xml:",omitempty"` // Region
Nazione string // Country Code
}
func newAddress(addr *org.Address) *address {
ad := &address{
Indirizzo: addressStreet(addr),
NumeroCivico: addr.Number,
Comune: addr.Locality,
Provincia: addr.Region,
Nazione: addr.Country.String(),
}
if addr.Country == l10n.IT {
ad.CAP = addr.Code
} else {
ad.CAP = foreignCAP
}
return ad
}
func addressStreet(address *org.Address) string {
if address.PostOfficeBox != "" {
return address.PostOfficeBox
}
return address.Street
}