← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70 into lp:openerp-mgmtsystem

 

You have been requested to review the proposed merge of lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70 into lp:openerp-mgmtsystem.

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70/+merge/192730

This patch adds openupgrade migration scripts which should migrate mgmtsystem documents, actions and nonconformities properly.

-- 
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70/+merge/192730
Your team OpenERP Community Reviewer/Maintainer is requested to review the proposed merge of lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70 into lp:openerp-mgmtsystem.
=== added directory 'document_page_environment_manual/migrations'
=== added directory 'document_page_environment_manual/migrations/7.0.1.0'
=== added file 'document_page_environment_manual/migrations/7.0.1.0/pre-migration.py'
--- document_page_environment_manual/migrations/7.0.1.0/pre-migration.py	1970-01-01 00:00:00 +0000
+++ document_page_environment_manual/migrations/7.0.1.0/pre-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,54 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def pre_migrate_environment_manual_category(cr, version):
+    logged_query(cr, """\
+UPDATE document_page
+SET parent_id = (SELECT id FROM document_page WHERE name = 'Manuals' LIMIT 1),
+    name = name || ' (' || %s || ')'
+WHERE parent_id = (SELECT id FROM document_page WHERE name = 'Environment Manual' AND type = 'category')
+     AND type = 'content';""", [version])
+    logged_query(cr, """\
+UPDATE document_page
+SET name = name || ' (' || %s || ')'
+WHERE name = 'Environment Manual' AND type = 'category';""", [version])
+
+
+def migrate(cr, version):
+    pre_migrate_environment_manual_category(cr, version)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'document_page_environmental_aspect/migrations'
=== added directory 'document_page_environmental_aspect/migrations/7.0.1.0'
=== added file 'document_page_environmental_aspect/migrations/7.0.1.0/post-migration.py'
--- document_page_environmental_aspect/migrations/7.0.1.0/post-migration.py	1970-01-01 00:00:00 +0000
+++ document_page_environmental_aspect/migrations/7.0.1.0/post-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,64 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def post_migrate_environmental_aspect_category(cr, version):
+    logged_query(cr, """\
+UPDATE document_page
+SET parent_id = (SELECT id FROM document_page
+                 WHERE name = 'Environmental Aspect' AND type = 'category'
+                 ORDER BY id DESC
+                 LIMIT 1),
+    name = name || ' (' || %s || ')'
+WHERE parent_id = (SELECT id FROM document_page
+                   WHERE name = 'Environmental Aspect' AND type = 'category'
+                   ORDER BY id ASC
+                   LIMIT 1)
+     AND type = 'content';""", [version])
+    logged_query(cr, """\
+UPDATE document_page
+SET name = name || ' (' || %s || ')'
+WHERE id = (SELECT id FROM document_page
+            WHERE name = 'Environmental Aspect' AND type = 'category'
+            ORDER BY id ASC
+            LIMIT 1)
+     AND type = 'category';""", [version])
+
+
+def migrate(cr, version):
+    post_migrate_environmental_aspect_category(cr, version)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'document_page_procedure/migrations'
=== added directory 'document_page_procedure/migrations/7.0.1.0'
=== added file 'document_page_procedure/migrations/7.0.1.0/post-migration.py'
--- document_page_procedure/migrations/7.0.1.0/post-migration.py	1970-01-01 00:00:00 +0000
+++ document_page_procedure/migrations/7.0.1.0/post-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,65 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def post_migrate_category(cr, version, category):
+    logged_query(cr, """\
+UPDATE document_page
+SET parent_id = (SELECT id FROM document_page
+                 WHERE name = %s AND type = 'category'
+                 ORDER BY id DESC
+                 LIMIT 1),
+    name = name || ' (' || %s || ')'
+WHERE parent_id = (SELECT id FROM document_page
+                   WHERE name = %s AND type = 'category'
+                   ORDER BY id ASC
+                   LIMIT 1)
+     AND type = 'content';""", (category, version, category))
+    logged_query(cr, """\
+UPDATE document_page
+SET name = name || ' (' || %s || ')'
+WHERE id = (SELECT id FROM document_page
+            WHERE name = %s AND type = 'category'
+            ORDER BY id ASC
+            LIMIT 1)
+     AND type = 'category';""", (version, category))
+
+
+def migrate(cr, version):
+    post_migrate_category(cr, version, 'Procedure')
+    post_migrate_category(cr, version, 'Work Instructions')
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'document_page_quality_manual/migrations'
=== added directory 'document_page_quality_manual/migrations/7.0.1.0'
=== added file 'document_page_quality_manual/migrations/7.0.1.0/pre-migration.py'
--- document_page_quality_manual/migrations/7.0.1.0/pre-migration.py	1970-01-01 00:00:00 +0000
+++ document_page_quality_manual/migrations/7.0.1.0/pre-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,54 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def pre_migrate_quality_manual_category(cr, version):
+    logged_query(cr, """\
+UPDATE document_page
+SET parent_id = (SELECT id FROM document_page WHERE name = 'Manuals' LIMIT 1),
+    name = name || ' (' || %s || ')'
+WHERE parent_id = (SELECT id FROM document_page WHERE name = 'Quality Manual' AND type = 'category')
+     AND type = 'content';""", [version])
+    logged_query(cr, """\
+UPDATE document_page
+SET name = name || ' (' || %s || ')'
+WHERE name = 'Quality Manual' AND type = 'category';""", [version])
+
+
+def migrate(cr, version):
+    pre_migrate_quality_manual_category(cr, version)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'document_page_work_instructions/migrations'
=== added directory 'document_page_work_instructions/migrations/7.0.1.0'
=== added file 'document_page_work_instructions/migrations/7.0.1.0/post-migration.py'
--- document_page_work_instructions/migrations/7.0.1.0/post-migration.py	1970-01-01 00:00:00 +0000
+++ document_page_work_instructions/migrations/7.0.1.0/post-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,64 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def post_migrate_category(cr, version, category):
+    logged_query(cr, """\
+UPDATE document_page
+SET parent_id = (SELECT id FROM document_page
+                 WHERE name = %s AND type = 'category'
+                 ORDER BY id DESC
+                 LIMIT 1),
+    name = name || ' (' || %s || ')'
+WHERE parent_id = (SELECT id FROM document_page
+                   WHERE name = %s AND type = 'category'
+                   ORDER BY id ASC
+                   LIMIT 1)
+     AND type = 'content';""", (category, version, category))
+    logged_query(cr, """\
+UPDATE document_page
+SET name = name || ' (' || %s || ')'
+WHERE id = (SELECT id FROM document_page
+            WHERE name = %s AND type = 'category'
+            ORDER BY id ASC
+            LIMIT 1)
+     AND type = 'category';""", (version, category))
+
+
+def migrate(cr, version):
+    post_migrate_category(cr, version, 'Work Instructions')
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'mgmtsystem_action/migrations/7.0.1.0'
=== added file 'mgmtsystem_action/migrations/7.0.1.0/post-migration.py'
--- mgmtsystem_action/migrations/7.0.1.0/post-migration.py	1970-01-01 00:00:00 +0000
+++ mgmtsystem_action/migrations/7.0.1.0/post-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,78 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import get_legacy_name
+    from openupgrade.openupgrade import logged_query
+except ImportError:
+    from openerp import release
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def get_legacy_name(original_name):
+        return 'legacy_' + ('_').join(
+            map(str, release.version_info[0:2])) + '_' + original_name
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def migrate_stage_id(cr):
+    stage_states = [
+        ('draft', 'New'),
+        ("open", "Accepted as Claim"),
+        ("open", "Actions Defined"),
+        ("open", "Qualification"),
+        ("open", "Proposition"),
+        ("open", "Negotiation"),
+        ("done", "Actions Done"),
+        ("done", "Won"),
+        ("done", "Dead"),
+        ("cancel", "Won't fix"),
+        ("cancel", "Lost"),
+    ]
+    logged_query(cr, """
+        UPDATE mgmtsystem_action
+        SET stage_id = NULL""")
+    legacy_stage_name = get_legacy_name("stage_id")
+    query = """
+        UPDATE mgmtsystem_action
+        SET stage_id = (SELECT id
+                        FROM crm_claim_stage
+                        WHERE state = %%s
+                        LIMIT 1)
+        WHERE %s IN (SELECT id
+                     FROM crm_case_stage
+                     WHERE name = %%s)""" % legacy_stage_name
+    for i in stage_states:
+        logged_query(cr, query, i)
+
+
+def migrate(cr, version):
+    migrate_stage_id(cr)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'mgmtsystem_action/migrations/7.0.1.0/pre-migration.py'
--- mgmtsystem_action/migrations/7.0.1.0/pre-migration.py	1970-01-01 00:00:00 +0000
+++ mgmtsystem_action/migrations/7.0.1.0/pre-migration.py	2013-11-07 22:30:27 +0000
@@ -0,0 +1,55 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This module copyright (C) 2013 Savoir-faire Linux
+#    (<http://www.savoirfairelinux.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+try:
+    from openupgrade.openupgrade import rename_columns
+except ImportError:
+    from openerp import release
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def get_legacy_name(original_name):
+        return 'legacy_' + ('_').join(
+            map(str, release.version_info[0:2])) + '_' + original_name
+
+    def rename_columns(cr, column_spec):
+        for table in column_spec.keys():
+            for (old, new) in column_spec[table]:
+                if new is None:
+                    new = get_legacy_name(old)
+                logger.info("table %s, column %s: renaming to %s",
+                            table, old, new)
+                cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (table, old, new,))
+                cr.execute('DROP INDEX IF EXISTS "%s_%s_index"' % (table, old))
+
+
+column_renames = {
+    'mgmtsystem_action': [
+        ('stage_id', None)
+    ]
+}
+
+
+def migrate(cr, version):
+    rename_columns(cr, column_renames)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'mgmtsystem_nonconformity/migrations/7.0.1.0/post-migration.py'
--- mgmtsystem_nonconformity/migrations/7.0.1.0/post-migration.py	2013-09-17 22:08:14 +0000
+++ mgmtsystem_nonconformity/migrations/7.0.1.0/post-migration.py	2013-11-07 22:30:27 +0000
@@ -19,33 +19,70 @@
 #
 ##############################################################################
 
-import logging
-
-logger = logging.getLogger('upgrade')
+try:
+    from openupgrade.openupgrade import logged_query, logger
+except ImportError:
+    import logging
+    logger = logging.getLogger('upgrade')
+
+    def logged_query(cr, query, args=None):
+        if args is None:
+            args = []
+        res = cr.execute(query, args)
+        logger.debug('Running %s', query % tuple(args))
+        logger.debug('%s rows affected', cr.rowcount)
+        return cr.rowcount
+
+
+def migrate_nonconformity_action_ids(cr, column_names):
+    logged_query(cr,  """
+        SELECT COUNT(*)
+        FROM mgmtsystem_nonconformity_action_rel""")
+    if cr.fetchone()[0] > 0:
+        logger.warning(
+            "Attempt to migrate nonconformity action IDs failed: migration was already done.")
+        return
+    logger.info(
+        "Moving nonconformity/action relations to mgmtsystem_nonconformity_action_rel")
+    logged_query(cr, """
+        SELECT column_name
+        FROM information_schema.columns
+        WHERE table_name = 'mgmtsystem_nonconformity'""")
+    action_fields = ['preventive_action_id', 'immediate_action_id', 'corrective_action_id']
+    available_fields = [i for i in action_fields if i in column_names]
+    for action_field in available_fields:
+        logged_query(cr,  """
+            INSERT INTO mgmtsystem_nonconformity_action_rel (nonconformity_id, action_id)
+            (SELECT id, %s action_id FROM mgmtsystem_nonconformity
+             WHERE %s IS NOT NULL);""" % (action_field, action_field))
+
+
+def concatenate_action_comments(cr, column_names):
+    logger.info("Concatenating action comments into evaluation_comments")
+    action_fields = ['effectiveness_preventive', 'effectiveness_immediate', 'effectiveness_corrective']
+    concatenation = " || ' ' || ".join([i for i in action_fields if i in column_names])
+    if concatenation:
+        logged_query(cr,  """
+            UPDATE mgmtsystem_nonconformity
+            SET evaluation_comments = %s
+            WHERE evaluation_comments IS NULL;""" % concatenation)
+
+
+def update_state_flags(cr):
+    logger.info("Updating state flags")
+    for i in [('open', 'o'), ('done', 'c')]:
+        logged_query(cr,  """
+            UPDATE mgmtsystem_nonconformity
+            SET state = %s
+            WHERE state = %s;""", i)
 
 
 def migrate(cr, version):
-    logger.info("Migrating mgmtsystem_nonconformity from version %s", version)
-    cr.execute("select count(*) from mgmtsystem_nonconformity_action_rel")
-    rowcount = cr.fetchone()[0]
-    if rowcount == 0:
-        logger.info("Moving nonconformity/action relations to mgmtsystem_nonconformity_action_rel")
-        for action_field in ('preventive_action_id', 'immediate_action_id', 'corrective_action_id'):
-            cr.execute("insert into mgmtsystem_nonconformity_action_rel"
-                       "(nonconformity_id, action_id) "
-                       "(SELECT id, %s FROM "
-                       "mgmtsystem_nonconformity "
-                       "WHERE %s IS NOT NULL )" % (action_field, action_field))
-    else:
-        logger.warning("Attempt to migrate nonconformity action IDs failed: migration was already done.")
-
-    logger.info("Concatening action comments into evaluation_comments")
-    cr.execute("update mgmtsystem_nonconformity set evaluation_comments = "
-               "effectiveness_preventive || ' ' || effectiveness_immediate || ' ' || effectiveness_corrective "
-               "where evaluation_comments is null")
-
-    logger.info("Updating state flags")
-    cr.execute("update mgmtsystem_nonconformity set state = 'open' where state = 'o'")
-    cr.execute("update mgmtsystem_nonconformity set state = 'done' where state = 'c'")
-
-    logger.info("mgmtsystem_nonconformity update... done!")
+    logged_query(cr, """
+        SELECT column_name
+        FROM information_schema.columns
+        WHERE table_name = 'mgmtsystem_nonconformity'""")
+    column_names = (i[0] for i in cr.fetchall())
+    migrate_nonconformity_action_ids(cr, column_names)
+    concatenate_action_comments(cr, column_names)
+    update_state_flags(cr)