コード例 #1
0
ファイル: facxml.py プロジェクト: neftali-lopez/erp_cdgb
    def data_acq(self, conn, d_rdirs, **kwargs):

        usr_id = kwargs.get('usr_id', None)
        prefact_id = kwargs.get('prefact_id', None)

        if usr_id is None:
            raise DocBuilderStepError("user id not fed")
        if prefact_id is None:
            raise DocBuilderStepError("prefact id not fed")

        ed = self.__q_emisor(conn, usr_id)
        sp = self.__q_sign_params(conn, usr_id)

        # dirs with full emisor rfc path
        sslrfc_dir = os.path.join(d_rdirs['ssl'], ed['RFC'])

        cert_file = os.path.join(sslrfc_dir, self.__q_cert_file(conn, usr_id))
        certb64 = None
        with open(cert_file, 'rb') as f:
            content = f.read()
            certb64 = base64.b64encode(content).decode('ascii')

        conceptos = self.__q_conceptos(conn, prefact_id)
        traslados = self.__calc_traslados(conceptos,
                                          self.__q_ieps(conn, usr_id),
                                          self.__q_ivas(conn))

        return {
            'TIME_STAMP':
            '{0:%Y-%m-%dT%H:%M:%S}'.format(datetime.datetime.now()),
            'CONTROL':
            self.__q_serie_folio(conn, usr_id),
            'CERT_B64':
            certb64,
            'KEY_PRIVATE':
            os.path.join(sslrfc_dir, sp['PKNAME']),
            'XSLT_SCRIPT':
            os.path.join(d_rdirs['cfdi_xslt'], "cadenaoriginal_3_3.xslt"),
            'EMISOR':
            ed,
            'NUMERO_CERTIFICADO':
            self.__q_no_certificado(conn, usr_id),
            'RECEPTOR':
            self.__q_receptor(conn, prefact_id),
            'MONEDA':
            self.__q_moneda(conn, prefact_id),
            'METODO_PAGO':
            self.__q_metodo_pago(conn, prefact_id),
            'FORMA_PAGO':
            self.__q_forma_pago(conn, prefact_id),
            'LUGAR_EXPEDICION':
            self.__q_lugar_expedicion(conn, usr_id),
            'CONCEPTOS':
            conceptos,
            'TRASLADOS':
            traslados,
            'TOTALES':
            self.__calc_totales(conceptos)
        }
コード例 #2
0
ファイル: facpdf.py プロジェクト: gmas01/erp_saar
 def fetch_info(f):
     parser = xmlreader.SaxReader()
     try:
         return parser(f)
     except xml.sax.SAXParseException as e:
         raise DocBuilderStepError("cfdi xml could not be parsed : {}".format(e))
     except Exception as e:
         raise DocBuilderStepError("xsl could not be applied : {}".format(e))
コード例 #3
0
ファイル: gen.py プロジェクト: linuxero80/cfdiengine
 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)
コード例 #4
0
ファイル: facpdf.py プロジェクト: gmas01/erp_saar
    def data_acq(self, conn, d_rdirs, **kwargs):

        def fetch_info(f):
            parser = xmlreader.SaxReader()
            try:
                return parser(f)
            except xml.sax.SAXParseException as e:
                raise DocBuilderStepError("cfdi xml could not be parsed : {}".format(e))
            except Exception as e:
                raise DocBuilderStepError("xsl could not be applied : {}".format(e))

        def extra(serie_folio, c):
            try:
                return self.__load_extra_info(conn, serie_folio, c)
            except Exception as e:
                raise DocBuilderStepError("loading extra info fails: {}".format(e))

        rfc = kwargs.get('rfc', None)
        if rfc is None:
            raise DocBuilderStepError("rfc not found")

        xml = kwargs.get('xml', None)
        if xml is None:
            raise DocBuilderStepError("xml not found")
        f_xml = os.path.join(d_rdirs['cfdi_output'], rfc, xml)
        if not os.path.isfile(f_xml):
            raise DocBuilderStepError("cfdi xml not found")

        cap = kwargs.get('cap', 'SPA')
        if not cap in self.__CAPTIONS:
            raise DocBuilderStepError("caption {0} not found".format(cap))

        logo_filename = os.path.join(d_rdirs['images'], "{}_logo.png".format(rfc))
        if not os.path.isfile(logo_filename):
            raise DocBuilderStepError("logo image {0} not found".format(logo_filename))

        xml_parsed, original = fetch_info(f_xml)
        serie_folio = "%s%s" % (xml_parsed['CFDI_SERIE'], xml_parsed['CFDI_FOLIO'])
        lack = self.__cover_xml_lacks(conn, serie_folio, cap)
        einfo = extra(serie_folio, cap)
        f_qr = qrcode_cfdi(self.__VERIFICATION_URL, xml_parsed['UUID'],
            xml_parsed['INCEPTOR_RFC'], xml_parsed['RECEPTOR_RFC'],
            xml_parsed['CFDI_TOTAL'], xml_parsed['CFD_SEAL'][-8:]
        )

        return {
            'CAP_LOADED': self.__CAPTIONS[cap],
            'QRCODE': f_qr,
            'LOGO': logo_filename,
            'STAMP_ORIGINAL_STR': original,
            'XML_PARSED': xml_parsed,
            'XML_LACK': lack,
            'CUSTOMER_WWW': lack['WWW'],
            'CUSTOMER_PHONE': lack['TEL'],
            'FOOTER_ABOUT': "ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI",
            'EXTRA_INFO': einfo
        }
コード例 #5
0
ファイル: pagpdf.py プロジェクト: pianodaemon/erp
    def data_acq(self, conn, d_rdirs, **kwargs):
        def fetch_info(f):
            parser = xmlreader.SaxReader()
            try:
                return parser(f)
            except xml.sax.SAXParseException as e:
                raise DocBuilderStepError(
                    "cfdi xml could not be parsed : {}".format(e))
            except Exception as e:
                raise DocBuilderStepError(
                    "xsl could not be applied : {}".format(e))

        rfc = kwargs.get('rfc', None)
        if rfc is None:
            raise DocBuilderStepError("rfc not found")

        xml = kwargs.get('xml', None)
        if xml is None:
            raise DocBuilderStepError("xml not found")
        f_xml = os.path.join(d_rdirs['cfdi_output'], rfc, xml)
        if not os.path.isfile(f_xml):
            raise DocBuilderStepError("cfdi xml not found")

        xml_parsed, original = fetch_info(f_xml)

        f_qr = qrcode_cfdi(self.__VERIFICATION_URL, xml_parsed['UUID'],
                           xml_parsed['INCEPTOR_RFC'],
                           xml_parsed['RECEPTOR_RFC'],
                           xml_parsed['CFDI_TOTAL'],
                           xml_parsed['CFD_SEAL'][-8:])

        logo_filename = os.path.join(d_rdirs['images'],
                                     "{}_logo.png".format(rfc))
        if not os.path.isfile(logo_filename):
            raise DocBuilderStepError(
                "logo image {0} not found".format(logo_filename))

        return {
            'STAMP_ORIGINAL_STR':
            original,
            'XML_PARSED':
            xml_parsed,
            'QRCODE':
            f_qr,
            'LOGO':
            logo_filename,
            'FOOTER_ABOUT':
            "ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI",
        }
コード例 #6
0
    def data_acq(self, conn, d_rdirs, **kwargs):

        usr_id = kwargs.get('usr_id', None)

        if usr_id is None:
            raise DocBuilderStepError("user id not fed")

        ed = self.__q_emisor(conn, usr_id)
        sp = self.__q_sign_params(conn, usr_id)

        # dirs with full emisor rfc path
        sslrfc_dir = os.path.join(d_rdirs['ssl'], ed['RFC'])
        cert_file = os.path.join(sslrfc_dir, self.__q_cert_file(conn, usr_id))

        certb64 = None
        with open(cert_file, 'rb') as f:
            content = f.read()
            certb64 = base64.b64encode(content).decode('ascii')

        pag_id = kwargs.get('pag_id', None)

        if pag_id is None:
            raise DocBuilderStepError("pag id not fed")

        conceptos = self.__q_conceptos(conn)

        return {
            'MONEDA': self.__q_moneda(conn, pag_id),
            'TIME_STAMP':
            '{0:%Y-%m-%dT%H:%M:%S}'.format(datetime.datetime.now()),
            'CONTROL': self.__q_serie_folio(conn, usr_id),
            'CERT_B64': certb64,
            'KEY_PRIVATE': os.path.join(sslrfc_dir, sp['PKNAME']),
            'XSLT_SCRIPT': os.path.join(d_rdirs['cfdi_xslt'], self.__XSLT_PAG),
            'EMISOR': ed,
            'NUMERO_CERTIFICADO': self.__q_no_certificado(conn, usr_id),
            'RECEPTOR': self.__q_receptor(conn, pag_id),
            'LUGAR_EXPEDICION': self.__q_lugar_expedicion(conn, usr_id),
            'CONCEPTOS': conceptos,
            'COMPLEMENTO_PAGOS': self.__q_pago(conn, pag_id)
        }
コード例 #7
0
ファイル: facpdf.py プロジェクト: pianodaemon/erp_sumar
    def __harness_cove_info(self, conn, serie_folio, concepts_inxml):
        def format_cove(cove_rows):
            rd = {}
            for i in cove_rows:
                rd["%s" % (i['sku'])] = {
                    'cove_lts': "%s" % (i['cove_lts']),
                    'cove_kgs': "%s" % (i['cove_kgs']),
                    'mul_lit': "%s" % (i['mul_lit']),
                    'mul_kgs': "%s" % (i['mul_kgs']),
                    'aduana_up': "%s" % (i['aduana_up'])
                }
            return rd

        def find_concept_in_cove(sku, cove_rows):
            """
            find an item over cove rows,
            this methods is not very smart
            due to it is using brute force
            """
            for item in cove_rows:
                if sku == "%s" % (item["sku"]):
                    return True
            return False

        def load_cove(conn, serie_folio):
            SQL = """SELECT fac_docs.serie_folio,  inv_prod.sku,
                fac_docs_detalles.cantidad, inv_prod_cove.cove_lts,
                inv_prod_cove.cove_kgs,
                (fac_docs_detalles.cantidad * inv_prod_cove.cove_lts) as mul_lit,
                (fac_docs_detalles.cantidad * inv_prod_cove.cove_kgs) as mul_kgs,
                inv_prod_unidades.titulo as aduana_up
                FROM fac_docs
                JOIN fac_docs_detalles ON fac_docs.id = fac_docs_detalles.fac_doc_id
                JOIN inv_prod_cove ON inv_prod_cove.inv_prod_id = fac_docs_detalles.inv_prod_id
                JOIN inv_prod ON inv_prod_cove.inv_prod_id = inv_prod.id
                JOIN inv_prod_unidades ON inv_prod.unidad_id = inv_prod_unidades.id
                WHERE fac_docs_detalles.inv_prod_id=inv_prod_cove.inv_prod_id AND
                fac_docs.serie_folio like"""
            return self.pg_query(conn, "{0}'{1}'".format(SQL, serie_folio))

        cove_rows = load_cove(conn, serie_folio)
        for c in concepts_inxml:
            if not find_concept_in_cove(c['NOIDENTIFICACION'], cove_rows):
                raise DocBuilderStepError("concept not found in cove.")
        return format_cove(cove_rows)
コード例 #8
0
 def extra(serie_folio, c):
     try:
         return self.__load_extra_info(conn, serie_folio, c)
     except Exception as e:
         raise DocBuilderStepError(
             "loading extra info fails: {}".format(e))