diff --git a/service.py b/service.py index 82bbe0f..c0cdde7 100755 --- a/service.py +++ b/service.py @@ -20,6 +20,7 @@ PROCESSED_DIR = Path("data/processed") OUTPUT_DIR = Path("data/output") HTML_DIR = Path("data/html") SAP_B1_DIR = Path("data/sap_b1") +ERRORS_DIR = Path("data/errors") TEMPLATE_FILE = _BASE / "template.html" POST_TO_SAP_B1 = True @@ -242,10 +243,21 @@ def process_file(xml_path: Path): county = result["County"] log.info("CardCode={} (desde CRD1)".format(cardcode)) else: - cardcode = emisor - city = "" - county = "" - log.info("CardCode={} (fallback emisor)".format(cardcode)) + cardcode = "" + log.warning("No se obtuvo Socio de negocios para el {}.{}".format(emisor, lugar_entrega)) + try: + from mail_sender import send_mail + send_mail( + subject=f"OC {cab.get('numero_oc', '')} — Sin socio de negocios", + text=f"No se obtuvo Socio de negocios para el {emisor}.{lugar_entrega}", + ) + log.info("Correo de notificación enviado") + except Exception as e: + log.warning("Error enviando correo de notificación: {}".format(e)) + ERRORS_DIR.mkdir(parents=True, exist_ok=True) + shutil.move(str(xml_path), str(ERRORS_DIR / xml_path.name)) + log.info("📁 XML movido a errors/") + return item_catalog = get_item_catalog(cardcode) pricelist = get_price_list(cardcode)