NeoVe
NeoVe

Reputation: 3907

TypeError: unsupported operand type(s) for +: 'bool' and 'str' - Odoo v8 to Odoo v10 migration

I have this method:

@api.multi
def search_partner_seniat(self):
    """ Check vat of the partner and update iva rate
    """
    self.ensure_one()
    vat = self.vat.upper()
    res = {
        'name': _('The requested contributor does not exist'),
        'vat_subjected': False,
        'vat': vat,
        'wh_iva_agent': False,
        'wh_iva_rate': 0.0
    }

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

    # assumption: both methods in new api style
    if self.env['res.partner'].check_vat_ve(vat): 
        res = self.env['seniat.url']._dom_giver(vat) 
    self.write(res)

    return {
        'type': 'ir.actions.act_window',
        'res_model': 'search.info.partner.seniat',
        'view_mode': 'form',
        'view_type': 'form',
        'res_id': self.id,
        'views': [(False, 'form')],
        'target': 'new',
    }

It is a button, this method calls for _dom_giver which is like follows:

@api.multi
def _dom_giver(self, vat):
    """ Check and validates that the vat is a passport,
    id or rif, to send information to SENIAT and returns the
    partner info that provides.
    """

    url_obj = self.search([], limit=1)
    url1 = url_obj.name + '%s'
    url2 = url_obj.url_seniat + '%s'
    vat = self._validate_rif(vat)
    if vat:
        return self._get_rif(vat, url1, url2)
    else:
        return False

The error comes on this line 'url1 = url.obj.name + '%s'', the complete traceback:

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)  # _dom_giver() should be @api.model
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 215, in _dom_giver
url1 = url_obj.name + '%s'
TypeError: unsupported operand type(s) for +: 'bool' and 'str'

Originally, _dom_giver method looked like this:

def _dom_giver(self, cr, uid, vat, context=None):
    """ Check and validates that the vat is a passport,
    id or rif, to send information to SENIAT and returns the
    partner info that provides.
    """
    if context is None:
        context = {}

    url_obj = self.browse(cr, uid, self.search(cr, uid, []))[0]
    url1 = url_obj.name + '%s'
    url2 = url_obj.url_seniat + '%s'
    vat = self._validate_rif(cr, uid, vat, context=None)
    if vat:
        return self._get_rif(cr, uid, vat, url1, url2, context=context)
    else:
        return False

Any ideas?

Upvotes: 1

Views: 12152

Answers (3)

Hilar AK
Hilar AK

Reputation: 1675

please check my answer in odoo forumclick here

which has solved.

Upvotes: 0

Charif DZ
Charif DZ

Reputation: 14751

url1 = url_obj.name + '%s'

same error if you do this :

False + "hello"

TypeError: unsupported operand type(s) for +: 'bool' and 'str'

that's mean the name of url_obj is False in odoo means it None because odoo change null to False

Upvotes: 1

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11141

Problem with your following code:

url1 = url_obj.name + '%s'
url2 = url_obj.url_seniat + '%s'

Either name or url_seniat or both value come as False. And you are trying to concatenate with string. We can not concatenate two different object/type. We have do type casting.

Try with following code to avoid error:

name = ''
url_seniat = ''

if url_obj.name:
    name = url_obj.name

if url_obj.url_seniat
    url_seniat = url_obj.url_seniat

url1 = name + '%s'
url2 = url_seniat + '%s'

Upvotes: 1

Related Questions