This question has been flagged

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

Avatar
Discard
Best Answer

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):
Avatar
Discard
Best Answer

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

Avatar
Discard