def purchase_ncf_validate(self): if not self.journal_id.purchase_type == 'normal': return number = self.move_name if self.move_name else None if not ncf.is_valid(number): raise UserError( _("NCF mal digitado\n\n" "El comprobante *{}* no tiene la estructura correcta " "valide si lo ha digitado correctamente".format(number))) if number[-10:-8] not in ('01', '03', '04', '11', '12', '13', '14', '15'): raise ValidationError( _("NCF *{}* NO corresponde con el tipo de documento\n\n" "Verifique lo ha digitado correctamente y que no sea un " "Comprobante Consumidor Final (02)".format(number))) if self.id: ncf_in_draft = self.search_count([ ('id', '!=', self.id), ('partner_id', '=', self.partner_id.id), ('move_name', '=', number), ('state', 'in', ('draft', 'cancel')) ]) else: ncf_in_draft = self.search_count([ ('partner_id', '=', self.partner_id.id), ('move_name', '=', number), ('state', 'in', ('draft', 'cancel')) ]) if ncf_in_draft: raise UserError( _("NCF en Factura Borrador o Cancelada\n\n" "El comprobante *{}* ya se encuentra " "registrado con este mismo proveedor en una factura " "en borrador o cancelada".format(number))) ncf_exist = self.search_count([('partner_id', '=', self.partner_id.id), ('number', '=', number), ('state', 'in', ('open', 'paid'))]) if ncf_exist: raise UserError( _("NCF Duplicado\n\n" "El comprobante *{}* ya se encuentra registrado con el" " mismo proveedor en otra factura".format(number))) if self.journal_id.ncf_remote_validation and not ncf.check_dgii( self.partner_id.vat, number): raise UserError( _(u"NCF NO pasó validación en DGII\n\n" u"¡El número de comprobante *{}* del proveedor " u"*{}* no pasó la validación en " "DGII! Verifique que el NCF y el RNC del " u"proveedor estén correctamente " u"digitados, o si los números de ese NCF se " "le agotaron al proveedor".format(number, self.partner_id.name)))
def invoice_ncf_validation(self, invoice): if not invoice.journal_id.ncf_remote_validation: return True elif not invoice.journal_id.purchase_type in ['exterior', 'import', 'others'] and invoice.journal_id.type == "purchase": if invoice.id: inv_in_draft = self.env["account.invoice"].search_count([('id', '!=', invoice.id), ('partner_id', '=', invoice.partner_id.id), ('move_name', '=', invoice.move_name), ('state', 'in', ('draft', 'cancel'))]) else: inv_in_draft = self.env["account.invoice"].search_count([('partner_id', '=', invoice.partner_id.id), ('move_name', '=', invoice.move_name), ('state', 'in', ('draft', 'cancel'))]) if inv_in_draft: return (200, u"Ncf duplicado", u"El número de comprobante fiscal digitado para este proveedor \n" u"ya se encuentra en una factura en borrador o cancelada.") inv_exist = self.env["account.invoice"].search_count( [('partner_id', '=', invoice.partner_id.id), ('number', '=', invoice.move_name), ('state', 'in', ('open', 'paid'))]) if inv_exist: return (300, u"Ncf duplicado", u"Este número de comprobante ya fue registrado para este proveedor!") if not ncf.is_valid(invoice.move_name): return (500, u"Ncf invalido", u"El numero de comprobante fiscal no es valido! " u"no paso la validacion en DGII, Verifique que el NCF y el RNC del " u"proveedor esten correctamente digitados, si es de proveedor informal o de " u"gasto menor vefifique si debe solicitar nuevos numero.") return True
def validate_fiscal_purchase(self): for inv in self.filtered( lambda i: i.type == "in_invoice" and i.state == "draft"): ncf = inv.reference if inv.reference else None if ncf and ncf_dict.get(inv.fiscal_type_id.prefix) == "fiscal": if ncf[-10:-8] == "02" or ncf[1:3] == "32": raise ValidationError( _("NCF *{}* does not correspond with the fiscal type\n\n" "You cannot register Consumo (02 or 32) for purchases" ).format(ncf)) elif inv.fiscal_type_id.requires_document and not inv.partner_id.vat: raise ValidationError( _("Partner [{}] {} doesn't have RNC/Céd, " "is required for NCF type {}").format( inv.partner_id.id, inv.partner_id.name, inv.fiscal_type_id.name, )) elif not ncf_validation.is_valid(ncf): raise UserError( _("NCF wrongly typed\n\n" "This NCF *{}* does not have the proper structure, " "please validate if you have typed it correctly."). format(ncf)) # TODO move this to l10n_do_external_validation_ncf elif (self.journal_id.l10n_do_ncf_remote_validation and not ncf_validation.check_dgii(self.partner_id.vat, ncf)): raise ValidationError( _("NCF rejected by DGII\n\n" "NCF *{}* of supplier *{}* was rejected by DGII's " "validation service. Please validate if the NCF and " "the supplier RNC are type correctly. Otherwhise " "your supplier might not have this sequence approved " "yet.").format(ncf, self.partner_id.name)) ncf_in_invoice = (inv.search_count([ ("id", "!=", inv.id), ("company_id", "=", inv.company_id.id), ("partner_id", "=", inv.partner_id.id), ("reference", "=", ncf), ("state", "in", ("draft", "open", "paid", "cancel")), ("type", "in", ("in_invoice", "in_refund")), ]) if inv.id else inv.search_count([ ("partner_id", "=", inv.partner_id.id), ("company_id", "=", inv.company_id.id), ("reference", "=", ncf), ("state", "in", ("draft", "open", "paid", "cancel")), ("type", "in", ("in_invoice", "in_refund")), ])) if ncf_in_invoice: raise ValidationError( _("NCF already used in another invoice\n\n" "The NCF *{}* has already been registered in another " "invoice with the same supplier. Look for it in " "invoices with canceled or draft states").format( ncf))
def validate_fiscal_purchase(self): NCF = self.reference if self.reference else None if NCF and self.journal_id.purchase_type == 'normal': if NCF[-10:-8] == '02': raise ValidationError( _("NCF *{}* NO corresponde con el tipo de documento\n\n" "No puede registrar Comprobantes Consumidor Final (02)"). format(NCF)) elif not ncf_validation.is_valid(NCF): raise UserError( _("NCF mal digitado\n\n" "El comprobante *{}* no tiene la estructura correcta " "valide si lo ha digitado correctamente").format(NCF)) elif not self.partner_id.vat: raise ValidationError( _(u"Proveedor sin RNC/Céd\n\n" u"El proveedor *{}* no tiene RNC o Cédula y es requerido " u"para registrar compras Fiscales").format( self.partner_id.name)) elif (self.journal_id.ncf_remote_validation and not ncf_validation.check_dgii(self.partner_id.vat, NCF)): raise ValidationError( _(u"NCF NO pasó validación en DGII\n\n" u"¡El número de comprobante *{}* del proveedor " u"*{}* no pasó la validación en " "DGII! Verifique que el NCF y el RNC del " u"proveedor estén correctamente " u"digitados, o si los números de ese NCF se " "le agotaron al proveedor").format( NCF, self.partner_id.name)) ncf_in_invoice = self.search_count([ ('id', '!=', self.id), ('company_id', '=', self.company_id.id), ('partner_id', '=', self.partner_id.id), ('reference', '=', NCF), ('state', 'in', ('draft', 'open', 'paid', 'cancel')), ('type', 'in', ('in_invoice', 'in_refund')) ]) if self.id else self.search_count([('partner_id', '=', self.partner_id.id), ('company_id', '=', self.company_id.id), ('reference', '=', NCF), ('state', 'in', ('draft', 'open', 'paid', 'cancel')), ('type', 'in', ('in_invoice', 'in_refund'))]) if ncf_in_invoice: raise ValidationError( _("NCF Duplicado en otra Factura\n\n" "El comprobante *{}* ya se encuentra " "registrado con este mismo proveedor en una factura " "en borrador o cancelada").format(NCF))
def onchange_ncf(self): if self.journal_id.purchase_type in ('normal', 'informal', 'minor'): self.validate_fiscal_purchase() if self.origin_out and (self.type == 'out_refund' or self.type == 'in_refund'): if self.journal_id.purchase_type in ( 'normal', 'informal', 'minor') or self.journal_id.ncf_control: ncf = self.origin_out if not ncf_validation.is_valid(ncf) and ncf[-10:-8] != '04': raise UserError(_( "NCF mal digitado\n\n" "El comprobante *{}* no tiene la estructura correcta " "valide si lo ha digitado correctamente").format(ncf))
def _format_document_number(self, document_number): """ Make validation of Import Dispatch Number * making validations on the document_number. * format the document_number against a pattern and return it """ self.ensure_one() if self.country_id != self.env.ref("base.do"): return super()._format_document_number(document_number) if not document_number: return False msg = "'%s' " + _("is not a valid value for") + " '%s'.<br/>%s" # Import NCF Number Validator if not is_valid(document_number): raise UserError(msg % ( document_number, self.name, _("Please check the number and try again"), )) return document_number