Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
apardods committed Nov 27, 2024
1 parent c6487b3 commit b9dad6e
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 162 deletions.
6 changes: 2 additions & 4 deletions cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Client) GenerateCancel(env *gobl.Envelope) (*doc.VeriFactu, error) {
}

// Create the document
cd, err := doc.NewDocument(inv, ts, c.issuerRole, c.software, true)
cd, err := doc.NewVerifactu(inv, ts, c.issuerRole, c.software, true)
if err != nil {
return nil, err
}
Expand All @@ -38,9 +38,7 @@ func (c *Client) GenerateCancel(env *gobl.Envelope) (*doc.VeriFactu, error) {
}

// FingerprintCancel generates a fingerprint for the cancellation document using the
// data provided from the previous chain data. If there was no previous
// document in the chain, the parameter should be nil. The document is updated
// in place.
// data provided from the previous chain data. The document is updated in place.
func (c *Client) FingerprintCancel(d *doc.VeriFactu, prev *doc.ChainData) error {
return d.FingerprintCancel(prev)
}
2 changes: 1 addition & 1 deletion cmd/gobl.verifactu/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *cancelOpts) runE(cmd *cobra.Command, args []string) error {
if c.production {
opts = append(opts, verifactu.InProduction())
} else {
opts = append(opts, verifactu.InTesting())
opts = append(opts, verifactu.InSandbox())
}

tc, err := verifactu.New(c.software(), opts...)
Expand Down
3 changes: 1 addition & 2 deletions cmd/gobl.verifactu/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (o *rootOpts) cmd() *cobra.Command {

cmd.AddCommand(versionCmd())
cmd.AddCommand(send(o).cmd())
cmd.AddCommand(sendTest(o).cmd())
cmd.AddCommand(convert(o).cmd())
cmd.AddCommand(cancel(o).cmd())

Expand Down Expand Up @@ -64,7 +63,7 @@ func (o *rootOpts) software() *doc.Software {
NombreSistemaInformatico: o.swName,
TipoUsoPosibleSoloVerifactu: "S",
TipoUsoPosibleMultiOT: "S",
IndicadorMultiplesOT: "S",
IndicadorMultiplesOT: "N",
}
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/gobl.verifactu/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/invopop/gobl"
verifactu "github.com/invopop/gobl.verifactu"
"github.com/invopop/gobl.verifactu/doc"
"github.com/invopop/xmldsig"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,14 +54,19 @@ func (c *sendOpts) runE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unmarshaling gobl envelope: %w", err)
}

cert, err := xmldsig.LoadCertificate(c.cert, c.password)
if err != nil {
return err
}

opts := []verifactu.Option{
verifactu.WithThirdPartyIssuer(),
verifactu.WithCertificate(cert),
}

if c.production {
opts = append(opts, verifactu.InProduction())
} else {
opts = append(opts, verifactu.InTesting())
opts = append(opts, verifactu.InSandbox())
}

tc, err := verifactu.New(c.software(), opts...)
Expand Down
126 changes: 0 additions & 126 deletions cmd/gobl.verifactu/sendtest.go

This file was deleted.

16 changes: 8 additions & 8 deletions doc/breakdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestBreakdownConversion(t *testing.T) {
t.Run("basic-invoice", func(t *testing.T) {
inv := test.LoadInvoice("inv-base.json")
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)

assert.Equal(t, 1800.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, "01", d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].Impuesto)
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, 21.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].CuotaRepercutida)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, 0.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].CuotaRepercutida)
Expand All @@ -151,7 +151,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
_, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
_, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.Error(t, err)
})

Expand All @@ -175,7 +175,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, 21.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].CuotaRepercutida)
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, 10.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].CuotaRepercutida)
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestBreakdownConversion(t *testing.T) {
},
}
_ = inv.Calculate()
d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, false)
require.NoError(t, err)
assert.Equal(t, 1000.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].BaseImponibleOImporteNoSujeto)
assert.Equal(t, 100.00, d.RegistroFactura.RegistroAlta.Desglose.DetalleDesglose[0].CuotaRepercutida)
Expand Down
6 changes: 3 additions & 3 deletions doc/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestNewRegistroAnulacion(t *testing.T) {
t.Run("basic", func(t *testing.T) {
inv := test.LoadInvoice("cred-note-base.json")

d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleSupplier, nil, true)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleSupplier, nil, true)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAnulacion
Expand All @@ -33,7 +33,7 @@ func TestNewRegistroAnulacion(t *testing.T) {
t.Run("customer issuer", func(t *testing.T) {
inv := test.LoadInvoice("cred-note-base.json")

d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleCustomer, nil, true)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleCustomer, nil, true)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAnulacion
Expand All @@ -51,7 +51,7 @@ func TestNewRegistroAnulacion(t *testing.T) {
t.Run("third party issuer", func(t *testing.T) {
inv := test.LoadInvoice("cred-note-base.json")

d, err := doc.NewDocument(inv, time.Now(), doc.IssuerRoleThirdParty, nil, true)
d, err := doc.NewVerifactu(inv, time.Now(), doc.IssuerRoleThirdParty, nil, true)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAnulacion
Expand Down
4 changes: 2 additions & 2 deletions doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func init() {
}
}

// NewDocument creates a new VeriFactu document
func NewDocument(inv *bill.Invoice, ts time.Time, r IssuerRole, s *Software, c bool) (*VeriFactu, error) {
// NewVerifactu creates a new VeriFactu document
func NewVerifactu(inv *bill.Invoice, ts time.Time, r IssuerRole, s *Software, c bool) (*VeriFactu, error) {
doc := &VeriFactu{
Cabecera: &Cabecera{
Obligado: Obligado{
Expand Down
2 changes: 1 addition & 1 deletion doc/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestInvoiceConversion(t *testing.T) {

t.Run("should contain basic document info", func(t *testing.T) {
inv := test.LoadInvoice("inv-base.json")
doc, err := doc.NewDocument(inv, ts, role, sw, false)
doc, err := doc.NewVerifactu(inv, ts, role, sw, false)

require.NoError(t, err)
assert.Equal(t, "Invopop S.L.", doc.Cabecera.Obligado.NombreRazon)
Expand Down
8 changes: 4 additions & 4 deletions doc/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestNewRegistroAlta(t *testing.T) {

t.Run("should contain basic document info", func(t *testing.T) {
inv := test.LoadInvoice("inv-base.json")
d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAlta
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestNewRegistroAlta(t *testing.T) {
inv.SetTags(tax.TagSimplified)
inv.Customer = nil

d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

assert.Equal(t, "S", d.RegistroFactura.RegistroAlta.FacturaSinIdentifDestinatarioArt61d)
Expand All @@ -64,7 +64,7 @@ func TestNewRegistroAlta(t *testing.T) {
t.Run("should handle rectificative invoices", func(t *testing.T) {
inv := test.LoadInvoice("cred-note-base.json")

d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAlta
Expand All @@ -89,7 +89,7 @@ func TestNewRegistroAlta(t *testing.T) {
},
}

d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

reg := d.RegistroFactura.RegistroAlta
Expand Down
8 changes: 4 additions & 4 deletions doc/party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewParty(t *testing.T) {
sw := &doc.Software{}
t.Run("with tax ID", func(t *testing.T) {
inv := test.LoadInvoice("inv-base.json")
d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

p := d.RegistroFactura.RegistroAlta.Destinatarios[0].IDDestinatario
Expand All @@ -40,7 +40,7 @@ func TestNewParty(t *testing.T) {
},
}

d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

p := d.RegistroFactura.RegistroAlta.Destinatarios[0].IDDestinatario
Expand All @@ -61,7 +61,7 @@ func TestNewParty(t *testing.T) {
},
}

d, err := doc.NewDocument(inv, ts, role, sw, false)
d, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.NoError(t, err)

p := d.RegistroFactura.RegistroAlta.Destinatarios[0].IDDestinatario
Expand All @@ -79,7 +79,7 @@ func TestNewParty(t *testing.T) {
Name: "Simple Company",
}

_, err := doc.NewDocument(inv, ts, role, sw, false)
_, err := doc.NewVerifactu(inv, ts, role, sw, false)
require.Error(t, err)
})
}
Loading

0 comments on commit b9dad6e

Please sign in to comment.