Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][OU-ADD] sale_margin: Migration scripts #3096

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules130-140.rst
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ Module coverage 13.0 -> 14.0
+--------------------------------------------+-------------------------------------------------+
|sale_management | Done |
+--------------------------------------------+-------------------------------------------------+
|sale_margin | |
|sale_margin | Done |
+--------------------------------------------+-------------------------------------------------+
|sale_mrp | |
+--------------------------------------------+-------------------------------------------------+
Expand Down
26 changes: 26 additions & 0 deletions openupgrade_scripts/scripts/sale_margin/14.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, installed_version):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE sale_order_line
ADD COLUMN IF NOT EXISTS margin_percent double precision;

ALTER TABLE sale_order
ADD COLUMN IF NOT EXISTS margin_percent double precision;
""",
)

openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order_line
SET margin_percent = COALESCE(margin / NULLIF(price_subtotal, 0), 0);

UPDATE sale_order
SET margin_percent = COALESCE(margin / NULLIF(amount_untaxed, 0), 0);
""",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---Models in module 'sale_margin'---
---Fields in module 'sale_margin'---
sale_margin / sale.order / margin_percent (float) : NEW : function, stored
sale_margin / sale.order.line / margin_percent (float) : NEW isfunction: function, stored
# DONE: pre-migration fast filled

sale_margin / sale.order.line / purchase_price (float) : now a function
# NOTHING TO DO

---XML records in module 'sale_margin'---
NEW ir.ui.view: sale_margin.sale_margin_sale_order_pivot
# NOTHING TO DO