Fix month-change MetricasDiarias corruption and -0€ display in Slack report
- run.py: skip metricas update when campaign has no prior-month GACampaignMes record instead of silently writing into the new month - slack_reporter.py: round before formatting so small negative margins don't render as "-0€"
This commit is contained in:
parent
bfd130578a
commit
94745cfda3
9
run.py
9
run.py
@ -400,6 +400,8 @@ def run():
|
||||
if cambio_mes:
|
||||
# Ayer pertenece al mes anterior: redirigir escritura al GACampaignMes correcto
|
||||
prev_map = at.get_gcm_id_map_for_month(ayer.month, ayer.year)
|
||||
redirected = []
|
||||
omitidos = []
|
||||
for u in metricas_updates:
|
||||
gid = next(
|
||||
(item["campaign"]["google_campaign_id"]
|
||||
@ -408,6 +410,13 @@ def run():
|
||||
)
|
||||
if gid and gid in prev_map:
|
||||
u["airtable_id"] = prev_map[gid]
|
||||
redirected.append(u)
|
||||
else:
|
||||
omitidos.append(gid)
|
||||
metricas_updates = redirected
|
||||
if omitidos:
|
||||
print(f" ⚠️ {len(omitidos)} campañas sin GACampaignMes en {ayer.month}/{ayer.year}, "
|
||||
f"MetricasDiarias del día anterior omitido para no contaminar el mes nuevo: {omitidos}")
|
||||
at.batch_update_metricas_diarias(metricas_updates)
|
||||
print(" ✓ MetricasDiarias actualizado.")
|
||||
|
||||
|
||||
@ -73,8 +73,9 @@ def _trunc(text: str, limit: int = 2950) -> str:
|
||||
|
||||
|
||||
def _fmt_eur(v: float) -> str:
|
||||
sign = "+" if v > 0 else ""
|
||||
return f"{sign}{v:,.0f}€".replace(",", ".")
|
||||
v_int = round(v)
|
||||
sign = "+" if v_int > 0 else ""
|
||||
return f"{sign}{v_int:,.0f}€".replace(",", ".")
|
||||
|
||||
|
||||
def _curso(name: str, max_len: int = 40) -> str:
|
||||
@ -196,7 +197,8 @@ def build_and_send(collected: list, dry_run: bool, prev_month_metricas: dict = N
|
||||
return f"{v:,.0f}€".replace(",", ".")
|
||||
|
||||
def _marg(v: float) -> str:
|
||||
return ("+" if v >= 0 else "") + f"{v:,.0f}€".replace(",", ".")
|
||||
v_int = round(v)
|
||||
return ("+" if v_int >= 0 else "") + f"{v_int:,.0f}€".replace(",", ".")
|
||||
|
||||
def _pct(v: float) -> str:
|
||||
return ("+" if v >= 0 else "") + f"{v:.1f}%"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user