Skip to Content
Menu
This question has been flagged

Consider this function:

    @api.multi
    def _validate_rif(self, vat): #, cr, uid, vat, context=None
        '''validates if the VE VAT NUMBER is right
        @param vat: string: Vat number to Check
        returns vat when right otherwise returns False

        '''
        if not vat:
            return False

        if 'VE' in vat:
            vat = vat[2:]

        if re.search(r'^[VJEGP][0-9]{9}$', vat):
            valid_digit = self._get_valid_digit()
            if valid_digit is None:
                return False
            if int(vat[9]) == valid_digit:
                return vat
            else:
                self._print_error(_('Vat Error !'), _('Invalid VAT!'))
        elif re.search(r'^([VE][0-9]{1,8})$', vat):
            vat = vat[0] + vat[1:].rjust(8, '0')
            valid_digit = self._get_valid_digit()
            vat += str(valid_digit)
            return vat
        return False

This is from a migration I'm doing from v8 to v10 community.

The error comes on this line: `valid_digit = self._get_valid_digit()`

This calls for this function:

    @api.multi
    def _get_valid_digit(self, vat): #, cr, uid, vat, context=None
        '''
        @param vat: string
        returns validating digit
        '''
        #vat = ''
        divisor = 11
        vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
        mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
        valid_digit = None

        vat_type = vat_type.get(vat[0].upper())
        if vat_type:
            sum_vat = vat_type * 4
            for i in range(8):
                sum_vat += int(vat[i + 1]) * mapper[i + 1]

            valid_digit = divisor - sum_vat % divisor
            if valid_digit >= 10:
                valid_digit = 0
        return valid_digit

Every time I click on this button it throws me this:

    Traceback (most recent call last):
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
    result = self._call_function(**self.params)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
    return checked_call(self.db, *args, **kwargs)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
    return f(dbname, *args, **kwargs)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
    result = self.endpoint(*a, **kw)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
    return self.method(*args, **kw)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
    response = f(*args, **kw)
    File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 866, in call_button
    action = self._call_kw(model, method, args, {})
    File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 681, in call_kw
    return call_kw_multi(method, model, args, kwargs)
    File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 672, in call_kw_multi
    result = method(recs, *args, **kwargs)
    File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/search_info_partner_seniat.py", line 64, in search_partner_seniat
    res = self.env['seniat.url']._dom_giver(vat) 
    File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 226, in _dom_giver
    vat = self._validate_rif(vat)
    File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 98, in _validate_rif
    valid_digit = self._get_valid_digit()
    TypeError: _get_valid_digit() takes exactly 2 arguments (1 given)

These methods originally looked like this:

    def _get_valid_digit(self, cr, uid, vat, context=None):
        '''
        @param vat: string
        returns validating digit
        '''
        divisor = 11
        vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
        mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
        valid_digit = None

        vat_type = vat_type.get(vat[0].upper())
        if vat_type:
            sum_vat = vat_type * 4
            for i in range(8):
                sum_vat += int(vat[i + 1]) * mapper[i + 1]

            valid_digit = divisor - sum_vat % divisor
            if valid_digit >= 10:
                valid_digit = 0
        return valid_digit

    def _validate_rif(self, cr, uid, vat, context=None):
        '''validates if the VE VAT NUMBER is right
        @param vat: string: Vat number to Check
        returns vat when right otherwise returns False

        '''
        if not vat:
            return False

        if 'VE' in vat:
            vat = vat[2:]

        if re.search(r'^[VJEGP][0-9]{9}$', vat):
            valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
            if valid_digit is None:
                return False
            if int(vat[9]) == valid_digit:
                return vat
            else:
                self._print_error(_('Vat Error !'), _('Invalid VAT!'))
        elif re.search(r'^([VE][0-9]{1,8})$', vat):
            vat = vat[0] + vat[1:].rjust(8, '0')
            valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
            vat += str(valid_digit)
            return vat
        return False

Any ideas?

Avatar
Discard
Best Answer

Hi,

I think in this line: valid_digit = self._get_valid_digit()  you forgot to pass the vat argument to the function !

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 17
11310
2
Nov 17
33629
0
Mar 17
2502
1
Mar 17
9752
1
Mar 23
4420