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: Design improves and new buttons in calendar planner event #3073

Merged
merged 1 commit into from May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sale_planner_calendar/README.rst
Expand Up @@ -118,6 +118,7 @@ Contributors
* Sergio Teruel
* Carlos Dauden
* Carlos Roca
* Pilar Vargas

Maintainers
~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion sale_planner_calendar/__manifest__.py
Expand Up @@ -18,16 +18,18 @@
"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",
"wizard/sale_planner_calendar_reassign.xml",
"wizard/sale_planner_calendar_wizard.xml",
# # Menu position fixed
# Menu position fixed
"views/sale_planner_calendar_menu.xml",
],
"assets": {
Expand Down
15 changes: 15 additions & 0 deletions sale_planner_calendar/data/sale_planner_calendar_event_profile.xml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="event_profile_face_to_face" model="sale.planner.calendar.event.profile">
<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">
<field name="name">Telephone</field>
<field name="icon">fa-phone</field>
</record>
<record id="event_profile_message" model="sale.planner.calendar.event.profile">
<field name="name">Message</field>
<field name="icon">fa-envelope</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions sale_planner_calendar/models/__init__.py
Expand Up @@ -6,6 +6,7 @@
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
4 changes: 4 additions & 0 deletions sale_planner_calendar/models/calendar.py
Expand Up @@ -19,6 +19,9 @@ class CalendarEvent(models.Model):
string="Sale planner partner",
help="Is the partner used in planner",
)
calendar_event_profile_id = fields.Many2one(
comodel_name="sale.planner.calendar.event.profile"
)
currency_id = fields.Many2one(
comodel_name="res.currency", related="target_partner_id.currency_id"
)
Expand Down Expand Up @@ -122,6 +125,7 @@ def _create_event_planner(self):
"user_id": self.user_id.id,
"calendar_event_date": self.start,
"calendar_event_id": self.id,
"calendar_event_profile_id": self.calendar_event_profile_id.id,
}
)

Expand Down
33 changes: 32 additions & 1 deletion sale_planner_calendar/models/sale_planner_calendar_event.py
@@ -1,6 +1,8 @@
# Copyright 2021 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import re

from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval

Expand Down Expand Up @@ -45,6 +47,9 @@
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", currency_field="currency_id"
Expand Down Expand Up @@ -73,6 +78,9 @@
partner_mobile = fields.Char(compute="_compute_contact")
partner_contact_name = fields.Char(compute="_compute_contact")
partner_city = fields.Char(related="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")

@api.depends("sale_ids.amount_untaxed")
def _compute_sale_order_subtotal(self):
Expand Down Expand Up @@ -130,6 +138,30 @@
)
rec.partner_contact_name = contact.name

def _compute_sanitized_partner_mobile(self):
self.sanitized_partner_mobile = False

Check warning on line 142 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L142

Added line #L142 was not covered by tests
for rec in self.filtered("partner_mobile"):
rec.sanitized_partner_mobile = re.sub(r"\W+", "", rec.partner_mobile)

Check warning on line 144 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L144

Added line #L144 was not covered by tests

def _compute_location_url(self):
# The url is built to access the location from a google link. This will be done
# taking into account the location of the calendar event associated with the calendar
# planner event. If this location is not defined, the client's coordinates will
# be taken into account if they are defined, otherwise the client's address
# will be taken into account.
self.location_url = False

Check warning on line 152 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L152

Added line #L152 was not covered by tests
for rec in self:
event_location = rec.calendar_event_id.location
partner_latitude = str(rec.partner_id.partner_latitude).replace(",", ".")
partner_longitude = str(rec.partner_id.partner_longitude).replace(",", ".")
partner_location = f"{rec.partner_city}+{rec.partner_street}"

Check warning on line 157 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L154-L157

Added lines #L154 - L157 were not covered by tests
if event_location:
self.location_url = event_location.replace(" ", "+")

Check warning on line 159 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L159

Added line #L159 was not covered by tests
elif partner_latitude != "0.0" or partner_longitude != "0.0":
self.location_url = f"{partner_latitude}%2C{partner_longitude}"

Check warning on line 161 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L161

Added line #L161 was not covered by tests
elif partner_location:
self.location_url = partner_location.replace(" ", "+")

Check warning on line 163 in sale_planner_calendar/models/sale_planner_calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/sale_planner_calendar_event.py#L163

Added line #L163 was not covered by tests

def action_open_sale_order(self, new_order=False):
"""
Search or Create an event planner linked to sale order
Expand Down Expand Up @@ -176,7 +208,6 @@
action = self.env["ir.actions.act_window"]._for_xml_id(
"sale_payment_sheet.action_invoice_sale_payment_sheet"
)

ctx = safe_eval(action["context"])
ctx.update(
{
Expand Down
@@ -0,0 +1,18 @@
# 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")
1 change: 1 addition & 0 deletions sale_planner_calendar/readme/CONTRIBUTORS.rst
Expand Up @@ -3,3 +3,4 @@
* Sergio Teruel
* Carlos Dauden
* Carlos Roca
* Pilar Vargas
1 change: 1 addition & 0 deletions sale_planner_calendar/security/ir.model.access.csv
Expand Up @@ -5,3 +5,4 @@ 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
2 changes: 2 additions & 0 deletions sale_planner_calendar/static/description/index.html
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -452,6 +453,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Sergio Teruel</li>
<li>Carlos Dauden</li>
<li>Carlos Roca</li>
<li>Pilar Vargas</li>
</ul>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion sale_planner_calendar/views/calendar_view.xml
Expand Up @@ -77,7 +77,7 @@
<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
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_sale_planner_calendar_event_profile_tree" model="ir.ui.view">
<field name="name">sale.planner.calendar.event.profile.tree</field>
<field name="model">sale.planner.calendar.event.profile</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="name" />
<field name="icon" />
</tree>
</field>
</record>

<record
id="action_sale_planner_calendar_event_profile"
model="ir.actions.act_window"
>
<field name="name">Event Profile</field>
<field name="res_model">sale.planner.calendar.event.profile</field>
<field name="view_mode">tree</field>
</record>

</odoo>