Skip to content

Commit

Permalink
[FIX] Compatibility for OpenERP versions prior to 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Sep 27, 2015
1 parent be23068 commit 7eca332
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,31 @@
import os
import inspect
import logging
from openerp import release, tools, SUPERUSER_ID
from openerp.tools.yaml_import import yaml_import
from openerp.osv import orm
from openerp.modules.registry import RegistryManager
import openerp.osv.fields
from . import openupgrade_tools
if release.version_info[0] >= 7:
from openerp.tools.mail import plaintext2html
if release.version_info[0] >= 8:
from openerp.fields import Many2many, One2many
try:
from openerp import release
except ImportError:
import release
Many2many = False
One2many = False
if hasattr(release, 'version_info'):
from openerp import tools, SUPERUSER_ID
from openerp.tools.yaml_import import yaml_import
from openerp.osv.orm import except_orm
from openerp.modules.registry import RegistryManager
from openerp.osv.fields import many2many, one2many
if release.version_info[0] >= 7:
from openerp.tools.mail import plaintext2html
if release.version_info[0] >= 8:
from openerp.fields import Many2many, One2many
else:
Many2many = False
One2many = False
# version < 6.1
import tools
SUPERUSER_ID = 1
from tools.yaml_import import yaml_import
from osv.osv import except_osv as except_orm
RegistryManager = None
from osv.fields import many2many, one2many

if sys.version_info[0] == 3:
unicode = str
Expand Down Expand Up @@ -499,7 +511,7 @@ def write_value(ids, field, value):
for model in default_spec.keys():
obj = pool.get(model)
if not obj:
raise orm.except_orm(
raise except_orm(
"Error",
"Migration: error setting default, no such model: %s" % model)
for field, value in default_spec[model]:
Expand Down Expand Up @@ -536,7 +548,7 @@ def write_value(ids, field, value):
field, model))
logger.error(error)
# this exception seems to get lost in a higher up try block
orm.except_orm("OpenUpgrade", error)
except_orm("OpenUpgrade", error)
else:
write_value(ids, field, value)

Expand Down Expand Up @@ -648,13 +660,15 @@ def m2o_to_x2m(cr, model, table, field, source_field):
.. versionadded:: 8.0
"""
if not model._columns.get(field):
raise orm.except_orm(
raise except_orm(
"Error", "m2o_to_x2m: field %s doesn't exist in model %s" % (
field, model._name))
if isinstance(model._columns[field], (openerp.osv.fields.many2many,
Many2many)):
rel, id1, id2 = openerp.osv.fields.many2many._sql_names(
model._columns[field], model)
if isinstance(model._columns[field], (many2many, Many2many)):
if hasattr(release, 'version_info'):
rel, id1, id2 = many2many._sql_names(model._columns[field], model)
else:
# version < 6.1
rel, id1, id2 = model._rel, model._id1, model._id2
logged_query(
cr,
"""
Expand All @@ -664,8 +678,7 @@ def m2o_to_x2m(cr, model, table, field, source_field):
WHERE %s is not null
""" %
(rel, id1, id2, source_field, table, source_field))
elif isinstance(model._columns[field], (One2many,
openerp.osv.fields.one2many)):
elif isinstance(model._columns[field], (One2many, one2many)):
if isinstance(model._columns[field], One2many):
target_table = (
model.pool[model._columns[field].comodel_name]._table)
Expand All @@ -685,7 +698,7 @@ def m2o_to_x2m(cr, model, table, field, source_field):
'source_field': source_field,
'source_table': table})
else:
raise orm.except_orm(
raise except_orm(
"Error", "m2o_to_x2m: field %s of model %s is not a "
"many2many/one2many one" % (field, model._name))

Expand Down

0 comments on commit 7eca332

Please sign in to comment.