forked from OCA/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by MiquelRForgeFlow
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
openupgrade_scripts/scripts/sale_stock/17.0.1.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,33 @@ | ||
# Copyright 2025 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Fill delivery_date and incoterm_location according | ||
# https://github.com/odoo/odoo/blob/00818b7bfaf22635b0c40b3b9c7e37e0c9789da1/ | ||
# addons/sale_stock/models/account_move.py#L116-L134 | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
WITH sub AS ( | ||
SELECT | ||
MAX(so.effective_date) as effective_date, | ||
MAX(COALESCE(so.incoterm_location, '')) as incoterm_location, | ||
am.id as move_id | ||
FROM sale_order so | ||
JOIN sale_order_line sol ON sol.order_id = so.id | ||
JOIN sale_order_line_invoice_rel rel ON rel.order_line_id = sol.id | ||
JOIN account_move_line aml ON rel.invoice_line_id = aml.id | ||
JOIN account_move am ON aml.move_id = am.id | ||
GROUP BY am.id | ||
) | ||
UPDATE account_move am | ||
SET delivery_date = sub.effective_date, | ||
incoterm_location = sub.incoterm_location | ||
FROM sub | ||
WHERE sub.move_id = am.id | ||
""", | ||
) |