Skip to content

Commit

Permalink
[MIG]sale_margin: migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
hieu1211 committed Jan 17, 2022
1 parent 4c181fb commit 2f226a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
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

0 comments on commit 2f226a6

Please sign in to comment.