diff --git a/demo/demo.sql b/demo/demo.sql index 7f35ab2..a0cbda6 100644 --- a/demo/demo.sql +++ b/demo/demo.sql @@ -8,9 +8,19 @@ values ('demo@numerus', 'Demo User', 'demo', 'invoicer') , ('admin@numerus', 'Demo Admin', 'admin', 'admin') ; +set constraints "company_default_payment_method_id_fkey" deferred; + alter sequence company_company_id_seq restart; -insert into company (business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, legal_disclaimer) -values ('Juli Verd', 'ES40404040D', 'Pesebre', parse_packed_phone_number('972 50 60 70', 'ES'), 'info@numerus.cat', 'https://numerus.cat/', 'C/ de l’Hort', 'Castelló d’Empúries', 'Girona', '17486', 'ES', 'EUR', 'Juli Verd és responsable del tractament de les seves dades d’acord amb el RGPD i la LOPDGDD, i les tracta per a mantenir una relació mercantil/comercial amb vostè. Les conservarà mentre es mantingui aquesta relació i no es comunicaran a tercers. Pot exercir els drets d’accés, rectificació, portabilitat, supressió, limitació i oposició a Juli Verd, amb domicili Carrer de l’Hort 71, 17486 Castelló d’Empúries o enviant un correu electrònic a info@numerus.cat. Per a qualsevol reclamació pot acudir a agpd.es. Per a més informació pot consultar la nostra política de privacitat a numerus.cat.'); +insert into company (business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id, legal_disclaimer) +values ('Juli Verd', 'ES40404040D', 'Pesebre', parse_packed_phone_number('972 50 60 70', 'ES'), 'info@numerus.cat', 'https://numerus.cat/', 'C/ de l’Hort', 'Castelló d’Empúries', 'Girona', '17486', 'ES', 'EUR', 2, 'Juli Verd és responsable del tractament de les seves dades d’acord amb el RGPD i la LOPDGDD, i les tracta per a mantenir una relació mercantil/comercial amb vostè. Les conservarà mentre es mantingui aquesta relació i no es comunicaran a tercers. Pot exercir els drets d’accés, rectificació, portabilitat, supressió, limitació i oposició a Juli Verd, amb domicili Carrer de l’Hort 71, 17486 Castelló d’Empúries o enviant un correu electrònic a info@numerus.cat. Per a qualsevol reclamació pot acudir a agpd.es. Per a més informació pot consultar la nostra política de privacitat a numerus.cat.'); + +alter sequence payment_method_payment_method_id_seq restart; +insert into payment_method (company_id, name, instructions) +values (1, 'Efectiu', 'Pagament en efectiu al comptat.') + , (1, 'Transferència', E'Pagament per transferència bancària al compte:\n\nES0123456789012345678901\n\nBIC AAAABBCCDD') +; + +set constraints "company_default_payment_method_id_fkey" immediate; insert into company_user (company_id, user_id) values (1, 1) diff --git a/deploy/company_default_payment_method.sql b/deploy/company_default_payment_method.sql new file mode 100644 index 0000000..c3fae9e --- /dev/null +++ b/deploy/company_default_payment_method.sql @@ -0,0 +1,13 @@ +-- Deploy numerus:company_default_payment_method to pg +-- requires: schema_numerus +-- requires: company +-- requires: payment_method + +begin; + +set search_path to numerus, public; + +alter table company +add column default_payment_method_id integer not null references payment_method deferrable; + +commit; diff --git a/pkg/invoices.go b/pkg/invoices.go index dd56ccf..e73f962 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -325,14 +325,14 @@ func HandleNewInvoiceAction(w http.ResponseWriter, r *http.Request, _ httprouter } type invoiceForm struct { - locale *Locale - company *Company - Customer *SelectField - Number *InputField - Date *InputField - Notes *InputField - Tax *SelectField - Products []*invoiceProductForm + locale *Locale + company *Company + Customer *SelectField + Number *InputField + Date *InputField + Notes *InputField + PaymentMethod *SelectField + Products []*invoiceProductForm } func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Company) *invoiceForm { @@ -358,15 +358,16 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co Required: true, }, Notes: &InputField{ - Name: "description", + Name: "notes", Label: pgettext("input", "Notes", locale), Type: "textarea", }, - Tax: &SelectField{ - Name: "text", - Label: pgettext("input", "Taxes", locale), - Multiple: true, - Options: mustGetTaxOptions(ctx, conn, company), + PaymentMethod: &SelectField{ + Name: "payment_method", + Required: true, + Label: pgettext("input", "Payment Method", locale), + Selected: []string{conn.MustGetText(ctx, "", "select default_payment_method_id::text from company where company_id = $1", company.Id)}, + Options: MustGetOptions(ctx, conn, "select payment_method_id::text, name from payment_method where company_id = $1", company.Id), }, } } @@ -380,11 +381,12 @@ func (form *invoiceForm) Parse(r *http.Request) error { form.Date.FillValue(r) form.Notes.FillValue(r) if _, ok := r.Form["product.id.0"]; ok { + taxOptions := mustGetTaxOptions(r.Context(), getConn(r), form.company) for index := 0; true; index++ { if _, ok := r.Form["product.id."+strconv.Itoa(index)]; !ok { break } - productForm := newInvoiceProductForm(index, form.company, form.locale, form.Tax.Options) + productForm := newInvoiceProductForm(index, form.company, form.locale, taxOptions) if err := productForm.Parse(r); err != nil { return err } @@ -401,7 +403,7 @@ func (form *invoiceForm) Validate() bool { if validator.CheckRequiredInput(form.Date, gettext("Invoice date can not be empty.", form.locale)) { validator.CheckValidDate(form.Date, gettext("Invoice date must be a valid date.", form.locale)) } - validator.CheckValidSelectOption(form.Tax, gettext("Selected tax is not valid.", form.locale)) + validator.CheckValidSelectOption(form.PaymentMethod, gettext("Selected payment method is not valid.", form.locale)) allOK := validator.AllOK() for _, product := range form.Products { @@ -427,8 +429,9 @@ func (form *invoiceForm) AddProducts(ctx context.Context, conn *Conn, productsId index := len(form.Products) 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() + taxOptions := mustGetTaxOptions(ctx, conn, form.company) for rows.Next() { - product := newInvoiceProductForm(index, form.company, form.locale, form.Tax.Options) + 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 { panic(err) } diff --git a/po/ca.po b/po/ca.po index 5f58f40..037f51a 100644 --- a/po/ca.po +++ b/po/ca.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: numerus\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2023-03-03 16:38+0100\n" +"POT-Creation-Date: 2023-03-04 22:11+0100\n" "PO-Revision-Date: 2023-01-18 17:08+0100\n" "Last-Translator: jordi fita mas \n" "Language-Team: Catalan \n" @@ -69,28 +69,28 @@ msgstr "Preu" msgid "No products added yet." msgstr "No hi ha cap producte." -#: web/template/invoices/products.gohtml:65 web/template/invoices/new.gohtml:60 +#: web/template/invoices/products.gohtml:65 web/template/invoices/new.gohtml:61 msgctxt "action" msgid "Add products" msgstr "Afegeix productes" -#: web/template/invoices/new.gohtml:41 web/template/invoices/view.gohtml:58 +#: web/template/invoices/new.gohtml:42 web/template/invoices/view.gohtml:58 msgctxt "title" msgid "Subtotal" msgstr "Subtotal" -#: web/template/invoices/new.gohtml:51 web/template/invoices/view.gohtml:62 +#: web/template/invoices/new.gohtml:52 web/template/invoices/view.gohtml:62 #: web/template/invoices/view.gohtml:102 msgctxt "title" msgid "Total" msgstr "Total" -#: web/template/invoices/new.gohtml:63 +#: web/template/invoices/new.gohtml:64 msgctxt "action" msgid "Update" msgstr "Actualitza" -#: web/template/invoices/new.gohtml:65 web/template/invoices/index.gohtml:13 +#: web/template/invoices/new.gohtml:66 web/template/invoices/index.gohtml:13 msgctxt "action" msgid "New invoice" msgstr "Nova factura" @@ -408,44 +408,44 @@ msgstr "No podeu deixar la contrasenya en blanc." msgid "Invalid user or password." msgstr "Nom d’usuari o contrasenya incorrectes." -#: pkg/products.go:165 pkg/invoices.go:469 +#: pkg/products.go:165 pkg/invoices.go:472 msgctxt "input" msgid "Name" msgstr "Nom" -#: pkg/products.go:171 pkg/invoices.go:474 +#: pkg/products.go:171 pkg/invoices.go:477 msgctxt "input" msgid "Description" msgstr "Descripció" -#: pkg/products.go:176 pkg/invoices.go:478 +#: pkg/products.go:176 pkg/invoices.go:481 msgctxt "input" msgid "Price" msgstr "Preu" -#: pkg/products.go:186 pkg/invoices.go:367 pkg/invoices.go:504 +#: pkg/products.go:186 pkg/invoices.go:507 msgctxt "input" msgid "Taxes" msgstr "Imposts" -#: pkg/products.go:206 pkg/profile.go:92 pkg/invoices.go:400 -#: pkg/invoices.go:540 +#: pkg/products.go:206 pkg/profile.go:92 pkg/invoices.go:402 +#: pkg/invoices.go:543 msgid "Name can not be empty." msgstr "No podeu deixar el nom en blanc." -#: pkg/products.go:207 pkg/invoices.go:541 +#: pkg/products.go:207 pkg/invoices.go:544 msgid "Price can not be empty." msgstr "No podeu deixar el preu en blanc." -#: pkg/products.go:208 pkg/invoices.go:542 +#: pkg/products.go:208 pkg/invoices.go:545 msgid "Price must be a number greater than zero." msgstr "El preu ha de ser un número major a zero." -#: pkg/products.go:210 pkg/invoices.go:404 pkg/invoices.go:550 +#: pkg/products.go:210 pkg/invoices.go:553 msgid "Selected tax is not valid." msgstr "Heu seleccionat un impost que no és vàlid." -#: pkg/products.go:211 pkg/invoices.go:551 +#: pkg/products.go:211 pkg/invoices.go:554 msgid "You can only select a tax of each class." msgstr "Només podeu seleccionar un impost de cada classe." @@ -581,42 +581,51 @@ msgctxt "input" msgid "Notes" msgstr "Notes" -#: pkg/invoices.go:401 +#: pkg/invoices.go:368 +msgctxt "input" +msgid "Payment Method" +msgstr "Mètode de pagament" + +#: pkg/invoices.go:403 msgid "Invoice date can not be empty." msgstr "No podeu deixar la data de la factura en blanc." -#: pkg/invoices.go:402 +#: pkg/invoices.go:404 msgid "Invoice date must be a valid date." msgstr "La data de facturació ha de ser vàlida." -#: pkg/invoices.go:464 +#: pkg/invoices.go:406 +msgid "Selected payment method is not valid." +msgstr "Heu seleccionat un mètode de pagament que no és vàlid." + +#: pkg/invoices.go:467 msgctxt "input" msgid "Id" msgstr "Identificador" -#: pkg/invoices.go:487 +#: pkg/invoices.go:490 msgctxt "input" msgid "Quantity" msgstr "Quantitat" -#: pkg/invoices.go:495 +#: pkg/invoices.go:498 msgctxt "input" msgid "Discount (%)" msgstr "Descompte (%)" -#: pkg/invoices.go:544 +#: pkg/invoices.go:547 msgid "Quantity can not be empty." msgstr "No podeu deixar la quantitat en blanc." -#: pkg/invoices.go:545 +#: pkg/invoices.go:548 msgid "Quantity must be a number greater than zero." msgstr "La quantitat ha de ser un número major a zero." -#: pkg/invoices.go:547 +#: pkg/invoices.go:550 msgid "Discount can not be empty." msgstr "No podeu deixar el descompte en blanc." -#: pkg/invoices.go:548 +#: pkg/invoices.go:551 msgid "Discount must be a percentage between 0 and 100." msgstr "El descompte ha de ser un percentatge entre 0 i 100." diff --git a/po/es.po b/po/es.po index d54ea8f..da4f2c2 100644 --- a/po/es.po +++ b/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: numerus\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2023-03-03 16:38+0100\n" +"POT-Creation-Date: 2023-03-04 22:11+0100\n" "PO-Revision-Date: 2023-01-18 17:45+0100\n" "Last-Translator: jordi fita mas \n" "Language-Team: Spanish \n" @@ -69,28 +69,28 @@ msgstr "Precio" msgid "No products added yet." msgstr "No hay productos." -#: web/template/invoices/products.gohtml:65 web/template/invoices/new.gohtml:60 +#: web/template/invoices/products.gohtml:65 web/template/invoices/new.gohtml:61 msgctxt "action" msgid "Add products" msgstr "Añadir productos" -#: web/template/invoices/new.gohtml:41 web/template/invoices/view.gohtml:58 +#: web/template/invoices/new.gohtml:42 web/template/invoices/view.gohtml:58 msgctxt "title" msgid "Subtotal" msgstr "Subtotal" -#: web/template/invoices/new.gohtml:51 web/template/invoices/view.gohtml:62 +#: web/template/invoices/new.gohtml:52 web/template/invoices/view.gohtml:62 #: web/template/invoices/view.gohtml:102 msgctxt "title" msgid "Total" msgstr "Total" -#: web/template/invoices/new.gohtml:63 +#: web/template/invoices/new.gohtml:64 msgctxt "action" msgid "Update" msgstr "Actualizar" -#: web/template/invoices/new.gohtml:65 web/template/invoices/index.gohtml:13 +#: web/template/invoices/new.gohtml:66 web/template/invoices/index.gohtml:13 msgctxt "action" msgid "New invoice" msgstr "Nueva factura" @@ -305,7 +305,7 @@ msgstr "Moneda" #: web/template/tax-details.gohtml:37 msgctxt "title" msgid "Invoicing" -msgstr "Facturació" +msgstr "Facturación" #: web/template/tax-details.gohtml:54 msgctxt "title" @@ -408,46 +408,46 @@ msgstr "No podéis dejar la contraseña en blanco." msgid "Invalid user or password." msgstr "Nombre de usuario o contraseña inválido." -#: pkg/products.go:165 pkg/invoices.go:469 +#: pkg/products.go:165 pkg/invoices.go:472 msgctxt "input" msgid "Name" msgstr "Nombre" -#: pkg/products.go:171 pkg/invoices.go:474 +#: pkg/products.go:171 pkg/invoices.go:477 msgctxt "input" msgid "Description" msgstr "Descripción" -#: pkg/products.go:176 pkg/invoices.go:478 +#: pkg/products.go:176 pkg/invoices.go:481 msgctxt "input" msgid "Price" msgstr "Precio" -#: pkg/products.go:186 pkg/invoices.go:367 pkg/invoices.go:504 +#: pkg/products.go:186 pkg/invoices.go:507 msgctxt "input" msgid "Taxes" msgstr "Impuestos" -#: pkg/products.go:206 pkg/profile.go:92 pkg/invoices.go:400 -#: pkg/invoices.go:540 +#: pkg/products.go:206 pkg/profile.go:92 pkg/invoices.go:402 +#: pkg/invoices.go:543 msgid "Name can not be empty." msgstr "No podéis dejar el nombre en blanco." -#: pkg/products.go:207 pkg/invoices.go:541 +#: pkg/products.go:207 pkg/invoices.go:544 msgid "Price can not be empty." msgstr "No podéis dejar el precio en blanco." -#: pkg/products.go:208 pkg/invoices.go:542 +#: pkg/products.go:208 pkg/invoices.go:545 msgid "Price must be a number greater than zero." msgstr "El precio tiene que ser un número mayor a cero." -#: pkg/products.go:210 pkg/invoices.go:404 pkg/invoices.go:550 +#: pkg/products.go:210 pkg/invoices.go:553 msgid "Selected tax is not valid." msgstr "Habéis escogido un impuesto que no es válido." -#: pkg/products.go:211 pkg/invoices.go:551 +#: pkg/products.go:211 pkg/invoices.go:554 msgid "You can only select a tax of each class." -msgstr "Solo podéis escojer un impuesto de cada clase." +msgstr "Solo podéis escoger un impuesto de cada clase." #: pkg/company.go:98 msgctxt "input" @@ -581,44 +581,53 @@ msgctxt "input" msgid "Notes" msgstr "Notas" -#: pkg/invoices.go:401 +#: pkg/invoices.go:368 +msgctxt "input" +msgid "Payment Method" +msgstr "Método de pago" + +#: pkg/invoices.go:403 msgid "Invoice date can not be empty." msgstr "No podéis dejar la fecha de la factura en blanco." -#: pkg/invoices.go:402 +#: pkg/invoices.go:404 msgid "Invoice date must be a valid date." msgstr "La fecha de factura debe ser válida." -#: pkg/invoices.go:464 +#: pkg/invoices.go:406 +msgid "Selected payment method is not valid." +msgstr "Habéis escogido un método de pago que no es válido." + +#: pkg/invoices.go:467 msgctxt "input" msgid "Id" msgstr "Identificador" -#: pkg/invoices.go:487 +#: pkg/invoices.go:490 msgctxt "input" msgid "Quantity" msgstr "Cantidad" -#: pkg/invoices.go:495 +#: pkg/invoices.go:498 msgctxt "input" msgid "Discount (%)" msgstr "Descuento (%)" -#: pkg/invoices.go:544 +#: pkg/invoices.go:547 msgid "Quantity can not be empty." msgstr "No podéis dejar la cantidad en blanco." -#: pkg/invoices.go:545 +#: pkg/invoices.go:548 msgid "Quantity must be a number greater than zero." msgstr "La cantidad tiene que ser un número mayor a cero." -#: pkg/invoices.go:547 +#: pkg/invoices.go:550 msgid "Discount can not be empty." msgstr "No podéis dejar el descuento en blanco." -#: pkg/invoices.go:548 +#: pkg/invoices.go:551 msgid "Discount must be a percentage between 0 and 100." -msgstr "El descuento tiene que ser un percentage entre 0 y 100." +msgstr "El descuento tiene que ser un porcentaje entre 0 y 100." #: pkg/contacts.go:143 msgctxt "input" diff --git a/revert/company_default_payment_method.sql b/revert/company_default_payment_method.sql new file mode 100644 index 0000000..ab9b68a --- /dev/null +++ b/revert/company_default_payment_method.sql @@ -0,0 +1,8 @@ +-- Revert numerus:company_default_payment_method from pg + +begin; + +alter table numerus.company +drop column if exists default_payment_method_id; + +commit; diff --git a/sqitch.plan b/sqitch.plan index 0c85e29..629b635 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -36,6 +36,8 @@ country_i18n [schema_numerus country_code language country] 2023-01-27T19:20:43Z available_countries [schema_numerus country country_i18n] 2023-01-27T18:49:28Z jordi fita mas # Add the list of available countries company [schema_numerus extension_vat email extension_pg_libphonenumber extension_uri currency_code currency country_code country] 2023-01-24T15:03:15Z jordi fita mas # Add the relation for companies company_user [schema_numerus user company] 2023-01-24T17:50:06Z jordi fita mas # Add the relation of companies and their users +payment_method [schema_numerus company] 2023-03-03T15:00:41Z jordi fita mas # Add relation of payment method +company_default_payment_method [schema_numerus company payment_method] 2023-03-04T20:25:20Z jordi fita mas # Add the company’s default payment method property tax_class [schema_numerus company] 2023-02-28T10:13:14Z jordi fita mas # Add the relation for tax classes tax_rate [schema_numerus] 2023-01-28T11:33:39Z jordi fita mas # Add domain for tax rates tax [schema_numerus company tax_rate tax_class] 2023-01-28T11:45:47Z jordi fita mas # Add relation for taxes @@ -47,7 +49,7 @@ invoice_status [schema_numerus] 2023-02-07T14:50:26Z jordi fita mas # Add relation for invoice status’ translatable texts available_invoice_status [schema_numerus invoice_status invoice_status_i18n] 2023-02-07T15:07:06Z jordi fita mas # Add the list of available invoice status product_tax [schema_numerus product tax] 2023-02-08T11:36:49Z jordi fita mas # Add relation of product taxes -invoice [schema_numerus company contact invoice_status currency] 2023-02-09T09:52:21Z jordi fita mas # Add relation for invoice +invoice [schema_numerus company contact invoice_status payment_method currency] 2023-02-09T09:52:21Z jordi fita mas # Add relation for invoice discount_rate [schema_numerus] 2023-02-10T17:22:40Z jordi fita mas # Add domain for discount rates invoice_product [schema_numerus invoice discount_rate] 2023-02-10T17:07:08Z jordi fita mas # Add relation for invoice product add_product [schema_numerus product product_tax parse_price company currency] 2023-02-14T10:32:18Z jordi fita mas # Add function to add new products @@ -62,4 +64,3 @@ invoice_product_amount [schema_numerus invoice_product invoice_product_tax] 2023 invoice_amount [schema_numerus invoice_product invoice_product_amount] 2023-02-22T12:58:46Z jordi fita mas # Add view to compute subtotal and total for invoices new_invoice_amount [schema_numerus] 2023-02-23T12:08:25Z jordi fita mas # Add type to return when computing new invoice amounts compute_new_invoice_amount [schema_numerus company currency tax new_invoice_product new_invoice_amount] 2023-02-23T12:20:13Z jordi fita mas # Add function to compute the subtotal, taxes, and total amounts for a new invoice -payment_method [schema_numerus company] 2023-03-03T15:00:41Z jordi fita mas # Add relation of payment method diff --git a/test/add_invoice.sql b/test/add_invoice.sql index 81ddaf6..b7b0ab2 100644 --- a/test/add_invoice.sql +++ b/test/add_invoice.sql @@ -29,14 +29,24 @@ truncate contact cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, invoice_number_format) -values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', '"F"YYYY0000') - , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', '"INV"000-YY') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, invoice_number_format, default_payment_method_id) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', '"F"YYYY0000', 111) + , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', '"INV"000-YY', 222) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into invoice_number_counter (company_id, year, currval) values (1, 2023, '5') , (2, 2023, '55') diff --git a/test/add_product.sql b/test/add_product.sql index e2e73d2..a5b1061 100644 --- a/test/add_product.sql +++ b/test/add_product.sql @@ -25,15 +25,24 @@ truncate product_tax cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; +set constraints "company_default_payment_method_id_fkey" deferred; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) + , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 222) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') , (22, 2, 'tax') diff --git a/test/company.sql b/test/company.sql index 9cdaaf3..51f436f 100644 --- a/test/company.sql +++ b/test/company.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(90); +select plan(96); set search_path to numerus, auth, public; @@ -106,6 +106,13 @@ select col_not_null('company', 'legal_disclaimer'); select col_has_default('company', 'legal_disclaimer'); select col_default_is('company', 'legal_disclaimer', ''); +select has_column('company', 'default_payment_method_id'); +select col_is_fk('company', 'default_payment_method_id'); +select fk_ok('company', 'default_payment_method_id', 'payment_method', 'payment_method_id'); +select col_type_is('company', 'default_payment_method_id', 'integer'); +select col_not_null('company', 'default_payment_method_id'); +select col_hasnt_default('company', 'default_payment_method_id'); + select has_column('company', 'created_at'); select col_type_is('company', 'created_at', 'timestamp with time zone'); select col_not_null('company', 'created_at'); @@ -115,6 +122,7 @@ select col_default_is('company', 'created_at', current_timestamp); set client_min_messages to warning; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -124,12 +132,22 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') - , (6, 'Company 6', 'XX345', '', '777-777-777', 'c@c', '', '', '', '', '', 'DE', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 20) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 40) + , (6, 'Company 6', 'XX345', '', '777-777-777', 'c@c', '', '', '', '', '', 'DE', 'USD', 60) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (20, 2, 'cash', 'cash') + , (40, 4, 'cash', 'cash') + , (60, 6, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (2, 5) @@ -175,8 +193,8 @@ select throws_ok( reset role; select throws_ok( $$ - insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) - values (7, ' ', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') + insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) + values (7, ' ', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 20) $$, '23514', 'new row for relation "company" violates check constraint "business_name_not_empty"', 'Should not allow companies with blank business name' diff --git a/test/compute_new_invoice_amount.sql b/test/compute_new_invoice_amount.sql index fb1d9c5..6b228da 100644 --- a/test/compute_new_invoice_amount.sql +++ b/test/compute_new_invoice_amount.sql @@ -22,13 +22,22 @@ select function_privs_are('numerus', 'compute_new_invoice_amount', array ['integ set client_min_messages to warning; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') ; diff --git a/test/contact.sql b/test/contact.sql index b07ac53..553f83e 100644 --- a/test/contact.sql +++ b/test/contact.sql @@ -109,20 +109,30 @@ select col_default_is('contact', 'created_at', current_timestamp); set client_min_messages to warning; truncate contact cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; +set constraints "company_default_payment_method_id_fkey" deferred; + insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at) values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e', current_timestamp + interval '1 month') , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/edit_product.sql b/test/edit_product.sql index 88b7138..2b82ac1 100644 --- a/test/edit_product.sql +++ b/test/edit_product.sql @@ -25,15 +25,24 @@ truncate product_tax cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; +set constraints "company_default_payment_method_id_fkey" deferred; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) + , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 222) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') , (22, 2, 'tax') diff --git a/test/invoice.sql b/test/invoice.sql index 1447bfa..9e2b409 100644 --- a/test/invoice.sql +++ b/test/invoice.sql @@ -94,6 +94,7 @@ truncate invoice cascade; truncate contact cascade; truncate company_user cascade; truncate company cascade; +truncate payment_method cascade; truncate auth."user" cascade; reset client_min_messages; @@ -102,11 +103,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/invoice_amount.sql b/test/invoice_amount.sql index ba82012..8ca21b1 100644 --- a/test/invoice_amount.sql +++ b/test/invoice_amount.sql @@ -33,13 +33,22 @@ truncate contact cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') ; diff --git a/test/invoice_number_counter.sql b/test/invoice_number_counter.sql index 4601984..c83c9e6 100644 --- a/test/invoice_number_counter.sql +++ b/test/invoice_number_counter.sql @@ -37,6 +37,7 @@ select col_hasnt_default('invoice_number_counter', 'currval'); set client_min_messages to warning; truncate invoice_number_counter cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -46,11 +47,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/invoice_product.sql b/test/invoice_product.sql index a2b6104..6dabb59 100644 --- a/test/invoice_product.sql +++ b/test/invoice_product.sql @@ -78,6 +78,7 @@ truncate invoice cascade; truncate product cascade; truncate contact cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -87,11 +88,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/invoice_product_amount.sql b/test/invoice_product_amount.sql index ff9ce9a..916d3d2 100644 --- a/test/invoice_product_amount.sql +++ b/test/invoice_product_amount.sql @@ -33,13 +33,22 @@ truncate contact cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') ; diff --git a/test/invoice_product_tax.sql b/test/invoice_product_tax.sql index db65b4e..c754692 100644 --- a/test/invoice_product_tax.sql +++ b/test/invoice_product_tax.sql @@ -46,6 +46,7 @@ truncate tax cascade; truncate tax_class cascade; truncate contact cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -55,11 +56,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/invoice_tax_amount.sql b/test/invoice_tax_amount.sql index 605472a..6e52de2 100644 --- a/test/invoice_tax_amount.sql +++ b/test/invoice_tax_amount.sql @@ -33,13 +33,22 @@ truncate contact cascade; truncate product cascade; truncate tax cascade; truncate tax_class cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (1, 'Company 1', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into tax_class (tax_class_id, company_id, name) values (11, 1, 'tax') ; diff --git a/test/next_invoice_number.sql b/test/next_invoice_number.sql index c23443a..45b180c 100644 --- a/test/next_invoice_number.sql +++ b/test/next_invoice_number.sql @@ -22,14 +22,24 @@ select function_privs_are('numerus', 'next_invoice_number', array ['integer', 'd set client_min_messages to warning; truncate invoice_number_counter cascade; +truncate payment_method cascade; truncate company cascade; reset client_min_messages; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, invoice_number_format) -values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', '"F"YYYY0000') - , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', '"INV"000-YY') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, invoice_number_format, default_payment_method_id) +values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', '"F"YYYY0000', 111) + , (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', '"INV"000-YY', 222) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (111, 1, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into invoice_number_counter (company_id, year, currval) values (1, 2010, 5) , (2, 2010, 6) diff --git a/test/payment_method.sql b/test/payment_method.sql index 657fff7..5dadebb 100644 --- a/test/payment_method.sql +++ b/test/payment_method.sql @@ -59,9 +59,11 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; insert into company_user (company_id, user_id) @@ -69,12 +71,14 @@ values (2, 1) , (4, 5) ; -insert into payment_method(company_id, name, instructions) -values (2, 'Cash', 'Payment in cash.') - , (2, 'Wire Transfer', 'Please, transfer money to my Nigerian bank') - , (4, 'Pigeon', 'Send money via carrier pigeon.') +insert into payment_method(payment_method_id, company_id, name, instructions) +values (222, 2, 'Cash', 'Payment in cash.') + , (223, 2, 'Wire Transfer', 'Please, transfer money to my Nigerian bank') + , (444, 4, 'Pigeon', 'Send money via carrier pigeon.') ; +set constraints "company_default_payment_method_id_fkey" immediate; + prepare payment_method_data as select company_id, name, instructions from payment_method; diff --git a/test/product.sql b/test/product.sql index e2f76bc..499c657 100644 --- a/test/product.sql +++ b/test/product.sql @@ -68,6 +68,7 @@ select col_default_is('product', 'created_at', current_timestamp); set client_min_messages to warning; truncate product cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -77,11 +78,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/product_tax.sql b/test/product_tax.sql index 5fc699f..bb1ce12 100644 --- a/test/product_tax.sql +++ b/test/product_tax.sql @@ -38,6 +38,7 @@ truncate product cascade; truncate tax cascade; truncate tax_class cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -47,11 +48,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/tax.sql b/test/tax.sql index dbe3738..a2ef25a 100644 --- a/test/tax.sql +++ b/test/tax.sql @@ -59,6 +59,7 @@ truncate tax cascade; truncate tax_class cascade; truncate company_user cascade; truncate company cascade; +truncate payment_method cascade; truncate auth."user" cascade; reset client_min_messages; @@ -67,11 +68,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/test/tax_class.sql b/test/tax_class.sql index 3580251..28263e1 100644 --- a/test/tax_class.sql +++ b/test/tax_class.sql @@ -45,6 +45,7 @@ select col_hasnt_default('tax_class', 'name'); set client_min_messages to warning; truncate tax_class cascade; truncate company_user cascade; +truncate payment_method cascade; truncate company cascade; truncate auth."user" cascade; reset client_min_messages; @@ -54,11 +55,20 @@ values (1, 'demo@tandem.blog', 'Demo', 'test', 'invoicer', '44facbb30d8a419dfd4b , (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524', current_timestamp + interval '1 month') ; -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code) -values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR') - , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD') +set constraints "company_default_payment_method_id_fkey" deferred; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 222) + , (4, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', 'FR', 'USD', 444) ; +insert into payment_method (payment_method_id, company_id, name, instructions) +values (444, 4, 'cash', 'cash') + , (222, 2, 'cash', 'cash') +; + +set constraints "company_default_payment_method_id_fkey" immediate; + insert into company_user (company_id, user_id) values (2, 1) , (4, 5) diff --git a/verify/company_default_payment_method.sql b/verify/company_default_payment_method.sql new file mode 100644 index 0000000..ad8362c --- /dev/null +++ b/verify/company_default_payment_method.sql @@ -0,0 +1,9 @@ +-- Verify numerus:company_default_payment_method on pg + +begin; + +select default_payment_method_id +from numerus.company +where false; + +rollback; diff --git a/web/template/invoices/new.gohtml b/web/template/invoices/new.gohtml index aa9a30f..652048d 100644 --- a/web/template/invoices/new.gohtml +++ b/web/template/invoices/new.gohtml @@ -21,6 +21,7 @@ {{ template "input-field" .Number }} {{ template "input-field" .Date }} {{ template "input-field" .Notes }} + {{ template "select-field" .PaymentMethod }} {{- range $product := .Products }}