From f40feeec13a65eed5ba01671135249a71bdb9f0c Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Wed, 23 Oct 2024 21:49:13 +0200 Subject: [PATCH] [IMP] sale_planner_calendar: Use calendar_event_type and remove sale_planner_calendar_event_profile --- sale_planner_calendar/__manifest__.py | 3 +- ...nt_profile.xml => calendar_event_type.xml} | 6 ++-- .../migrations/16.0.2.0.0/post-migration.py | 31 +++++++++++++------ .../migrations/16.0.2.0.0/pre-migration.py | 10 ++++++ sale_planner_calendar/models/__init__.py | 1 - .../models/calendar_event.py | 5 +-- .../models/calendar_event_type.py | 4 ++- .../sale_planner_calendar_event_profile.py | 18 ----------- .../security/ir.model.access.csv | 1 - .../views/calendar_event_type_view.xml | 1 + sale_planner_calendar/views/calendar_view.xml | 14 +++++++-- ...le_planner_calendar_event_profile_view.xml | 24 -------------- .../sale_planner_calendar_event_view.xml | 5 +-- .../views/sale_planner_calendar_menu.xml | 4 +-- .../wizard/sale_planner_calendar_reassign.py | 4 +++ .../wizard/sale_planner_calendar_reassign.xml | 6 ++++ .../wizard/sale_planner_calendar_wizard.xml | 1 + 17 files changed, 67 insertions(+), 71 deletions(-) rename sale_planner_calendar/data/{sale_planner_calendar_event_profile.xml => calendar_event_type.xml} (59%) delete mode 100644 sale_planner_calendar/models/sale_planner_calendar_event_profile.py delete mode 100644 sale_planner_calendar/views/sale_planner_calendar_event_profile_view.xml diff --git a/sale_planner_calendar/__manifest__.py b/sale_planner_calendar/__manifest__.py index 4975648091d..84c83d1b94f 100644 --- a/sale_planner_calendar/__manifest__.py +++ b/sale_planner_calendar/__manifest__.py @@ -18,12 +18,11 @@ "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", + "data/calendar_event_type.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", diff --git a/sale_planner_calendar/data/sale_planner_calendar_event_profile.xml b/sale_planner_calendar/data/calendar_event_type.xml similarity index 59% rename from sale_planner_calendar/data/sale_planner_calendar_event_profile.xml rename to sale_planner_calendar/data/calendar_event_type.xml index 061746ee3d4..626a97dd04e 100644 --- a/sale_planner_calendar/data/sale_planner_calendar_event_profile.xml +++ b/sale_planner_calendar/data/calendar_event_type.xml @@ -1,14 +1,14 @@ - + Face-to-Face fa-car - + Telephone fa-phone - + Message fa-envelope diff --git a/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py b/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py index 1f663f1002e..8f23af41fbe 100644 --- a/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py +++ b/sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py @@ -61,15 +61,26 @@ def _payment_sheet_to_calendar_event(env): ) -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 _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 + """, + ) + + # 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 + """, + ) @openupgrade.migrate() @@ -77,4 +88,4 @@ def migrate(env, version): _sale_planner_calendar_event_to_calendar_event(env) _sale_order_to_calendar_event(env) _payment_sheet_to_calendar_event(env) - # _remove_selection_field_values(env) + _profiles_to_calendar_event_type(env) diff --git a/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py b/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py index 5c8de1f187b..5f3571db763 100644 --- a/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py +++ b/sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py @@ -21,7 +21,17 @@ def _remove_selection_field_values(env): 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) diff --git a/sale_planner_calendar/models/__init__.py b/sale_planner_calendar/models/__init__.py index 303fd940cfe..29fa5771974 100644 --- a/sale_planner_calendar/models/__init__.py +++ b/sale_planner_calendar/models/__init__.py @@ -6,6 +6,5 @@ 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_issue_type from . import sale_planner_calendar_summary diff --git a/sale_planner_calendar/models/calendar_event.py b/sale_planner_calendar/models/calendar_event.py index ea6d19adef9..03dea76b6a6 100644 --- a/sale_planner_calendar/models/calendar_event.py +++ b/sale_planner_calendar/models/calendar_event.py @@ -53,9 +53,6 @@ class CalendarEvent(models.Model): calendar_issue_type_id = fields.Many2one( comodel_name="sale.planner.calendar.issue.type", ondelete="restrict" ) - calendar_event_profile_id = fields.Many2one( - comodel_name="sale.planner.calendar.event.profile" - ) comment = fields.Text() sale_order_subtotal = fields.Monetary( compute="_compute_sale_order_subtotal", @@ -89,7 +86,7 @@ class CalendarEvent(models.Model): partner_city = fields.Char(related="target_partner_id.city") sanitized_partner_mobile = fields.Char(compute="_compute_sanitized_partner_mobile") location_url = fields.Char(compute="_compute_location_url") - profile_icon = fields.Char(related="calendar_event_profile_id.icon") + profile_icon = fields.Char(related="categ_ids.icon") @api.depends("recurrence_id", "recurrence_id.calendar_event_ids") def _compute_is_base_recurrent_event(self): diff --git a/sale_planner_calendar/models/calendar_event_type.py b/sale_planner_calendar/models/calendar_event_type.py index ad75dfab021..97e3b5e1be1 100644 --- a/sale_planner_calendar/models/calendar_event_type.py +++ b/sale_planner_calendar/models/calendar_event_type.py @@ -1,4 +1,5 @@ -# Copyright 2021 Tecnativa - Sergio Teruel +# Copyright 2021-2024 Tecnativa - Sergio Teruel +# Copyright 2021-2024 Tecnativa - Carlos Dauden # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import fields, models @@ -8,3 +9,4 @@ class CalendarEventType(models.Model): _inherit = "calendar.event.type" duration = fields.Float() + icon = fields.Char(help="Font awesome icon e.g. fa-tasks") diff --git a/sale_planner_calendar/models/sale_planner_calendar_event_profile.py b/sale_planner_calendar/models/sale_planner_calendar_event_profile.py deleted file mode 100644 index 44fdb778abf..00000000000 --- a/sale_planner_calendar/models/sale_planner_calendar_event_profile.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2024 Tecnativa - Pilar Vargas -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import fields, models - - -class CalendarEventType(models.Model): - """ - Calendar planner event profiles are used to categorise such events. Each type is a - type of activity, e.g. face-to-face, telephone, message. This will allow an icon - identifying the event to be displayed - """ - - _name = "sale.planner.calendar.event.profile" - _description = "Sale Planner Calendar Event Profile" - - name = fields.Char(required=True) - icon = fields.Char(help="Font awesome icon e.g. fa-tasks") diff --git a/sale_planner_calendar/security/ir.model.access.csv b/sale_planner_calendar/security/ir.model.access.csv index a81a9bb40d4..e57738cdc0f 100644 --- a/sale_planner_calendar/security/ir.model.access.csv +++ b/sale_planner_calendar/security/ir.model.access.csv @@ -4,4 +4,3 @@ access_sale_planner_calendar_issue_type,access_sale_planner_calendar_issue_type, access_sale_planner_calendar_reassign_wiz,access_sale_planner_calendar_reassign_wiz,model_sale_planner_calendar_reassign_wiz,sales_team.group_sale_salesman,1,1,1,1 access_sale_planner_calendar_reassign_line_wiz,access_sale_planner_calendar_reassign_line_wiz,model_sale_planner_calendar_reassign_line_wiz,sales_team.group_sale_salesman,1,1,1,1 access_sale_planner_calendar_wizard,access_sale_planner_calendar_wizard,model_sale_planner_calendar_wizard,sales_team.group_sale_salesman,1,1,1,1 -sale_planner_calendar.access_sale_planner_calendar_event_profile,access_sale_planner_calendar_event_profile,sale_planner_calendar.model_sale_planner_calendar_event_profile,sales_team.group_sale_salesman,1,1,1,1 diff --git a/sale_planner_calendar/views/calendar_event_type_view.xml b/sale_planner_calendar/views/calendar_event_type_view.xml index 64d1fc96919..84d41fcba46 100644 --- a/sale_planner_calendar/views/calendar_event_type_view.xml +++ b/sale_planner_calendar/views/calendar_event_type_view.xml @@ -8,6 +8,7 @@ + diff --git a/sale_planner_calendar/views/calendar_view.xml b/sale_planner_calendar/views/calendar_view.xml index 2d3ff25530c..67a2f5a0d76 100644 --- a/sale_planner_calendar/views/calendar_view.xml +++ b/sale_planner_calendar/views/calendar_view.xml @@ -22,7 +22,12 @@ - + @@ -77,7 +82,6 @@