savoirfairelinux-openerp team mailing list archive
-
savoirfairelinux-openerp team
-
Mailing list archive
-
Message #00443
[Merge] lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70 into lp:openerp-mgmtsystem
Sandy Carter (http://www.savoirfairelinux.com) has proposed merging lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70 into lp:openerp-mgmtsystem.
Requested reviews:
OpenERP Management System Core Editors (openerp-mgmtsystem-core-editors)
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 Savoir-faire Linux' OpenERP is subscribed to branch lp:~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70.
=== 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-10-25 16:55:43 +0000
@@ -0,0 +1,42 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+from openupgrade.openupgrade import logged_query
+
+
+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])
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,52 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+from openupgrade.openupgrade import logged_query
+
+
+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])
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,53 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+from openupgrade.openupgrade import logged_query
+
+
+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))
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,42 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+from openupgrade.openupgrade import logged_query
+
+
+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])
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,52 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+from openupgrade.openupgrade import logged_query
+
+
+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))
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,44 @@
+# -*- 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/>.
+#
+
+from openerp.openupgrade import openupgrade
+
+
+def migrate_stage_id(cr):
+ openupgrade.logged_query(cr, """UPDATE mgmtsystem_action SET stage_id = NULL""")
+ for i in [('draft', 'New', 'lead'), ('open', 'Accepted as Claim', 'claim'), ]:
+ openupgrade.logged_query(cr, """
+ UPDATE mgmtsystem_action AS a
+ SET stage_id = (SELECT id
+ FROM crm_claim_stage
+ WHERE state = %s
+ LIMIT 1)
+ WHERE a.openupgrade_legacy_7_0_stage_id = (SELECT id
+ FROM crm_case_stage
+ WHERE name = %s
+ AND type = %s
+ LIMIT 1)""", i)
+
+
+@openupgrade.migrate()
+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-10-25 16:55:43 +0000
@@ -0,0 +1,34 @@
+# -*- 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/>.
+#
+
+from openupgrade import openupgrade
+
+column_renames = {
+ 'mgmtsystem_action': [
+ ('stage_id', None)
+ ]
+}
+
+
+@openupgrade.migrate()
+def migrate(cr, version):
+ openupgrade.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-10-25 16:55:43 +0000
@@ -19,33 +19,59 @@
#
##############################################################################
-import logging
-
-logger = logging.getLogger('upgrade')
-
-
+from openupgrade import openupgrade
+
+
+def migrate_nonconformity_action_ids(cr, column_names):
+ openupgrade.logged_query(cr, """
+ SELECT COUNT(*)
+ FROM mgmtsystem_nonconformity_action_rel""")
+ if cr.fetchone()[0] > 0:
+ openupgrade.logger.warning(
+ "Attempt to migrate nonconformity action IDs failed: migration was already done.")
+ return
+ openupgrade.logger.info(
+ "Moving nonconformity/action relations to mgmtsystem_nonconformity_action_rel")
+ openupgrade.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:
+ openupgrade.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):
+ openupgrade.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:
+ openupgrade.logged_query(cr, """
+ UPDATE mgmtsystem_nonconformity
+ SET evaluation_comments = %s
+ WHERE evaluation_comments IS NULL;""" % concatenation)
+
+
+def update_state_flags(cr):
+ openupgrade.logger.info("Updating state flags")
+ for i in [('open', 'o'), ('done', 'c')]:
+ openupgrade.logged_query(cr, """
+ UPDATE mgmtsystem_nonconformity
+ SET state = %s
+ WHERE state = %s;""", i)
+
+
+@openupgrade.migrate()
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!")
+ openupgrade.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)
Follow ups