Skip to content

Commit

Permalink
Merge pull request #3096 from hieu1211/v14_mig_sale_margin
Browse files Browse the repository at this point in the history
[OU-ADD] sale_margin: migration script
  • Loading branch information
pedrobaeza authored Mar 27, 2022
2 parents e6f2258 + 2f226a6 commit 1958e8d
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 @@ -600,7 +600,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 1958e8d

Please sign in to comment.