feat(pos): refunds at the counter on a fiscal driver layer (platform-v2 3.3e)
- services/fiscal/: one driver interface (prepare_receipt / prepare_credit_note -> send,
credit_notes flag, status); the dTEC100extra folder bridge moved into txt_file.py as the
first driver, same command files. fiscal_service.py removed, callers moved.
- Refunds: models/refund.py + Alembic 0016 (refunds, refund_items; ordering.refunds for
existing owners/managers). services/refunds.py: today's business day, the cashier's open
shift, partial quantities, items from another shift need ordering.refunds or a manager's
approval (check()/authorize() return the override row). Paid items are never edited.
- POS: GET /api/pos/receipts, GET /api/pos/receipts/{id}, POST /api/pos/orders/{id}/refund
(cash opens the drawer; fiscal "manual" when the driver can't issue credit notes).
- Shift totals subtract refunds and now count discounts; day close and business-day
reports carry refunds.
- Terminal: Receipts mode (ReceiptsView, ReceiptPanel, logic/refunds.js), en/el texts.
- Tests: test_pos_refunds.py (12), terminal unit +1, terminal.mjs +7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""refunds + refund_items: money given back for paid items; key ordering.refunds for owners and managers (plan step 3.3e)
|
||||
|
||||
Revision ID: 0016_refunds
|
||||
Revises: 0015_item_claims
|
||||
Create Date: 2026-11-15 18:00:00
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from core.timeutil import UTCDateTime
|
||||
|
||||
|
||||
revision = '0016_refunds'
|
||||
down_revision = '0015_item_claims'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table('refunds',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('order_id', sa.Integer(), nullable=False),
|
||||
sa.Column('business_day_id', sa.Integer(), nullable=True),
|
||||
sa.Column('shift_id', sa.Integer(), nullable=True),
|
||||
sa.Column('refunded_by', sa.Integer(), nullable=False),
|
||||
sa.Column('approved_by', sa.Integer(), nullable=True),
|
||||
sa.Column('device_id', sa.Integer(), nullable=True),
|
||||
sa.Column('method', sa.String(), nullable=False),
|
||||
sa.Column('amount', sa.Float(), nullable=False),
|
||||
sa.Column('reason', sa.Text(), nullable=True),
|
||||
sa.Column('fiscal_status', sa.String(), nullable=True),
|
||||
sa.Column('fiscal_reference', sa.String(), nullable=True),
|
||||
sa.Column('created_at', UTCDateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['order_id'], ['orders.id']),
|
||||
sa.ForeignKeyConstraint(['business_day_id'], ['business_days.id']),
|
||||
sa.ForeignKeyConstraint(['shift_id'], ['waiter_shifts.id']),
|
||||
sa.ForeignKeyConstraint(['refunded_by'], ['users.id']),
|
||||
sa.ForeignKeyConstraint(['approved_by'], ['users.id']),
|
||||
sa.ForeignKeyConstraint(['device_id'], ['devices.id']),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
with op.batch_alter_table('refunds', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_refunds_id'), ['id'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_refunds_order_id'), ['order_id'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_refunds_business_day_id'), ['business_day_id'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_refunds_shift_id'), ['shift_id'], unique=False)
|
||||
|
||||
op.create_table('refund_items',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('refund_id', sa.Integer(), nullable=False),
|
||||
sa.Column('order_item_id', sa.Integer(), nullable=False),
|
||||
sa.Column('quantity', sa.Float(), nullable=False),
|
||||
sa.Column('amount', sa.Float(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['refund_id'], ['refunds.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['order_item_id'], ['order_items.id']),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
with op.batch_alter_table('refund_items', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_refund_items_id'), ['id'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_refund_items_refund_id'), ['refund_id'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_refund_items_order_item_id'), ['order_item_id'], unique=False)
|
||||
|
||||
# the new key `ordering.refunds` for the roles whose template has it (new users get it from
|
||||
# the template; existing owners and managers here)
|
||||
op.get_bind().execute(sa.text("insert or ignore into user_permissions (user_id, key) "
|
||||
"select id, 'ordering.refunds' from users where role in ('owner', 'store_manager')"))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.get_bind().execute(sa.text("delete from user_permissions where key = 'ordering.refunds'"))
|
||||
op.drop_table('refund_items')
|
||||
op.drop_table('refunds')
|
||||
Reference in New Issue
Block a user