forked from OCA/hr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] partner_phonecall_schedule: Know partner's best phonecall time (O…
- Loading branch information
1 parent
468346b
commit 062f2e1
Showing
10 changed files
with
460 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
=========================== | ||
Partner phonecalls schedule | ||
=========================== | ||
|
||
If you know the best moment to call your partners, use this addon to keep | ||
track of it and be able to filter partners that you can comfortably call now. | ||
|
||
Usage | ||
===== | ||
|
||
To use the phonecall schedules, you need to: | ||
|
||
#. Go to any partner form. | ||
#. Go to the *Phone calls* tab. | ||
#. Select any of the available schedules. | ||
#. A readonly checkbox will tell you if it is a good time to call him/her. | ||
#. A readonly aggregated schedule is visible too. | ||
|
||
To filter partners available to call right now: | ||
|
||
#. Go to the partners view. | ||
#. Use the built-in filter *Available for phone calls now* | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/111/9.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/crm/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jairo Llopis <jairo.llopis@tecnativa.com> | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Funders | ||
------- | ||
|
||
The development of this module has been financially supported by: | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_ | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Partner phonecalls schedule", | ||
"summary": "Track the time and days your partners expect phone calls", | ||
"version": "9.0.1.0.0", | ||
"category": "Customer Relationship Management", | ||
"website": "https://github.com/OCA/crm", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"resource", | ||
], | ||
"data": [ | ||
"views/res_partner_view.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * partner_phonecall_schedule | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 9.0c\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2017-09-15 12:30+0000\n" | ||
"PO-Revision-Date: 2017-09-15 14:32+0200\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
"X-Generator: Poedit 2.0.3\n" | ||
"Last-Translator: Jairo Llopis <yajo.sk8@gmail.com>\n" | ||
"Language: es_ES\n" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model.fields,field_description:partner_phonecall_schedule.field_res_partner_phonecall_calendar_attendance_ids | ||
msgid "Aggregated phonecall schedule" | ||
msgstr "Horario agregado de llamadas telefónicas" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.ui.view,arch_db:partner_phonecall_schedule.view_res_partner_filter | ||
msgid "Available for phone calls now" | ||
msgstr "Disponible para llamar por teléfono ahora" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model.fields,field_description:partner_phonecall_schedule.field_res_partner_phonecall_available | ||
msgid "Available to call" | ||
msgstr "Disponible para llamar" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model.fields,help:partner_phonecall_schedule.field_res_partner_phonecall_calendar_ids | ||
msgid "Best schedule when the contact expects to be called." | ||
msgstr "El mejor horario para llamar por teléfono al contacto." | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model.fields,help:partner_phonecall_schedule.field_res_partner_phonecall_available | ||
msgid "Is it now a good time to call this partner?" | ||
msgstr "¿Es un buen momento para llamar a este contacto?" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model,name:partner_phonecall_schedule.model_res_partner | ||
msgid "Partner" | ||
msgstr "Contacto" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.ui.view,arch_db:partner_phonecall_schedule.view_partner_form | ||
msgid "Phone calls" | ||
msgstr "Llamadas telefónicas" | ||
|
||
#. module: partner_phonecall_schedule | ||
#: model:ir.model.fields,field_description:partner_phonecall_schedule.field_res_partner_phonecall_calendar_ids | ||
msgid "Phonecall schedule" | ||
msgstr "Horario de llamadas telefónicas" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from __future__ import division | ||
from datetime import datetime | ||
from openerp import api, fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
phonecall_available = fields.Boolean( | ||
"Available to call", | ||
compute="_compute_phonecall_available", | ||
search="_search_phonecall_available", | ||
help="Is it now a good time to call this partner?", | ||
) | ||
phonecall_calendar_ids = fields.Many2many( | ||
comodel_name="resource.calendar", | ||
string="Phonecall schedule", | ||
help="Best schedule when the contact expects to be called.", | ||
) | ||
phonecall_calendar_attendance_ids = fields.One2many( | ||
comodel_name="resource.calendar.attendance", | ||
string="Aggregated phonecall schedule", | ||
compute="_compute_phonecall_calendar_ids", | ||
help="Aggregation of all available phonecall schedules.", | ||
) | ||
|
||
@api.depends("phonecall_calendar_ids", "phonecall_calendar_attendance_ids") | ||
def _compute_phonecall_available(self): | ||
"""Know if a partner is available to call right now.""" | ||
Attendance = self.env["resource.calendar.attendance"] | ||
for one in self: | ||
domain = [ | ||
("calendar_id", "in", one.phonecall_calendar_ids.ids) | ||
] + one._phonecall_available_domain() | ||
found = Attendance.search(domain, limit=1) | ||
one.phonecall_available = bool(found) | ||
|
||
@api.depends("phonecall_calendar_ids") | ||
def _compute_phonecall_calendar_ids(self): | ||
"""Fill attendance aggregation.""" | ||
for one in self: | ||
one.phonecall_calendar_attendance_ids = one.mapped( | ||
"phonecall_calendar_ids.attendance_ids") | ||
|
||
def _search_phonecall_available(self, operator, value): | ||
"""Search quickly if partner is available to call right now.""" | ||
Attendance = self.env["resource.calendar.attendance"] | ||
available = Attendance.search( | ||
self._phonecall_available_domain(), | ||
) | ||
if operator == "!=" or "not" in operator: | ||
value = not value | ||
operator = "in" if value else "not in" | ||
return [("phonecall_calendar_ids.attendance_ids", | ||
operator, available.ids)] | ||
|
||
def _phonecall_available_domain(self): | ||
"""Get a domain to know if we are available to call a partner.""" | ||
now = self.env.context.get("now", datetime.now()) | ||
try: | ||
now = fields.Datetime.from_string(now) | ||
except TypeError: | ||
# `now` is already a datetime object | ||
pass | ||
date = fields.Date.to_string(now) | ||
now_tz = fields.Datetime.context_timestamp(self, now) | ||
float_time = now_tz.hour + ((now_tz.minute / 60) + now_tz.second) / 60 | ||
return [ | ||
("dayofweek", "=", str(now.weekday())), | ||
"|", ("date_from", "=", False), ("date_from", "<=", date), | ||
"|", ("date_to", "=", False), ("date_to", ">=", date), | ||
("hour_from", "<=", float_time), | ||
("hour_to", ">=", float_time), | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_schedule |
Oops, something went wrong.