Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
5594 Переглядів

Hello All,

i have an code related to pycompat library in odoo 12 when i tried to upgrade this code in odoo 13.it gives me below error:

if isinstance(res_ids, pycompat.integer_types):
AttributeError: module 'odoo.tools.pycompat' has no attribute 'integer_types'

my python code is below:

def generate_email(self, res_ids, fields=None):
self.ensure_one()
  multi_mode = True
if
isinstance(res_ids, pycompat.integer_types):
  res_ids = [res_ids]
  multi_mode = False
if
fields is None:
  fields = ['subject''body_html''email_from''email_to''partner_to''email_cc''email_bcc''reply_to',
'scheduled_date']

  res_ids_to_templates = self.get_email_template(res_ids)

So, what kind of changes i need to do in this code?

Thanks in advance

Аватар
Відмінити
Найкраща відповідь

Hello Pawan Sharma,

pycompat.integer_types

was compatible for Odoo v12 and Python2

From Odoo v13 one could directly compare isinstance with int or str as required.

Like in your case it should be :

if isinstance(res_ids, int):
Аватар
Відмінити
Найкраща відповідь

I got the same issue with string_types instead string_types and I think that the issues and the solutions are the same :

The issue :
in v13, pycompat is far shorter than in v12. I think that it is because v12 was still a version of transition between python2 and python3, and now, with v13 or higher, Odoo is full-python3.
So there is not anymore need to define specific compatibility stuff like string_types and integer_types

My solution :
As in pycompat v12 in the "python3" part, string_types and integer_types was defined respectively as (str,) and (int,)
I replaced in my code references of string_types and integer_types by simply str and int

and I think it is the good way to solve the issue

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
серп. 21
2477
1
квіт. 21
3932
0
квіт. 21
2413
1
черв. 23
3260
1
січ. 23
3057