From 6897b81102a9a2425115aaf2337e1d5195054a0e Mon Sep 17 00:00:00 2001 From: David Date: Thu, 18 May 2023 09:38:56 +0200 Subject: [PATCH] [OU-ADD] commission: Migration scripts TT43411 --- .../migrations/15.0.2.0.0/post-migration.py | 22 ++++++++++++++++ .../migrations/15.0.2.0.0/pre-migration.py | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 commission/migrations/15.0.2.0.0/post-migration.py create mode 100644 commission/migrations/15.0.2.0.0/pre-migration.py diff --git a/commission/migrations/15.0.2.0.0/post-migration.py b/commission/migrations/15.0.2.0.0/post-migration.py new file mode 100644 index 000000000..a22e2f9aa --- /dev/null +++ b/commission/migrations/15.0.2.0.0/post-migration.py @@ -0,0 +1,22 @@ +# Copyright 2023 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + """Convert the former `agent_line` m2m relation in `commission.line.mixin` into + the new `settlement_line_ids` o2m relation.""" + openupgrade.logged_query( + env.cr, + """ + UPDATE commission_settlement_line + SET invoice_agent_line_id = sal_rel.agent_line_id + FROM ( + SELECT DISTINCT ON (agent_line_id) agent_line_id, settlement_id + FROM settlement_agent_line_rel + ORDER BY agent_line_id + ) AS sal_rel + WHERE id = sal_rel.settlement_id + """, + ) diff --git a/commission/migrations/15.0.2.0.0/pre-migration.py b/commission/migrations/15.0.2.0.0/pre-migration.py new file mode 100644 index 000000000..2a9d469ce --- /dev/null +++ b/commission/migrations/15.0.2.0.0/pre-migration.py @@ -0,0 +1,26 @@ +# Copyright 2023 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + +table_renames = [ + ("sale_commission", "commission"), + ("sale_commission_settlement", "commission_settlement"), + ("sale_commission_make_invoice", "commission_make_invoice"), + ("sale_commission_settlement_line", "commission_settlement_line"), + ("sale_commission_make_settle", "commission_make_settle"), +] +model_renames = [ + ("sale.commission", "commission"), + ("sale.commission.mixin", "commission.mixin"), + ("sale.commission.line.mixin", "commission.line.mixin"), + ("sale.commission.settlement", "commission.settlement"), + ("sale.commission.make.invoice", "commission.make.invoice"), + ("sale.commission.settlement.line", "commission.settlement.line"), + ("sale.commission.make.settle", "commission.make.settle"), +] + + +@openupgrade.migrate(no_version=True) +def migrate(env, version): + openupgrade.rename_tables(env.cr, table_renames) + openupgrade.rename_models(env.cr, model_renames)