2
votes

I purchased a module from Odoo Apps website which compatible with Odoo CE version 12.

Now i', planing to upgrade it to Odoo CE version 13 and i'm facing with an error like that:

ImportError: cannot import name 'binary_content' from 'odoo.addons.web.controllers.main' (e:\odoo\homing_missile13\addons\web\controllers\main.py)

Traceback (most recent call last):

File "E:\Odoo\homing_missile13\odoo\http.py", line 624, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "E:\Odoo\homing_missile13\odoo\http.py", line 310, in _handle_exception

raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

File "E:\Odoo\homing_missile13\odoo\tools\pycompat.py", line 14, in reraise

raise value

File "E:\Odoo\homing_missile13\odoo\http.py", line 669, in dispatch

result = self._call_function(**self.params)

File "E:\Odoo\homing_missile13\odoo\http.py", line 350, in _call_function

return checked_call(self.db, args, *kwargs)

File "E:\Odoo\homing_missile13\odoo\service\model.py", line 93, in wrapper

return f(dbname, args, *kwargs)

File "E:\Odoo\homing_missile13\odoo\http.py", line 339, in checked_call

result = self.endpoint(*a, **kw)

File "E:\Odoo\homing_missile13\odoo\http.py", line 915, in call

return self.method(*args, **kw)

File "E:\Odoo\homing_missile13\odoo\http.py", line 515, in response_wrap

response = f(*args, **kw)

File "e:\odoo\homing_missile13\addons\web\controllers\main.py", line 1326, in call_button

action = self._call_kw(model, method, args, kwargs)

File "e:\odoo\homing_missile13\addons\web\controllers\main.py", line 1314, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "E:\Odoo\homing_missile13\odoo\api.py", line 387, in call_kw

result = _call_kw_multi(method, model, args, kwargs)

File "E:\Odoo\homing_missile13\odoo\api.py", line 374, in _call_kw_multi

result = method(recs, args, *kwargs)

File "", line 2, in button_immediate_install

File "E:\Odoo\homing_missile13\odoo\addons\base\models\ir_module.py", line 72, in check_and_log

return method(self, args, *kwargs)

File "E:\Odoo\homing_missile13\odoo\addons\base\models\ir_module.py", line 463, in button_immediate_install

return self._button_immediate_function(type(self).button_install)

File "E:\Odoo\homing_missile13\odoo\addons\base\models\ir_module.py", line 573, in _button_immediate_function

modules.registry.Registry.new(self._cr.dbname, update_module=True)

File "E:\Odoo\homing_missile13\odoo\modules\registry.py", line 86, in new

odoo.modules.load_modules(registry._db, force_demo, status, update_module)

File "E:\Odoo\homing_missile13\odoo\modules\loading.py", line 423, in load_modules

loaded_modules, update_module, models_to_check)

File "E:\Odoo\homing_missile13\odoo\modules\loading.py", line 315, in load_marked_modules

perform_checks=perform_checks, models_to_check=models_to_check

File "E:\Odoo\homing_missile13\odoo\modules\loading.py", line 182, in load_module_graph

load_openerp_module(package.name)

File "E:\Odoo\homing_missile13\odoo\modules\module.py", line 382, in load_openerp_module

__import__('odoo.addons.' + module_name)

File "e:\odoo\homing_missile13\custom_addons\sync_documents__init__.py", line 5, in

from . import controllers

File "e:\odoo\homing_missile13\custom_addons\sync_documents\controllers__init__.py", line 4, in

from . import main

File "e:\odoo\homing_missile13\custom_addons\sync_documents\controllers\main.py", line 9, in

from odoo.addons.web.controllers.main import binary_content

ImportError: cannot import name 'binary_content' from 'odoo.addons.web.controllers.main' (e:\odoo\homing_missile13\addons\web\controllers\main.py).

By looking at the code i saw the file main.py has some code which is obsoleted (i reckon) in version 13 >

from odoo.addons.web.controllers.main import binary_content from odoo.addons.http_routing.models.ir_http import slug

So can you help me guys?

What the replacement of binary_content is in Odoo CE version 13?

The same question with slug.

Apart from that, Pycharm also shows the errors at odoo.addons.web and odoo.addons.http_routing.

Any helps are much appriciated.

Thank you

2

2 Answers

3
votes

Yes, there is a change in Odoo-13.

You can import and used this function content_image.The slug can use for "Transform a string to that can be used in a URL path" and your function is for the binary type content operation.

Thanks

1
votes

Just adding this answer for Odoo 14, because I couldn't find anything related to version 14.

In my case, I had to import like this:

from odoo.addons.web.controllers.main import Binary

& in the code:

Binary.content_image as mentioned by Dipen in this answer.


Also, found another interesting thing, as mentioned in this link, answered by Niyas Raphy, instead of importing binary_content, I could've also used request.env['ir.http'].sudo().binary_content(.

See a use case in V13: status, headers, _content = request.env['ir.http'].sudo().binary_content( model='res.partner', id=partner_id, field='image_128', default_mimetype='image/png')