-
-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #832 from Tecnativa/13.0-stock_picking_invoice_lin…
…k-mig_scripts [13.0][OU-ADD] stock_picking_invoice_link: Migration scripts [ci skip]
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
stock_picking_invoice_link/migrations/13.0.1.0.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2021 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.logging() | ||
def insert_invoice_line_stock_move_rel(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
INSERT INTO stock_move_invoice_line_rel | ||
(invoice_line_id, move_id) | ||
SELECT aml.id, rel.move_id | ||
FROM old_stock_move_invoice_line_rel rel | ||
JOIN account_move_line aml ON aml.old_invoice_line_id = rel.invoice_line_id""", | ||
) | ||
|
||
|
||
def insert_invoice_picking_rel(env): | ||
# Remove temp table and re-create m2m table through ORM method | ||
openupgrade.logged_query(env.cr, "DROP TABLE account_move_stock_picking_rel") | ||
Move = env["account.move"] | ||
Move._fields["picking_ids"].update_db(Move, False) | ||
# Fill values from existing table | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
INSERT INTO account_move_stock_picking_rel | ||
(account_move_id, stock_picking_id) | ||
SELECT am.id, rel.stock_picking_id | ||
FROM account_invoice_stock_picking_rel rel | ||
JOIN account_move am ON am.old_invoice_id = rel.account_invoice_id""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
insert_invoice_line_stock_move_rel(env) | ||
insert_invoice_picking_rel(env) |
19 changes: 19 additions & 0 deletions
19
stock_picking_invoice_link/migrations/13.0.1.0.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2021 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
from openupgradelib import openupgrade | ||
|
||
_table_renames = [("stock_move_invoice_line_rel", "old_stock_move_invoice_line_rel")] | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_tables(env.cr, _table_renames) | ||
# Remove FKs on old relations for avoiding further problems | ||
openupgrade.lift_constraints(env.cr, _table_renames[0][1], "move_id") | ||
openupgrade.lift_constraints( | ||
env.cr, "account_invoice_stock_picking_rel", "picking_id" | ||
) | ||
# Add temporary table for avoiding the automatic launch of the compute method | ||
openupgrade.logged_query( | ||
env.cr, "CREATE TABLE account_move_stock_picking_rel (temp INTEGER)", | ||
) |