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

[16.0] [IMP] sale_planner_calendar: Add rating to calendar events #3397

Draft
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions sale_planner_calendar/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"web.assets_backend": [
"sale_planner_calendar/static/src/xml/categ_icons_widget_template.xml",
"sale_planner_calendar/static/src/xml/sale_planner_calendar_event_sales.xml",
"sale_planner_calendar/static/src/xml/activity_menu_view.xml",
"sale_planner_calendar/static/src/scss/sale_planner_calendar.scss",
"sale_planner_calendar/static/src/js/*.js",
],
Expand Down
20 changes: 17 additions & 3 deletions sale_planner_calendar/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-30 16:12+0000\n"
"PO-Revision-Date: 2024-10-30 17:12+0100\n"
"Last-Translator: Sergio Teruel <sergio.teruel@tecnativa.com>\n"
"POT-Creation-Date: 2024-11-07 12:50+0000\n"
"PO-Revision-Date: 2024-11-07 13:54+0100\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -390,6 +390,11 @@ msgstr "Meses posteriores para crear eventos de calendario"
msgid "Friday"
msgstr "Viernes"

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
msgid "Future"
msgstr "Futuro"

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_summary_search
Expand Down Expand Up @@ -693,6 +698,11 @@ msgstr "Pedido"
msgid "Orders"
msgstr "Pedidos"

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
msgid "Past"
msgstr "Pasado"

#. module: sale_planner_calendar
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_reassign_line_wiz__partner_id
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_reassign_wiz__partner_id
Expand Down Expand Up @@ -871,8 +881,11 @@ msgid "Sale planner calendar event"
msgstr "Eventos de rutero"

#. module: sale_planner_calendar
#. odoo-python
#: code:addons/sale_planner_calendar/models/res_users.py:0
#: model:ir.actions.act_window,name:sale_planner_calendar.action_sale_planner_calendar_event
#: model:ir.ui.menu,name:sale_planner_calendar.menu_sale_planner_calendar_event
#, python-format
msgid "Sale planner calendar events"
msgstr "Eventos de rutero"

Expand Down Expand Up @@ -1139,6 +1152,7 @@ msgid "Until"
msgstr "Hasta"

#. module: sale_planner_calendar
#: model:ir.model,name:sale_planner_calendar.model_res_users
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_summary__user_id
msgid "User"
msgstr "Usuario"
Expand Down
16 changes: 16 additions & 0 deletions sale_planner_calendar/i18n/sale_planner_calendar.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-07 12:50+0000\n"
"PO-Revision-Date: 2024-11-07 12:50+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -380,6 +382,11 @@ msgstr ""
msgid "Friday"
msgstr ""

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
msgid "Future"
msgstr ""

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_summary_search
Expand Down Expand Up @@ -677,6 +684,11 @@ msgstr ""
msgid "Orders"
msgstr ""

#. module: sale_planner_calendar
#: model_terms:ir.ui.view,arch_db:sale_planner_calendar.view_sale_planner_calendar_search
msgid "Past"
msgstr ""

#. module: sale_planner_calendar
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_reassign_line_wiz__partner_id
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_reassign_wiz__partner_id
Expand Down Expand Up @@ -855,8 +867,11 @@ msgid "Sale planner calendar event"
msgstr ""

#. module: sale_planner_calendar
#. odoo-python
#: code:addons/sale_planner_calendar/models/res_users.py:0
#: model:ir.actions.act_window,name:sale_planner_calendar.action_sale_planner_calendar_event
#: model:ir.ui.menu,name:sale_planner_calendar.menu_sale_planner_calendar_event
#, python-format
msgid "Sale planner calendar events"
msgstr ""

Expand Down Expand Up @@ -1115,6 +1130,7 @@ msgid "Until"
msgstr ""

#. module: sale_planner_calendar
#: model:ir.model,name:sale_planner_calendar.model_res_users
#: model:ir.model.fields,field_description:sale_planner_calendar.field_sale_planner_calendar_summary__user_id
msgid "User"
msgstr ""
Expand Down
1 change: 1 addition & 0 deletions sale_planner_calendar/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import calendar_attendee
from . import res_config_settings
from . import res_partner
from . import res_users
from . import sale_order
from . import sale_payment_sheet
from . import sale_planner_calendar_issue_type
Expand Down
19 changes: 19 additions & 0 deletions sale_planner_calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
sanitized_partner_mobile = fields.Char(compute="_compute_sanitized_partner_mobile")
location_url = fields.Char(compute="_compute_location_url")
categ_icons = fields.Char(compute="_compute_categ_icons")
sale_planner_rating = fields.Selection(
[
("1", "🙁"),
("3", "😐"),
("5", "🙂"),
],
required=True,
)

@api.depends("recurrence_id", "recurrence_id.calendar_event_ids")
def _compute_is_base_recurrent_event(self):
Expand Down Expand Up @@ -350,6 +358,7 @@
{
"sale_planner_state": "pending",
"comment": False,
"sale_planner_rating": False,
}
)

Expand All @@ -363,6 +372,16 @@
def action_apply_issue(self):
pass

def action_open_rating(self):
action = self.env["ir.actions.act_window"]._for_xml_id(

Check warning on line 376 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L376

Added line #L376 was not covered by tests
"sale_planner_calendar.action_sale_planner_calendar_rating"
)
action["res_id"] = self.id
return action

Check warning on line 380 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L379-L380

Added lines #L379 - L380 were not covered by tests

def action_set_sale_planner_rating(self):
self.action_done()

Check warning on line 383 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L383

Added line #L383 was not covered by tests

def _get_hour_tz_offset(self):
timezone = self._context.get("tz") or self.env.user.partner_id.tz or "UTC"
self_tz = self.with_context(tz=timezone)
Expand Down
73 changes: 73 additions & 0 deletions sale_planner_calendar/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2024 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json
from datetime import datetime

import pytz

from odoo import _, api, fields, models, modules


class ResUsers(models.Model):
_inherit = "res.users"

def _get_sale_planner_calendar_events_domain(self):
return [

Check warning on line 15 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L15

Added line #L15 was not covered by tests
("user_id", "=", self.env.user.id),
("target_partner_id", "!=", False),
("sale_planner_state", "=", "pending"),
]

@api.model
def get_action_sale_planner_calendar_event(self):
return self.env["ir.actions.act_window"]._for_xml_id(

Check warning on line 23 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L23

Added line #L23 was not covered by tests
"sale_planner_calendar.action_sale_planner_calendar_event"
)

@api.model
def systray_get_activities(self):
res = super().systray_get_activities()

Check warning on line 29 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L29

Added line #L29 was not covered by tests
# Get user timezone or UTC if not set
user_tz = pytz.timezone(self.env.user.tz or "UTC")

Check warning on line 31 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L31

Added line #L31 was not covered by tests
# Get current time in user's timezone
datetime_now = datetime.now(user_tz)
domain = self._get_sale_planner_calendar_events_domain()

Check warning on line 34 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L33-L34

Added lines #L33 - L34 were not covered by tests
# Start of day in user's timezone
start_date_today_tz = datetime_now.replace(hour=0, minute=0, second=0)

Check warning on line 36 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L36

Added line #L36 was not covered by tests
# Convert to UTC for domain
start_date_today_utc = start_date_today_tz.astimezone(pytz.UTC)

Check warning on line 38 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L38

Added line #L38 was not covered by tests
# End of day in user's timezone
end_date_today_tz = datetime_now.replace(hour=23, minute=59, second=59)

Check warning on line 40 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L40

Added line #L40 was not covered by tests
# Convert to UTC for domain
end_date_today_utc = end_date_today_tz.astimezone(pytz.UTC)
domain_today = domain + [

Check warning on line 43 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L42-L43

Added lines #L42 - L43 were not covered by tests
("start", ">=", fields.Datetime.to_string(start_date_today_utc)),
("start", "<=", fields.Datetime.to_string(end_date_today_utc)),
]
events_today_count = self.env["calendar.event"].search_count(domain_today)
events_overdue_count = self.env["calendar.event"].search_count(

Check warning on line 48 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L47-L48

Added lines #L47 - L48 were not covered by tests
domain + [("start", "<", start_date_today_utc)]
)
events_planned_count = self.env["calendar.event"].search_count(

Check warning on line 51 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L51

Added line #L51 was not covered by tests
domain + [("start", ">", end_date_today_utc)]
)
total_count = events_today_count + events_overdue_count

Check warning on line 54 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L54

Added line #L54 was not covered by tests
if total_count:
res.append(

Check warning on line 56 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L56

Added line #L56 was not covered by tests
{
"id": self.env["ir.model"]._get("calendar.event").id,
"type": "activity",
"name": _("Sale planner calendar events"),
"model": "calendar.event",
"icon": modules.module.get_module_icon(
self.env["calendar.event"]._original_module
),
"total_count": total_count,
"today_count": events_today_count,
"overdue_count": events_overdue_count,
"planned_count": events_planned_count,
"is_planner": True,
"domain": json.dumps(domain),
}
)
return res

Check warning on line 73 in sale_planner_calendar/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/res_users.py#L73

Added line #L73 was not covered by tests
Binary file added sale_planner_calendar/static/img/rating_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sale_planner_calendar/static/img/rating_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sale_planner_calendar/static/img/rating_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions sale_planner_calendar/static/src/js/activity_group_view.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @odoo-module **/

import {registerPatch} from "@mail/model/model_core";
import {attr} from "@mail/model/model_field";

registerPatch({
name: "ActivityGroup",
modelMethods: {
convertData(data) {
const data2 = this._super(data);
data2.is_planner = data.is_planner;
return data2;
},
},
fields: {
is_planner: attr({default: false}),
},
});

registerPatch({
name: "ActivityGroupView",
recordMethods: {
onClickFilterButton(ev) {
this._super(...arguments);
const data = _.extend({}, $(ev.currentTarget).data(), $(ev.target).data());
if (data.is_planner === 1) {
const context = {};
if (data.filter === "my") {
context.search_default_planner_overdue = 1;
context.search_default_planner_today = 1;
} else {
context["search_default_planner_" + data.filter] = 1;
}
this.env.services.orm
.call("res.users", "get_action_sale_planner_calendar_event")
.then((action) => {
action.domain = data.domain;
const action_ctx = JSON.parse(
action.context.replace(/'/g, '"')
);
action.context = {...action_ctx, ...context};
delete action.context.search_default_my_event_planner;
this.env.services.action.doAction(action, {
clearBreadcrumbs: true,
});
});
}
},
},
});
13 changes: 13 additions & 0 deletions sale_planner_calendar/static/src/xml/activity_menu_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-inherit="mail.ActivityMenuView" t-inherit-mode="extension">
<xpath
expr="//*[hasclass('o_ActivityMenuView_activityGroup')]"
position="attributes"
>
<attribute
name="t-att-data-is_planner"
>activityGroupView.activityGroup.is_planner ? 1 : 0</attribute>
</xpath>
</t>
</templates>
Loading
Loading