def validate_rnc_cedula(self, number, model='partner'): if number: result, dgii_vals = {}, False model = 'res.partner' if model == 'partner' else 'res.company' if number.isdigit() and len(number) in (9, 11): message = u"El contacto: %s, está registrado con este RNC/Céd." contact = self.search([('vat', '=', number)]) if contact: name = contact.name if len(contact) == 1 else ", ".join( [x.name for x in contact]) raise UserError(_(message % name)) try: is_rnc = len(number) == 9 rnc.validate(number) if is_rnc else cedula.validate(number) except Exception as e: raise ValidationError(_(u"RNC/Ced Inválido")) dgii_vals = rnc.check_dgii(number) if dgii_vals is None: if is_rnc: raise ValidationError(_("RNC no disponible en DGII")) result['vat'] = number result['sale_fiscal_type'] = "final" else: result['name'] = dgii_vals.get( "name", False) or dgii_vals.get("commercial_name", "") result['vat'] = dgii_vals.get('rnc') if model == 'res.partner': result['is_company'] = True if is_rnc else False, result['sale_fiscal_type'] = "fiscal" return result
def validate_rnc_cedula(self, number): if number: if number.isdigit() and len(number) in (9, 11): message = "El contacto: %s, esta registrado con este RNC/Céd." contact = self.search([('vat', '=', number)]) if contact: name = contact.name if len(contact) == 1 else ", ".join( [x.name for x in contact]) raise UserError(_(message % name)) is_rnc = len(number) == 9 try: rnc.validate(number) if is_rnc else cedula.validate(number) except Exception as e: raise ValidationError(_("RNC/Ced Inválido")) dgii_vals = rnc.check_dgii(number) if dgii_vals is None: if is_rnc: raise ValidationError(_("RNC no disponible en DGII")) self.vat = number else: self.name = dgii_vals.get("name", False) or dgii_vals.get( "commercial_name", "") self.vat = dgii_vals.get('rnc') self.is_company = True if is_rnc else False, self.sale_fiscal_type = "fiscal" if is_rnc else "final"
def validate_rnc_cedula(self, number, model='partner'): if number: result, dgii_vals = {}, False model = 'res.partner' if model == 'partner' else 'res.company' if number.isdigit() and len(number) in (9, 11): message = "El contacto: %s, esta registrado con este RNC/Céd." self_id = self.id if self.id else 0 # Considering multi-company scenarios domain = [('vat', '=', number), ('id', '!=', self_id), ('parent_id', '=', False)] if self.env.ref('base.res_partner_rule').active: domain.extend([('company_id', '=', self.env.user.company_id.id)]) contact = self.search(domain) if contact: name = contact.name if len(contact) == 1 else ", ".join( [x.name for x in contact if x.name]) raise UserError(_(message) % name) try: is_rnc = len(number) == 9 rnc.validate(number) if is_rnc else cedula.validate(number) except Exception: _logger.warning( "RNC/Ced Inválido en el contacto {}".format(self.name)) dgii_vals = rnc.check_dgii(number) if dgii_vals is None: if is_rnc: _logger.error( "RNC {} del contacto {} no está disponible en DGII" .format(number, self.name)) result['vat'] = number result['sale_fiscal_type'] = "final" else: result['name'] = dgii_vals.get( "name", False) or dgii_vals.get("commercial_name", "") result['vat'] = dgii_vals.get('rnc') if model == 'res.partner': result['is_company'] = True if is_rnc else False result['sale_fiscal_type'] = "fiscal" return result