Do not give “false ID” to invoice products that come from quotations
When adding “free-form products” to quotes they do not have a product ID, but i has coalescing the NULL to zero because product_id is an integer and can not coalesce a nullable integer to an empty string. However, that causes problems when trying to create the invoice for that quote, because it tries to add products that have an ID of 0 and the foreign key, obviously, fail. At first i modified NewInvoiceProductArray.EncodeBinary to check for "0" as well as the empty string, but i realized this was wrong: the problem was because i gave these products an ID when they do not have any. And the solution is to cast product_id to a text, which is what will get converted anyway because i the only thing i do to it is to store to a string-backed InputForm field. Closes #73.
This commit is contained in:
parent
0c4ef97dff
commit
1c6375b51d
|
@ -958,7 +958,7 @@ func (form *invoiceForm) MustFillFromQuote(ctx context.Context, conn *Conn, slug
|
|||
return false
|
||||
}
|
||||
form.Products = []*invoiceProductForm{}
|
||||
form.mustAddProductsFromQuery(ctx, conn, "select '', coalesce(product_id, 0), name, description, to_price(price, $2), quantity, (discount_rate * 100)::integer, array_remove(array_agg(tax_id), null) from quote_product left join quote_product_product using (quote_product_id) left join quote_product_tax using (quote_product_id) where quote_id = $1 group by quote_product_id, coalesce(product_id, 0), name, description, discount_rate, price, quantity", quoteId, form.company.DecimalDigits)
|
||||
form.mustAddProductsFromQuery(ctx, conn, "select '', coalesce(product_id::text, ''), name, description, to_price(price, $2), quantity, (discount_rate * 100)::integer, array_remove(array_agg(tax_id), null) from quote_product left join quote_product_product using (quote_product_id) left join quote_product_tax using (quote_product_id) where quote_id = $1 group by quote_product_id, coalesce(product_id::text, ''), name, description, discount_rate, price, quantity", quoteId, form.company.DecimalDigits)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue