Skip to content

Commit

Permalink
[OU-ADD] pos_sale module
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Dec 20, 2023
1 parent 73c8df2 commit 219587e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules150-160.rst
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| |new| pos_restaurant_stripe | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| pos_sale | | |
| pos_sale | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| |new| pos_sale_loyalty | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
42 changes: 42 additions & 0 deletions openupgrade_scripts/scripts/pos_sale/16.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 219587e

Please sign in to comment.