dodil/erp-brick-tax

DODIL ERP brick: tax

src/brick_tax/migrations/00002_audit1/up.sql

-- 00002_audit1 (v0.1.1): the author's sub beside their email (a rule, a rate, a registration, an override: the approver is
-- refused if EITHER identity matches), and the tax of an ISSUED document stored at freeze (per line and per rate), so a
-- later change to the rounding code never changes issued tax. At the END of each CREATE in schema.sql (a new bucket) and
-- added here for a bucket on 00001. erp-migrate marks an ADD COLUMN DISRUPTIVE: migrate the test copy first, the live one
-- at a quiet hour, before rolling the 0.1.1 image. A document frozen before this has nothing stored to read back: it
-- keeps being read by recomputing, as before.
ALTER TABLE tax_registration ADD COLUMN created_sub VARCHAR;
ALTER TABLE tax_rate ADD COLUMN created_sub VARCHAR;
ALTER TABLE tax_rule ADD COLUMN created_sub VARCHAR;
ALTER TABLE tax_document_line ADD COLUMN override_by_sub VARCHAR;
ALTER TABLE tax_document_line ADD COLUMN calc_net NUMERIC(18,2);
ALTER TABLE tax_document_line ADD COLUMN calc_vat NUMERIC(18,2);
ALTER TABLE tax_document_line ADD COLUMN calc_vat_due NUMERIC(18,2);
ALTER TABLE tax_document_line ADD COLUMN calc_gross NUMERIC(18,2);

CREATE TABLE IF NOT EXISTS tax_document_summary (
    document_ref VARCHAR NOT NULL,
    tax_code VARCHAR NOT NULL,
    rate_pct NUMERIC(19,4),
    charged_pct NUMERIC(19,4),
    net NUMERIC(18,2),
    vat NUMERIC(18,2),
    vat_due NUMERIC(18,2),
    gross NUMERIC(18,2),
    created_at TIMESTAMP,
    updated_at TIMESTAMP,
    PRIMARY KEY (document_ref, tax_code)
);