Esempio n. 1
0
    def validate_rnc(self, **kwargs):
        """
        Check if the number provided is a valid RNC
            :param self:
            :param **kwargs dict :the parameters received
            :param rnc string : the character of the client or his rnc
        """
        num = kwargs.get("rnc", False)
        if num.isdigit():
            if (len(num) == 9
                    and rnc.is_valid(num)) or (len(num) == 11
                                               and cedula.is_valid(num)):
                try:
                    info = rnc.check_dgii(num)
                except Exception as err:
                    info = None
                    _logger.error(">>> " + str(err))

                if info is not None:
                    # remove all duplicate white space from the name
                    info["name"] = " ".join(
                        re.split(r"\s+", info["name"], flags=re.UNICODE))

                return json.dumps({"is_valid": True, "info": info})

        return json.dumps({"is_valid": False})
Esempio n. 2
0
    def _check_rnc(self):
        for partner_rnc in self:
            if partner_rnc.vat:
                if (
                    len(partner_rnc.vat) not in [9, 11]
                ):
                    raise UserError(
                        _(
                            "Check Vat Format or should not have any Caracter like '-'"
                        )
                    )
                    
                if (
                    not (
                        (len(partner_rnc.vat) == 9 and rnc.is_valid(partner_rnc.vat))
                        or (len(partner_rnc.vat) == 11 and cedula.is_valid(partner_rnc.vat))
                    )
                ):

                    raise UserError(
                        _(
                            "Check Vat, Seems like it's not correct"
                        )
                    )
                else:

                    result = rnc.check_dgii(partner_rnc.vat)
                    if result is not None:
                        # remove all duplicate white space from the name
                        result["name"] = " ".join(
                            re.split(r"\s+", result["name"], flags=re.UNICODE))
                        
                        partner_rnc.name = result["name"]
Esempio n. 3
0
def handle_zipfile(f):
    """Parse the ZIP file and return a set of invalid RNC and Cedula."""
    # collections of invalid numbers found
    invalidrnc = set()
    invalidcedula = set()
    # read the information from the ZIP file
    z = zipfile.ZipFile(f, 'r')
    for line in z.open('TMP/DGII_RNC.TXT'):
        number = line.split('|', 1)[0].strip()
        if len(number) <= 9:
            if not rnc.is_valid(number):
                invalidrnc.add(number)
        else:
            if not cedula.is_valid(number):
                invalidcedula.add(number)
    # return invalid numbers
    return invalidrnc, invalidcedula
def handle_zipfile(f):
    """Parse the ZIP file and return a set of invalid RNC and Cedula."""
    # collections of invalid numbers found
    invalidrnc = set()
    invalidcedula = set()
    # read the information from the ZIP file
    z = zipfile.ZipFile(f, 'r')
    for line in z.open('TMP/DGII_RNC.TXT'):
        number = line.split('|', 1)[0].strip()
        if len(number) <= 9:
            if not rnc.is_valid(number):
                invalidrnc.add(number)
        else:
            if not cedula.is_valid(number):
                invalidcedula.add(number)
    # return invalid numbers
    return invalidrnc, invalidcedula
Esempio n. 5
0
    def create(self, vals):
        if vals.get("sale_fiscal_type", None) == "fiscal":

            partner_id = self.env["res.partner"].browse(vals['partner_id'])
            vat = str(partner_id.vat)

            if partner_id and vat and vat.isdigit():
                if len(vat) not in [
                        9, 11
                ] or not (rnc.is_valid(vat) or cedula.is_valid(vat)):
                    raise ValidationError(_(
                        "El RNC del cliente NO pasó la validación en DGII\n\n"
                        "No es posible crear una factura con Crédito Fiscal "
                        "si el RNC del cliente es inválido."
                        "Verifique el RNC del cliente a fin de corregirlo y "
                        "vuelva a guardar la factura"))

        return super(AccountInvoice, self).create(vals)