Skip to content

Commit

Permalink
Fixing tests and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Nov 21, 2023
1 parent 1df6d37 commit ef2da5b
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 182 deletions.
11 changes: 8 additions & 3 deletions addendas/addendas.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Package addendas adds additional functionality for "Addendas" to the CFDI documents.
package addendas

import "github.com/invopop/gobl/bill"

// For returns a set of addenda objects for the given invoice.
func For(inv *bill.Invoice) []any {
func For(inv *bill.Invoice) ([]any, error) {
list := make([]any, 0)

if isMabe(inv) {
list = append(list, newMabe(inv))
ad, err := newMabe(inv)
if err != nil {
return nil, err
}
list = append(list, ad)
}

return list
return list, nil
}
6 changes: 5 additions & 1 deletion cfdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ func addComplementos(doc *Document, complements []*schema.Object) error {
}

func addAddendas(doc *Document, inv *bill.Invoice) error {
for _, ad := range addendas.For(inv) {
ads, err := addendas.For(inv)
if err != nil {
return err
}
for _, ad := range ads {
doc.Addendas = append(doc.Addendas, &ContentWrapper{ad})
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/invopop/gobl.cfdi
go 1.20

require (
github.com/invopop/gobl v0.62.2-0.20231121142901-bd3349ee3ec6
github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d
github.com/joho/godotenv v1.5.1
github.com/magefile/mage v1.15.0
github.com/spf13/cobra v1.7.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.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.62.1-0.20231121111925-64c5be7b0226 h1:Qca7HXgrRZOLuu++CdcFmlMWvLumkdiLR8/YfzjKuTE=
github.com/invopop/gobl v0.62.1-0.20231121111925-64c5be7b0226/go.mod h1:sEngvTr2gAxexosO0rmQInVSL8C613TUPvBcFT4xMyM=
github.com/invopop/gobl v0.62.2-0.20231121142901-bd3349ee3ec6 h1:O2U9Fkj+1F6kI0GO3Cx8IBRbG69jCmyC6QPjz2SJrk4=
github.com/invopop/gobl v0.62.2-0.20231121142901-bd3349ee3ec6/go.mod h1:sEngvTr2gAxexosO0rmQInVSL8C613TUPvBcFT4xMyM=
github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d h1:tPpq1L2YH8IyGS452WCPGlbsbjw8u0okxmuhZ21wZi0=
github.com/invopop/gobl v0.62.2-0.20231121145421-5d7dce0fd42d/go.mod h1:sEngvTr2gAxexosO0rmQInVSL8C613TUPvBcFT4xMyM=
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.3.0 h1:o260kbjXzoBO/ypXDSSrCLL7SxEFUXBsX09YTE9AxZw=
Expand Down
2 changes: 1 addition & 1 deletion internal/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ClaveUnidad(line *bill.Line) string {
return string(line.Item.Unit.UNECE())
}

// ClaveProdServe determines the line's Product-Service code
// ClaveProdServ determines the line's Product-Service code
func ClaveProdServ(line *bill.Line) string {
if line.Item == nil {
return ""
Expand Down
10 changes: 3 additions & 7 deletions taxes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cfdi

import (
"github.com/invopop/gobl.cfdi/internal/format"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/currency"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/regimes/mx"
"github.com/invopop/gobl/tax"
)
Expand Down Expand Up @@ -88,7 +88,7 @@ func newImpuesto(rate *tax.RateTotal, currency *currency.Code, catDef *tax.Categ
Base: rate.Base.Rescale(cu).String(),
Importe: rate.Amount.Rescale(cu).String(),
Impuesto: catDef.Map[mx.KeySATImpuesto].String(),
TasaOCuota: formatTaxPercent(rate.Percent),
TasaOCuota: format.TaxPercent(rate.Percent),
TipoFactor: TipoFactorTasa,
}

Expand Down Expand Up @@ -130,13 +130,9 @@ func newConceptoImpuesto(line *bill.Line, tax *tax.Combo, catDef *tax.Category)
Base: line.Total.String(),
Importe: taxAmount.String(),
Impuesto: catDef.Map[mx.KeySATImpuesto].String(),
TasaOCuota: formatTaxPercent(tax.Percent),
TasaOCuota: format.TaxPercent(tax.Percent),
TipoFactor: TipoFactorTasa,
}

return i
}

func formatTaxPercent(percent *num.Percentage) string {
return percent.Amount.Rescale(6).String()
}
Loading

0 comments on commit ef2da5b

Please sign in to comment.