Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] load_data: update to version 17.0 #369

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def check_values_selection_field(cr, table_name, field_name, allowed_values):
return res


def load_data(cr, module_name, filename, idref=None, mode="init"):
def load_data(env_or_cr, module_name, filename, idref=None, mode="init"):
"""
Load an xml, csv or yml data file from your post script. The usual case for
this is the
Expand All @@ -288,6 +288,8 @@ def load_data(cr, module_name, filename, idref=None, mode="init"):
marked with 'noupdate' (other named items will be deleted
automatically).

Notes: Argument "env_or_cr" is an cr until 16 and is an env is required since 17.


:param module_name: the name of the module
:param filename: the path to the filename, relative to the module \
Expand All @@ -305,6 +307,15 @@ def load_data(cr, module_name, filename, idref=None, mode="init"):
filled which are not contained in the data file.
"""

cr = env_or_cr
if version_info[0] >= 17:
if not isinstance(env_or_cr, core.api.Environment):
logger.error(
"Pass argument 'env_or_cr' as Environment parameter since 17.0"
)
cr = env_or_cr.cr
elif not isinstance(env_or_cr, core.sql_db.Cursor):
logger.error("Pass argument 'env_or_cr' as Cursor parameter until 16.0")
if idref is None:
idref = {}
logger.info("%s: loading %s" % (module_name, filename))
Expand All @@ -329,21 +340,21 @@ def load_data(cr, module_name, filename, idref=None, mode="init"):
if ext == ".csv":
noupdate = True
tools.convert_csv_import(
cr, module_name, pathname, fp.read(), idref, mode, noupdate
env_or_cr, module_name, pathname, fp.read(), idref, mode, noupdate
)
elif ext == ".yml":
yaml_import(cr, module_name, fp, None, idref=idref, mode=mode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one hasn't been changed, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaml_import was removed from Odoo after 11 anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but right now, the code will fail in 11-, as cr has no value for that case. Assign previously cr = env_or_cr, or directly put here env_or_cr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I added more at line 310

elif mode == "init_no_create":
for fp2 in _get_existing_records(cr, fp, module_name):
tools.convert_xml_import(
cr,
env_or_cr,
module_name,
fp2,
idref,
mode="init",
)
else:
tools.convert_xml_import(cr, module_name, fp, idref, mode=mode)
tools.convert_xml_import(env_or_cr, module_name, fp, idref, mode=mode)
finally:
fp.close()

Expand Down
Loading