Deduplicate the SQL for getting the options for customer’s select field

This commit is contained in:
jordi fita mas 2023-05-03 12:40:07 +02:00
parent 5984745c89
commit 97ad76d82c
1 changed files with 6 additions and 2 deletions

View File

@ -159,7 +159,7 @@ func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, compa
Name: "customer", Name: "customer",
Label: pgettext("input", "Customer", locale), Label: pgettext("input", "Customer", locale),
EmptyLabel: gettext("All customers", locale), EmptyLabel: gettext("All customers", locale),
Options: MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id), Options: mustGetContactOptions(ctx, conn, company),
}, },
InvoiceStatus: &SelectField{ InvoiceStatus: &SelectField{
Name: "invoice_status", Name: "invoice_status",
@ -579,7 +579,7 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co
Name: "customer", Name: "customer",
Label: pgettext("input", "Customer", locale), Label: pgettext("input", "Customer", locale),
Required: true, Required: true,
Options: MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id), Options: mustGetContactOptions(ctx, conn, company),
}, },
Date: &InputField{ Date: &InputField{
Name: "date", Name: "date",
@ -738,6 +738,10 @@ func mustGetTaxOptions(ctx context.Context, conn *Conn, company *Company) []*Sel
return MustGetGroupedOptions(ctx, conn, "select tax_id::text, tax.name, tax_class.name from tax join tax_class using (tax_class_id) where tax.company_id = $1 order by tax_class.name, tax.name", company.Id) return MustGetGroupedOptions(ctx, conn, "select tax_id::text, tax.name, tax_class.name from tax join tax_class using (tax_class_id) where tax.company_id = $1 order by tax_class.name, tax.name", company.Id)
} }
func mustGetContactOptions(ctx context.Context, conn *Conn, company *Company) []*SelectOption {
return MustGetOptions(ctx, conn, "select contact_id::text, business_name from contact where company_id = $1 order by business_name", company.Id)
}
type invoiceProductForm struct { type invoiceProductForm struct {
locale *Locale locale *Locale
company *Company company *Company