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:
@@ -34,3 +34,4 @@ import models.device # noqa: F401 Device, DevicePairRequest (step 1.8)
|
||||
import models.access_override # noqa: F401 AccessOverride (manager override, step 1.9)
|
||||
import models.support_challenge # noqa: F401 SupportChallenge (support access, step 1.10)
|
||||
import models.notification # noqa: F401 Notification, NotificationRead (step 1.11)
|
||||
import models.refund # noqa: F401 Refund, RefundItem (step 3.3e)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Refunds (plan step 3.3e): money given back for paid items, kept apart from the sale.
|
||||
|
||||
The paid items are never edited: a refund row says how much of which items went back, how
|
||||
(cash from the drawer or back to the card), in whose shift (that cashier's cash goes down)
|
||||
and what the fiscal device made of it (a credit note, or done by hand on the machine).
|
||||
"""
|
||||
from sqlalchemy import Column, Float, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from core.timeutil import UTCDateTime, utcnow
|
||||
from database import Base
|
||||
|
||||
|
||||
class Refund(Base):
|
||||
__tablename__ = "refunds"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
order_id = Column(Integer, ForeignKey("orders.id"), nullable=False, index=True)
|
||||
business_day_id = Column(Integer, ForeignKey("business_days.id"), nullable=True, index=True)
|
||||
shift_id = Column(Integer, ForeignKey("waiter_shifts.id"), nullable=True, index=True) # the refunding cashier's
|
||||
refunded_by = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
approved_by = Column(Integer, ForeignKey("users.id"), nullable=True) # a manager's override, if one was needed
|
||||
device_id = Column(Integer, ForeignKey("devices.id"), nullable=True)
|
||||
method = Column(String, nullable=False) # cash | card
|
||||
amount = Column(Float, nullable=False)
|
||||
reason = Column(Text, nullable=True)
|
||||
# None (fiscal off) | manual (cashier issues it on the machine) | pending | success | failed
|
||||
fiscal_status = Column(String, nullable=True)
|
||||
fiscal_reference = Column(String, nullable=True)
|
||||
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
|
||||
|
||||
items = relationship("RefundItem", back_populates="refund", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class RefundItem(Base):
|
||||
__tablename__ = "refund_items"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
refund_id = Column(Integer, ForeignKey("refunds.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
order_item_id = Column(Integer, ForeignKey("order_items.id"), nullable=False, index=True)
|
||||
quantity = Column(Float, nullable=False)
|
||||
amount = Column(Float, nullable=False)
|
||||
|
||||
refund = relationship("Refund", back_populates="items")
|
||||
order_item = relationship("OrderItem")
|
||||
Reference in New Issue
Block a user