diff --git a/sale_planner_calendar/migrations/15.0.2.2.1/post-migration.py b/sale_planner_calendar/migrations/15.0.2.2.1/post-migration.py new file mode 100644 index 00000000000..ea17168d478 --- /dev/null +++ b/sale_planner_calendar/migrations/15.0.2.2.1/post-migration.py @@ -0,0 +1,26 @@ +# Copyright 2024 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +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): + _remove_renamed_selection_values(env) diff --git a/sale_planner_calendar/wizard/sale_planner_calendar_wizard.py b/sale_planner_calendar/wizard/sale_planner_calendar_wizard.py index cf643814f33..79ff36dc394 100644 --- a/sale_planner_calendar/wizard/sale_planner_calendar_wizard.py +++ b/sale_planner_calendar/wizard/sale_planner_calendar_wizard.py @@ -29,7 +29,8 @@ class SalePlannerCalendarWizard(models.TransientModel): ], string="Weekday", ) - calendar_event_ids = fields.Many2many( + # Special hack One2many field to manage and save records directly + calendar_event_ids = fields.One2many( comodel_name="calendar.event", compute="_compute_calendar_event_ids", readonly=False,