Skip to content

Commit

Permalink
Merge pull request #76 from vshn/feat/invoice-titles
Browse files Browse the repository at this point in the history
Add support for custom invoice titles
  • Loading branch information
HappyTetrahedron authored Feb 24, 2023
2 parents 8570f59 + f621907 commit f3234ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions invoice/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// CreateInvoice creates a new invoice in Odoo.
func CreateInvoice(ctx context.Context, client *model.Odoo, invoice invoice.Invoice, options ...Option) (int, error) {
func CreateInvoice(ctx context.Context, client *model.Odoo, invoice invoice.Invoice, invoiceTitle string, options ...Option) (int, error) {
opts := buildOptions(options)

partnerID, err := strconv.Atoi(invoice.Tenant.Target)
Expand All @@ -31,7 +31,7 @@ func CreateInvoice(ctx context.Context, client *model.Odoo, invoice invoice.Invo
if partner.Parent.Valid {
nameOnInvoice = partner.Parent.Name
}
name := fmt.Sprintf("%s APPUiO Cloud %s %d", nameOnInvoice, invoice.PeriodStart.Month(), invoice.PeriodStart.Year())
name := fmt.Sprintf("%s %s %s %d", nameOnInvoice, invoiceTitle, invoice.PeriodStart.Month(), invoice.PeriodStart.Year())
toCreate := opts.invoiceDefaults
toCreate.Name = name
toCreate.Date = odoo.Date(opts.InvoiceDateOrNow())
Expand Down
6 changes: 4 additions & 2 deletions invoice/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestOdooInvoiceCreator_CreateInvoice(t *testing.T) {
}

partnerId := 19680000
invoiceTitle := "APPUiO Cloud"
subject := invoice.Invoice{
PeriodStart: time.Date(2021, time.December, 1, 0, 0, 0, 0, time.UTC),
Tenant: invoice.Tenant{
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestOdooInvoiceCreator_CreateInvoice(t *testing.T) {
mockCalculateTaxCall(mockExecutor),
)

_, err := CreateInvoice(context.Background(), model.NewOdoo(mockExecutor), subject,
_, err := CreateInvoice(context.Background(), model.NewOdoo(mockExecutor), subject, invoiceTitle,
WithInvoiceDate(invoiceDate),
WithInvoiceDefaults(invoiceDefaults),
WithInvoiceLineDefaults(invoiceLineDefaults),
Expand All @@ -102,6 +103,7 @@ func TestOdooInvoiceCreator_CreateInvoiceWithParentID(t *testing.T) {
}

partnerId := 19680000
invoiceTitle := "APPUiO Cloud"
subject := invoice.Invoice{
PeriodStart: time.Date(2021, time.December, 1, 0, 0, 0, 0, time.UTC),
Tenant: invoice.Tenant{
Expand All @@ -125,7 +127,7 @@ func TestOdooInvoiceCreator_CreateInvoiceWithParentID(t *testing.T) {
mockCalculateTaxCall(mockExecutor),
)

_, err := CreateInvoice(context.Background(), model.NewOdoo(mockExecutor), subject,
_, err := CreateInvoice(context.Background(), model.NewOdoo(mockExecutor), subject, invoiceTitle,
WithInvoiceDate(invoiceDate),
WithInvoiceDefaults(invoiceDefaults),
WithInvoiceLineDefaults(invoiceLineDefaults),
Expand Down
6 changes: 5 additions & 1 deletion invoice_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type invoiceCommand struct {
InvoiceDefaultsPath string

ItemDescriptionTemplatesPath string

InvoiceTitle string
}

var invoiceCommandName = "invoice"
Expand All @@ -54,6 +56,8 @@ func newinvoiceCommand() *cli.Command {
EnvVars: envVars("INVOICE_DEFAULTS_PATH"), Destination: &command.InvoiceDefaultsPath, Required: false},
&cli.StringFlag{Name: "item-description-templates-path", Usage: "Path to a directory with templates. The Files must be named `PRODUCT_SOURCE.gotmpl`.",
EnvVars: envVars("ITEM_DESCRIPTION_TEMPLATES_PATH"), Destination: &command.ItemDescriptionTemplatesPath, Value: "description_templates/", Required: false},
&cli.StringFlag{Name: "invoice-title", Usage: "Title of the generated invoice.",
EnvVars: envVars("INVOICE_TITLE"), Destination: &command.InvoiceTitle, Value: "APPUiO Cloud", Required: false},
},
}
}
Expand Down Expand Up @@ -103,7 +107,7 @@ func (cmd *invoiceCommand) execute(context *cli.Context) error {
}

for _, inv := range invoices {
id, err := invoice.CreateInvoice(ctx, o, inv,
id, err := invoice.CreateInvoice(ctx, o, inv, cmd.InvoiceTitle,
invoice.WithInvoiceDefaults(invDefault),
invoice.WithInvoiceLineDefaults(invLineDefault),
invoice.WithItemDescriptionRenderer(descTemplates),
Expand Down

0 comments on commit f3234ce

Please sign in to comment.