Skip to content

Commit

Permalink
Merge pull request #2955 from ForgeFlow/14.0-imp-project
Browse files Browse the repository at this point in the history
[14.0][IMP] project: pre-create computed stored fields
  • Loading branch information
pedrobaeza authored Nov 12, 2021
2 parents fc63130 + e1facc0 commit 11ed145
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def map_project_project_rating_status(env):

def _fill_res_users_m2m_tables(env):
# TODO: Take into account channels and task followers part of the old rule
# Remove temp table and re-create m2m table through ORM method
openupgrade.logged_query(env.cr, "DROP TABLE project_allowed_internal_users_rel")
openupgrade.logged_query(env.cr, "DROP TABLE project_allowed_portal_users_rel")
openupgrade.logged_query(env.cr, "DROP TABLE project_task_res_users_rel")
env.registry.init_models(
env.cr, ["project.project", "project.task"], env.context, install=False
)
openupgrade.logged_query(
env.cr,
"""
Expand Down
25 changes: 25 additions & 0 deletions openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ def _set_default_rating_status_period(env):
)


def fast_fill_stored_calculated_fields(env):
""" Faster way """
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE project_task
ADD COLUMN partner_phone varchar,
ADD COLUMN partner_email varchar""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE project_task pt
SET partner_email = rp.email, partner_phone = rp.phone
FROM res_partner rp
WHERE pt.partner_id = rp.id""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.copy_columns(
Expand Down Expand Up @@ -47,8 +66,14 @@ def migrate(env, version):
"""CREATE TABLE project_allowed_internal_users_rel
(project_project_id INTEGER, res_users_id INTEGER)""",
)
openupgrade.logged_query(
env.cr,
"""CREATE TABLE project_allowed_portal_users_rel
(project_project_id INTEGER, res_users_id INTEGER)""",
)
openupgrade.logged_query(
env.cr,
"""CREATE TABLE project_task_res_users_rel
(project_task_id INTEGER, res_users_id INTEGER)""",
)
fast_fill_stored_calculated_fields(env)
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ project / project.task / allowed_user_ids (many2many) : NEW re
# DONE: pre-migration: Pre-create tables for not launching the default + computed
# DONE: post-migration: fill these tables from followers

project / project.task / partner_phone (char) : NEW isfunction: function, stored
project / project.task / partner_email (char) : NEW isfunction: function, stored
# DONE: pre-migration: filled by SQL, to avoid computations and inverses

project / project.task / company_id (many2one) : now a function
project / project.task / email_from (char) : now a function
project / project.task / partner_email (char) : NEW isfunction: function, stored
project / project.task / partner_id (many2one) : now a function
project / project.task / partner_phone (char) : NEW isfunction: function, stored
project / project.task / project_id (many2one) : now a function
project / project.task / stage_id (many2one) : now a function
# NOTHING TO DO: compute methods that will launch when loading
Expand Down

0 comments on commit 11ed145

Please sign in to comment.