Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] sale_planner_calendar: Backport improvements from 16.0 #3422

Open
wants to merge 11 commits into
base: 15.0
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions sale_planner_calendar/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale planner calendar",
"summary": "Sale planner calendar",
"version": "15.0.2.3.0",
"version": "15.0.3.0.0",
"development_status": "Beta",
"category": "Sale",
"website": "https://github.com/OCA/sale-workflow",
Expand All @@ -18,12 +18,10 @@
"data/sale_planner_calendar_action_server.xml",
"data/sale_planner_calendar_cron.xml",
"data/sale_planner_calendar_data.xml",
"data/sale_planner_calendar_event_profile.xml",
"views/calendar_event_type_view.xml",
"views/calendar_view.xml",
"views/res_config_settings_views.xml",
"views/res_partner_view.xml",
"views/sale_planner_calendar_event_profile_view.xml",
"views/sale_planner_calendar_event_view.xml",
"views/sale_planner_calendar_issue_type_view.xml",
"views/sale_planner_calendar_summary_view.xml",
Expand Down
8 changes: 8 additions & 0 deletions sale_planner_calendar/data/sale_planner_calendar_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
<record id="event_type_commercial_visit" model="calendar.event.type">
<field name="name">Commercial visit</field>
<field name="duration">0.25</field>
<field name="icon">fa-car</field>
</record>
<record id="event_type_remote_selling" model="calendar.event.type">
<field name="name">Remote selling</field>
<field name="duration">0.25</field>
<field name="icon">fa-phone</field>
</record>
<record id="event_type_delivery" model="calendar.event.type">
<field name="name">Delivery</field>
<field name="duration">0.25</field>
<field name="icon">fa-truck</field>
</record>
<record id="event_type_message" model="calendar.event.type">
<field name="name">Message</field>
<field name="duration">0.25</field>
<field name="icon">fa-envelope</field>
</record>

<!-- Event planner issue types -->
Expand Down
15 changes: 0 additions & 15 deletions sale_planner_calendar/data/sale_planner_calendar_event_profile.xml

This file was deleted.

262 changes: 104 additions & 158 deletions sale_planner_calendar/i18n/es.po

Large diffs are not rendered by default.

242 changes: 92 additions & 150 deletions sale_planner_calendar/i18n/sale_planner_calendar.pot

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions sale_planner_calendar/migrations/15.0.3.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
from psycopg2.extensions import AsIs


def _sale_planner_calendar_event_to_calendar_event(env):
"""Move all data from sale_planner_calendar_event to code model calendar_event"""
sql = """
UPDATE calendar_event SET
sale_planner_state = spce.state,
calendar_issue_type_id = spce.calendar_issue_type_id,
calendar_event_profile_id = spce.calendar_event_profile_id,
comment = spce.comment,
calendar_summary_id = spce.calendar_summary_id,
off_planning = spce.off_planning
FROM sale_planner_calendar_event spce
WHERE spce.calendar_event_id = calendar_event.id
"""
openupgrade.logged_query(env.cr, sql)


def _sale_order_to_calendar_event(env):
"""Link sale order to calendar events instead of sale planner calendar event model"""
# drop_constraint(env.cr, 'sale_order', 'sale_order_sale_planner_calendar_event_id_fkey')
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order SET
sale_planner_calendar_event_id = spce.calendar_event_id
FROM sale_planner_calendar_event spce
WHERE sale_order.%(old_column)s = spce.id
""",
{
"old_column": AsIs(
openupgrade.get_legacy_name("sale_planner_calendar_event_id")
)
},
)


def _payment_sheet_to_calendar_event(env):
"""Link sale payment sheet to calendar events instead of sale planner calendar
event model
"""
# drop_constraint(env.cr, 'sale_payment_sheet_line',
# 'sale_payment_sheet_line_sale_planner_calendar_event_id_fkey')
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_payment_sheet_line SET
sale_planner_calendar_event_id = spce.calendar_event_id
FROM sale_planner_calendar_event spce
WHERE sale_payment_sheet_line.%(old_column)s = spce.id
""",
{
"old_column": AsIs(
openupgrade.get_legacy_name("sale_planner_calendar_event_id")
)
},
)


def _profiles_to_calendar_event_type(env):
openupgrade.logged_query(
env.cr,
"""
INSERT INTO calendar_event_type (name, icon, old_sale_planner_profile_id)
SELECT name, icon, id FROM sale_planner_calendar_event_profile
ON CONFLICT (name)
DO UPDATE SET
icon = EXCLUDED.icon,
old_sale_planner_profile_id = EXCLUDED.old_sale_planner_profile_id;
""",
)

# Update event linked to profiles
openupgrade.logged_query(
env.cr,
"""
INSERT INTO meeting_category_rel (event_id, type_id)
SELECT ce.id, cet.id
FROM calendar_event ce
JOIN calendar_event_type cet
ON cet.old_sale_planner_profile_id = ce.calendar_event_profile_id
""",
)


def _remove_renamed_selection_values(env):
"""After rename value from upper to lower the values are duplicated.
This method removes old upper values"""
week_list_field = env.ref(
"sale_planner_calendar.field_sale_planner_calendar_wizard__week_list"
)
value_ids = week_list_field.selection_ids.filtered(lambda x: x.value.isupper()).ids
if value_ids:
openupgrade.logged_query(
env.cr,
"""
DELETE FROM ir_model_fields_selection
WHERE id in %(selection_value_ids)s
""",
{"selection_value_ids": tuple(value_ids)},
)


@openupgrade.migrate()
def migrate(env, version):
_sale_planner_calendar_event_to_calendar_event(env)
_sale_order_to_calendar_event(env)
_payment_sheet_to_calendar_event(env)
_profiles_to_calendar_event_type(env)
_remove_renamed_selection_values(env)
37 changes: 37 additions & 0 deletions sale_planner_calendar/migrations/15.0.3.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

_column_renames = {
"sale_order": [
("sale_planner_calendar_event_id", None),
],
"sale_payment_sheet_line": [("sale_planner_calendar_event_id", None)],
}


def _remove_selection_field_values(env):
sql = """
DELETE FROM ir_model_fields_selection
WHERE field_id IN
(SELECT id
FROM ir_model_fields
WHERE ttype='selection' AND model='sale.planner.calendar.event')
"""
openupgrade.logged_query(env.cr, sql)


def _add_event_profile_helper_column(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE calendar_event_type
ADD COLUMN old_sale_planner_profile_id integer""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_columns(env.cr, _column_renames)
_remove_selection_field_values(env)
_add_event_profile_helper_column(env)
4 changes: 1 addition & 3 deletions sale_planner_calendar/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import calendar
from . import calendar_event
from . import calendar_event_type
from . import calendar_attendee
from . import res_config_settings
from . import res_partner
from . import sale_order
from . import sale_payment_sheet
from . import sale_planner_calendar_event_profile
from . import sale_planner_calendar_event
from . import sale_planner_calendar_issue_type
from . import sale_planner_calendar_summary
Loading
Loading