Exemplo n.º 1
0
	def invoice_stamp(self):
		certificate_lib = self.pool.get('facturae.certificate.library')
		params = self.get_params_for_cfdi()

		params['certificates']['cer_file'] = certificate_lib.binary2file(binary_data=self.company_id.certificate_ids[0].certificate_file, file_suffix='.cer', file_prefix='TUCA650305GV5')
		params['certificates']['key_file'] = certificate_lib.binary2file(binary_data=self.company_id.certificate_ids[0].certificate_key_file, file_suffix='.key', file_prefix='TUCA650305GV5')
		params['certificates']['password'] = self.company_id.certificate_ids[0].certificate_password

		certificates = params['certificates']

		cfdi = CFDI(params)
		xml = cfdi.get_xml(certificates)

		# _logger.info(xml)
		return True
Exemplo n.º 2
0
	def invoice_stamp(self, cr, uid, credit_aml_id, context=None):
		certificate_lib = self.pool.get('facturae.certificate.library')
		params = self.get_params_for_cfdi()

		params['certificates']['cer_file'] = certificate_lib.binary2file(binary_data=self.company_id.certificate_ids[0].certificate_file, file_suffix='.cer', file_prefix='LAM9805184I8')
		params['certificates']['key_file'] = certificate_lib.binary2file(binary_data=self.company_id.certificate_ids[0].certificate_key_file, file_suffix='.key', file_prefix='LAM9805184I8')
		params['certificates']['password'] = self.company_id.certificate_ids[0].certificate_password

		certificates = params['certificates']

		cfd = CFDI(params)
		xml = cfd.get_xml(certificates)

		# Username and Password, assigned by IOFACTURO
		rfc = 'LAM9805184I8'
		username = '******'
		password = '******'
		message = ''

		url = "https://pruebaiotunel.iofacturo.mx/ServicioTimbrado.svc?singleWsdl"
		client = Client(url,cache=None)

		client.service.AutenticaUsuario(rfc,username,password,message)

		response = client.last_received().getChild("s:Envelope").getChild("s:Body").getChild("AutenticaUsuarioResponse")

		if response.getChild("AutenticaUsuarioResult").text:
			value = response.getChild("AutenticaUsuarioResult").text.split('|')
			idusuario = value[0] 
			token = value[1] 
		else:
			_logger.error(response.getChild("Mensaje").text)

		comprob = xml
		idusuario = idusuario
		token = token
		tipoDeRespuesta = 'C'
		certificadoSucursal = ''

		client.service.TimbrarCFDI(comprob,idusuario,token,tipoDeRespuesta,certificadoSucursal)

		response = client.last_received().getChild("s:Envelope").getChild("s:Body").getChild("TimbrarCFDIResponse").getChild('TimbrarCFDIResult')

		xml_bin = etree.fromstring(str(response))

		utf8_parser = etree.XMLParser(encoding='utf-8')

		children_bin = etree.fromstring(xml_bin.text.encode('utf-8'), parser=utf8_parser)

		if children_bin.find('cfdi').find('{http://www.sat.gob.mx/cfd/3}Comprobante') is not None:

			xml_stamp = etree.tostring(children_bin.find('cfdi').find('{http://www.sat.gob.mx/cfd/3}Comprobante'))

			self.cfdi.stamp = True 	

			attachment_obj = self.pool.get('ir.attachment')
			file_name = 'archivo.xml'
			result = xml_stamp
			identifier = self.id

			_logger.info(identifier)
			_logger.info(self._name)	

			_logger.info("CR")
			_logger.info(cr)

			uid = None

			attachment_id = attachment_obj.create(cr, uid,{
				'name': file_name,
				'datas': base64.b64encode(result),
				'datas_fname': file_name,
				'res_model': self._name,
				'res_id': identifier,
				'type': 'binary'
			}, context=None)

			_logger.info(xml_stamp)
		else:
			_logger.error(children_bin.find("codError").text)

		return True