from pprint import pprint


def reativa_op(cursor, op):
    return([])

@@ -24,48 +24,946 @@
 nt%0A%0A
-%0Adef reativa_op(cursor, op):%0A    return(%5B%5D)
+from django.db import DatabaseError, transaction%0A%0A%0Adef reativa_op(cursor, op):%0A%0A    def update_op():%0A        sql = f%22%22%22%0A            UPDATE PCPC_020 o -- op%0A            SET%0A              o.SITUACAO = 4%0A            , o.COD_CANCELAMENTO = 0%0A            , o.DT_CANCELAMENTO = NULL%0A            WHERE 1=1%0A              AND o.ORDEM_PRODUCAO = %7Bop%7D%0A              AND o.SITUACAO %3C%3E 4%0A              AND o.COD_CANCELAMENTO %3C%3E 0%0A              AND o.DT_CANCELAMENTO IS NOT NULL%0A        %22%22%22%0A        cursor.execute(sql)%0A%0A    def update_lotes():%0A        sql = f%22%22%22%0A            UPDATE PCPC_040 l -- lote%0A            SET%0A              l.SITUACAO_ORDEM = 1 %0A            WHERE 1=1%0A              AND l.ORDEM_PRODUCAO = %7Bop%7D%0A              AND l.SITUACAO_ORDEM %3C%3E 1%0A        %22%22%22%0A        cursor.execute(sql)%0A%0A    try:%0A        with transaction.atomic():%0A            update_op()%0A            update_lotes()%0A    except DatabaseError:%0A        return False%0A    return True
 %0A

query reativa_op funcional