From 2a73c8a311840b0f2d69f3f85716261bbd2b0b20 Mon Sep 17 00:00:00 2001 From: rodley82 Date: Tue, 25 Nov 2025 12:38:19 -0300 Subject: [PATCH] generacion comprobantes --- afip_ingresar_generacion_comprobantes.lua | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 afip_ingresar_generacion_comprobantes.lua diff --git a/afip_ingresar_generacion_comprobantes.lua b/afip_ingresar_generacion_comprobantes.lua new file mode 100644 index 0000000..c6bfa81 --- /dev/null +++ b/afip_ingresar_generacion_comprobantes.lua @@ -0,0 +1,57 @@ +local json = require("json") + +---------------------------------------------------------------------- +-- Helpers +---------------------------------------------------------------------- +local function logErrorAndExit(message) + log(message) + error(message) +end + +---------------------------------------------------------------------- +-- Main logic +---------------------------------------------------------------------- +local function main() + log("afip_ingresar_generacion_comprobantes: starting") + + -------------------------------------------------------------------- + -- Decode payload (currently unused but kept for future extensibility) + -------------------------------------------------------------------- + local payload, err = json.decode(json_payload or "{}") + if err then + logErrorAndExit("afip_ingresar_generacion_comprobantes: error decoding payload: " .. err) + end + + -------------------------------------------------------------------- + -- Click on the Generar Comprobantes button + -- This mirrors the Go logic that waits for and clicks the element + -- with id="btn_gen_cmp" using chromedp. + -------------------------------------------------------------------- + local btnId = "btn_gen_cmp" + + -- Ensure the element is visible first + err = waitVisibleById(btnId) + if err then + logErrorAndExit( + "afip_ingresar_generacion_comprobantes: waitVisibleById failed for btnId= " .. + tostring(btnId) .. ": " .. tostring(err) + ) + end + + -- Click using id + err = clickElementById(btnId) + if err then + logErrorAndExit( + "afip_ingresar_generacion_comprobantes: clickElementById failed for btnId= " .. + tostring(btnId) .. ": " .. tostring(err) + ) + end + + log("afip_ingresar_generacion_comprobantes: completed successfully") +end + +local ok, err = pcall(main) +if not ok then + -- Let Go see this as a Lua error so it can fall back to legacy + logErrorAndExit("afip_ingresar_generacion_comprobantes failed: " .. tostring(err)) +end