feat: integer cents money handling, order page fixes, and vendor filter persistence
Money Handling Architecture: - Store all monetary values as integer cents (€105.91 = 10591) - Add app/utils/money.py with Money class and conversion helpers - Add static/shared/js/money.js for frontend formatting - Update all database models to use _cents columns (Product, Order, etc.) - Update CSV processor to convert prices to cents on import - Add Alembic migration for Float to Integer conversion - Create .architecture-rules/money.yaml with 7 validation rules - Add docs/architecture/money-handling.md documentation Order Details Page Fixes: - Fix customer name showing 'undefined undefined' - use flat field names - Fix vendor info empty - add vendor_name/vendor_code to OrderDetailResponse - Fix shipping address using wrong nested object structure - Enrich order detail API response with vendor info Vendor Filter Persistence Fixes: - Fix orders.js: restoreSavedVendor now sets selectedVendor and filters - Fix orders.js: init() only loads orders if no saved vendor to restore - Fix marketplace-letzshop.js: restoreSavedVendor calls selectVendor() - Fix marketplace-letzshop.js: clearVendorSelection clears TomSelect dropdown - Align vendor selector placeholder text between pages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
# models/database/cart.py
|
||||
"""Cart item database model."""
|
||||
"""Cart item database model.
|
||||
|
||||
Money values are stored as integer cents (e.g., €105.91 = 10591).
|
||||
See docs/architecture/money-handling.md for details.
|
||||
"""
|
||||
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Float,
|
||||
ForeignKey,
|
||||
Index,
|
||||
Integer,
|
||||
@@ -13,6 +16,7 @@ from sqlalchemy import (
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
from app.utils.money import cents_to_euros, euros_to_cents
|
||||
from models.database.base import TimestampMixin
|
||||
|
||||
|
||||
@@ -22,6 +26,8 @@ class CartItem(Base, TimestampMixin):
|
||||
|
||||
Stores cart items per session, vendor, and product.
|
||||
Sessions are identified by a session_id string (from browser cookies).
|
||||
|
||||
Price is stored as integer cents for precision.
|
||||
"""
|
||||
|
||||
__tablename__ = "cart_items"
|
||||
@@ -33,7 +39,7 @@ class CartItem(Base, TimestampMixin):
|
||||
|
||||
# Cart details
|
||||
quantity = Column(Integer, nullable=False, default=1)
|
||||
price_at_add = Column(Float, nullable=False) # Store price when added to cart
|
||||
price_at_add_cents = Column(Integer, nullable=False) # Price in cents when added
|
||||
|
||||
# Relationships
|
||||
vendor = relationship("Vendor")
|
||||
@@ -49,7 +55,24 @@ class CartItem(Base, TimestampMixin):
|
||||
def __repr__(self):
|
||||
return f"<CartItem(id={self.id}, session='{self.session_id}', product_id={self.product_id}, qty={self.quantity})>"
|
||||
|
||||
# === PRICE PROPERTIES (Euro convenience accessors) ===
|
||||
|
||||
@property
|
||||
def price_at_add(self) -> float:
|
||||
"""Get price at add in euros."""
|
||||
return cents_to_euros(self.price_at_add_cents)
|
||||
|
||||
@price_at_add.setter
|
||||
def price_at_add(self, value: float):
|
||||
"""Set price at add from euros."""
|
||||
self.price_at_add_cents = euros_to_cents(value)
|
||||
|
||||
@property
|
||||
def line_total_cents(self) -> int:
|
||||
"""Calculate line total in cents."""
|
||||
return self.price_at_add_cents * self.quantity
|
||||
|
||||
@property
|
||||
def line_total(self) -> float:
|
||||
"""Calculate line total."""
|
||||
return self.price_at_add * self.quantity
|
||||
"""Calculate line total in euros."""
|
||||
return cents_to_euros(self.line_total_cents)
|
||||
|
||||
Reference in New Issue
Block a user