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>
113 lines
3.2 KiB
Python
113 lines
3.2 KiB
Python
# tests/fixtures/customer_fixtures.py
|
|
"""
|
|
Customer-related test fixtures.
|
|
|
|
Note: Fixtures should NOT use db.expunge() as it breaks lazy loading.
|
|
See tests/conftest.py for details on fixture best practices.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from models.database.customer import Customer, CustomerAddress
|
|
from models.database.order import Order
|
|
|
|
|
|
@pytest.fixture
|
|
def test_customer(db, test_vendor):
|
|
"""Create a test customer."""
|
|
customer = Customer(
|
|
vendor_id=test_vendor.id,
|
|
email="testcustomer@example.com",
|
|
hashed_password="hashed_password",
|
|
first_name="John",
|
|
last_name="Doe",
|
|
customer_number="TEST001",
|
|
is_active=True,
|
|
)
|
|
db.add(customer)
|
|
db.commit()
|
|
db.refresh(customer)
|
|
return customer
|
|
|
|
|
|
@pytest.fixture
|
|
def test_customer_address(db, test_vendor, test_customer):
|
|
"""Create a test customer address."""
|
|
address = CustomerAddress(
|
|
vendor_id=test_vendor.id,
|
|
customer_id=test_customer.id,
|
|
address_type="shipping",
|
|
first_name="John",
|
|
last_name="Doe",
|
|
address_line_1="123 Main St",
|
|
city="Luxembourg",
|
|
postal_code="L-1234",
|
|
country="Luxembourg",
|
|
is_default=True,
|
|
)
|
|
db.add(address)
|
|
db.commit()
|
|
db.refresh(address)
|
|
return address
|
|
|
|
|
|
@pytest.fixture
|
|
def test_order(db, test_vendor, test_customer, test_customer_address):
|
|
"""Create a test order with customer/address snapshots."""
|
|
from datetime import datetime, timezone
|
|
|
|
order = Order(
|
|
vendor_id=test_vendor.id,
|
|
customer_id=test_customer.id,
|
|
order_number="TEST-ORD-001",
|
|
status="pending",
|
|
channel="direct",
|
|
subtotal=99.99,
|
|
total_amount=99.99,
|
|
currency="EUR",
|
|
order_date=datetime.now(timezone.utc),
|
|
# Customer snapshot
|
|
customer_first_name=test_customer.first_name,
|
|
customer_last_name=test_customer.last_name,
|
|
customer_email=test_customer.email,
|
|
customer_phone=None,
|
|
# Shipping address snapshot
|
|
ship_first_name=test_customer_address.first_name,
|
|
ship_last_name=test_customer_address.last_name,
|
|
ship_address_line_1=test_customer_address.address_line_1,
|
|
ship_city=test_customer_address.city,
|
|
ship_postal_code=test_customer_address.postal_code,
|
|
ship_country_iso="LU",
|
|
# Billing address snapshot
|
|
bill_first_name=test_customer_address.first_name,
|
|
bill_last_name=test_customer_address.last_name,
|
|
bill_address_line_1=test_customer_address.address_line_1,
|
|
bill_city=test_customer_address.city,
|
|
bill_postal_code=test_customer_address.postal_code,
|
|
bill_country_iso="LU",
|
|
)
|
|
db.add(order)
|
|
db.commit()
|
|
db.refresh(order)
|
|
return order
|
|
|
|
|
|
@pytest.fixture
|
|
def test_order_item(db, test_order, test_product):
|
|
"""Create a test order item."""
|
|
from models.database.order import OrderItem
|
|
|
|
order_item = OrderItem(
|
|
order_id=test_order.id,
|
|
product_id=test_product.id,
|
|
product_name="Test Product",
|
|
product_sku="TEST-SKU-001",
|
|
quantity=1,
|
|
unit_price=49.99,
|
|
total_price=49.99,
|
|
)
|
|
db.add(order_item)
|
|
db.commit()
|
|
db.refresh(order_item)
|
|
return order_item
|