Update routes/stylist.py
Browse files- routes/stylist.py +14 -4
routes/stylist.py
CHANGED
@@ -190,13 +190,23 @@ def get_monthly_revenue(account_id: str) -> Dict[str, Any]:
|
|
190 |
# Adiciona ao total dos últimos 6 meses
|
191 |
total_revenue_last_6_months += transfer.amount
|
192 |
|
|
|
193 |
result = list(monthly_data.values())
|
194 |
-
|
|
|
195 |
|
|
|
196 |
for i in range(len(result)):
|
197 |
current_month_data = result[i]
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
current_amount = current_month_data["amount"]
|
201 |
|
202 |
if previous_amount > 0:
|
@@ -205,7 +215,7 @@ def get_monthly_revenue(account_id: str) -> Dict[str, Any]:
|
|
205 |
growth_percentage = 100 if current_amount > 0 else 0
|
206 |
|
207 |
current_month_data["growth"] = {
|
208 |
-
"status": "up" if growth_percentage > 0 else "down",
|
209 |
"percentage": round(growth_percentage, 1),
|
210 |
"formatted": f"{round(growth_percentage, 1)}%"
|
211 |
}
|
|
|
190 |
# Adiciona ao total dos últimos 6 meses
|
191 |
total_revenue_last_6_months += transfer.amount
|
192 |
|
193 |
+
# Convertendo para lista e ordenando por mês
|
194 |
result = list(monthly_data.values())
|
195 |
+
# Ordenar do mês mais recente para o mais antigo
|
196 |
+
result.sort(key=lambda x: (now_ny.year * 12 + now_ny.month - (x["month"])) % 12)
|
197 |
|
198 |
+
# Calcular crescimento baseado no mês anterior
|
199 |
for i in range(len(result)):
|
200 |
current_month_data = result[i]
|
201 |
+
|
202 |
+
# Encontrar o mês anterior (próximo item na lista ordenada)
|
203 |
+
prev_index = i + 1 if i + 1 < len(result) else None
|
204 |
+
|
205 |
+
if prev_index is not None:
|
206 |
+
previous_amount = result[prev_index]["amount"]
|
207 |
+
else:
|
208 |
+
previous_amount = 0
|
209 |
+
|
210 |
current_amount = current_month_data["amount"]
|
211 |
|
212 |
if previous_amount > 0:
|
|
|
215 |
growth_percentage = 100 if current_amount > 0 else 0
|
216 |
|
217 |
current_month_data["growth"] = {
|
218 |
+
"status": "up" if growth_percentage > 0 else "down" if growth_percentage < 0 else "same",
|
219 |
"percentage": round(growth_percentage, 1),
|
220 |
"formatted": f"{round(growth_percentage, 1)}%"
|
221 |
}
|