Skip to content

Commit

Permalink
[14.0][IMP] sale_global_discount, added init hook to avoid memory iss…
Browse files Browse the repository at this point in the history
…ues on big database installation
  • Loading branch information
ChrisOForgeFlow authored and ferran-S73 committed Jun 20, 2024
1 parent 257971e commit ded6836
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_global_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import _pre_init_global_discount_fields
1 change: 1 addition & 0 deletions sale_global_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
"data": ["views/sale_order_views.xml", "views/report_sale_order.xml"],
"application": False,
"installable": True,
"pre_init_hook": "_pre_init_global_discount_fields",
}
40 changes: 40 additions & 0 deletions sale_global_discount/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from odoo.tools.sql import column_exists


def _pre_init_global_discount_fields(cr):
if not column_exists(cr, "sale_order", "amount_global_discount"):
cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_global_discount" double precision DEFAULT 0
"""
)
cr.execute(
"""
ALTER TABLE "sale_order" ALTER COLUMN "amount_global_discount" DROP DEFAULT
"""
)
if not column_exists(cr, "sale_order", "amount_untaxed_before_global_discounts"):
cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_untaxed_before_global_discounts" double precision
"""
)
cr.execute(
"""
update sale_order set amount_untaxed_before_global_discounts = amount_untaxed
"""
)
if not column_exists(cr, "sale_order", "amount_total_before_global_discounts"):
cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_total_before_global_discounts" double precision
"""
)
cr.execute(
"""
update sale_order set amount_total_before_global_discounts = amount_total
"""
)

0 comments on commit ded6836

Please sign in to comment.