Skip to content

Commit

Permalink
Simplified invoices not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Aug 22, 2024
1 parent a62a5e5 commit d1fd506
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions facturae.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func NewInvoice(env *gobl.Envelope, opts ...Option) (*Document, error) {
return nil, errors.New("expected an invoice")
}

if invoice.Customer == nil {
return nil, errors.New("customer required")
}

// Make sure we're dealing with raw data
var err error
invoice, err = invoice.RemoveIncludedTaxes()
Expand Down Expand Up @@ -144,11 +148,16 @@ func NewInvoice(env *gobl.Envelope, opts ...Option) (*Document, error) {
d.Parties.Seller.LegalEntity = NewLegalEntity(invoice.Supplier)
}

d.Parties.Buyer.TaxID = NewTaxID(invoice.Customer.TaxID.Code, invoice.Customer.TaxID.Country)
if d.Parties.Buyer.TaxID.PersonTypeCode == "F" {
d.Parties.Buyer.Individual = NewIndividual(invoice.Customer)
} else {
d.Parties.Buyer.LegalEntity = NewLegalEntity(invoice.Customer)
if invoice.Customer != nil && invoice.Customer.TaxID != nil {
// Simplified invoices are not supported by FacturaE, but this is where
// they'd be handled if the situation changes.
b := d.Parties.Buyer
b.TaxID = NewTaxID(invoice.Customer.TaxID.Code, invoice.Customer.TaxID.Country)
if b.TaxID.PersonTypeCode == "F" {
b.Individual = NewIndividual(invoice.Customer)
} else {
b.LegalEntity = NewLegalEntity(invoice.Customer)
}
}

d.Invoices = &Invoices{
Expand Down
6 changes: 4 additions & 2 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ func (l *InvoiceLine) addTaxes(total num.Amount, taxes *tax.Total, rates tax.Set

tax := new(Tax)
tax.Code = categoryTaxCodeMap[ct.Code]
tax.Rate = rate.Percent.StringWithoutSymbol()
tax.Base = makeAmount(total)
tax.Amount = makeAmount(rate.Percent.Of(total))
if rate.Percent != nil {
tax.Rate = rate.Percent.StringWithoutSymbol()
tax.Amount = makeAmount(rate.Percent.Of(total))
}
if rate.Surcharge != nil {
p := *rate.Surcharge
p.Amount = p.Amount.Rescale(4)
Expand Down

0 comments on commit d1fd506

Please sign in to comment.