Commit Graph
512 Commits
Author SHA1 Message Date
Raphael Collet f934b29a8a [REF] core: speed up the retrieval of fields on models
Fields are no longer retrieved with inspect.getmembers(), which is
time-consuming.  Instead, the classes defining models automatically
collect their own fields (via Field.__set_name__()), and the field
retrieval is done by using those collections.  Also, a field no longer
needs to introspect its model class to find its field definitions.

A class that defines a model automatically determines its '_name',
'_inherit' and '_module' upon creation, and the fields determine their
'name', 'model_name' and '_module' via Field.__set_name__().

Loading a registry with 290 modules from scratch is now 25% faster.
2021-05-03 12:33:29 +00:00
Simon Genin (ges) ecfe85db84 [REF] web: static/src/(img|fonts) => static/(img|fonts) 2021-04-29 07:34:40 +00:00
Thibault Delavallée effebe148f [FW][FIX] mail, various: fix document access link computation
Purpose of this commit is to fix computation of access link. In some cases
msg_vals modification leads to invalid URL computation, notably for frontend
or backend differentiation for target recipients.

Followup of odoo/odoo#63292 .

Task ID-2513724
COM PR odoo/odoo#69607
ENT PR odoo/enterprise#17849

X-original-commit: e618597876692f2d24f8e9308c747b8d1f2d8905
2021-04-23 15:24:58 +00:00
Noe Antoine 335701b35e [IMP] crm : develop a smart calendar view from crm opportunity
Before, when the user clicked on a crm opportunity "meetings" smart button,
the calendar view was centered on the present day, and with default mode
(week, month,...) as a scale. This behavior leads to calendar views that
were possibly not including those meetings.

This smart calendar improves this by computing the target date and the scale
to make sure that the user is taken to the useful time period when using the
smart button from crm opportunity. The meetings considered are only the
relevant one, that is only the ones not finished yet, if there are some, and
all (finished) meetings otherwise. The calendar works as follows :

 -If no meetings: show current week
 -If one: show that week
 -If more than one and same week : show that week
 -If more than one and same month : show that month
 -If more than one month, show month of the first meeting.

This is done according to user language week_start and timezone. This way
the user always see what is the most relevant.

Also added python tests in class TestCRMLeadSmartCalendar.

Task ID-2431245

closes odoo/odoo#64807

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-04-01 18:59:48 +00:00
Thibault Delavallée 389d74fab3 [IMP] crm: allow team members to opt-out from assign
Purpose is to allow members to quickly opt-out / opt-in from assign
process. For example if for some reason (leaves, too much leads, temporarily
working on something else) a salesperson cannot handle more leads he may
opt-out from assign process.

When member is opt-out, hide assign details from both kanban and form
views. It allows notably to see at a glance who is out and who is in.

Task ID-2494749
COM PR odoo/odoo#68476
UPG PR odoo/upgrade#2318

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-30 14:41:16 +00:00
nounoubensebia 6c81ee556f [REF] [crm_]mail_client_extension, base_setup, crm[_iap_lead_enrich], iap: split mail specific and crm specific code
- split the mail_client_extension module onto two modules:
  1) module mail_client_extension having mail/contact specific code,
  depends on iap and contacts only
  2) module crm_mail_client_extension having crm specific code,
  depends on CRM and mail_client_extension.

  Purpose is to allow the user to use the mail_client_extension
  without needing to install CRM, this will also allow
  the usage of the mail connector in other modules without
  the need for CRM.

- add the module_mail_client_extension field to the
  res_config_settings model of the base_setup module
  in order to enable the user to install the
  mail_client_extension module directly from the settings

- move the crm_lead model from the mail_client_extension_module
  to the newly created crm_mail_client_extension_module, as this
  model is no longer needed by the mail_client_extension module
  because it no longer not implemants CRM functionality

- move the iap_enrich_api model from the crm_iap_lead_enrich
  module onto the iap module as it is only related to contacts
  and not to CRM, this way it can be used in other modules such
  as the mail_client_extension module without the need for CRM
  module

Task-2382870
UPG-PR: https://github.com/odoo/upgrade/pull/2156
COM-PR: https://github.com/odoo/odoo/pull/66139
2021-03-29 11:59:11 +00:00
Ipsita Borisagar 7e5ee53035 [FIX] crm: avoid to display false in case of void subject
Before this commit:

If there is no subject for message, it effectively displays "False" in case of
void subject.

After this commit:

If there is no subject for message, it will not display "False" in case of void
subject.

Tasks-2156170

closes odoo/odoo#68243

X-original-commit: 4b2f0ddcbe859ec8453e537aec9d5b0685876eca
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-23 13:52:19 +00:00
Munaf Khan 8f88307c18 [FX][FIX] crm: prevent email_from propagation if only formatting differs
Before this commit when we update the email_from field on lead with only
formatting differing from partner a warning ribbon was displayed. It
considered email had changed and had to be propagated. Moreover unnecessary
update on partner was done to propagate the new email onto the customer.

In this commit we propagate email only if normalized versions are different.
It means that if lead email_from is "Hermes Conrad <email@example.com>" and
partner email is "Jonathan Conrad <email@example.com"> no update from lead
to partner is performed. Indeed normalized versions are the same.

Task ID-2461308
PR odoo/odoo#66890

X-Original-Commit odoo/odoo@3dd972c35b

closes odoo/odoo#67859

Related: odoo/enterprise#17191
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-22 07:52:19 +00:00
Noe Antoine 374134a04c [IMP] crm: inline email and phone sync warnings on crm lead
Reduce eye catchiness of warning message when warning the user that
his changes on email and phone will also update customer.

Before, used a ribbon (ribbon_message). It is removed from crm lead model
and also of crm lead form view.

Now, only displays an orange alert sign at the end of the fields when a change
would update the customer profile. Hovering on the alert sign displays
the appropriate message. The warning icon is added on crm lead view for
both lead and opportunity types.

Python compute method of ribbon field is split in two compute methods,
one per boolean field partner_email/phone_update.

Also updates ribbon_message tests accordingly.

TaskId 2456105
COM PR odoo/odoo#66909
UPG PR odoo/upgrade#2258

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-15 16:16:59 +00:00
Aurélien Warnon cd117b15d4 [IMP] crm: improve crm.lead kanban ribbon display
Since e86f892a7b

We have the possibility to display a "lost" and a "won" ribbon on the crm.lead
kanban view.

In this commit, we change things around a bit:
- The "WON" ribbon was removed.
  Since it was redundant with the stage anyway and not very useful.
- The "LOST" ribbon is now always displayed in the kanban view.
  And not only when coming from "duplicate leads".

In addition, leads displayed when coming from the stat button on the
res.partner form view now also shows lost leads (active_test=False).
This can be helpful for the end user because he wants to know "all the deals
that are in progress/lost/won with this specific contact".

Task-2349526

closes odoo/odoo#67693

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-12 09:38:35 +00:00
Julien Banken e86f892a7b [IMP] crm: Duplicate leads on lead form view
PURPOSE

Duplicate lead records are an issue for CRM users
To prevent sales representatives from contacting a prospect that:

- Already refused an offer from another sales
- Already accepted an offer from another sales
- Is already discussing with another sales

The purpose of this task is to inform the CRM user that there are
some possible duplicates for one lead and let the user decide how
to handle the case.

SPECIFICATION

- Add a computed field to count the number of potential duplicates.
- Add a stat button on the form view of a lead to display the number
of potential duplicates. When the user clicks on it, the leads
considered as duplicate will be displayed in a kanban view.
- Add a lost ribbon on the kanban view to quickly visualize the lead
state since the duplicates can be lost leads.

LINKS

Task ID : 2151017

closes odoo/odoo#61834

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-10 14:29:50 +00:00
Nicolas Seinlet 35c0bad900 [IMP] crm: assign faster by commiting less
commit at each lead makes the system spend 80% of the time recomputing
bayesian probabilities. Avoid to commit too often speed up the process
while not altering final result.

Task ID-2475352

closes odoo/odoo#67275

X-original-commit: 34f6e38e68208b9509a429cdb09f8316a7ef566f
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-04 15:49:53 +00:00
Damien Abeloos 7498f6b87b [IMP] crm: change the search order for a won stage
* The "Mark As Won" button should first look for "won stages" that
  have a higher sequence than the one the opportunity currently is.
  If none is found, then it's "ok" to go to a stage with a lower sequence.

* In Fine, we would like to prevent a "not won" stage to have a higher
  sequence than any "is won" stage. But while this is not the case, searching
  for the "is won" stage while alterning the sequence order will correctly
  handle the following case :
    - stage sequence :
        [x] [x is won] [y] [y is won] [z] [z is won]
    - scenario :
        an opportunity in [y] and marked as "won" should go to [y is won].
        (not in [x is won] nor [z is won])

Task ID : 2410217
PR : https://github.com/odoo/odoo/pull/63370
2021-03-03 12:43:30 +00:00
Damien Abeloos b0134452c0 [IMP] crm: add a reschedule action for activities
* Replace the "Snooze 7d" action for lead-related activities linked to
  a calendar event by a "Reschedule" action, which will redirect the user
  to the calendar view with the focus on the next event related to the
  opportunity
    - The "Snooze 7d" action only impacted the activity and not the meeting,
      and snoozing a meeting is not very logical anyway. The "Reschedule" fits
      better in this use case.

* It was discussed to show only a modal allowing to reschedule the next
  calendar event, but that could lead to inconsistent states (out of order
  sequence of scheduled events, if the first is rescheduled after the
  second).

* The reschedule option will be shown next to any activity related to a
  calendar_event regardless of its activity type. There are some edge cases
  that we may want to change in the future :
    - When changing the activity type of a 'meeting' activity associated to
      a calendar event to any other activity type, but without removing the
      calendar event, the reschedule action is still showing (since the event
      is still ongoing and was not deleted from the calendar).
    - Conversely, with a meeting which is not (yet?) related to a calendar event,
      the reschedule action will not be available.

* Add a new field to MailActivityMixin in the calendar module context. This
  field is the event linked to the next activity, if there is one such event.
  It is used to check whether the reschedule action should be available to the user.

* Add a test for this new field to validate the expected behavior.

* Add the priority widget to the priority field in the opportunity tree view

Task ID : 2410217
PR : https://github.com/odoo/odoo/pull/63370
2021-03-03 12:43:22 +00:00
ijas ahammed 79476eb349 [IMP] sales_team, crm{_iap}*: improve action helpers and usability
This commit improves the action helpers for the actions bound to below listed
menus for better usability:

  * My Activities
  * Leads
  * Leads Analysis

Along with that, this commit also improves the following:

  * while generating leads, make 'Industries' field required on the modal so
    that results obtained are actionable instead of random leads;
  * after trying to generate leads, if no result is found, the same pop-up
    opens again with same criteria and displays a waring in the pop-up. It
    informs users that leads are not found and no credits are spent for their
    last search;
  * improve the warning message for unsuccessful enrichment due to invalid
    email;

COM PR odoo/odoo#64075
ENT PR odoo/enterprise#15561
Task ID-2393253
2021-03-03 15:56:23 +00:00
Nikunj Ladava ee30ecef0d [IMP] crm: propagate partner's company_name to lead partner_name
When setting a partner on a lead if we select the individual customer that
is not a company with company_name being set, propagate it to partner_name
on lead.

Task ID-2446969
PR #65846
2021-03-03 08:30:47 +00:00
Munaf Khan f56205f85a [FIX] crm: prevent crash due to invalid system parameter
Right now, if someone changes the `crm.pls_start_date` system parameter
to something that is not valid, opening a settings gives you traceback.

This commit improves the behavior by making sure that the compute field on
settings page `predictive_lead_scoring_start_date` always contains a valid
date. For doing so, if the system parameter is not a valid date(or not set
or deleted), we set the above field to the date 8 days prior to current
date, and thus, when saving the settings, the system parameter is again
set with a valid date.

closes odoo/odoo#66988

Taskid: 2448248
X-original-commit: 19577c40f8f2878286ef63da5d30b341d7ab5cbf
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-01 10:26:42 +00:00
Thibault Francois 9b4c101484 [IMP] crm|mail: Use flanker to check email correctness
Context
-------
Lead assignement is now based on PLS probability.
We want to avoid giving the same score to real email addresses
and email addresses that are just well formed

Flanker try to acheive that be checking specific
criteria according to the domain, check the dns and mx record

Improvement
-----------
Define a mail_validate function seach as phone_validate.
If flanker is installed, use flanker for validation of
email addresses else use email_normalize.
It should help the PLS to give a bad score to well formed addresses
that flanker suspect to be wrong.

Setup
-----
NB: flanker is not available as debian package, we make it optional

To install flanker
```
pip install flanker
pip install redis
pip install dnsq
```

If you have installed it as root you may need to run
```py
from flanker.addresslib import address
```
as root for the first initialisation

closes odoo/odoo#66429

X-original-commit: f540976c8751e2bf402fed8db830ec0fbf98f654
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-02-18 09:15:35 +00:00
ijas ahammed 0c90469efa [IMP] crm: for first won lead, display rainbowman regardless of revenue
Right now, if the expected revenue is not set on the opportunity, the
rainbowman is not displayed and it does make sense to ask for a revenue
so that we can measure if this is a record or not. However, revnue is not
necessary to congratulate the user for his first win.

With this commit, for the first won lead of a user, we congratulate user
with rainbowman, even if there is no exptected revenue set.

closes odoo/odoo#65378

Task-id: 2410443
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-02-09 10:11:26 +00:00
Thibault Delavallée c146e63779 [FW][FIX] crm: split computed fields linked to partner
RATIONALE

Stored editable fields receive their values either from compute either from
user input. If a user input is given to create / write compute method is not
called. If multiple fields are computed through the same method giving one
field value discard call to compute method and other fields are not called.

SPECIFICATIONS

Split ``_compute_partner_id_values`` compute method so that partner related
fields are independent :

  * have a method for address fields as those are computed in group. Indeed
    either we take all from partner either none. Otherwise it would create mixed
    addresses that make no sense;
  * have a specific computation for partner_name and contact_name coming
    from ``_prepare_partner_values``;
  * have other fields separated (function, title, ...) acting like related on partner
    if not set by user;

LINKS

COM PR odoo/odoo#65381
Task ID-2451339

X-original-commit odoo/odoo@78eb46352e

closes odoo/odoo#65658

X-original-commit: bb13421d3a7f04ede9350b3b28c1650c3d9890f8
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-02-05 17:51:33 +00:00
dht-odoo 66b0fede39 [IMP] crm: improve update of probabilities from settings
Right now there is a button in the CRM settings called 'Update Probabilities'.
When clicking on it probabilities of leads created after certain date
are updated. Problem with this flow is that user can click on the button by
mistake and there is no going back.

Moreover this does not trigger a save on settings and changes done by user
are not saved. This is standard behavior of config settings.

This commit improves the behavior by opening a wizard on click of the button
instead of directmy updating the probabilities. It allows users to change
fields used in PLS, change start date, or even cancel the update process.

Task ID-2355562

closes odoo/odoo#60733

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-02-02 16:19:41 +00:00
Jérémy Hennecart 095e59c8b7 [IMP] crm: add tracking on recurring_revenue field
Add tracking on the recurring_revenue field like the expected
revenue.

odoo/odoo#61999
odoo/upgrade#2060
task-2387268
2021-02-01 16:18:36 +00:00
Thibault Delavallée 9d0965926d [IMP] crm: take highest priority when merging leads
When merging leads final priority is currently the one of the lead considered
as the master lead. This is based on ``_sort_by_confidence_level`` who sorts
on confidence but not on priority.

We think final priority should be the highest one from merged leads. Indeed
if a top priority lead is merged into a low priority one we should not loose
the priority information. It is better to keep the final lead with an high
priority and let salesmen move it downwards.

LINKS

Task ID-2446759 (lead merge priority field management)
Task ID-2446883 (query counters fix)
PR odoo/odoo#65016
2021-01-29 08:55:24 +00:00
Thibault Delavallée 3fff6f6a94 [REF] crm: improve code of value computation in _merge_opportunity
Purpose of this commit is to make clearer how final opportunity value are
computed or chosen when merging leads. Functionally nothing should change
with this commit.

LINKS

Task ID-2446759 (lead merge priority field management)
Task ID-2446883 (query counters fix)
PR odoo/odoo#65016
2021-01-29 08:55:24 +00:00
nounoubensebia cb311051cc [IMP] phone_validation, crm, sms: improve phone/mobile search results
Before this commit the user had to type in the exact same formatting to find contacts.
After this commit the user will be able to get better search results and does not have to type the same formatting.

To avoid code duplication, the existing _search_mobile_phone method has been moved to the mail_thread_phone class, so that it could be used by both the crm and res_partner models.

Task-2435233

closes odoo/odoo#64490

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-26 13:29:43 +00:00
Thibault Delavallée 0edc854a84 [REF] crm: add multi company check on lead model
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and clean

SPECIFICATIONS

Set _check_company_auto on lead model to enable automatic company check when
updating company_id field.

Add a company check on user_id field to ensure user and lead company match.
Also add a company check on team_id to ensure team and lead company match.

Add a dynamic domain to be used in form view to limit available users to set
on leads to those matching domain.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 12:22:09 +00:00
Thibault Delavallée 30e3fc1377 [REF] crm: continue filling salespersons pipe when they win leads
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

When counting assigned leads for members when dealing with automatic assignment
exclude won leads. Indeed purpose of automatic assignment is to ensure
salespersons always have some leads in their pipe. If they won a lot of leads
instead of stopping assignment we should simply fill their pipe again.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 12:22:09 +00:00
Thibault Delavallée 476f6d5e16 [REF] crm: ensure automatic assignment works out of the box
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Assignment max being set to 0 means member is out of automatic assign process.
In that case assignment information (domain in form view, gauge in kanban
view) are hidden to lighten member form view.

Its default value is now set to 30. It means that newly created members by
default are available for automatic assignment.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 12:22:09 +00:00
Thibault Delavallée 5016b47a06 [REF] crm: include leads with probability being 100 but still not won into assign process
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Include leads with probability 100 but not in a won stage when doing automatic
assignment. Otherwise those are not assigned but still not really won as not
in the right stage. Probability 100 means they will be won easily but they
still have to be managed by a salesperson.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#9966
2021-01-21 12:22:09 +00:00
Thibault Delavallée 675623d390 [REF] crm: simplify evaluation of assignment domains
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Remove safe_eval and its support of datetime and context_today. Check in
existing dbs show that it is not used in team or member assignment domains.
We therefore choose to limit content of domains to what goes through a
literal_eval. It allows to reduce potential issues.

We also improve warning messages in order to give clearer message to users
when dealing with input errors.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 12:22:09 +00:00
Thibault Delavallée f84270b072 [IMP] crm: log manual assign and improve feedback message
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Improve wording and feedback given when running automatic assignment. When
running on a single team some more details can be given on its configuration.

Log a message when a manual assign is called from a team. Purpose is to
ensure this action is logged. Otherwise team leaders may try to fetch some
quality leads without notifying anyone.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#9966
2021-01-21 12:22:09 +00:00
Thibault Delavallée 6df2f0cfc0 [REF] crm: limit allocation to teams when running automatic assign
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Currently when assignment runs all free leads are allocated to teams. They
are then assigned to members according to their capacity. This means that
no lead is kept free. If assignment is performed on a subset of teams this
means that other teams have no free lead anymore.

During assignment evaluate which teams still need to receive leads. This is
based on team maximum capacity. We consider a team should receive twice its
capacity as leads. That way members will receive leads and can pick some leads
in team unassigned pool of leads.

e.g. a team has a total of capacity of 90 leads / month among its 3 members.
When running a daily assignment process, an equivalent of twice this running
time is assigned to members (see previous commits). It leads to assignment
of (90 / 30) * 2 = 6 leads. Twice this count is allocated to the team aka
12 leads. Remaining leads will be allocated in next assignment run or are
available for manual assign.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 12:22:09 +00:00
Thibault Delavallée 8fd1066367 [REF] crm: improve team opt-out from lead automatic assignment
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS: TEAM OPT-OUT OF ASSIGN

Allow teams to individually opt-out automatic assignment. If automatic
assignment is activated one can make some team opt-out of automatic process.
Manual assignment on team through an action button is possible even when
opt-outed.

Allow teams to individually opt-out automatic assignment. If automatic
assignment is activated one can make some team opt-out of automatic process.
Manual assignment on team through an action button is possible even when
opt-outed.

SPECIFICATIONS: RESTRICT ASSIGN TO OPPORTUNITIES ENABLED TEAMS

Only teams with use_leads or use_oppotunities should be included in automatic
assign. Indeed other teams like POS, website) do not handle opportunities
or leads. Automatically assigning them leads makes no sense.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 11:07:35 +00:00
Thibault Delavallée adbf69680a [REF] crm: finalize multi sales-team and auto assign integration
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Make final integration of members management by taking into consideration
both multi-membership and automatic lead assignment features.

Correctly hide assignment options and fields if auto assign is not activated.
This means that

  * when being in mono membership mode without automatic assign: display
    users on team form view;
  * when being in multi membership mode or with automatic assign: display
    members o2m records, as configuration is done on this model;
  * hide the whole right column in sales team form view about assignment when
    assignment is not activated in settings;

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 11:07:26 +00:00
Thibault Delavallée ed40fcd48c [REF][MOV] crm: handle automatic lead assignment
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Move sales team automatic lead assignment from website_crm_score (enterprise)
directly into sales_team. Some cleaning and renaming is performed while moving
the code as it is old fashioned.

Scoring feature is removed completely from lead assignment. Indeed we consider
PLS is a better feature and provides more accurate results.

Minimal scoring specific field on team is removed. Indeed it can also be
integrated directly into domains linked to a sales team as this is a field
directly available on lead using ``probability``. It allows to reduce fields
of team model and move all logic in the team's domain itself.

Overall behavior as been kept as close as possible from the original one.
Purpose is to avoid too much undesired changes between versions.

In this commit we also add tests for automatic lead assignment.

ASSIGNMENT PROCESS DESCRIPTION

1- LEAD TO TEAM ALLOCATION

Allocate leads to teams given by self. This method sets ``team_id`` field
on lead records that are unassigned (no team and no responsible). No
salesperson is assigned in this process. Its purpose is simply to allocate
leads within teams.

Heuristic of this method is the following:
  * first we randomize all teams;
  * then for each team

    * find unassigned leads, aka leads being

      * without team, without user -> not assigned;
      * not in a won stage, and not having False/0 (lost) or 100 (won)
        probability) -> live leads;
      * if set, a delay after creation can be applied (see BUNDLE_HOURS_DELAY)
        parameter explanations here below;

    * keep only leads matching the team's assignment domain (empty means
      everything);
    * assign maximum BUNDLE_SIZE leads to the team, then move to the next team.
      This is done to ensure every team will have leads enough to fill its
      capacity based on its domain;
    * when setting a team on leads, leads belonging to the current batch
      are also merged. Purpose is to clean database and avoid assigning
      duplicates to same or different teams;

  * for all teams that still have capacity (aka: a search on unassigned
    available leads with team domain still give results), do another
    assignment round. Each round teams are randomized so that team order
    is not always the same;

Note that leads are assigned in batch meaning a team could receive leads that
could better fit another team. However this heuristics is based on hypothesis
that team domains do not overlap. Indeed if a company has several teams they
will probably target separate market segments: country-based, customer type or
size, ... Having several teams using same assignment domain could lead to less
fairness in assignment process but this should not be the target use case of this
heuristic.

Leads are allocated by batch. This can be configured using a config parameter.
Batch size depends on cron frequency, lead pipeline size and members assignment
maximum. Finding an optimal heuristic for this parameter is not easy as it
depends on internal processes and organization. Higher batch size leads to
better performances when running automatic assignment. It can also give unfair
results if teams domain overlap or if pipeline is not big enough to fill all
teams capacity.

2- LEAD TO MEMBER ASSIGN

Main processing method to assign leads to sales team members. It also converts
them into opportunities. Its main purpose is therefore to distribute team
workload on its members based on their capacity.

Preparation

  * prepare lead domain for each member. It is done using a logical AND with
    team's domain and member's domain. Member domains further restricts team
    domain;
  * prepare a set of available leads for each member by searching for leads
    matching domain with a sufficient limit to ensure all members will receive
    leads;
  * prepare a weighted population sample. Population are members that should
    receive leads. Initial weight is the number of leads to assign to that
    specific member. This is minimum value between

    * remaining this month: assignment_max - number of lead already assigned
      this month;
    * days-based assignment: assignment_max with a ratio based on ``work_days``
    * e.g. Michel Poilvache (max: 30 - currently assigned: 15) limit
      for 2 work days: min(30-15, 30/15) -> 2 leads assigned
    * e.g. Michel Tartopoil (max: 30 - currently assigned: 26) limit
      for 10 work days: min(30-26, 30/3) -> 4 leads assigned

Assign process then follows the following heuristic

  * take a weighted random choice in population;
  * find first available (not yet assigned) lead in its lead set;
  * if found:

    * convert it into an opportunity and assign member as salesperson;
    * lessen member's weight so that other members have an higher
      probability of being picked up next;

  * if not found: consider this member is out of assignment process,
    remove it from population so that it is not picked up anymore;

Assignment is performed one lead at a time for fairness purpose. Indeed members
may have overlapping domains within a given team. To ensure some fairness in
process once a member receives a lead, a new choice is performed with updated
weights. This is not optimal from performance point of view but increases
probability leads are correctly distributed within the team.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 11:00:40 +00:00
Thibault Delavallée 297bee205f [REF] sales_team, crm: support mono/multi team membership mode
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS

Purpose of this commit is to allow to use either mono salesteam mode, either
multi salesteams mode. Basic CRM use mono membership: a salesperson belongs
to a single sales team. It is however possible to choose to work using multiple
memberships. This is configured through a configuration parameter available in
CRM configuration settings.

Mono salesteam behavior
  * a given user can be member of a single sales team at a time;
  * when moving an user from team to team, its existing memberships are
    archived to keep history of what has been done within this team;
  * display an alert when creating a new team member that would archive
    existing memberships;
  * displayed members on team form view are directly res.users records to
    avoid displaying unnecessary layer when using a simple CRM;

Multi salesteam behavior
  * a given user can be member of several sales team at a time;
  * unicity contraint (user_id, crm_team_id) is still enforced;
  * displayed members on team form view are crm.team.member records as
    advanced configuration can be done directly at that level;

In all cases when adding a new member check for archived membership before
creating it. If an archived version of the member exists it is unlinked in
order to avoid breaking the unicity constraint.

Archived memberships can be managed in its dedicated menu for advanced sales
team use.

SPECIFICATIONS: SETTINGS VIEW

Move Multi Teams checkbox below Recurring Revenues / Leads checkboxes. On its
right alias configuration should appear if Leads is checked.

PLS take third configuration line. On its right future commits will gradually
add automatic assignment configuration.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 10:59:24 +00:00
Thibault Delavallée e1355dae7a [REF] sales_team: improve crm.team.member model and data
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICATIONS: MODEL CLEANING

In this commit we improve team member model to make it more usable and
aligned with current Odoo views and usability.

This commit contains notably
  * add some related fields on the user: phone, mobile, company, email;
  * rename "team_user_domain" to "assignment_domain";
  * rename "maximum_user_leads" to "assignment_max";
  * improve member views globally;

We also introduce dynamic domain computation for users and teams when seeing
team members. This allows to limit selection of users or teams depending
on already existing configuration. Purpose is to avoid having people trying
to create wrong configuration (duplicates, ...) and receiving error messages.

Also
  * clean some data and demo about teams and members;
  * fix some views glitches;
  * improve views: add some fields in search views, improve wording of
    fields or actions, ... globally improve usability and US as well as
    feedback given to users;
  * group sales team members by team by default as it help getting an
    overview of team members distribution;
  * update tests to create team members instead of writing directly on m2m
    towards users;

SPECIFICATIONS: SALE_TEAM_ID FIELD ON RES.USERS

In this commit we also rewrite sale_team_id field of res.users. Previously in
crm it was simply a many2one field linking to a crm.team. It was used to compute
team membership as a standard many2one / one2many relationship. In enterprise
module ``website_crm_score`` this field was set as a related on first user
teams. Indeed scoring changed relationship between users and teams to a
many2many.

This field is now directly a computed many2one field that links to the
"main" team of the user even in multi memberships mode. As memberships can
now be de-activated we changed this field to a computed stored field. It is
based on oldest active membership of user. That way default team of documents
will be the user's oldest team considered as its "main team".

SPECIFICATIONS: LEAD_ALL_ASSIGNED_MONTH_COUNT

Improve crm_team ``lead_all_assigned_month_count`` field computation. It is
now simply the sum of assigned leads of team members. Differences may
happen if a lead in teamA is assigned to an user working in teamB. This should
not happen if team / user is correctly set at lead level which is generally
the case. However if that happens, old field counted it. New field will not
count it as it is not directly linked to a team's member.

SPECIFICATIONS: DEMO DATA

Make crm.lead demo data coherent with user_id / team_id . As demo data should
be using a mono-membership behavior for users and teams, we have to ensure
user_id and team_id effectively matches. It allows to have coherent reporting
and assignment demo flows.

Also avoid having Odoobot responsible of leads. Instead of undefined user_id
and team_id leading to Odoobot being responsible of some leads, force it
to be False. Those demo data allow to test automatic assignment of lead

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996
2021-01-21 10:56:37 +00:00
Thibault Delavallée 9790d7dcfb [REF][MOV] sales_team, crm: move team membership model to sales_team
GLOBAL PURPOSE

Ability to have salesmen belonging to several sales team is a core requirement
of CRM. It is therefore moved from website_crm_score to crm along with cleaning
and behavior improvement. Automatic lead assignment is also moved and cleaned.

SPECIFICIATIONS

Move sales team membership model from website_crm_score (enterprise) directly
into sales_team. It allows to have the base requirements to correctly handle
mono and multi sales team for salesperson.

Membership is modeled using a decorated many2many relationship. Members of
a sales team are res.users. Subscriptions are crm.team.member linking a team
and an user. It is a rename of team.user model coming from website_crm_score
as well as some other relational fields renaming.

Part of old team.user model is moved directly to sales team, part of it to
crm module (notably assignment limits). Its support will be improved in the
upcoming commits. Assignment related fields will be cleaned and used when
moving assignment directly into CRM.

LINKS

Task ID-2086889 (main task)
Task ID-2357969 (scoring migration task)
Community PR odoo/odoo#48422
Enterprise PR odoo/enterprise#499
Upgrade PR odoo/upgrade#996996
2021-01-21 10:56:19 +00:00
Thibault Delavallée 75f23a6a89 [REF] phone_validation, various: remove phone.validation.mixin and inline it
PURPOSE

Remove complex or technical code adding few value.

RATIONALE

phone.validation.mixin is used in two models: crm.lead and res.partner. It only
add a phone_format method used in onchange. We can inline this code in those
two models and remove the whole mixin itself. It lessens inherit and class
complexity.

SPECIFICATIONS

Remove phone.validation.mixin. Inline code in crm.lead (CRM application)
and res.partner (phone validation module). Make phone_format private as
it is now some internal tool method on those two models.

Everything should behave as before this commit. No functional change is
intended.

LINKS

Task ID-2416789
COM PR odoo/odoo#63333
ENT PR odoo/enterprise#15296
UPG PR odoo/upgrade#2025

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-15 08:14:01 +00:00
Achraf (abz)andThibault Delavallée f5adb5b25d [FIX] mail: send notification mail with right access link when using mail.thread
PURPOSE

Notification may be sent using a generic mail.thread record, notably when
sending user notifications. In that case links to view document are
incorrect.

HOW TO REPRODUCE

Issue

    - Install "Approvals"
    - Submit new approval with you as "Request Owner"
    - Click on "View Approval Request" in your mailbox

    The link redirects to a 505 error

Cause

    The model is not the correct one and the res_id is undefined

Solution

    Specify the model and the res_id to _notify_get_action_link
    when creating the link with kwargs

SPECIFICATIONS

Propagate message value through various notification sub methods. That way
we can rely on them if model seems void.

Also limit values given as URL parameters to some white listed values.

LINKS

opw-2358846
Task ID-2379766
Followup of odoo/odoo#60998
Followup of odoo/odoo#61545
Closes odoo/odoo#63292
Closes odoo/enterprise#15585

closes odoo/odoo#64229

X-original-commit: 58bac5d242d6548d54f0163328fa64b319852e40
Related: odoo/enterprise#15634
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Achraf Ben Azzouz <abz@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-01-07 17:44:37 +00:00
Thibault Delavallée fff19019de [IMP] crm: make some internal methods private
PURPOSE

Prepare sales team membership and lead assignment improvements by
reorganizing and cleaning some code bits.

SPECIFICATIONS

Tools methods should be private by default to indicate those are not part of
official convert or merge API for leads. In this commit we make convert and
merge tool methods private, keeping only main API methods public.

LINKS

Task ID-2428882
Prepares Task ID-2086889
COM PR odoo/odoo#64196
ENT PT odoo/enterprise#15610
2021-01-07 11:16:28 +00:00
Thibault Delavallée 4819df905e [MOV] crm: reorganize convert / merge tool methods
PURPOSE

Prepare sales team membership and lead assignment improvements by
reorganizing and cleaning some code bits.

SPECIFICATIONS

Separate business methods from tool methods. It eases their discovering and
their re-use through various other methods and models. Moreover it helps
reading business oriented methods without being disturbed by tools.

LINKS

Task ID-2428882
Prepares Task ID-2086889
COM PR odoo/odoo#64196
ENT PT odoo/enterprise#15610
2021-01-07 11:15:47 +00:00
Thibault Delavallée 1d86be9baa [FIX] crm: correctly handle won lost at create
Fix typo preventing a correct management of won/lost when creating
multiple leads in a row.

closes odoo/odoo#64149

X-original-commit: 0024b592b2d589138f34e27c724b8d471d213a4d
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-06 12:24:37 +00:00
Thibault Delavallée 17aa8679a0 [IMP] crm: do not set environment user as responsible of leads created through gateway
PURPOSE

Remove the alias setting option because it is a weird and hackish way to
proceed. We would prefer users to configure their alias through sales teams.
Improve alias configuration on teams.

SPECIFICATIONS

We do not want to explicitly set an user as responsible when an incoming email
creates a lead or an opportunity. We prefer that assignment is done either
automatically (scoring) or manually.

Using environment user would lead to set either root (gateway user - already
prevented) either alias owner (through alias_user_id) either user sending
email if email_from matches. Doing it also allows to exclude portal / public
users that would send an email to the mailgateway.

LINKS

Task ID-2414079
COM PR odoo/odoo#63160
UPG PR odoo/upgrade#2017
2021-01-05 11:15:28 +00:00
Thibault Delavallée ebbece6d55 [IMP] crm: synchronize teams use_lead and alias with setting
PURPOSE

Remove the alias setting option because it is a weird and hackish way to
proceed. We would prefer users to configure their alias through sales teams.
Improve alias configuration on teams.

SPECIFICATIONS

When changing "use leads" from CRM settings automatically regenerate apply this
option to all sales teams using opportunities. When de-activating it no team
should have this option activated as menus and options are hidden. When
activating it we consider that all teams should be upgraded by default.

LINKS

Task ID-2414079
COM PR odoo/odoo#63160
UPG PR odoo/upgrade#2017
2021-01-05 11:15:27 +00:00
Thibault Delavallée 1ee68e6119 [REF] crm: remove global lead alias
PURPOSE

Remove the alias setting option because it is a weird and hackish way to
proceed. We would prefer users to configure their alias through sales teams.
Improve alias configuration on teams.

RATIONALE

"​Incoming Emails" option has many flaws

  * it creates collision when you try to set an alias that is already used
    and it is not easy to find them back;
  * it has no default value (no sales team, no type, ...) and works through the
    'owner' field. This is set with the admin on activation of the feature
    which is not correct.  The admin is potentially not a salesperson. If you
    set the field to blank, you get leads without team and without assigned
    responsible.
  * this alias is not team-bound which thus asks the question: in which team
    should the lead ever go? To the first team? Why?

All this make it seem way healthier to handle this through the Sales Team.
=> By default, we'll already have one working with an alias.

If users really want a global lead alias it can be setup manually through
alias menu in configuration. Shortcut and default alias in crm are removed
but feature is still doable if requested.

SPECIFICATIONS

Remove the s "Incoming emails" setting that allows to setup a global alias for
leads / opportunities with a default value being 'contact'. Also remove related
alias data as it has no use anymore.

LINKS

Task ID-2414079
Sort of follow-up of Task ID-2373095.
COM PR odoo/odoo#63160
UPG PR odoo/upgrade#2017
2021-01-05 11:15:27 +00:00
ijas ahammedandThibault Delavallée 0b6a2ee5fb [FIX] crm: do not propagate lead phone to partner if formatting differs
With a recent commit[1], we fixed the issue of false warning while changing
the partner on lead. But that fix ignored the fact that the lead has an
automatic formatting that may lead to false warning.

Right way to detect a phone number change is
  * lead phone is different from partner phone;
  * lead formatted phone is different from partner formatted phone;

If those two conditions are met we are quite sure numbers are different and
not only differs in their formatting.

In this commit we also fix inverse of phone number. When updating lead phone
value we have to use the same heuristic to update partner phone value. That
was we avoid unnecessary partner update when only formatting differs.

Tests are added to ensure new behavior and that ribbon message is effectively
trig erred with correct content.

LINKS

Task ID-2390287

[1] - https://github.com/odoo/odoo/commit/d29862c1de6208f7fdb7c8104afe0d35241d130b

closes odoo/odoo#63521

X-original-commit: 5154f40544e7913f7bcd0ff73f034d111700f580
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Ijas Ahammed <ija@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2020-12-17 11:32:52 +00:00
Aurélien Warnon dd06e081b1 [FIX] web, crm: fix rainbowman when lead is marked as "won"
When you mark an crm.lead as "won" using the "mark as won" button, the user
will be shown a rainbowman under certain conditions. This happens notably
when you win your first lead.

This commit fixes the 'ir.actions.act_window_close' model to allow the
'effect' key within its readable fields (even if it's not a real field) which
is in turn picked up by the web client to display the infamous rainbowman.

At the same time, we add the tour that is testing the rainbowman of the crm app
in the test suite, since it was missing and never actually executed by the CI.
Some fixes were also necessary to make the test run properly.

Task ID-2394745

closes odoo/odoo#63259

X-original-commit: 47079f67f586adf45da15fc98dbc81571f7a9100
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-12-11 15:47:33 +00:00
Aurélien Warnon dd7b327eb5 [FW][FIX] crm: change default 'crm_alias_prefix' to 'contact'
This commit changes the default crm alias prefix from 'info' to 'contact'.

As the alias of the default sales team is configured to 'info', also having
'info' for the "crm_alias_prefix" setting was leading to an alias collision.

This change allows an easier configuration by the end user and avoids confusion
when first playing with your CRM settings.

Task 2373095

closes odoo/odoo#62025

X-original-commit: 31497e17e2369147fa40ab8b3f82cb2602ec9012
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: awa-odoo <awa-odoo@users.noreply.github.com>
2020-11-19 14:51:49 +00:00
Nicolas Lempereur 35809389a6 [FIX] crm: show newly created meetings in calendar
When clicking on the stat button "Meetings" on a contact:

- before dac91bc18 (November 2019): only meetings with participant
  matching contact name are shown

- after dac91bc18 (November 2019): all meetings are shown => this was
  because the view was used to create new meeting, so it makes sense to
  see other meetings and not have a conflict.

- after 16206d72 (August 2020): only meeting of the contact are shown

- after 7449c8a6 and d11fb611 (November 2020): more complicated logic
  that will also show partner events, and child partner events.

Since August 2020, when you create a new event, since we are showing a
list of IDs at the time the button was clicked, the new event will not
appear unless you go back to the contact, then click on "Meetings" anew.

With this changeset, we still show a list of IDs, but add an alternative
to also show the events of the current partner (that should be in the
list of IDs, but will match new events).

opw-2374021
closes #61490

closes odoo/odoo#61690

X-original-commit: eb6e03908bfb6ed8bbe231da2a4422ec2e149834
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2020-11-12 17:41:06 +00:00