Move call to mustGetTaxOptions of AddProducts

I was trying to query the database while the connection was still busy
quering the products.
This commit is contained in:
jordi fita mas 2023-03-05 18:43:22 +01:00
parent 31ef3ea47a
commit 93e92cf62d
1 changed files with 1 additions and 1 deletions

View File

@ -427,9 +427,9 @@ func (form *invoiceForm) Update() {
func (form *invoiceForm) AddProducts(ctx context.Context, conn *Conn, productsId []string) { func (form *invoiceForm) AddProducts(ctx context.Context, conn *Conn, productsId []string) {
index := len(form.Products) index := len(form.Products)
taxOptions := mustGetTaxOptions(ctx, conn, form.company)
rows := conn.MustQuery(ctx, "select product_id, name, description, to_price(price, decimal_digits), 1 as quantity, 0 as discount, array_remove(array_agg(tax_id), null) from product join company using (company_id) join currency using (currency_code) left join product_tax using (product_id) where product_id = any ($1) group by product_id, name, description, price, decimal_digits", productsId) rows := conn.MustQuery(ctx, "select product_id, name, description, to_price(price, decimal_digits), 1 as quantity, 0 as discount, array_remove(array_agg(tax_id), null) from product join company using (company_id) join currency using (currency_code) left join product_tax using (product_id) where product_id = any ($1) group by product_id, name, description, price, decimal_digits", productsId)
defer rows.Close() defer rows.Close()
taxOptions := mustGetTaxOptions(ctx, conn, form.company)
for rows.Next() { for rows.Next() {
product := newInvoiceProductForm(index, form.company, form.locale, taxOptions) product := newInvoiceProductForm(index, form.company, form.locale, taxOptions)
if err := rows.Scan(product.ProductId, product.Name, product.Description, product.Price, product.Quantity, product.Discount, product.Tax); err != nil { if err := rows.Scan(product.ProductId, product.Name, product.Description, product.Price, product.Quantity, product.Discount, product.Tax); err != nil {