Esempio n. 1
0
 def _transform_xml(self,
                    cr,
                    uid,
                    ids,
                    fname_xml,
                    fname_xslt,
                    fname_out,
                    context=None):
     """
     @param fname_xml : Path and name of the XML of Facturae
     @param fname_xslt : Path where is located the file 'Cadena Original'.xslt
     @param fname_out : Path and name of the file.xml that is send to sign
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(
         cr, uid, ids, context)
     if not app_xsltproc_fullpath:
         raise osv.except_osv(
             _("Error!"),
             _("Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"
               % (app_xsltproc)))
     cmd = '"%s" "%s" "%s" >"%s"' % (app_xsltproc_fullpath, fname_xslt,
                                     fname_xml, fname_out)
     args = tuple(cmd.split(' '))
     input, output = exec_command_pipe(*args)
     result = self._read_file_attempts(open(fname_out, "r"))
     input.close()
     output.close()
     return result
Esempio n. 2
0
 def check_xml_scheme(self,
                      cr,
                      uid,
                      ids,
                      fname_xml,
                      fname_scheme,
                      fname_out,
                      type_scheme="xsd",
                      context=None):
     #xmlstarlet val -e --xsd cfdv2.xsd cfd_example.xml
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(
         cr, uid, ids, context)
     if app_xmlstarlet_fullpath:
         cmd = ''
         if type_scheme == 'xsd':
             cmd = '"%s" val -e --%s "%s" "%s" 1>"%s" 2>"%s"' % (
                 app_xmlstarlet_fullpath, type_scheme, fname_scheme,
                 fname_xml, fname_out + "1", fname_out)
         if cmd:
             args = tuple(cmd.split(' '))
             input, output = exec_command_pipe(*args)
             result = self._read_file_attempts(open(fname_out, "r"))
             input.close()
             output.close()
     else:
         _logger.warning(
             "Failed to find in path 'xmlstarlet' app. Can't validate xml structure. You should make a manual check to xml file."
         )
         result = ""
     return result
Esempio n. 3
0
 def _get_params(self,
                 cr,
                 uid,
                 ids,
                 fname,
                 params=None,
                 fname_out=None,
                 type='DER',
                 context=None):
     """
     @params: list [noout serial startdate enddate subject issuer dates]
     @type: str DER or PEM
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(
         cr, uid, ids, context)
     if not app_openssl_fullpath:
         raise osv.except_osv(
             _("Error!"),
             _("Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"
               % (app_openssl)))
     cmd_params = ' -'.join(params)
     cmd_params = cmd_params and '-' + cmd_params or ''
     cmd = '"%s" x509 -inform "%s" -in "%s" -noout "%s" -out "%s"' % (
         app_openssl_fullpath, type, fname, cmd_params, fname_out)
     args = tuple(cmd.split(' '))
     # input, output = tools.exec_command_pipe(*args)
     input, output = exec_command_pipe(*args)
     result = self._read_file_attempts(output)
     input.close()
     output.close()
     return result
Esempio n. 4
0
 def _sign(self, cr, uid, ids, fname, fname_xslt, fname_key, fname_out, encrypt='sha1',
     type_key='PEM', context=None):
     """
      @params fname : Path and name of the XML of Facturae
      @params fname_xslt : Path where is located the file 'Cadena Original'.xslt
      @params fname_key : Path and name of the file.pem with data of the key
      @params fname_out : Path and name of the file.txt with info encrypted
      @params encrypt : Type of encryptation for file
      @params type_key : Type of KEY
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = \
                 facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     result = ""
     cmd = ''
     if type_key == 'PEM':
         if not app_xsltproc_fullpath:
             raise osv.except_osv(_("Error!"), _(
                 "Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"%(app_xsltproc) ))
         cmd = '"%s" "%s" "%s" | "%s" dgst -%s -sign "%s" | "%s" enc -base64 -A -out "%s"' % (
             app_xsltproc_fullpath, fname_xslt, fname, app_openssl_fullpath,
                 encrypt, fname_key, app_openssl_fullpath, fname_out)
     elif type_key == 'DER':
         # TODO: Dev for type certificate DER
         pass
     if cmd:
         input, output = exec_command_pipe(cmd)
         result = self._read_file_attempts(open(fname_out, "r"))
         input.close()
         output.close()
     return result
Esempio n. 5
0
 def _sign(self,
           cr,
           uid,
           ids,
           fname,
           fname_xslt,
           fname_key,
           fname_out,
           encrypt='sha1',
           type_key='PEM',
           context=None):
     """
      @params fname : Path and name of the XML of Facturae
      @params fname_xslt : Path where is located the file 'Cadena Original'.xslt
      @params fname_key : Path and name of the file.pem with data of the key
      @params fname_out : Path and name of the file.txt with info encrypted
      @params encrypt : Type of encryptation for file
      @params type_key : Type of KEY
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = \
                 facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     result = ""
     cmd = ''
     if type_key == 'PEM':
         if not app_xsltproc_fullpath:
             raise osv.except_osv(
                 _("Error!"),
                 _("Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"
                   % (app_xsltproc)))
         cmd = '"%s" "%s" "%s" | "%s" dgst -%s -sign "%s" | "%s" enc -base64 -A -out "%s"' % (
             app_xsltproc_fullpath, fname_xslt, fname, app_openssl_fullpath,
             encrypt, fname_key, app_openssl_fullpath, fname_out)
     elif type_key == 'DER':
         # TODO: Dev for type certificate DER
         pass
     if cmd:
         input, output = exec_command_pipe(cmd)
         result = self._read_file_attempts(open(fname_out, "r"))
         input.close()
         output.close()
     return result
Esempio n. 6
0
 def check_xml_scheme(self, cr, uid, ids, fname_xml, fname_scheme, fname_out, type_scheme="xsd",
                         context=None):
     #xmlstarlet val -e --xsd cfdv2.xsd cfd_example.xml
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     if app_xmlstarlet_fullpath:
         cmd = ''
         if type_scheme == 'xsd':
             cmd = '"%s" val -e --%s "%s" "%s" 1>"%s" 2>"%s"'%(app_xmlstarlet_fullpath, type_scheme, fname_scheme, fname_xml, fname_out+"1", fname_out)
         if cmd:
             args = tuple( cmd.split(' ') )
             input, output = exec_command_pipe(*args)
             result = self._read_file_attempts( open(fname_out, "r") )
             input.close()
             output.close()
     else:
         _logger.warning("Failed to find in path 'xmlstarlet' app. Can't validate xml structure. You should make a manual check to xml file.")
         result = ""
     return result
Esempio n. 7
0
 def _transform_xml(self, cr, uid, ids, fname_xml, fname_xslt, fname_out, context=None):
     """
     @param fname_xml : Path and name of the XML of Facturae
     @param fname_xslt : Path where is located the file 'Cadena Original'.xslt
     @param fname_out : Path and name of the file.xml that is send to sign
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     if not app_xsltproc_fullpath:
         raise osv.except_osv(_("Error!"), _(
             "Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"%(app_xsltproc) ))
     cmd = '"%s" "%s" "%s" >"%s"' % (
         app_xsltproc_fullpath, fname_xslt, fname_xml, fname_out)
     args = tuple(cmd.split(' '))
     input, output = exec_command_pipe(*args)
     result = self._read_file_attempts(open(fname_out, "r"))
     input.close()
     output.close()
     return result
Esempio n. 8
0
 def _get_params(self, cr, uid, ids, fname, params=None, fname_out=None, type='DER', context=None):
     """
     @params: list [noout serial startdate enddate subject issuer dates]
     @type: str DER or PEM
     """
     if context is None:
         context = {}
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     if not app_openssl_fullpath:
         raise osv.except_osv(_("Error!"), _(
             "Failed to find in path '%s' app. This app is required for sign Mexican Electronic Invoice"%(app_openssl) ))
     cmd_params = ' -'.join(params)
     cmd_params = cmd_params and '-' + cmd_params or ''
     cmd = '"%s" x509 -inform "%s" -in "%s" -noout "%s" -out "%s"' % (
         app_openssl_fullpath, type, fname, cmd_params, fname_out)
     args = tuple(cmd.split(' '))
     # input, output = tools.exec_command_pipe(*args)
     input, output = exec_command_pipe(*args)
     result = self._read_file_attempts(output)
     input.close()
     output.close()
     return result
 def signal_confirm(self, cr, uid, ids, context=None):
     if context is None:
         context = {}
     from l10n_mx_facturae_lib import facturae_lib
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     if msj:
         raise osv.except_osv(_('Warning'),_(msj))
     try:
         if context is None:
             context = {}
         ids = isinstance(ids, (int, long)) and [ids] or ids
         invoice_obj = self.pool.get('account.invoice')
         attach = ''
         msj = ''
         index_xml = ''
         attach = self.browse(cr, uid, ids[0])
         invoice = attach.invoice_id
         type = attach.type
         wf_service = netsvc.LocalService("workflow")
         save_attach = None
         if 'cbb' in type:
             msj = _("Confirmed")
             save_attach = False
         elif 'cfdi' in type:
             fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
                 '_V3_2.xml' or ''
             fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
                 cr, uid, [invoice.id], context=context)
             attach = self.pool.get('ir.attachment').create(cr, uid, {
                 'name': fname_invoice,
                 'datas': base64.encodestring(xml_data),
                 'datas_fname': fname_invoice,
                 'res_model': 'account.invoice',
                 'res_id': invoice.id,
             }, context=None)
             msj = _("Attached Successfully XML CFDI 3.2\n")
             save_attach = True
         elif 'cfd' in type and not 'cfdi' in type:
             fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
                 '.xml' or ''
             fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
                 cr, uid, [invoice.id], context=context)
             attach = self.pool.get('ir.attachment').create(cr, uid, {
                 'name': fname_invoice,
                 'datas': base64.encodestring(xml_data),
                 'datas_fname': fname_invoice,
                 'res_model': 'account.invoice',
                 'res_id': invoice.id,
             }, context=None)
             if attach:
                 index_xml = self.pool.get('ir.attachment').browse(
                     cr, uid, attach).index_content
                 msj = _("Attached Successfully XML CFD 2.2")
             save_attach = True
         else:
             raise osv.except_osv(_("Type Electronic Invoice Unknow!"), _(
                 "The Type Electronic Invoice:" + (type or '')))
         if save_attach:
             self.write(cr, uid, ids,
                        {'file_input': attach or False,
                            'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
                            'msj': msj,
                            'file_xml_sign_index': index_xml}, context=context)
         wf_service.trg_validate(
             uid, self._name, ids[0], 'action_confirm', cr)
         return True
     except Exception, e:
         error = tools.ustr(traceback.format_exc())
         self.write(cr, uid, ids, {'msj': error}, context=context)
         _logger.error(error)
         return False
Esempio n. 10
0
 def signal_confirm(self, cr, uid, ids, context=None):
     if context is None:
         context = {}
     from l10n_mx_facturae_lib import facturae_lib
     msj, app_xsltproc_fullpath, app_openssl_fullpath, app_xmlstarlet_fullpath = facturae_lib.library_openssl_xsltproc_xmlstarlet(cr, uid, ids, context)
     if msj:
         raise osv.except_osv(_('Warning'),_(msj))
     if context is None:
         context = {}
     ids = isinstance(ids, (int, long)) and [ids] or ids
     invoice_obj = self.pool.get('account.invoice')
     attachment_obj = self.pool.get('ir.attachment')
     attach = ''
     msj = ''
     index_xml = ''
     attach = self.browse(cr, uid, ids[0])
     invoice = attach.invoice_id
     type = attach.type
     wf_service = netsvc.LocalService("workflow")
     status = False
     if 'cbb' in type:
         msj = _("Confirmed")
         status = False
     elif 'cfdi' in type:
         fname_invoice = invoice.fname_invoice and invoice.fname_invoice + \
             '_V3_2.xml' or ''
         fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
             cr, uid, [invoice.id], context=context)
         attach = attachment_obj.create(cr, uid, {
             'name': fname_invoice,
             'datas': base64.encodestring(xml_data),
             'datas_fname': fname_invoice,
             'res_model': 'account.invoice',
             'res_id': invoice.id,
         }, context=None)
         msj = _("Attached Successfully XML CFDI 3.2\n")
         status = True
     elif 'cfd' in type and not 'cfdi' in type:
         fname_invoice = invoice.fname_invoice and invoice.fname_invoice + '.xml' or ''
         fname, xml_data = invoice_obj._get_facturae_invoice_xml_data(
             cr, uid, [invoice.id], context=context)
         attach = attachment_obj.create(cr, uid, {
             'name': fname_invoice,
             'datas': base64.encodestring(xml_data),
             'datas_fname': fname_invoice,
             'res_model': 'account.invoice',
             'res_id': invoice.id,
         }, context=None)
         if attach:
             msj = _("Attached Successfully XML CFD 2.2")
         status = True
     else:
         raise osv.except_osv(_("Type Electronic Invoice Unknow!"), _(
             "The Type Electronic Invoice:" + (type or '')))
     if status:
         doc_xml = xml.dom.minidom.parseString(xml_data)
         index_xml = doc_xml.toprettyxml()
         self.write(cr, uid, ids,
                    {'file_input': attach or False,
                        'last_date': time.strftime('%Y-%m-%d %H:%M:%S'),
                        'msj': msj,
                        'file_input_index': index_xml}, context=context)
         wf_service.trg_validate(uid, self._name, ids[0], 'action_confirm', cr)
     return status