feat(backend): expense lines (quantity, price before VAT, VAT %) and documents (PDF / photo)
An expense can list what it bought; the lines make its total (net, VAT half up per line), are
replaced on edit ([] removes them) and the total still can't drop below what was paid. Files kept
with an expense: POST/GET/DELETE /api/expenses/{id}/documents[/{doc}], PDF / JPG / PNG / WebP /
HEIC by their bytes, at most 15 MB, under MEDIA_DIR/expenses/<id>/ (removed with the expense).
Migration 0039.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Expense lines and documents (UI review 2026-11-20): what an expense bought (quantity, price
|
||||
before VAT, VAT rate; the lines make the total) and the files kept with it (the invoice as a
|
||||
PDF, a photo of the receipt).
|
||||
|
||||
Revision ID: 0039_expense_lines_documents
|
||||
Revises: 0038_lookup_indexes
|
||||
Create Date: 2026-11-20 16:00:00
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from core.timeutil import UTCDateTime
|
||||
|
||||
revision = '0039_expense_lines_documents'
|
||||
down_revision = '0038_lookup_indexes'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
'expense_lines',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('expense_id', sa.Integer(), nullable=False),
|
||||
sa.Column('position', sa.Integer(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=False),
|
||||
sa.Column('quantity', sa.Float(), nullable=False),
|
||||
sa.Column('unit_price', sa.Float(), nullable=False),
|
||||
sa.Column('vat_rate', sa.Float(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['expense_id'], ['expenses.id']),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_expense_lines_id', 'expense_lines', ['id'])
|
||||
op.create_index('ix_expense_lines_expense_id', 'expense_lines', ['expense_id'])
|
||||
op.create_table(
|
||||
'expense_documents',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('expense_id', sa.Integer(), nullable=False),
|
||||
sa.Column('filename', sa.String(), nullable=False),
|
||||
sa.Column('stored_name', sa.String(), nullable=False),
|
||||
sa.Column('content_type', sa.String(), nullable=False),
|
||||
sa.Column('size', sa.Integer(), nullable=False),
|
||||
sa.Column('uploaded_by_id', sa.Integer(), nullable=True),
|
||||
sa.Column('uploaded_at', UTCDateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['expense_id'], ['expenses.id']),
|
||||
sa.ForeignKeyConstraint(['uploaded_by_id'], ['users.id']),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_expense_documents_id', 'expense_documents', ['id'])
|
||||
op.create_index('ix_expense_documents_expense_id', 'expense_documents', ['expense_id'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table('expense_documents')
|
||||
op.drop_table('expense_lines')
|
||||
Reference in New Issue
Block a user