From bec1305e8ab48db252844808d56e9ae2688dac5f Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 26 May 2023 13:33:49 +0200 Subject: [PATCH] Add an empty product to blank invoice form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no point in creating a new invoice without products, thus we were forcing users to always use the “Add product” button for no reason other than it was easier for me…. I wanted to add the product inside ServeInvoice, when the slug is “new”, but then it tried to compute the invoice total without price or quantity and it failed. Thus, i add that product after it has done the computation query. --- pkg/invoices.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/invoices.go b/pkg/invoices.go index 2944f8c..c892503 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -413,6 +413,9 @@ func newNewInvoicePage(form *invoiceForm, r *http.Request) *newInvoicePage { if err != nil { panic(err) } + if len(form.Products) == 0 { + form.Products = append(form.Products, newInvoiceProductForm(0, company, getLocale(r), mustGetTaxOptions(r.Context(), conn, company))) + } return page }