forked from OCA/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73c8df2
commit 219587e
Showing
3 changed files
with
52 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
42 changes: 42 additions & 0 deletions
42
openupgrade_scripts/scripts/pos_sale/16.0.1.1/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,42 @@ | ||
# Copyright 2023 GRAP - Sylvain LE GAL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
|
||
from openupgradelib import openupgrade | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _fast_fill_sale_order_amount_unpaid(env): | ||
_logger.info("Fast computation of sale_order.amount_unpaid ...") | ||
openupgrade.logged_query( | ||
env.cr, | ||
"ALTER TABLE sale_order ADD COLUMN IF NOT EXISTS amount_unpaid numeric", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE sale_order | ||
set amount_unpaid = tmp.amount_unpaid | ||
FROM (SELECT | ||
so.id, | ||
so.amount_total - sum(COALESCE(aml.price_total, 0)) as amount_unpaid | ||
FROM sale_order so | ||
INNER JOIN sale_order_line sol | ||
ON sol.order_id = so.id | ||
LEFT JOIN sale_order_line_invoice_rel rel | ||
ON rel.order_line_id = sol.id | ||
LEFT JOIN account_move_line aml | ||
ON aml.id = rel.invoice_line_id | ||
AND aml.parent_state != 'cancel' | ||
GROUP BY so.id | ||
) tmp | ||
WHERE sale_order.id = tmp.id; | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_fast_fill_sale_order_amount_unpaid(env) |
9 changes: 9 additions & 0 deletions
9
openupgrade_scripts/scripts/pos_sale/16.0.1.1/upgrade_analysis_work.txt
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,9 @@ | ||
---Models in module 'pos_sale'--- | ||
---Fields in module 'pos_sale'--- | ||
pos_sale / sale.order / amount_unpaid (float) : NEW isfunction: function, stored | ||
# Fast Computation in pre-migration | ||
|
||
---XML records in module 'pos_sale'--- | ||
NEW ir.ui.view: pos_sale.res_config_settings_view_form | ||
DEL ir.ui.view: pos_sale.pos_config_view_form_pos_sale | ||
# Nothing to do. |