feat: add VAT tax rate, cost, and Letzshop feed settings
Product Model: - Add tax_rate_percent (NOT NULL, default 17) for Luxembourg VAT - Add cost_cents for profit calculation - Add profit calculation properties: net_price, vat_amount, profit, margin - Rename supplier_cost_cents to cost_cents MarketplaceProduct Model: - Add tax_rate_percent (NOT NULL, default 17) Vendor Model (Letzshop feed settings): - letzshop_default_tax_rate: Default VAT for new products (0, 3, 8, 14, 17) - letzshop_boost_sort: Product sort priority (0.0-10.0) - letzshop_delivery_method: nationwide, package_delivery, self_collect - letzshop_preorder_days: Pre-order shipping delay VAT Strategy: - Store prices as gross (VAT-inclusive) for B2C - Calculate net from gross when needed for profit - Luxembourg VAT rates: 0%, 3%, 8%, 14%, 17% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -100,6 +100,11 @@ class MarketplaceProduct(Base, TimestampMixin):
|
||||
sale_price_cents = Column(Integer) # Parsed numeric sale price in cents
|
||||
currency = Column(String(3), default="EUR")
|
||||
|
||||
# === TAX / VAT ===
|
||||
# Luxembourg VAT rates: 0 (exempt), 3 (super-reduced), 8 (reduced), 14 (intermediate), 17 (standard)
|
||||
# Prices are stored as gross (VAT-inclusive). Default to standard rate.
|
||||
tax_rate_percent = Column(Integer, default=17, nullable=False)
|
||||
|
||||
# === MEDIA ===
|
||||
image_link = Column(String)
|
||||
additional_image_link = Column(String) # Legacy single string
|
||||
|
||||
@@ -75,10 +75,15 @@ class Product(Base, TimestampMixin):
|
||||
download_url = Column(String)
|
||||
license_type = Column(String(50))
|
||||
|
||||
# === SUPPLIER TRACKING ===
|
||||
# === TAX / VAT ===
|
||||
# Luxembourg VAT rates: 0 (exempt), 3 (super-reduced), 8 (reduced), 14 (intermediate), 17 (standard)
|
||||
# Prices are stored as gross (VAT-inclusive). Tax rate is used for profit calculation.
|
||||
tax_rate_percent = Column(Integer, default=17, nullable=False)
|
||||
|
||||
# === SUPPLIER TRACKING & COST ===
|
||||
supplier = Column(String(50)) # 'codeswholesale', 'internal', etc.
|
||||
supplier_product_id = Column(String) # Supplier's product reference
|
||||
supplier_cost_cents = Column(Integer) # What we pay the supplier (in cents)
|
||||
cost_cents = Column(Integer) # What vendor pays to acquire (in cents) - for profit calculation
|
||||
margin_percent_x100 = Column(Integer) # Markup percentage * 100 (e.g., 25.5% = 2550)
|
||||
|
||||
# === VENDOR-SPECIFIC (No inheritance) ===
|
||||
@@ -165,16 +170,16 @@ class Product(Base, TimestampMixin):
|
||||
self.sale_price_cents = euros_to_cents(value) if value is not None else None
|
||||
|
||||
@property
|
||||
def supplier_cost(self) -> float | None:
|
||||
"""Get supplier cost in euros."""
|
||||
if self.supplier_cost_cents is not None:
|
||||
return cents_to_euros(self.supplier_cost_cents)
|
||||
def cost(self) -> float | None:
|
||||
"""Get cost in euros (what vendor pays to acquire)."""
|
||||
if self.cost_cents is not None:
|
||||
return cents_to_euros(self.cost_cents)
|
||||
return None
|
||||
|
||||
@supplier_cost.setter
|
||||
def supplier_cost(self, value: float | None):
|
||||
"""Set supplier cost from euros."""
|
||||
self.supplier_cost_cents = euros_to_cents(value) if value is not None else None
|
||||
@cost.setter
|
||||
def cost(self, value: float | None):
|
||||
"""Set cost from euros."""
|
||||
self.cost_cents = euros_to_cents(value) if value is not None else None
|
||||
|
||||
@property
|
||||
def margin_percent(self) -> float | None:
|
||||
@@ -188,6 +193,77 @@ class Product(Base, TimestampMixin):
|
||||
"""Set margin percent."""
|
||||
self.margin_percent_x100 = int(value * 100) if value is not None else None
|
||||
|
||||
# === TAX / PROFIT CALCULATION PROPERTIES ===
|
||||
|
||||
@property
|
||||
def net_price_cents(self) -> int | None:
|
||||
"""Calculate net price (excluding VAT) from gross price.
|
||||
|
||||
Formula: Net = Gross / (1 + rate/100)
|
||||
Example: €119 gross at 17% VAT = €119 / 1.17 = €101.71 net
|
||||
"""
|
||||
gross = self.effective_price_cents
|
||||
if gross is None:
|
||||
return None
|
||||
# Use integer math to avoid floating point issues
|
||||
# Net = Gross * 100 / (100 + rate)
|
||||
return int(gross * 100 / (100 + self.tax_rate_percent))
|
||||
|
||||
@property
|
||||
def net_price(self) -> float | None:
|
||||
"""Get net price in euros."""
|
||||
cents = self.net_price_cents
|
||||
return cents_to_euros(cents) if cents is not None else None
|
||||
|
||||
@property
|
||||
def vat_amount_cents(self) -> int | None:
|
||||
"""Calculate VAT amount in cents.
|
||||
|
||||
Formula: VAT = Gross - Net
|
||||
"""
|
||||
gross = self.effective_price_cents
|
||||
net = self.net_price_cents
|
||||
if gross is None or net is None:
|
||||
return None
|
||||
return gross - net
|
||||
|
||||
@property
|
||||
def vat_amount(self) -> float | None:
|
||||
"""Get VAT amount in euros."""
|
||||
cents = self.vat_amount_cents
|
||||
return cents_to_euros(cents) if cents is not None else None
|
||||
|
||||
@property
|
||||
def profit_cents(self) -> int | None:
|
||||
"""Calculate profit in cents.
|
||||
|
||||
Formula: Profit = Net Revenue - Cost
|
||||
Returns None if cost is not set.
|
||||
"""
|
||||
net = self.net_price_cents
|
||||
if net is None or self.cost_cents is None:
|
||||
return None
|
||||
return net - self.cost_cents
|
||||
|
||||
@property
|
||||
def profit(self) -> float | None:
|
||||
"""Get profit in euros."""
|
||||
cents = self.profit_cents
|
||||
return cents_to_euros(cents) if cents is not None else None
|
||||
|
||||
@property
|
||||
def profit_margin_percent(self) -> float | None:
|
||||
"""Calculate profit margin as percentage of net revenue.
|
||||
|
||||
Formula: Margin% = (Profit / Net) * 100
|
||||
Example: €41.71 profit on €101.71 net = 41.0% margin
|
||||
"""
|
||||
net = self.net_price_cents
|
||||
profit = self.profit_cents
|
||||
if net is None or profit is None or net == 0:
|
||||
return None
|
||||
return round((profit / net) * 100, 2)
|
||||
|
||||
# === EFFECTIVE PROPERTIES (Override Pattern) ===
|
||||
|
||||
@property
|
||||
|
||||
@@ -57,6 +57,26 @@ class Vendor(Base, TimestampMixin):
|
||||
letzshop_csv_url_en = Column(String) # URL for English CSV in Letzshop
|
||||
letzshop_csv_url_de = Column(String) # URL for German CSV in Letzshop
|
||||
|
||||
# ========================================================================
|
||||
# Letzshop Feed Settings (atalanda namespace)
|
||||
# ========================================================================
|
||||
# These are default values applied to all products in the Letzshop feed
|
||||
# See https://letzshop.lu/en/dev#google_csv for documentation
|
||||
|
||||
# Default VAT rate for new products: 0 (exempt), 3 (super-reduced), 8 (reduced), 14 (intermediate), 17 (standard)
|
||||
letzshop_default_tax_rate = Column(Integer, default=17, nullable=False)
|
||||
|
||||
# Product sort priority on Letzshop (0.0-10.0, higher = displayed first)
|
||||
# Note: Having all products rated above 7 is not permitted by Letzshop
|
||||
letzshop_boost_sort = Column(String(10), default="5.0") # Stored as string for precision
|
||||
|
||||
# Delivery method: 'nationwide', 'package_delivery', 'self_collect' (comma-separated for multiple)
|
||||
# 'nationwide' automatically includes package_delivery and self_collect
|
||||
letzshop_delivery_method = Column(String(100), default="package_delivery")
|
||||
|
||||
# Pre-order days: number of days before item ships (default 1 day)
|
||||
letzshop_preorder_days = Column(Integer, default=1)
|
||||
|
||||
# Status (vendor-specific, can differ from company status)
|
||||
is_active = Column(
|
||||
Boolean, default=True
|
||||
|
||||
Reference in New Issue
Block a user