Add the invoice_status relation and its i18n

This commit is contained in:
jordi fita mas 2023-02-07 16:45:27 +01:00
parent 608ea16152
commit 44e8f030b3
12 changed files with 213 additions and 1 deletions

View File

@ -0,0 +1,28 @@
-- Deploy numerus:available_invoice_status to pg
-- requires: schema_numerus
-- requires: invoice_status
-- requires: invoice_status_i18n
begin;
set search_path to numerus;
insert into invoice_status (invoice_status, name)
values ('created', 'Created')
, ('sent', 'Sent')
, ('paid', 'Paid')
, ('unpaid', 'Unpaid')
;
insert into invoice_status_i18n (invoice_status, lang_tag, name)
values ('created', 'ca', 'Creada')
, ('sent', 'ca', 'Enviada')
, ('paid', 'ca', 'Cobrada')
, ('unpaid', 'ca', 'No cobrada')
, ('created', 'es', 'Creada')
, ('sent', 'es', 'Enviada')
, ('paid', 'es', 'Cobrada')
, ('unpaid', 'es', 'No cobrada')
;
commit;

16
deploy/invoice_status.sql Normal file
View File

@ -0,0 +1,16 @@
-- Deploy numerus:invoice_status to pg
-- requires: schema_numerus
begin;
set search_path to numerus, public;
create table invoice_status (
invoice_status text primary key,
name text not null
);
grant select on table invoice_status to invoicer;
grant select on table invoice_status to admin;
commit;

View File

@ -0,0 +1,20 @@
-- Deploy numerus:invoice_status_i18n to pg
-- requires: schema_numerus
-- requires: invoice_status
-- requires: language
begin;
set search_path to numerus, public;
create table invoice_status_i18n (
invoice_status text not null references invoice_status,
lang_tag text not null references language,
name text not null,
primary key (invoice_status, lang_tag)
);
grant select on table invoice_status_i18n to invoicer;
grant select on table invoice_status_i18n to admin;
commit;

View File

@ -0,0 +1,10 @@
-- Revert numerus:available_invoice_status from pg
begin;
set search_path to numerus;
delete from invoice_status_i18n;
delete from invoice_status;
commit;

View File

@ -0,0 +1,7 @@
-- Revert numerus:invoice_status from pg
begin;
drop table if exists numerus.invoice_status;
commit;

View File

@ -0,0 +1,7 @@
-- Revert numerus:invoice_status_i18n from pg
begin;
drop table if exists numerus.invoice_status_i18n;
commit;

View File

@ -33,7 +33,7 @@ available_currencies [schema_numerus currency] 2023-01-24T14:54:18Z jordi fita m
country_code [schema_numerus] 2023-01-27T18:33:26Z jordi fita mas <jordi@tandem.blog> # Add domain for country codes
country [schema_numerus country_code] 2023-01-27T18:39:44Z jordi fita mas <jordi@tandem.blog> # Add the relation for countries
country_i18n [schema_numerus country_code language country] 2023-01-27T19:20:43Z jordi fita mas <jordi@tandem.blog> # Add table for localization of country names
available_countries [schema_numerus country] 2023-01-27T18:49:28Z jordi fita mas <jordi@tandem.blog> # Add the list of available countries
available_countries [schema_numerus country country_i18n] 2023-01-27T18:49:28Z jordi fita mas <jordi@tandem.blog> # 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 <jordi@tandem.blog> # Add the relation for companies
company_user [schema_numerus user company] 2023-01-24T17:50:06Z jordi fita mas <jordi@tandem.blog> # Add the relation of companies and their users
tax_rate [schema_numerus] 2023-01-28T11:33:39Z jordi fita mas <jordi@tandem.blog> # Add domain for tax rates
@ -42,3 +42,6 @@ contact [schema_numerus company extension_vat email extension_pg_libphonenumber
product [schema_numerus company tax] 2023-02-04T09:17:24Z jordi fita mas <jordi@tandem.blog> # Add relation for products
parse_price [schema_public] 2023-02-05T11:04:54Z jordi fita mas <jordi@tandem.blog> # Add function to convert from price to cents
to_price [schema_numerus] 2023-02-05T11:46:31Z jordi fita mas <jordi@tandem.blog> # Add function to format cents to prices
invoice_status [schema_numerus] 2023-02-07T14:50:26Z jordi fita mas <jordi@tandem.blog> # A relation of invoice status
invoice_status_i18n [schema_numerus invoice_status language] 2023-02-07T14:56:18Z jordi fita mas <jordi@tandem.blog> # 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 <jordi@tandem.blog> # Add the list of available invoice status

35
test/invoice_status.sql Normal file
View File

@ -0,0 +1,35 @@
-- Test invoice_status
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(15);
set search_path to numerus, public;
select has_table('invoice_status');
select has_pk('invoice_status' );
select table_privs_are('invoice_status', 'guest', array []::text[]);
select table_privs_are('invoice_status', 'invoicer', array ['SELECT']);
select table_privs_are('invoice_status', 'admin', array ['SELECT']);
select table_privs_are('invoice_status', 'authenticator', array []::text[]);
select has_column('invoice_status', 'invoice_status');
select col_is_pk('invoice_status', 'invoice_status');
select col_type_is('invoice_status', 'invoice_status', 'text');
select col_not_null('invoice_status', 'invoice_status');
select col_hasnt_default('invoice_status', 'invoice_status');
select has_column('invoice_status', 'name');
select col_type_is('invoice_status', 'name', 'text');
select col_not_null('invoice_status', 'name');
select col_hasnt_default('invoice_status', 'name');
select *
from finish();
rollback;

View File

@ -0,0 +1,44 @@
-- Test invoice_status_i18n
set client_min_messages to warning;
create extension if not exists pgtap;
reset client_min_messages;
begin;
select plan(23);
set search_path to numerus, public;
select has_table('invoice_status_i18n');
select has_pk('invoice_status_i18n' );
select col_is_pk('invoice_status_i18n', array['invoice_status', 'lang_tag']);
select table_privs_are('invoice_status_i18n', 'guest', array []::text[]);
select table_privs_are('invoice_status_i18n', 'invoicer', array ['SELECT']);
select table_privs_are('invoice_status_i18n', 'admin', array ['SELECT']);
select table_privs_are('invoice_status_i18n', 'authenticator', array []::text[]);
select has_column('invoice_status_i18n', 'invoice_status');
select col_is_fk('invoice_status_i18n', 'invoice_status');
select fk_ok('invoice_status_i18n', 'invoice_status', 'invoice_status', 'invoice_status');
select col_type_is('invoice_status_i18n', 'invoice_status', 'text');
select col_not_null('invoice_status_i18n', 'invoice_status');
select col_hasnt_default('invoice_status_i18n', 'invoice_status');
select has_column('invoice_status_i18n', 'lang_tag');
select col_is_fk('invoice_status_i18n', 'lang_tag');
select fk_ok('invoice_status_i18n', 'lang_tag', 'language', 'lang_tag');
select col_type_is('invoice_status_i18n', 'lang_tag', 'text');
select col_not_null('invoice_status_i18n', 'lang_tag');
select col_hasnt_default('invoice_status_i18n', 'lang_tag');
select has_column('invoice_status_i18n', 'name');
select col_type_is('invoice_status_i18n', 'name', 'text');
select col_not_null('invoice_status_i18n', 'name');
select col_hasnt_default('invoice_status_i18n', 'name');
select *
from finish();
rollback;

View File

@ -0,0 +1,21 @@
-- Verify numerus:available_invoice_status on pg
begin;
set search_path to numerus;
select 1 / count(*) from invoice_status where invoice_status = 'created' and name ='Created';
select 1 / count(*) from invoice_status where invoice_status = 'sent' and name ='Sent';
select 1 / count(*) from invoice_status where invoice_status = 'paid' and name ='Paid';
select 1 / count(*) from invoice_status where invoice_status = 'unpaid' and name ='Unpaid';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'created' and name ='Creada' and lang_tag = 'ca';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'created' and name ='Creada' and lang_tag = 'es';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'sent' and name ='Enviada' and lang_tag= 'ca';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'sent' and name ='Enviada' and lang_tag= 'es';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'paid' and name ='Cobrada' and lang_tag= 'ca';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'paid' and name ='Cobrada' and lang_tag= 'es';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'unpaid' and name ='No cobrada' and lang_tag= 'ca';
select 1 / count(*) from invoice_status_i18n where invoice_status = 'unpaid' and name ='No cobrada' and lang_tag= 'es';
rollback;

10
verify/invoice_status.sql Normal file
View File

@ -0,0 +1,10 @@
-- Verify numerus:invoice_status on pg
begin;
select invoice_status
, name
from numerus.invoice_status
where false;
rollback;

View File

@ -0,0 +1,11 @@
-- Verify numerus:invoice_status_i18n on pg
begin;
select invoice_status
, lang_tag
, name
from numerus.invoice_status_i18n
where false;
rollback;