feat: reconcile dossier timelines with billing

This commit is contained in:
Repinoid
2026-10-31 10:08:26 +03:00
parent cba97e25dc
commit 8481044dea
6 changed files with 403 additions and 3 deletions
+11
View File
@@ -208,6 +208,7 @@ def _create_schema(conn):
price TEXT,
qty TEXT,
sum TEXT,
vat_rate TEXT,
vat_mode TEXT NOT NULL DEFAULT 'with_vat',
source_document_id TEXT REFERENCES documents(id) ON DELETE CASCADE,
closed_by_document_id TEXT REFERENCES documents(id) ON DELETE SET NULL,
@@ -250,6 +251,16 @@ def _create_schema(conn):
CREATE INDEX IF NOT EXISTS idx_exceptions_dossier ON exceptions_queue(dossier_id);
CREATE INDEX IF NOT EXISTS idx_exceptions_batch ON exceptions_queue(batch_id);
""")
# Existing /tmp databases survive application restarts. Additive migrations
# therefore inspect the live schema before ALTER TABLE, while fresh databases
# receive the same column from the CREATE TABLE definition above.
timeline_columns = {
row["name"] for row in conn.execute("PRAGMA table_info(timeline_intervals)").fetchall()
}
if "vat_rate" not in timeline_columns:
conn.execute("ALTER TABLE timeline_intervals ADD COLUMN vat_rate TEXT")
if not getattr(_local, "in_transaction", False):
conn.commit()
def cleanup_db():
+2 -2
View File
@@ -48,7 +48,7 @@ def insert_interval(data):
fields = (
"dossier_id", "service_item_id", "charge_type", "valid_from", "valid_to",
"date_status", "date_basis", "raw_name", "config_params_json", "price",
"qty", "sum", "vat_mode", "source_document_id", "closed_by_document_id",
"qty", "sum", "vat_mode", "vat_rate", "source_document_id", "closed_by_document_id",
"table_ref", "quote", "status",
)
values = [data[field] for field in fields if field in data]
@@ -77,7 +77,7 @@ def update_interval(interval_id, values):
"""Обновить разрешённый набор полей интервала без динамических имён от клиента."""
allowed = {
"valid_from", "valid_to", "date_status", "date_basis", "raw_name",
"config_params_json", "price", "qty", "sum", "vat_mode", "table_ref",
"config_params_json", "price", "qty", "sum", "vat_mode", "vat_rate", "table_ref",
"quote", "status", "closed_by_document_id", "source_document_id",
}
selected = {field: value for field, value in values.items() if field in allowed}