
Amazon Fba Calculator
- 4 installs
- 41 repo stars
- Updated April 19, 2026
- liangdabiao/amazon-skills-liang
Helps with ai & agent building tasks.
About
amazon-fba-calculator is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- amazon-fba-calculator
- AI & Agent Building
- AI-coding skill
Amazon Fba Calculator by the numbers
- 4 all-time installs (skills.sh)
- Ranked #13,348 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/liangdabiao/amazon-skills-liang --skill amazon-fba-calculatorAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 4 |
|---|---|
| repo stars | ★ 41 |
| Last updated | April 19, 2026 |
| Repository | liangdabiao/amazon-skills-liang ↗ |
What it does
Helps with ai & agent building tasks.
Files
亚马逊FBA计算器(精简版)
基于产品尺寸和重量的精确FBA费用计算。
功能
- 尺寸层级检测 - 自动分类
- FBA履约费用 - 2024年费率
- 月度仓储费 - 标准和旺季
- 长期仓储费 - 271天以上库存
- 推荐费 - 按类目
- 利润分析 - 毛/净利润率,投资回报率
- 优化建议 - 尺寸、重量、库存
尺寸层级(2024)
| 层级 | 最大重量 | 最大尺寸 |
|---|---|---|
| 小型标准 | 1磅 | 15"×12"×0.75" |
| 大型标准 | 20磅 | 18"×14"×8" |
| 小型大件 | 70磅 | 60"×30" |
| 中型大件 | 150磅 | 长度+周长 ≤108" |
| 大型大件 | 150磅 | 长度+周长 ≤165" |
| 特殊大件 | >150磅 | >165" |
输入
{
"length": 10.0,
"width": 6.0,
"height": 3.0,
"weight": 1.2,
"selling_price": 29.99,
"product_cost": 8.00,
"inbound_shipping_cost": 1.50,
"category": "kitchen"
}输出
- 尺寸层级分类
- 费用明细表格
- 利润指标(利润率,投资回报率)
- 优化建议
使用方法
python3 scripts/calculator.py
python3 scripts/calculator.py '{"length": 10, "width": 6, ...}' --zh---
_版本 1.0.0 | 平台:亚马逊 | 变体:精简版_
Amazon FBA 费用计算器 — 原理详解
概述
本工具基于 Amazon 2024 年 FBA(Fulfillment by Amazon)费率表,通过产品的物理尺寸、重量、售价和品类信息,精确计算所有 FBA 相关费用并输出利润分析报告。
核心计算原理
1. 尺寸分级判定(Size Tier)
Amazon 根据产品的最长边、次长边、最短边和重量将所有商品归入 6 个尺寸等级,每个等级对应完全不同的费用结构:
输入: length=10", width=6", height=3", weight=1.2lb
第1步: 将三维尺寸降序排列 → L=10, W=6, H=3
第2步: 逐级判定:
Small Standard → weight≤16oz 且 L≤15", W≤12", H≤0.75" → ❌ (H=3" > 0.75")
Large Standard → weight≤20lb 且 L≤18", W≤14", H≤8" → ✅ 匹配为什么这很重要:尺寸等级决定了配送费率。一个 0.8" 厚的产品如果优化包装到 0.75" 以内,可以从 Large Standard 降级到 Small Standard,单件配送费可节省约 $2-3。
2. 体积重量与计费重量
体积重量 = (长 × 宽 × 高) / 139 # Amazon 使用 139 的除数
计费重量 = max(实际重量, 体积重量) # 取较大值原理:轻抛货(如枕头)虽然实际重量轻,但占用仓储和运输空间大,Amazon 按体积重量计费。calculator.py:152-159 实现了这一逻辑。
3. FBA 配送费计算
配送费采用阶梯定价,不同尺寸等级有不同的计算方式:
| 尺寸等级 | 计费规则 |
|---|---|
| Small Standard | 基础 $3.22 + 超过 4oz 部分每盎司 $0.08 |
| Large Standard | 按重量区间阶梯:0-4oz → $3.86,4-8oz → $4.08,...,超过 3lb 每磅 +$0.38 |
| Small/Medium Oversize | 基础费 + 超过 1lb 部分每磅 $0.42 |
| Large/Special Oversize | 基础费 + 超过 90lb 部分每磅 $0.83 |
calculator.py:318-362 中的 calculate_fba_fulfillment_fee 函数实现了完整的阶梯计算。
4. 月度仓储费
仓储费 = 体积(立方英尺) × 费率
体积 = (长 × 宽 × 高) / 1728 # 立方英寸转立方英尺
费率:
标准季 (1-9月): 标准尺寸 $0.78/ft³, 超大尺寸 $0.56/ft³
旺季 (10-12月): 标准尺寸 $2.40/ft³, 超大尺寸 $1.40/ft³旺季费率是标准季的 3 倍以上。calculator.py:365-373 自动根据当前月份判断季节。
5. 长期仓储费
库存天数 271-365天: $1.50/ft³
库存天数 > 365天: $6.90/ft³ (超过365天部分)这是 Amazon 促使卖家加速库存周转的手段。calculator.py:376-382 实现了此逻辑。
6. 销售佣金(Referral Fee)
根据产品品类按售价百分比收取:
| 品类 | 佣金率 |
|---|---|
| 电子产品/电脑/相机 | 8% |
| 珠宝 | 20% |
| 服装 | 17% |
| 大部分其他品类 | 15%(默认) |
完整费率表见 calculator.py:104-126。
7. 利润分析
毛利润 = 售价 - 产品成本 - 佣金 - FBA配送费
净利润 = 售价 - 产品成本 - 所有费用(含仓储、运输、移除)
毛利率 = 毛利润 / 售价
净利率 = 净利润 / 售价
ROI = 净利润 / (产品成本 + 入库运输成本)calculator.py:417-425 实现了完整的利润计算链路。
8. 智能优化建议
脚本内置了 5 类优化检测逻辑(calculator.py:446-496):
- 尺寸优化:检测是否接近上一级尺寸阈值,给出缩小包装建议
- 体积重量优化:当体积重量 > 实际重量的 1.5 倍时发出警告
- 库存周转优化:库存天数 > 45 天时建议加速周转
- 长期仓储预警:库存龄 > 180 天时预警 271 天后的长期仓储费
- 利润率预警:净利率 < 15% 时建议提价或降本
使用方法
# 使用默认测试数据
python3 scripts/calculator.py
# 传入自定义产品参数
python3 scripts/calculator.py '{"length":10,"width":6,"height":3,"weight":1.2,"selling_price":29.99,"product_cost":8.00,"inbound_shipping_cost":1.50,"category":"kitchen"}'
# 中文输出
python3 scripts/calculator.py --zh数据来源
本技能的所有费用数据均来自内置的2024年Amazon FBA费率表,硬编码在 calculator.py 中的多个字典数据结构内,无任何外部API调用。具体包括以下约30条规则:FBA_FULFILLMENT_FEES 字典定义了6个尺寸等级(Small Standard、Large Standard、Small Oversize、Medium Oversize、Large Oversize、Special Oversize)的阶梯配送费率;STORAGE_FEE_PER_CUBIC_FOOT 字典定义了标准季(1-9月)和旺季(10-12月)的仓储费率;REFERRAL_FEE_RATES 字典定义了各品类的销售佣金比例(默认15%,珠宝20%,服装17%,电子产品8%等);此外还包含长期仓储费率、移除费、退货处理费等费用规则。
用户需提供产品物理参数(长、宽、高、重量)、售价、产品成本、入库运输成本、品类和库存天数等输入参数。脚本根据这些输入自动判定尺寸等级、计算体积重量,并查表得出各项费用。费率数据为固定快照,不会自动更新,建议卖家定期对照Amazon官方最新费率表进行核对。
目前仅支持美国站(US)的费率体系,不包含广告费、促销折扣、退货成本等可变费用项目。
局限性
- 费率数据来源于 Amazon 2024 年官方 FBA 费率表,硬编码在脚本中
- 仅覆盖 美国站 的费率
- 不包含广告费、促销折扣、退货成本等可变费用
- 实际费用可能因 Amazon 政策调整而变化,建议定期核对官方费率
#!/usr/bin/env python3
"""
Amazon FBA Calculator - Core Engine
Amazon FBA FeeCalculate - Core Engine
Features:
- SizedivideLevelJudgment (Size Tier)
- FBA Fulfillment Fee Precise calculation
- Monthly Storage Fee
- Referral Fee
- Long-term Storage Fee
- Profit Analysis
- FeeOptimization Suggestions
Based on 2024 years Amazon FBA Rate
Version: 1.0.0
"""
import json
from dataclasses import dataclass, field
from typing import List, Dict, Optional, Tuple
from enum import Enum
from datetime import datetime
import sys
class SizeTier(Enum):
"""FBA SizedivideLevel"""
SMALL_STANDARD = "Small Standard"
LARGE_STANDARD = "Large Standard"
SMALL_OVERSIZE = "Small Oversize"
MEDIUM_OVERSIZE = "Medium Oversize"
LARGE_OVERSIZE = "Large Oversize"
SPECIAL_OVERSIZE = "Special Oversize"
class StorageSeason(Enum):
"""StorageSeason"""
STANDARD = "standard" # Jan-Sep
PEAK = "peak" # Oct-Dec
# ============================================================
# 2024 FBA RateTable
# ============================================================
# FBA Fulfillment Fee (Fulfillmentfee) - 2024
FBA_FULFILLMENT_FEES = {
SizeTier.SMALL_STANDARD: {
# heavy quantity (oz): Fee
"base": 3.22,
"per_oz_above_4": 0.08,
"max_weight_oz": 16,
},
SizeTier.LARGE_STANDARD: {
# By weight tier
"tiers": [
(4, 3.86), # 0-4 oz
(8, 4.08), # 4+ to 8 oz
(12, 4.24), # 8+ to 12 oz
(16, 4.75), # 12+ to 16 oz (1 lb)
(32, 5.40), # 1+ to 2 lb
(48, 6.10), # 2+ to 3 lb
(320, 6.10), # 3+ to 20 lb (base + per lb)
],
"per_lb_above_3": 0.38,
},
SizeTier.SMALL_OVERSIZE: {
"base": 9.73,
"per_lb_above_1": 0.42,
},
SizeTier.MEDIUM_OVERSIZE: {
"base": 19.05,
"per_lb_above_1": 0.42,
},
SizeTier.LARGE_OVERSIZE: {
"base": 89.98,
"per_lb_above_90": 0.83,
},
SizeTier.SPECIAL_OVERSIZE: {
"base": 158.49,
"per_lb_above_90": 0.83,
},
}
# Monthly Storage Fee (monthsStoragefee) - 2024
STORAGE_FEE_PER_CUBIC_FOOT = {
SizeTier.SMALL_STANDARD: {"standard": 0.78, "peak": 2.40},
SizeTier.LARGE_STANDARD: {"standard": 0.78, "peak": 2.40},
SizeTier.SMALL_OVERSIZE: {"standard": 0.56, "peak": 1.40},
SizeTier.MEDIUM_OVERSIZE: {"standard": 0.56, "peak": 1.40},
SizeTier.LARGE_OVERSIZE: {"standard": 0.56, "peak": 1.40},
SizeTier.SPECIAL_OVERSIZE: {"standard": 0.56, "peak": 1.40},
}
# Long-term Storage Fee (PeriodStoragefee) - 2024
LONG_TERM_STORAGE_FEE = {
"271_365_days": 1.50, # Per cubic foot
"over_365_days": 6.90, # Per cubic foot
}
# Referral Fee (CommissionRate)
REFERRAL_FEE_RATES = {
"default": 0.15,
"electronics": 0.08,
"computers": 0.08,
"camera": 0.08,
"video_games": 0.15,
"books": 0.15,
"clothing": 0.17,
"shoes": 0.15,
"jewelry": 0.20,
"watches": 0.15,
"furniture": 0.15,
"home": 0.15,
"kitchen": 0.15,
"beauty": 0.15,
"health": 0.15,
"grocery": 0.15,
"pet": 0.15,
"toys": 0.15,
"baby": 0.15,
"sports": 0.15,
"automotive": 0.12,
}
# Removal/Disposal Fee
REMOVAL_FEE = {
SizeTier.SMALL_STANDARD: 0.97,
SizeTier.LARGE_STANDARD: 0.97,
SizeTier.SMALL_OVERSIZE: 4.15,
SizeTier.MEDIUM_OVERSIZE: 4.15,
SizeTier.LARGE_OVERSIZE: 6.87,
SizeTier.SPECIAL_OVERSIZE: 6.87,
}
# ============================================================
# Data Structures
# ============================================================
@dataclass
class ProductDimensions:
"""ProductSize"""
length: float # inches
width: float # inches
height: float # inches
weight: float # lbs
@property
def dimensional_weight(self) -> float:
"""Volume heavy (DIM weight)"""
return (self.length * self.width * self.height) / 139
@property
def billable_weight(self) -> float:
"""Billable weight (Take the greater of actual and dimensional weight)"""
return max(self.weight, self.dimensional_weight)
@property
def cubic_feet(self) -> float:
"""Cubic feet"""
return (self.length * self.width * self.height) / 1728
@property
def girth(self) -> float:
"""range (2*(width+height))"""
return 2 * (self.width + self.height)
@property
def length_plus_girth(self) -> float:
"""Degree + range"""
return self.length + self.girth
@dataclass
class ProductInput:
"""ProductInput"""
# BasicInformation
sku: str = "SKU001"
name: str = "Product"
# Size (inches)
length: float = 0.0
width: float = 0.0
height: float = 0.0
# heavy quantity (lbs)
weight: float = 0.0
# Price
selling_price: float = 0.0
product_cost: float = 0.0
# Logistics
inbound_shipping_cost: float = 0.0 # InboundCost/piece
# Other
category: str = "default"
monthly_units_sold: int = 100
inventory_days: int = 30
inventory_age_days: int = 0 # Libraryage (use at PeriodStoragefee)
@property
def dimensions(self) -> ProductDimensions:
return ProductDimensions(
length=self.length,
width=self.width,
height=self.height,
weight=self.weight
)
@dataclass
class FeeBreakdown:
"""FeeBreakdown"""
# FBA Fee
fba_fulfillment_fee: float = 0.0
monthly_storage_fee: float = 0.0
long_term_storage_fee: float = 0.0
referral_fee: float = 0.0
# OtherFee
inbound_shipping: float = 0.0
removal_fee: float = 0.0
# Summary
total_amazon_fees: float = 0.0
total_all_fees: float = 0.0
# Profit
gross_profit: float = 0.0
net_profit: float = 0.0
gross_margin: float = 0.0
net_margin: float = 0.0
roi: float = 0.0
@dataclass
class SizeTierInfo:
"""SizedivideLevelInformation"""
tier: SizeTier
reason: str
billable_weight: float
dimensional_weight: float
actual_weight: float
@dataclass
class OptimizationTip:
"""Optimization Suggestions"""
category: str
tip: str
tip_zh: str
potential_savings: float
@dataclass
class CalculationResult:
"""CalculateResult"""
product: ProductInput
size_tier: SizeTierInfo
fees: FeeBreakdown
optimization_tips: List[OptimizationTip]
summary: str
summary_zh: str
# ============================================================
# CoreCalculateFunction
# ============================================================
def determine_size_tier(dims: ProductDimensions) -> SizeTierInfo:
"""JudgmentSizedivideLevel"""
L, W, H = sorted([dims.length, dims.width, dims.height], reverse=True)
weight_oz = dims.weight * 16
# Small Standard: ≤15oz, ≤15"×12"×0.75"
if weight_oz <= 16 and L <= 15 and W <= 12 and H <= 0.75:
tier = SizeTier.SMALL_STANDARD
reason = f"Weight ≤1lb, dims ≤15×12×0.75"
# Large Standard: ≤20lb, ≤18"×14"×8"
elif dims.weight <= 20 and L <= 18 and W <= 14 and H <= 8:
tier = SizeTier.LARGE_STANDARD
reason = f"Weight ≤20lb, dims ≤18×14×8"
# Small Oversize: ≤70lb, ≤60"×30" (longest side ≤60, median ≤30)
elif dims.weight <= 70 and L <= 60 and W <= 30:
tier = SizeTier.SMALL_OVERSIZE
reason = f"Weight ≤70lb, longest ≤60, median ≤30"
# Medium Oversize: ≤150lb, length+girth ≤108"
elif dims.weight <= 150 and dims.length_plus_girth <= 108:
tier = SizeTier.MEDIUM_OVERSIZE
reason = f"Weight ≤150lb, L+girth ≤108"
# Large Oversize: ≤150lb, length+girth ≤165"
elif dims.weight <= 150 and dims.length_plus_girth <= 165:
tier = SizeTier.LARGE_OVERSIZE
reason = f"Weight ≤150lb, L+girth ≤165"
# Special Oversize
else:
tier = SizeTier.SPECIAL_OVERSIZE
reason = f"Exceeds Large Oversize limits"
return SizeTierInfo(
tier=tier,
reason=reason,
billable_weight=dims.billable_weight,
dimensional_weight=dims.dimensional_weight,
actual_weight=dims.weight
)
def calculate_fba_fulfillment_fee(size_tier: SizeTier, weight_lbs: float) -> float:
"""Calculate FBA Fulfillment"""
weight_oz = weight_lbs * 16
if size_tier == SizeTier.SMALL_STANDARD:
fee_info = FBA_FULFILLMENT_FEES[size_tier]
if weight_oz <= 4:
return fee_info["base"]
else:
extra_oz = min(weight_oz - 4, 12) # max 16oz total
return fee_info["base"] + extra_oz * fee_info["per_oz_above_4"]
elif size_tier == SizeTier.LARGE_STANDARD:
fee_info = FBA_FULFILLMENT_FEES[size_tier]
for max_oz, fee in fee_info["tiers"]:
if weight_oz <= max_oz:
return fee
# Above 3 lb
extra_lbs = weight_lbs - 3
base = 6.10
return base + extra_lbs * fee_info["per_lb_above_3"]
elif size_tier == SizeTier.SMALL_OVERSIZE:
fee_info = FBA_FULFILLMENT_FEES[size_tier]
if weight_lbs <= 1:
return fee_info["base"]
return fee_info["base"] + (weight_lbs - 1) * fee_info["per_lb_above_1"]
elif size_tier == SizeTier.MEDIUM_OVERSIZE:
fee_info = FBA_FULFILLMENT_FEES[size_tier]
if weight_lbs <= 1:
return fee_info["base"]
return fee_info["base"] + (weight_lbs - 1) * fee_info["per_lb_above_1"]
elif size_tier == SizeTier.LARGE_OVERSIZE:
fee_info = FBA_FULFILLMENT_FEES[size_tier]
if weight_lbs <= 90:
return fee_info["base"]
return fee_info["base"] + (weight_lbs - 90) * fee_info["per_lb_above_90"]
else: # Special Oversize
fee_info = FBA_FULFILLMENT_FEES[SizeTier.SPECIAL_OVERSIZE]
if weight_lbs <= 90:
return fee_info["base"]
return fee_info["base"] + (weight_lbs - 90) * fee_info["per_lb_above_90"]
def calculate_storage_fee(size_tier: SizeTier, cubic_feet: float, month: int = None) -> float:
"""CalculatemonthsStoragefee"""
if month is None:
month = datetime.now().month
season = "peak" if month >= 10 else "standard"
rate = STORAGE_FEE_PER_CUBIC_FOOT[size_tier][season]
return cubic_feet * rate
def calculate_long_term_storage_fee(cubic_feet: float, age_days: int) -> float:
"""CalculatePeriodStoragefee"""
if age_days > 365:
return cubic_feet * LONG_TERM_STORAGE_FEE["over_365_days"]
elif age_days > 270:
return cubic_feet * LONG_TERM_STORAGE_FEE["271_365_days"]
return 0.0
def calculate_referral_fee(selling_price: float, category: str) -> float:
"""CalculateCommission"""
rate = REFERRAL_FEE_RATES.get(category.lower(), REFERRAL_FEE_RATES["default"])
return selling_price * rate
def calculate_all_fees(product: ProductInput) -> Tuple[FeeBreakdown, SizeTierInfo]:
"""Calculateplace has Fee"""
dims = product.dimensions
size_info = determine_size_tier(dims)
# FBA Fulfillment
fba_fee = calculate_fba_fulfillment_fee(size_info.tier, size_info.billable_weight)
# monthsStoragefee ( by InventorydaysAllocate)
storage_monthly = calculate_storage_fee(size_info.tier, dims.cubic_feet)
storage_per_unit = storage_monthly * (product.inventory_days / 30)
# PeriodStoragefee
ltsf = calculate_long_term_storage_fee(dims.cubic_feet, product.inventory_age_days)
# Commission
referral = calculate_referral_fee(product.selling_price, product.category)
# Removal fee
removal = REMOVAL_FEE.get(size_info.tier, 0)
# Summary
total_amazon = fba_fee + storage_per_unit + ltsf + referral
total_all = total_amazon + product.inbound_shipping_cost
# ProfitCalculate
gross_profit = product.selling_price - product.product_cost - referral - fba_fee
net_profit = product.selling_price - product.product_cost - total_all
gross_margin = gross_profit / product.selling_price if product.selling_price > 0 else 0
net_margin = net_profit / product.selling_price if product.selling_price > 0 else 0
# ROI
total_investment = product.product_cost + product.inbound_shipping_cost
roi = net_profit / total_investment if total_investment > 0 else 0
fees = FeeBreakdown(
fba_fulfillment_fee=round(fba_fee, 2),
monthly_storage_fee=round(storage_per_unit, 2),
long_term_storage_fee=round(ltsf, 2),
referral_fee=round(referral, 2),
inbound_shipping=round(product.inbound_shipping_cost, 2),
removal_fee=round(removal, 2),
total_amazon_fees=round(total_amazon, 2),
total_all_fees=round(total_all, 2),
gross_profit=round(gross_profit, 2),
net_profit=round(net_profit, 2),
gross_margin=round(gross_margin, 4),
net_margin=round(net_margin, 4),
roi=round(roi, 4),
)
return fees, size_info
def generate_optimization_tips(product: ProductInput, fees: FeeBreakdown, size_info: SizeTierInfo) -> List[OptimizationTip]:
"""GenerateOptimization Suggestions"""
tips = []
# SizeOptimization
if size_info.tier == SizeTier.LARGE_STANDARD:
if product.length > 15 or product.width > 12:
tips.append(OptimizationTip(
category="Size",
tip="Consider smaller packaging to qualify for Small Standard tier",
tip_zh="Consider reducing package size to reach small standardLevelother",
potential_savings=fees.fba_fulfillment_fee - 3.22
))
# heavy quantityOptimization
if size_info.dimensional_weight > size_info.actual_weight * 1.5:
tips.append(OptimizationTip(
category="Weight",
tip="Product is being charged by dimensional weight. Reduce package size.",
tip_zh="ProductCharge by dimensional weight。ReducePackagingSizeCan reduceFee。",
potential_savings=0
))
# Inventoryweeksconvert
if product.inventory_days > 45:
tips.append(OptimizationTip(
category="Inventory",
tip=f"Inventory days ({product.inventory_days}) is high. Faster turnover reduces storage fees.",
tip_zh=f"Inventorydays ({product.inventory_days}) biasHigh。add fast weeksconvertCanReduceStoragefee。",
potential_savings=fees.monthly_storage_fee * 0.3
))
# PeriodStorage
if product.inventory_age_days > 180:
tips.append(OptimizationTip(
category="Long-term Storage",
tip="Watch out for long-term storage fees after 271 days",
tip_zh="Note 271 daysWill generate afterPeriodStoragefee",
potential_savings=0
))
# Profit Margin
if fees.net_margin < 0.15:
tips.append(OptimizationTip(
category="Pricing",
tip="Net margin below 15%. Consider raising price or reducing costs.",
tip_zh="Net Margin low at 15%。Consider raising price or reducingCost。",
potential_savings=0
))
return tips
def calculate(product: ProductInput) -> CalculationResult:
"""MainCalculateFunction"""
fees, size_info = calculate_all_fees(product)
tips = generate_optimization_tips(product, fees, size_info)
# GenerateSummary
if fees.net_margin >= 0.20:
status = "✅ Healthy"
status_zh = "✅ Healthy"
elif fees.net_margin >= 0.10:
status = "⚠️ Marginal"
status_zh = "⚠️ side edge"
elif fees.net_margin >= 0:
status = "🔴 Low"
status_zh = "🔴 low "
else:
status = "💀 Loss"
status_zh = "💀 Loss"
summary = f"{status} | Net margin: {fees.net_margin*100:.1f}% | FBA fee: ${fees.fba_fulfillment_fee}"
summary_zh = f"{status_zh} | Net Margin: {fees.net_margin*100:.1f}% | FBAfee: ${fees.fba_fulfillment_fee}"
return CalculationResult(
product=product,
size_tier=size_info,
fees=fees,
optimization_tips=tips,
summary=summary,
summary_zh=summary_zh
)
# ============================================================
# OutputFormat
# ============================================================
def format_report(result: CalculationResult, lang: str = "en") -> str:
"""FormatReport"""
p = result.product
f = result.fees
s = result.size_tier
if lang == "zh":
lines = [
"💰 **FBA FeeCalculateReport**",
"",
f"**Product**: {p.name} ({p.sku})",
f"**Size**: {p.length}\" × {p.width}\" × {p.height}\"",
f"** heavy quantity**: {p.weight} lbs ({p.weight*16:.0f} oz)",
f"**Selling Price**: ${p.selling_price:.2f}",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
f"## 📏 SizedivideLevel: {s.tier.value}",
f" {s.reason}",
f" Billable weight: {s.billable_weight:.2f} lbs",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💵 FeeBreakdown",
"",
f"```",
f"Selling Price ${p.selling_price:.2f}",
f"────────────────────────────────",
f"ProductCost -${p.product_cost:.2f}",
f"FBA Fulfillment -${f.fba_fulfillment_fee:.2f}",
f"monthsStoragefee (Allocate) -${f.monthly_storage_fee:.2f}",
f"PlatformCommission -${f.referral_fee:.2f}",
f"InboundShipping -${f.inbound_shipping:.2f}",
]
if f.long_term_storage_fee > 0:
lines.append(f"PeriodStoragefee -${f.long_term_storage_fee:.2f}")
lines.extend([
f"────────────────────────────────",
f"Amazon FeeTotal ${f.total_amazon_fees:.2f}",
f"totalFee ${f.total_all_fees:.2f}",
f"────────────────────────────────",
f"Gross Profit ${f.gross_profit:.2f} ({f.gross_margin*100:.1f}%)",
f"Net Profit ${f.net_profit:.2f} ({f.net_margin*100:.1f}%)",
f"ROI {f.roi*100:.1f}%",
f"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
result.summary_zh,
])
if result.optimization_tips:
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💡 Optimization Suggestions",
"",
])
for i, tip in enumerate(result.optimization_tips, 1):
lines.append(f"**{i}. [{tip.category}]** {tip.tip_zh}")
if tip.potential_savings > 0:
lines.append(f" potential in Save: ${tip.potential_savings:.2f}")
lines.append("")
else:
lines = [
"💰 **FBA Fee Calculation Report**",
"",
f"**Product**: {p.name} ({p.sku})",
f"**Dimensions**: {p.length}\" × {p.width}\" × {p.height}\"",
f"**Weight**: {p.weight} lbs ({p.weight*16:.0f} oz)",
f"**Selling Price**: ${p.selling_price:.2f}",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
f"## 📏 Size Tier: {s.tier.value}",
f" {s.reason}",
f" Billable Weight: {s.billable_weight:.2f} lbs",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💵 Fee Breakdown",
"",
f"```",
f"Selling Price ${p.selling_price:.2f}",
f"────────────────────────────────",
f"Product Cost -${p.product_cost:.2f}",
f"FBA Fulfillment Fee -${f.fba_fulfillment_fee:.2f}",
f"Monthly Storage (pro-rated) -${f.monthly_storage_fee:.2f}",
f"Referral Fee -${f.referral_fee:.2f}",
f"Inbound Shipping -${f.inbound_shipping:.2f}",
]
if f.long_term_storage_fee > 0:
lines.append(f"Long-term Storage -${f.long_term_storage_fee:.2f}")
lines.extend([
f"────────────────────────────────",
f"Total Amazon Fees ${f.total_amazon_fees:.2f}",
f"Total All Fees ${f.total_all_fees:.2f}",
f"────────────────────────────────",
f"Gross Profit ${f.gross_profit:.2f} ({f.gross_margin*100:.1f}%)",
f"Net Profit ${f.net_profit:.2f} ({f.net_margin*100:.1f}%)",
f"ROI {f.roi*100:.1f}%",
f"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
result.summary,
])
if result.optimization_tips:
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💡 Optimization Tips",
"",
])
for i, tip in enumerate(result.optimization_tips, 1):
lines.append(f"**{i}. [{tip.category}]** {tip.tip}")
if tip.potential_savings > 0:
lines.append(f" Potential Savings: ${tip.potential_savings:.2f}")
lines.append("")
return "\n".join(lines)
# ============================================================
# CLI
# ============================================================
def main():
# TestData
test_product = ProductInput(
sku="TEST001",
name="Kitchen Gadget",
length=10.0,
width=6.0,
height=3.0,
weight=1.2,
selling_price=29.99,
product_cost=8.00,
inbound_shipping_cost=1.50,
category="kitchen",
monthly_units_sold=100,
inventory_days=45,
inventory_age_days=60,
)
# ParseCommand line parameter
if len(sys.argv) > 1:
try:
data = json.loads(sys.argv[1])
test_product = ProductInput(**data)
except:
pass
result = calculate(test_product)
lang = "zh" if "--zh" in sys.argv else "en"
print(format_report(result, lang))
if __name__ == "__main__":
main()