Skip to content

Master with controller adhoc #87

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
odoo-module-migrator
====================

TODO documentar uso con controlador

``odoo-module-migrator`` is a python3 library that allows you to automatically migrate
module code to make it compatible with newer Odoo version.
for exemple:
Expand Down
116 changes: 116 additions & 0 deletions odoo_module_migrate/base_migration_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import glob
import yaml
import importlib
import requests


class BaseMigrationScript(object):
Expand All @@ -25,6 +26,36 @@ class BaseMigrationScript(object):
_GLOBAL_FUNCTIONS = [] # [function_object]
_module_path = ""

def _get_controller_data(self, version_from_to):
# data = request.get(url, version_from, version_to)
# version_from_to:
# - migrate_100_allways.py
# - migrate_160_170.py
# - migrate_allways.py
# [0] - migrate
# [1] - version_from
# [2] - version_to
list_version_from_to = version_from_to.split("_")
if len(list_version_from_to) != 3 or "allways" in list_version_from_to:
return False
version_from = list_version_from_to[1]
version_to = list_version_from_to[2]
return self._get_changes_from_adhoc(version_from, version_to)

def _get_changes_from_adhoc(self, init_version_name, target_version_name):
base_url = "https://adhoc.com.ar"
endpoint = "/version_changes/{from_version}/{to_version}".format(
from_version=init_version_name, to_version=target_version_name
)
uri = base_url + endpoint
self._requests = requests.Session()
response = self._requests.get(uri)

if response and response.ok:
data_version_changes = response.json()
return data_version_changes
return False

def parse_rules(self):
script_parts = inspect.getfile(self.__class__).split("/")
migrate_from_to = script_parts[-1].split(".")[0]
Expand Down Expand Up @@ -100,6 +131,91 @@ def parse_rules(self):
rules[rule]["doc"].update(new_rules)
elif rules[rule]["type"] == TYPE_ARRAY:
rules[rule]["doc"].extend(new_rules)

# Read form controller

data_version_changes = self._get_controller_data(migrate_from_to)
if data_version_changes:
for change in data_version_changes.values():
# {'2': {
# 'change_type': 'rename',
# 'major_version_id': '17.0',
# 'model': False,
# 'field': False,
# 'model_type': 'model',
# 'old_name': 'mail.channel',
# 'new_name': 'discuss.channel',
# 'notes': '<p>Más información sobre este cambio <a href="https://github.com/odoo/odoo/pull/118354/" target="_blank">en PR 118354</a></p>'
# }
# }

if (
change["change_type"] == "rename"
and change["model_type"] == "model"
):
# [(old.model.name, new.model.name, more_info)]
new_rules = [
[change["old_name"], change["new_name"], change["notes"]]
]
rules["_RENAMED_MODELS"]["doc"].extend(new_rules)

if (
change["change_type"] == "rename"
and change["model_type"] == "field"
):
# [(model_name, old_field_name, new_field_name, more_info), ...)]
new_rules = [
[
change["model"],
change["old_name"],
change["new_name"],
change["notes"],
]
]
rules["_RENAMED_FIELDS"]["doc"].extend(new_rules)

if (
change["change_type"] == "remove"
and change["model_type"] == "model"
):
# [(old.model.name, more_info)]
new_rules = [[change["old_name"], change["notes"]]]
rules["_REMOVED_MODELS"]["doc"].extend(new_rules)

if (
change["change_type"] == "remove"
and change["model_type"] == "field"
):
# [(model_name, field_name, more_info), ...)]
new_rules = [[change["model"], change["old_name"], change["notes"]]]
rules["_REMOVED_FIELDS"]["doc"].extend(new_rules)

if (
change["change_type"] == "rename"
and change["model_type"] == "xmlid"
):
# [(model_name, old_field_name, new_field_name, more_info), ...)]
new_rules = [
[
change["model"],
change["old_name"],
change["new_name"],
change["notes"],
]
]
warnings = rules["_TEXT_REPLACES"]["doc"].get("*", {})
warnings[change["old_name"]] = change["new_name"]
rules["_TEXT_REPLACES"]["doc"]["*"] = warnings

if (
change["change_type"] == "remove"
and change["model_type"] == "xmlid"
):
# [(model_name, field_name, more_info), ...)]
warnings = rules["_TEXT_WARNINGS"]["doc"].get("*", {})
warnings[change["old_name"]] = change["notes"]
rules["_TEXT_WARNINGS"]["doc"]["*"] = warnings

# extend
for rule, data in rules.items():
rtype = data["type"]
Expand Down
Loading