def _q_no_id_empresa(): q = """SELECT gral_emp.no_id::character varying as no_id FROM gral_usr_suc JOIN gral_suc ON gral_suc.id = gral_usr_suc.gral_suc_id JOIN gral_emp ON gral_emp.id = gral_suc.empresa_id WHERE gral_usr_suc.gral_usr_id =""" for row in HelperPg.query(conn, "{0}{1}".format(q, user_id)): # Just taking first row of query result return row['no_id']
def pg_query(self, conn, sql): try: self.logger.debug("Performing query: {}".format(sql)) return HelperPg.query(conn, sql) except psycopg2.Error as e: raise DocBuilderStepError( "An error occurred when executing query: {}".format(e)) except Exception as e: raise DocBuilderStepError(e)
def _q_serie_folio(): q = """select fac_cfds_conf_folios.serie as serie, fac_cfds_conf_folios.folio_actual::character varying as folio FROM gral_suc AS SUC LEFT JOIN fac_cfds_conf ON fac_cfds_conf.gral_suc_id = SUC.id LEFT JOIN fac_cfds_conf_folios ON fac_cfds_conf_folios.fac_cfds_conf_id = fac_cfds_conf.id LEFT JOIN gral_usr_suc AS USR_SUC ON USR_SUC.gral_suc_id = SUC.id WHERE fac_cfds_conf_folios.proposito = 'FAC' AND USR_SUC.gral_usr_id=""" for row in HelperPg.query(conn, "{0}{1}".format(q, user_id)): # Just taking first row of query result return {'SERIE': row['serie'], 'FOLIO': row['folio']}
def create(conn, user_id, cust_id): """creates a prefactura""" q = '''SELECT * FROM fac_global_prefact( {}::integer, {}::integer )'''.format( user_id, cust_id) res = HelperPg.query(conn, q, True) if len(res) != 1: raise Exception( 'unexpected result regarding execution of fac_global_prefact') return (res.pop())[0]
def remove_bad_atempt(conn, prefact_id): logger.debug("Executing sql to remove attempt failed".format(prefact_id)) q = """SELECT * FROM fac_global_rm_attempt( {}::integer ) AS result( rc integer, msg text )""".format(prefact_id) res = HelperPg.query(conn, q, True) if len(res) != 1: raise Exception( 'unexpected result regarding execution of fac_global_bad_atempt') rcode, rmsg = res.pop() if rcode != 0: raise Exception(rmsg)
def make_remain_prefacts_up(conn, user_id): """deals with the remain prefacts which are opened""" q = """SELECT * FROM fac_global_make_up( {}::integer ) AS result( rc integer, msg text )""".format(user_id) res = HelperPg.query(conn, q, True) if len(res) != 1: raise Exception( 'unexpected result regarding execution of fac_global_make_up') rcode, rmsg = res.pop() if rcode != 0: raise Exception(rmsg)
def validation(conn, user_id): """checks coherency before creation prefactura""" q = """SELECT * FROM fac_global_validation( {}::integer ) AS result( rc integer, msg text )""".format(user_id) res = HelperPg.query(conn, q, True) if len(res) != 1: raise Exception( 'unexpected result regarding execution of fac_global_validation') rcode, rmsg = res.pop() if rcode != 0: raise Exception(rmsg)