def set_barcode(self, xml):
        ted = False
        folio = self.Folio
        timbre = """<TED><DD><RE>99999999-9</RE><TD>11</TD><F>1</F>\
<FE>2000-01-01</FE><RR>99999999-9</RR><RSR>\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</RSR><MNT>10000</MNT><IT1>IIIIIII\
</IT1></DD></TED>"""
        parser = etree.XMLParser(remove_blank_text=True)
        result = etree.fromstring(timbre, parser=parser)
        xml.append(result)
        result.find('DD/RE').text = self.Emisor.RUTEmisor
        result.find('DD/TD').text = str(self.TipoDTE)
        result.find('DD/F').text = str(folio)
        if not self.FechaEmis:
            raise UserError("Problema con la fecha %s" % self.FechaEmis)
        result.find('DD/FE').text = self.FechaEmis
        if not self._receptor.RUTRecep:
            raise UserError("Completar RUT del Receptor")
        result.find('DD/RR').text = self._receptor.RUTRecep
        result.find('DD/RSR').text = util._acortar_str(
            self._receptor.RznSocRecep, 40)
        result.find('DD/MNT').text = str(self.MntTotal)
        if self.no_product:
            result.find('DD/MNT').text = '0'
        for line in self._lineas_detalle:
            if line.NroLinDet == 1:
                result.find('DD/IT1').text = util._acortar_str(
                    line.NmbItem, 40)
                break
        resultcaf = self.caf_files.get_caf_file(folio, self.TipoDTE)
        result.find('DD').append(resultcaf.find('CAF'))
        timestamp = util.time_stamp()
        etree.SubElement(result.find('DD'), 'TSTED').text = timestamp
        keypriv = resultcaf.find('RSASK').text.replace('\t', '')
        ddxml = etree.tostring(result.find('DD'),
                               encoding="ISO-8859-1",
                               xml_declaration=False).replace(b'\n', b'')
        firma_caf = Firma({
            'priv_key': keypriv,
            'init_signature': False,
            'rut_firmante': '60803000-K',
        })
        frmt = firma_caf.generar_firma(ddxml)
        result.set("version", "1.0")
        ted_xml = etree.SubElement(result, 'FRMT')
        ted_xml.set("algoritmo", "SHA1withRSA")
        ted_xml.text = frmt
        ted = etree.tostring(result,
                             encoding="ISO-8859-1",
                             xml_declaration=False).replace(b'\n', b'')
        self.sii_barcode = ted
        image = False
        if ted:
            barcodefile = BytesIO()
            image = self.pdf417bc(ted)
            image.save(barcodefile, 'PNG')
            data = barcodefile.getvalue()
            self.sii_barcode_img = base64.b64encode(data)
        ted_xml = etree.SubElement(xml, 'TmstFirma')
        ted_xml.text = timestamp
Beispiel #2
0
 def generar_firma(self, ddxml, privkey=False):
     if not privkey:
         privkey = self.priv_key
     firma = Firma({
         'priv_key': privkey,
         'cert': self.cert,
         'rut_firmante': self.subject_serial_number,
         'init_signature': False
     })
     return firma.generar_firma(texto=ddxml.decode())
 def generar_firma(self, ddxml, privkey=False):
     params = self.parametros_firma()
     if privkey:
         params["priv_key"] = privkey
     firma = Firma(params)
     return firma.generar_firma(texto=ddxml.decode())