Skip to content

Commit

Permalink
Merge pull request #4038 from Tecnativa/15.0-ou_add-website_event_que…
Browse files Browse the repository at this point in the history
…stions

[15.0][OU-ADD] website_event_questions: Migration scripts
  • Loading branch information
pedrobaeza authored Jul 5, 2023
2 parents ac26776 + 136f7d6 commit b95e9a6
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docsource/modules140-150.rst
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| website_event_meet_quiz | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| website_event_questions | | |
| website_event_questions | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| website_event_sale | Nothing to do | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="ir_rule_event_question_answer_event_user" model="ir.rule">
<field name="groups" eval="[(4, ref('event.group_event_registration_desk'))]"/>
<field name="groups" eval="[(3, ref('event.group_event_user')), (4, ref('event.group_event_registration_desk'))]"/>
</record>
<record id="ir_rule_event_question_event_user" model="ir.rule">
<field name="groups" eval="[(4, ref('event.group_event_registration_desk'))]"/>
<field name="groups" eval="[(3, ref('event.group_event_user')), (4, ref('event.group_event_registration_desk'))]"/>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def _unlink_non_applicable_questions(env):
"""Set event_type_id = NULL on existing questions if the field `event_question` was
not marked in the event type. This way, we preserve possible existing answers, but
non desired questions are not done for the events of that type.
"""
openupgrade.logged_query(
env.cr,
"""
UPDATE event_question eq
SET event_type_id = NULL
FROM event_type et
WHERE et.id = eq.event_type_id
AND NOT et.use_questions
""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(
env.cr, "website_event_questions", "15.0.1.2/noupdate_changes.xml"
)
_unlink_non_applicable_questions(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_xmlid_renames = [
(
"website_event_questions.event_question_all",
"website_event_questions.access_event_question",
),
(
"website_event_questions.event_question_event_user",
"website_event_questions.access_event_question_user",
),
(
"website_event_questions.event_question_answer_all",
"website_event_questions.access_event_question_answer",
),
(
"website_event_questions.event_question_answer_event_user",
"website_event_questions.access_event_question_answer_user",
),
]


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_xmlids(env.cr, _xmlid_renames)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---Models in module 'website_event_questions'---
---Fields in module 'website_event_questions'---
website_event_questions / event.type / use_questions (boolean) : DEL
# DONE: post-migration: Set event_type_id = NULL on existing questions if the field was not marked in the event type. This way, we preserve possible existing answers.

---XML records in module 'website_event_questions'---
NEW ir.model.access: website_event_questions.access_event_question
NEW ir.model.access: website_event_questions.access_event_question_answer
NEW ir.model.access: website_event_questions.access_event_question_answer_user
NEW ir.model.access: website_event_questions.access_event_question_user
DEL ir.model.access: website_event_questions.event_question_all
DEL ir.model.access: website_event_questions.event_question_answer_all
DEL ir.model.access: website_event_questions.event_question_answer_event_user
DEL ir.model.access: website_event_questions.event_question_event_user
# DONE: pre-migration: Renamed XML-IDs

DEL ir.model.access: website_event_questions.event_registration_answer_event_user
DEL ir.ui.view: website_event_questions.assets_tests
NEW ir.model.access: website_event_questions.access_event_registration_answer_registration
NEW ir.model.access: website_event_questions.access_event_question_answer_registration
# NOTHING TO DO: Extra noupdate=0 records

0 comments on commit b95e9a6

Please sign in to comment.