Esempio n. 1
0
 def on_change_vat(self): 
     xmlPath = os.path.dirname(os.path.abspath(__file__))+'/xml'
     for record in self:
         if (record.vat) :
             ruc = record.vat
             tipo_documento = record.sunat_tipo_documento
             if(ruc!=""):
                 SunatService = Service()
                 SunatService.setXMLPath(xmlPath)
                 response = {}
                 response = SunatService.consultRUC_Pydevs(tipo_documento,ruc)                    
                 #raise Warning(len(response['data']))
                 if len(response['data'])==0:
                     raise Warning("El RUC no fue encontrado en registros de SUNAT")
                 else:
                     
                     self.update_document(response)
Esempio n. 2
0
    def get_ruc(self, **kw):
        doc_num = kw.get('doc_num')
        doc_type = kw.get('doc_type')
        xmlPath = os.path.dirname(os.path.abspath(__file__)) + '/xml'
        xmlPath = xmlPath.replace("controllers", "models")
        response = {'status': "El documento no fue encontrado."}
        try:
            if (doc_num != ""):
                SunatService = Service()
                SunatService.setXMLPath(xmlPath)
                response_service = SunatService.consultRUC_Pydevs(
                    doc_type, doc_num)
                if len(response_service['data']) > 0:
                    if (int(doc_type) == 6):

                        query = "select id, name, code from res_country_state where length(code) = 6 and country_id = " + str(
                            173) + " and  name like'%" + str(
                                response_service["data"]['distrito']) + "%'"
                        request.cr.execute(query)
                        district = request.cr.dictfetchone()
                        ubigeo = str("")
                        if (district):
                            ubigeo = district["code"]

                        nombre = str(response_service["data"]
                                     ['nombre']).capitalize().replace(
                                         '"', '').strip()
                        nombre_comercial = str(
                            response_service["data"]
                            ['nombre_comercial']).capitalize().replace(
                                '"', '').strip()
                        nombre_comercial_tmp = nombre_comercial
                        nombre_comercial = nombre + nombre_comercial if nombre_comercial != "-" else ""
                        name = str(nombre) if str(nombre_comercial_tmp) == str(
                            "-") else str(nombre) + str(" -- ") + str(
                                nombre_comercial_tmp)
                        response = {
                            'status':
                            "OK",
                            'nmro':
                            doc_num,
                            'address':
                            str(response_service["data"]
                                ['domicilio_fiscal']).capitalize(),
                            'name':
                            name,
                            'tipo_contribuyente':
                            response_service["data"]['tipo_contribuyente'],
                            'nombre_comercial':
                            nombre_comercial,
                            'sistema_emision_comprobante':
                            str(response_service["data"]
                                ['sistema_emision_comprobante']).capitalize(),
                            'sistema_contabilidad':
                            str(response_service["data"]
                                ['sistema_contabilidad']).capitalize(),
                            'actividad_economica':
                            str(response_service["data"]
                                ['actividad_economica']).capitalize(),
                            'estado_contribuyente':
                            str(response_service["data"]
                                ['estado_contribuyente']).capitalize(),
                            'condicion_contribuyente':
                            str(response_service["data"]
                                ['condicion_contribuyente']).capitalize(),
                            'distrito':
                            response_service["data"]['distrito'],
                            'provincia':
                            response_service["data"]['provincia'],
                            'departamento':
                            response_service["data"]['departamento'],
                            'ubigeo':
                            ubigeo
                        }
                if (int(doc_type) == 1):
                    response = {
                        'status':
                        "OK",
                        'nmro':
                        doc_num,
                        'name':
                        str(
                            str(response_service["data"]['nombres']) +
                            str(" ") +
                            str(response_service["data"]['ape_paterno']) +
                            str(" ") +
                            str(response_service["data"]['ape_materno'])).
                        capitalize()
                    }

        except Exception as e:
            exc_traceback = sys.exc_info()
            #with open('/home/rockscripts/Documentos/log_.js', 'w') as outfile:
            #    json.dump(getattr(e, 'message', repr(e))+" ON LINE "+format(sys.exc_info()[-1].tb_lineno), outfile)
            return {'status': "FAIL"}

        return response