Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add omitempty to fields that can be empty according to KSeF schema #10

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Header struct {
FormCode *FormCode `xml:"KodFormularza"`
FormVariant int `xml:"WariantFormularza"`
CreationDate string `xml:"DataWytworzeniaFa"`
SystemInfo string `xml:"SystemInfo"`
SystemInfo string `xml:"SystemInfo,omitempty"`
}

// FormCode defines the XML structure for KSeF schema versioning
Expand Down
14 changes: 7 additions & 7 deletions lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "github.com/invopop/gobl/bill"
// Line defines the XML structure for KSeF item line
type Line struct {
LineNumber int `xml:"NrWierszaFa"`
Name string `xml:"P_7"`
Measure string `xml:"P_8A"`
Quantity string `xml:"P_8B"`
NetUnitPrice string `xml:"P_9A"`
UnitDiscount string `xml:"P_10"`
NetPriceTotal string `xml:"P_11"`
TaxRate string `xml:"P_12"`
Name string `xml:"P_7,omitempty"`
Measure string `xml:"P_8A,omitempty"`
Quantity string `xml:"P_8B,omitempty"`
NetUnitPrice string `xml:"P_9A,omitempty"`
UnitDiscount string `xml:"P_10,omitempty"`
NetPriceTotal string `xml:"P_11,omitempty"`
TaxRate string `xml:"P_12,omitempty"`
ExciseDuty string `xml:"KwotaAkcyzy,omitempty"`
SpecialGoodsCode string `xml:"GTU,omitempty"` // values GTU_1 to GTU_13
OSSTaxRate string `xml:"P_12_XII,omitempty"`
Expand Down
16 changes: 8 additions & 8 deletions parties.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Address struct {
CountryCode string `xml:"KodKraju"`
AddressL1 string `xml:"AdresL1"`
AddressL2 string `xml:"AdresL2"`
AddressL2 string `xml:"AdresL2,omitempty"`
}

// Seller defines the XML structure for KSeF seller
Expand Down Expand Up @@ -43,8 +43,8 @@ type Buyer struct {
Contact *ContactDetails `xml:"DaneKontaktowe,omitempty"`
}

// NewAddress gets the address data from GOBL address
func NewAddress(address *org.Address) *Address {
// newAddress gets the address data from GOBL address
func newAddress(address *org.Address) *Address {
adres := &Address{
CountryCode: string(address.Country),
AddressL1: addressLine1(address),
Expand All @@ -54,8 +54,8 @@ func NewAddress(address *org.Address) *Address {
return adres
}

// NameToString get the seller name out of the organization
func NameToString(name org.Name) string {
// nameToString get the seller name out of the organization
func nameToString(name org.Name) string {
return name.Prefix + nameMaybe(name.Given) +
nameMaybe(name.Middle) + nameMaybe(name.Surname) +
nameMaybe(name.Surname2) + nameMaybe(name.Suffix)
Expand All @@ -67,10 +67,10 @@ func NewSeller(supplier *org.Party) *Seller {
if supplier.Name != "" {
name = supplier.Name
} else {
name = NameToString(supplier.People[0].Name)
name = nameToString(supplier.People[0].Name)
}
seller := &Seller{
Address: NewAddress(supplier.Addresses[0]),
Address: newAddress(supplier.Addresses[0]),
NIP: string(supplier.TaxID.Code),
Name: name,
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func NewBuyer(customer *org.Party) *Buyer {
// TODO NrVatUE and UECode if applicable

if len(customer.Addresses) > 0 {
buyer.Address = NewAddress(customer.Addresses[0])
buyer.Address = newAddress(customer.Addresses[0])
}

if len(customer.Telephones) > 0 {
Expand Down
Loading