Files
Odoo-18.0-20251222/sale_discount_display_amount/hooks.py
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

58 lines
1.6 KiB
Python
Executable File

# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo.tools.sql import column_exists, create_column
_logger = logging.getLogger(__name__)
COLUMNS = (
("sale_order", "price_subtotal_no_discount"),
("sale_order", "price_total_no_discount"),
("sale_order", "discount_total"),
("sale_order_line", "price_subtotal_no_discount"),
("sale_order_line", "price_total_no_discount"),
("sale_order_line", "discount_total"),
("sale_order_line", "discount_subtotal"),
)
def pre_init_hook(env):
cr = env.cr # Retrieve the database cursor
for table, column in COLUMNS:
if not column_exists(cr, table, column):
_logger.info("Create discount column %s in database", column)
create_column(cr, table, column, "numeric")
def post_init_hook(env):
cr = env.cr # Retrieve the database cursor
_logger.info("Compute discount columns")
query = """
update sale_order_line
set
price_subtotal_no_discount = price_subtotal,
price_total_no_discount = price_total
where discount = 0.0
"""
cr.execute(query)
query = """
update sale_order
set
price_subtotal_no_discount = amount_untaxed,
price_total_no_discount = amount_total
"""
cr.execute(query)
query = """
select distinct order_id from sale_order_line where discount > 0.0;
"""
cr.execute(query)
order_ids = cr.fetchall()
orders = env["sale.order"].search([("id", "in", order_ids)])
orders.mapped("order_line")._update_discount_display_fields()