Skip to content

Commit

Permalink
[IMP] sale_planner_calendar: Use calendar_event_type and remove sale_…
Browse files Browse the repository at this point in the history
…planner_calendar_event_profile
  • Loading branch information
carlosdauden committed Oct 24, 2024
1 parent f1f04b5 commit f40feee
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 71 deletions.
3 changes: 1 addition & 2 deletions sale_planner_calendar/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="event_profile_face_to_face" model="sale.planner.calendar.event.profile">
<record id="event_type_face_to_face" model="calendar.event.type">
<field name="name">Face-to-Face</field>
<field name="icon">fa-car</field>
</record>
<record id="event_profile_telephone" model="sale.planner.calendar.event.profile">
<record id="event_type_telephone" model="calendar.event.type">
<field name="name">Telephone</field>
<field name="icon">fa-phone</field>
</record>
<record id="event_profile_message" model="sale.planner.calendar.event.profile">
<record id="event_type_message" model="calendar.event.type">
<field name="name">Message</field>
<field name="icon">fa-envelope</field>
</record>
Expand Down
31 changes: 21 additions & 10 deletions sale_planner_calendar/migrations/16.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,31 @@ 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()
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)
10 changes: 10 additions & 0 deletions sale_planner_calendar/migrations/16.0.2.0.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion sale_planner_calendar/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions sale_planner_calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion sale_planner_calendar/models/calendar_event_type.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

This file was deleted.

1 change: 0 additions & 1 deletion sale_planner_calendar/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions sale_planner_calendar/views/calendar_event_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<field name="arch" type="xml">
<field name="name" position="after">
<field name="duration" />
<field name="icon" />
</field>
</field>
</record>
Expand Down
14 changes: 11 additions & 3 deletions sale_planner_calendar/views/calendar_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
<field name="target_partner_id" optional="hide" />
<field name="start" string="Start Date" optional="show" />
<field name="until" optional="hide" />
<field name="categ_ids" widget="many2many_tags" optional="show" />
<field
name="categ_ids"
widget="many2many_tags"
optional="show"
options="{'color_field': 'color', 'no_create_edit': True}"
/>
<field name="location" optional="hide" />
<field name="duration" widget="float_time" optional="hide" />
<field name="recurrency" optional="hide" />
Expand Down Expand Up @@ -77,7 +82,6 @@
<field name="user_id" position="after">
<label for="target_partner_id" string="Sale planner partner" />
<field name="target_partner_id" nolabel="1" />
<field name="calendar_event_profile_id" />
</field>
<field name="recurrence_id" position="after">
<group attrs="{'invisible': [('recurrency', '=', False)]}">
Expand Down Expand Up @@ -124,7 +128,11 @@
/></span></strong>
</div>
<div class="col-4 text-end">
<field name="categ_ids" widget="many2many_tags" />
<field
name="categ_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"
/>
</div>
</div>
<div class="row">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@
<group>
<group>
<field
name="calendar_event_profile_id"
widget="selection"
name="categ_ids"
widget="many2many_tags"
options="{'color_field': 'color', 'no_create_edit': True}"
/>
<field name="calendar_issue_type_id" widget="selection" />
<field name="comment" />
Expand Down
4 changes: 2 additions & 2 deletions sale_planner_calendar/views/sale_planner_calendar_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
sequence="20"
/>
<menuitem
id="menu_sale_planner_calendar_event_profile"
id="menu_calendar_event_type"
parent="menu_calendar_event_configuration_root"
action="action_sale_planner_calendar_event_profile"
action="calendar.action_calendar_event_type"
sequence="30"
/>
<menuitem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def action_get_lines(self):
{
"reassign_wiz_id": self.id,
"calendar_event_id": calendar_event.id,
# "event_categ_ids": [(6, 0, calendar_event.categ_ids.ids)],
"event_user_id": calendar_event.user_id.id,
"partner_id": calendar_event.target_partner_id.id,
"event_start": calendar_event.start,
Expand Down Expand Up @@ -205,6 +206,9 @@ class SalePlannerCalendarReassignLineWiz(models.TransientModel):
reassign_wiz_id = fields.Many2one(comodel_name="sale.planner.calendar.reassign.wiz")
selected = fields.Boolean()
calendar_event_id = fields.Many2one(comodel_name="calendar.event", readonly=True)
event_categ_ids = fields.Many2many(
comodel_name="calendar.event.type", related="calendar_event_id.categ_ids"
)
partner_id = fields.Many2one(comodel_name="res.partner", readonly=True)
partner_user_id = fields.Many2one(
string="Partner salesperson",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
>
<field name="selected" widget="boolean_toggle" />
<field name="calendar_event_id" optional="show" />
<field
name="event_categ_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"
optional="hide"
/>
<field name="partner_id" />
<field name="event_user_id" optional="hide" />
<field name="partner_user_id" optional="hide" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
widget="many2many_tags"
optional="hide"
readonly="1"
options="{'color_field': 'color'}"
/>
<field name="start" optional="hide" readonly="1" />
<field name="stop" optional="hide" readonly="1" />
Expand Down

0 comments on commit f40feee

Please sign in to comment.