Skip to content

Instantly share code, notes, and snippets.

@name1984
Created April 9, 2025 19:10
Show Gist options
  • Save name1984/a727935a6e7ad4d6cb9edff69bd80070 to your computer and use it in GitHub Desktop.
Save name1984/a727935a6e7ad4d6cb9edff69bd80070 to your computer and use it in GitHub Desktop.
asientos_con_diferencias = set()
for line in records:
analytic = line.analytic_account_id
if analytic:
try:
categ_line = line.x_studio_categ_cost
categ_analytic = analytic.x_studio_categ_cost
except Exception:
continue
if categ_line != categ_analytic:
# Marcar el asiento para el resumen final
asientos_con_diferencias.add(line.move_id.name)
# Agregar mensaje en el chatter del asiento contable
line.move_id.message_post(body=(
"⚠️ Diferencia en categoría de costo:\n"
"- Cuenta analítica: %s\n"
"- Valor en la línea: %s\n"
"- Valor actual en la cuenta analítica: %s"
% (analytic.name or 'Sin nombre', categ_line or 'Vacío', categ_analytic or 'Vacío')
))
# Mostrar popup si hubo diferencias encontradas
if asientos_con_diferencias:
raise UserError(
"Se encontraron diferencias en los siguientes asientos contables:\n- %s" %
"\n- ".join(sorted(asientos_con_diferencias))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment