numerus/deploy/quote_tax_amount.sql

25 lines
592 B
PL/PgSQL

-- Deploy numerus:quote_tax_amount to pg
-- requires: roles
-- requires: schema_numerus
-- requires: quote_product
-- requires: quote_product_tax
begin;
set search_path to numerus, public;
create or replace view quote_tax_amount as
select quote_id
, tax_id
, sum(round(round(price * quantity * (1 - discount_rate))::integer * tax_rate)::integer)::integer as amount
from quote_product
join quote_product_tax using (quote_product_id)
group by quote_id
, tax_id
;
grant select on table quote_tax_amount to invoicer;
grant select on table quote_tax_amount to admin;
commit;