From 219587e3e735655087549741fe033ea4c879aa49 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 21 Dec 2023 00:01:21 +0100 Subject: [PATCH] [OU-ADD] pos_sale module --- docsource/modules150-160.rst | 2 +- .../pos_sale/16.0.1.1/pre-migration.py | 42 +++++++++++++++++++ .../16.0.1.1/upgrade_analysis_work.txt | 9 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/pos_sale/16.0.1.1/pre-migration.py create mode 100644 openupgrade_scripts/scripts/pos_sale/16.0.1.1/upgrade_analysis_work.txt diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index 75e498f7c66d..d818e974b468 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -614,7 +614,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | |new| pos_restaurant_stripe | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| pos_sale | | | +| pos_sale | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | |new| pos_sale_loyalty | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/pos_sale/16.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/pos_sale/16.0.1.1/pre-migration.py new file mode 100644 index 000000000000..3451a2ca6c7c --- /dev/null +++ b/openupgrade_scripts/scripts/pos_sale/16.0.1.1/pre-migration.py @@ -0,0 +1,42 @@ +# Copyright 2023 GRAP - Sylvain LE GAL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +def _fast_fill_sale_order_amount_unpaid(env): + _logger.info("Fast computation of sale_order.amount_unpaid ...") + openupgrade.logged_query( + env.cr, + "ALTER TABLE sale_order ADD COLUMN IF NOT EXISTS amount_unpaid numeric", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE sale_order + set amount_unpaid = tmp.amount_unpaid + FROM (SELECT + so.id, + so.amount_total - sum(COALESCE(aml.price_total, 0)) as amount_unpaid + FROM sale_order so + INNER JOIN sale_order_line sol + ON sol.order_id = so.id + LEFT JOIN sale_order_line_invoice_rel rel + ON rel.order_line_id = sol.id + LEFT JOIN account_move_line aml + ON aml.id = rel.invoice_line_id + AND aml.parent_state != 'cancel' + GROUP BY so.id + ) tmp + WHERE sale_order.id = tmp.id; + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _fast_fill_sale_order_amount_unpaid(env) diff --git a/openupgrade_scripts/scripts/pos_sale/16.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/pos_sale/16.0.1.1/upgrade_analysis_work.txt new file mode 100644 index 000000000000..37f7a3482b9a --- /dev/null +++ b/openupgrade_scripts/scripts/pos_sale/16.0.1.1/upgrade_analysis_work.txt @@ -0,0 +1,9 @@ +---Models in module 'pos_sale'--- +---Fields in module 'pos_sale'--- +pos_sale / sale.order / amount_unpaid (float) : NEW isfunction: function, stored +# Fast Computation in pre-migration + +---XML records in module 'pos_sale'--- +NEW ir.ui.view: pos_sale.res_config_settings_view_form +DEL ir.ui.view: pos_sale.pos_config_view_form_pos_sale +# Nothing to do.