Refactor getting the invoice status options in a single function

This commit is contained in:
jordi fita mas 2023-07-11 15:26:23 +02:00
parent fa97f53dd7
commit b7578a56df
1 changed files with 12 additions and 2 deletions

View File

@ -152,7 +152,7 @@ func newInvoiceFilterForm(ctx context.Context, conn *Conn, locale *Locale, compa
Name: "invoice_status", Name: "invoice_status",
Label: pgettext("input", "Invoice Status", locale), Label: pgettext("input", "Invoice Status", locale),
EmptyLabel: gettext("All status", locale), EmptyLabel: gettext("All status", locale),
Options: MustGetOptions(ctx, conn, "select invoice_status.invoice_status, isi18n.name from invoice_status join invoice_status_i18n isi18n using(invoice_status) where isi18n.lang_tag = $1 order by invoice_status", locale.Language.String()), Options: mustGetInvoiceStatusOptions(ctx, conn, locale),
}, },
InvoiceNumber: &InputField{ InvoiceNumber: &InputField{
Name: "number", Name: "number",
@ -691,7 +691,7 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co
Required: true, Required: true,
Label: pgettext("input", "Invoice Status", locale), Label: pgettext("input", "Invoice Status", locale),
Selected: []string{"created"}, Selected: []string{"created"},
Options: MustGetOptions(ctx, conn, "select invoice_status.invoice_status, isi18n.name from invoice_status join invoice_status_i18n isi18n using(invoice_status) where isi18n.lang_tag = $1 order by invoice_status", locale.Language.String()), Options: mustGetInvoiceStatusOptions(ctx, conn, locale),
}, },
Customer: &SelectField{ Customer: &SelectField{
Name: "customer", Name: "customer",
@ -724,6 +724,16 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co
} }
} }
func mustGetInvoiceStatusOptions(ctx context.Context, conn *Conn, locale *Locale) []*SelectOption {
return MustGetOptions(ctx, conn, `
select invoice_status.invoice_status
, isi18n.name
from invoice_status
join invoice_status_i18n isi18n using(invoice_status)
where isi18n.lang_tag = $1
order by invoice_status`, locale.Language.String())
}
func (form *invoiceForm) Parse(r *http.Request) error { func (form *invoiceForm) Parse(r *http.Request) error {
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
return err return err