Skip to content

Commit

Permalink
[MIG][FIX] contract: Move contracts, but disable them
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pedrobaeza committed Nov 18, 2019
1 parent 9d05255 commit 00d71f9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions contract/migrations/12.0.4.0.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', "
Expand All @@ -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),
Expand Down

0 comments on commit 00d71f9

Please sign in to comment.