From f47a8f567c5b17a23c75b105be4285b6b14a98cc Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 18 Sep 2019 19:36:21 +0200 Subject: [PATCH] [MIG+FIX] contract: Missing pieces for moving info from analytic account to contract --- .../migrations/12.0.4.0.0/pre-migration.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contract/migrations/12.0.4.0.0/pre-migration.py b/contract/migrations/12.0.4.0.0/pre-migration.py index ea8e54ec..3e28c29e 100644 --- a/contract/migrations/12.0.4.0.0/pre-migration.py +++ b/contract/migrations/12.0.4.0.0/pre-migration.py @@ -101,6 +101,26 @@ def create_contract_records(cr): sql.Identifier(contract_field_name), ), ) + mapping = [ + ('ir_attachment', 'res_model', 'res_id'), + ('mail_message', 'model', 'res_id'), + ('mail_activity', 'res_model', 'res_id'), + ('mail_followers', 'res_model', 'res_id'), + ] + for table, model_column, id_column in mapping: + # Move common stuff from one table to the other + openupgrade.logged_query( + cr, sql.SQL(""" + UPDATE {table} SET {model_column}='contract.contract' + WHERE {model_column}='account.analytic.account' + AND {id_column} IN (SELECT DISTINCT {col} FROM contract_line) + """).format( + table=sql.Identifier(table), + model_column=sql.Identifier(model_column), + id_column=sql.Identifier(id_column), + col=sql.Identifier(contract_field_name), + ), + ) @openupgrade.migrate()