From 63bf6fd51b82fa328773f5c8bfb6b2ca1e7a51b2 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 18 Nov 2019 10:12:46 +0100 Subject: [PATCH] [MIG][FIX] contract: Move contracts, but disable them There were an error in previous query for moving only contracts with the mark checked, but it's also more logic to move them, but remain them disabled. --- contract/migrations/12.0.4.0.0/pre-migration.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 70ff3aaa..a99aa2ab 100644 --- a/contract/migrations/12.0.4.0.0/pre-migration.py +++ b/contract/migrations/12.0.4.0.0/pre-migration.py @@ -97,11 +97,18 @@ def create_contract_records(cr): INSERT INTO contract_contract SELECT * FROM account_analytic_account WHERE id IN (SELECT DISTINCT {} FROM contract_line) - AND recurring_invoices """).format( sql.Identifier(contract_field_name), ), ) + # Deactivate disabled contracts + openupgrade.logged_query( + cr, """UPDATE contract_contract cc + SET active = False + FROM account_analytic_account aaa + WHERE aaa.id = cc.id + AND NOT aaa.recurring_invoices""", + ) # Handle id sequence cr.execute("CREATE SEQUENCE IF NOT EXISTS contract_contract_id_seq") cr.execute("SELECT setval('contract_contract_id_seq', " @@ -121,7 +128,6 @@ def create_contract_records(cr): UPDATE {table} SET {model_column}='contract.contract' WHERE {model_column}='account.analytic.account' AND {id_column} IN (SELECT DISTINCT {col} FROM contract_line) - AND recurring_invoices """).format( table=sql.Identifier(table), model_column=sql.Identifier(model_column),