Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules160-170.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| event_crm_sale | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| event_sale | | |
| event_sale | Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| event_sms | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
52 changes: 52 additions & 0 deletions openupgrade_scripts/scripts/event_sale/17.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2025 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


def _adjust_event_ticket_sequence(env):
"""As now the order is by sequence, and on v16 it was the price, we have to assign
the sequence numbers to preserve the previous order by default. Once in v17, you
can redefine the order to your choice if desired.
"""
openupgrade.logged_query(
env.cr,
"""
UPDATE event_event_ticket eet
SET sequence = sub.row_number
FROM (
SELECT id, event_id, row_number()
OVER (PARTITION BY event_id order by price)
FROM event_event_ticket
) as sub
WHERE sub.id = eet.id
""",
)


def _prefill_event_registration_sale_status(env):
openupgrade.add_columns(
env, [(False, "sale_status", "char", "to_pay", "event_registration")]
)
openupgrade.logged_query(
env.cr,
"""
UPDATE event_registration er
SET sale_status = 'free'
FROM sale_order_line sol
WHERE sol.id = er.sale_order_line_id AND sol.price_total = 0
""",
)
openupgrade.logged_query(
env.cr,
"""UPDATE event_registration
SET sale_status = 'sold'
WHERE is_paid AND sale_status = 'to_pay'
""",
)


@openupgrade.migrate()
def migrate(env, version):
_adjust_event_ticket_sequence(env)
_prefill_event_registration_sale_status(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---Models in module 'event_sale'---
---Fields in module 'event_sale'---
event_sale / event.event.ticket / _order : _order is now 'event_id, sequence, price, name, id' ('event_id, price')
# DONE: pre-migration: Preserve the previous order on existing tickets assigning the sequence by price

event_sale / event.event.ticket / price_incl (float) : NEW hasdefault: compute
# NOTHING TO DO: While computing by ORM is not optimal, given the complexity of the computations and the expected number of records, let's keep it this way for now

event_sale / event.registration / is_paid (boolean) : DEL
event_sale / event.registration / sale_status (selection) : NEW selection_keys: ['free', 'sold', 'to_pay'], isfunction: function, stored
# DONE: pre-migration: filled sale_status by SQL, using is_paid and SOL price as data source

event_sale / event.registration / state (False) : NEW mode: modify, hasdefault: compute
# NOTHING TO DO: existing field in event module being added a compute (which is not the best practice).

event_sale / product.template / detailed_type (False) : selection_keys is now '['combo', 'consu', 'event', 'product', 'service']' ('['consu', 'event', 'product', 'service']')
# NOTHING TO DO: The detailed_type value already exists

event_sale / sale.order.line / registration_ids (one2many) : NEW relation: event.registration
# NOTHING TO DO: one2many counterpart over existing m2o field

---XML records in module 'event_sale'---
NEW ir.ui.view: event_sale.event_registration_view_graph
DEL ir.ui.view: event_sale.event_report_template_full_page_ticket_inherit_sale
# NOTHING TO DO: ir noupdate=0 stuff