Skip to content

Commit

Permalink
Merge pull request #5 from legalsylvain/14.0-pr-4-without-apriori-2
Browse files Browse the repository at this point in the history
14.0 pr #4 without apriori
  • Loading branch information
legalsylvain authored Dec 7, 2020
2 parents f2298f1 + 0d867ba commit 1041dc7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
21 changes: 14 additions & 7 deletions upgrade_analysis/models/upgrade_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import os

from odoo import fields, models
from odoo.exceptions import UserError
from odoo.modules import get_module_path
from odoo.tools import config
from odoo.tools.translate import _

from .. import compare

Expand All @@ -35,7 +37,11 @@ class UpgradeAnalysis(models.Model):
log = fields.Text(readonly=True)
upgrade_path = fields.Char(
default=config.get("upgrade_path", False),
help="The base file path to save the analyse files of Odoo modules",
help=(
"The base file path to save the analyse files of Odoo modules. "
"Default is taken from Odoo's --upgrade-path command line option. "
),
required=True,
)

write_files = fields.Boolean(
Expand All @@ -56,17 +62,13 @@ def _write_file(
):
module = self.env["ir.module.module"].search([("name", "=", module_name)])[0]
if module.is_odoo_module:
if not self.upgrade_path:
return (
"ERROR: no upgrade_path set when writing analysis of %s\n"
% module_name
)
module_path = os.path.join(self.upgrade_path, module_name)
full_path = os.path.join(module_path, version)
else:
module_path = get_module_path(module_name)
full_path = os.path.join(module_path, "migrations", version)
if not module_path:
return "ERROR: could not find module path of '%s':\n" % (module_name)
full_path = os.path.join(module_path, "migrations", version)
if not os.path.exists(full_path):
try:
os.makedirs(full_path)
Expand Down Expand Up @@ -97,6 +99,11 @@ def analyze(self):
}
)

if not self.upgrade_path:
return (
"ERROR: no upgrade_path set when writing analysis of %s\n" % module_name
)

connection = self.config_id.get_connection()
RemoteRecord = self._get_remote_model(connection, "record")
LocalRecord = self.env["upgrade.record"]
Expand Down
10 changes: 9 additions & 1 deletion upgrade_analysis/models/upgrade_comparison_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2016 Opener B.V. <https://opener.am>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from urllib.error import URLError

import odoorpc

from odoo import api, fields, models
Expand Down Expand Up @@ -39,7 +41,13 @@ def _compute_analysis_qty(self):

def get_connection(self):
self.ensure_one()
remote = odoorpc.ODOO(self.server, port=self.port)
try:
remote = odoorpc.ODOO(self.server, port=self.port)
except URLError:
raise UserError(
_("Could not connect the Odoo server at %s:%s")
% (self.server, self.port)
)
remote.login(self.database, self.username, self.password)
self.version = remote.version
return remote
Expand Down
1 change: 0 additions & 1 deletion upgrade_analysis/odoo_patch/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import mrp
from . import point_of_sale
from . import stock
10 changes: 6 additions & 4 deletions upgrade_analysis/upgrade_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def get_record_id(cr, module, model, field, mode):
return record[0]
cr.execute(
"INSERT INTO upgrade_record "
"(module, model, field, mode, type) "
"VALUES (%s, %s, %s, %s, %s)",
"(create_date, module, model, field, mode, type) "
"VALUES (NOW() AT TIME ZONE 'UTC', %s, %s, %s, %s, %s)",
(module, model, field, mode, "field"),
)
cr.execute(
Expand Down Expand Up @@ -67,7 +67,8 @@ def compare_registries(cr, module, registry, local_registry):
if not cr.fetchone():
cr.execute(
"INSERT INTO upgrade_attribute "
"(name, value, record_id) VALUES (%s, %s, %s)",
"(create_date, name, value, record_id) "
"VALUES (NOW() AT TIME ZONE 'UTC', %s, %s, %s)",
(key, value, record_id),
)
old_field[key] = value
Expand Down Expand Up @@ -212,6 +213,7 @@ def log_xml_id(cr, module, xml_id):
if not cr.fetchone():
cr.execute(
"INSERT INTO upgrade_record "
"(module, model, name, type) values(%s, %s, %s, %s)",
"(create_date, module, model, name, type) "
"values(NOW() AT TIME ZONE 'UTC', %s, %s, %s, %s)",
(module, record[0], xml_id, "xmlid"),
)
5 changes: 3 additions & 2 deletions upgrade_analysis/wizards/upgrade_generate_record_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def generate(self):
# Log model records
self.env.cr.execute(
"""INSERT INTO upgrade_record
(module, name, model, type)
SELECT imd2.module, imd2.module || '.' || imd.name AS name,
(create_date, module, name, model, type)
SELECT NOW() AT TIME ZONE 'UTC',
imd2.module, imd2.module || '.' || imd.name AS name,
im.model, 'model' AS type
FROM (
SELECT min(id) as id, name, res_id
Expand Down

0 comments on commit 1041dc7

Please sign in to comment.