-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from invopop/address-numbers
Refactoring address number handling so no longer required
- Loading branch information
Showing
8 changed files
with
62 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,33 @@ | ||
package fatturapa | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/invopop/gobl/org" | ||
) | ||
|
||
// address from IndirizzoType | ||
type address struct { | ||
Indirizzo string | ||
NumeroCivico string `xml:",omitempty"` | ||
CAP string | ||
Comune string | ||
Provincia string `xml:",omitempty"` | ||
Nazione string | ||
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(p *org.Party) (*address, error) { | ||
if len(p.Addresses) == 0 { | ||
return nil, errors.New("party missing address") | ||
} | ||
|
||
addr := p.Addresses[0] | ||
|
||
func newAddress(addr *org.Address) *address { | ||
return &address{ | ||
Indirizzo: addressLine(addr), | ||
CAP: addr.Code, | ||
Comune: addr.Locality, | ||
Provincia: addr.Region, | ||
Nazione: addr.Country.String(), | ||
}, nil | ||
Indirizzo: addressStreet(addr), | ||
NumeroCivico: addr.Number, | ||
CAP: addr.Code, | ||
Comune: addr.Locality, | ||
Provincia: addr.Region, | ||
Nazione: addr.Country.String(), | ||
} | ||
} | ||
|
||
func addressLine(address *org.Address) string { | ||
func addressStreet(address *org.Address) string { | ||
if address.PostOfficeBox != "" { | ||
return address.PostOfficeBox | ||
} | ||
|
||
return address.Street + | ||
", " + address.Number + | ||
addressMaybe(address.Block) + | ||
addressMaybe(address.Floor) + | ||
addressMaybe(address.Door) | ||
} | ||
|
||
func addressMaybe(element string) string { | ||
if element != "" { | ||
return ", " + element | ||
} | ||
return "" | ||
return address.Street | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters