From 94745cfda3a001b9d39041a7a312fcfcdbef4717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20G=C3=B3mez?= Date: Thu, 2 Jul 2026 17:48:42 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20month-change=20MetricasDiarias=20corrupti?= =?UTF-8?q?on=20and=20-0=E2=82=AC=20display=20in=20Slack=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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€" --- run.py | 9 +++++++++ slack_reporter.py | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/run.py b/run.py index 23f80e2..df95ab0 100644 --- a/run.py +++ b/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.") diff --git a/slack_reporter.py b/slack_reporter.py index 7128519..66a4efc 100644 --- a/slack_reporter.py +++ b/slack_reporter.py @@ -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}%"