From 9c3b293a8984ed86b8226b72dbfacc98ae0ed19e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 9 Oct 2019 00:50:50 +0200 Subject: [PATCH] [MIG] contract: Assign old partner's salesman to migrated contracts As v11 takes salesman from linked partner and now the salesman is a field in the contract that is initialized to current user, we need to assign to the recently converted contracts following old logic, or they will have admin as responsible. --- contract/migrations/12.0.4.0.0/post-migration.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contract/migrations/12.0.4.0.0/post-migration.py b/contract/migrations/12.0.4.0.0/post-migration.py index aeea18c7..57d48ae8 100644 --- a/contract/migrations/12.0.4.0.0/post-migration.py +++ b/contract/migrations/12.0.4.0.0/post-migration.py @@ -36,6 +36,21 @@ def _init_invoicing_partner_id_on_contracts(env): contracts._inverse_partner_id() +def assign_salesman(env): + """As v11 takes salesman from linked partner and now the salesman is a + field in the contract that is initialized to current user, we need + to assign to the recently converted contracts following old logic, or they + will have admin as responsible. + """ + openupgrade.logged_query( + env.cr, """ + UPDATE contract_contract cc + SET user_id = rp.user_id + FROM res_partner rp + WHERE rp.id = cc.partner_id""", + ) + + @openupgrade.migrate() def migrate(env, version): _update_no_update_ir_cron(env) @@ -45,3 +60,4 @@ def migrate(env, version): # it was a PR _init_last_date_invoiced_on_contract_lines(env) _init_invoicing_partner_id_on_contracts(env) + assign_salesman(env)