Commit Graph
536 Commits
Author SHA1 Message Date
Thibault Francois 72e8e06ad3 [FIX] crm: make lead assignation cron more resilient
Use Case
========

The cron run perfectly well when there is no concurrent transaction.
But in real life users may interact with leads modified in the cron.

This cause two issue:

Concurrent update
-----------------

If a lead is modified in another transaction during a the transaction
where the lead is modified. The parameter crm.assignment.commit.bundle
allow to reduce the size of the transaction but before this commit
the first transaction was always way longer because it took the time
to handle the bundle + the fetching of all the data at the begining of
the cron.

The solution: start a new transaction after the preparation
of the data is done

Missing record
--------------
If the a lead is deleted in another transaction before
the transaction that modified the lead starts.

The code will then try to access a record which does not
exist anymore in the database causing a Cache Miss and Missing record
error.

The solution: Make sure a record exists in the current transaction
before using it. It reduce a little bit the performance of the cron
but avoiding the crashes is at this price.

Discussion
----------

This commit does not remove completely the risk of crash
due to concurrent update but reduce its probability a lot.
To remove the risk of crash, a proper exception management should be
implement in a further commit

closes odoo/odoo#74166

X-original-commit: 4a70f7539ec53b9c3419f83d584ad99111d2e172
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-23 12:48:43 +00:00
abd-msyukyu-odoo 2a48b989c1 [IMP] crm: implement the forecast feature for opportunities
Add a new submenu "Forecast" in "Reporting" for CRM

The Forecast shows 4 views:
  1. Kanban
  2. Graph
  3. Pivot
  4. List

Objective
  Shows the short term forecast for opportunities (crm_lead) based on their
  expected closing (date_deadline) and have an overview of the prorated
  revenues for each period (defaults to month).

Implementation
1. Kanban
- the progressbar is using the prorated_revenue
- the forecast_field is date_deadline
- the default groupby is date_deadline

2.3. Graph, Pivot
- the measure defaults to the prorated_revenue
- the row defaults to date_deadline

4. List
- shows the prorated_revenue

The special filter "Forecast" is defined to be used by the
forecastModelExtension (JS). (define the forecast_filter context key)

The forecast_field context key is defined in the action to be used by the
forecastModelExtension and the forecastService (JS).

The demo data for opportunities is updated to spread date_deadline over 4 months

Enable drag&drop and quickCreate features for the kanban view with the use of
the allow_group_range_value  <field> xml attribute

Add a "Won" flag for the forecast view to better distinguish opportunities that
need to be worked on

Test tour

Task-ID: 2243913
PR odoo/odoo#69380
ENT PR odoo/enterprise#18547
2021-06-30 09:51:42 +00:00
Denis Mudarisov 8100980773 [FIX] crm: make help note translatable
closes odoo/odoo#72789

X-original-commit: f21392f5290d298f43b4a64f4e4cdbbc992df627
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-25 12:43:12 +00:00
Thibault Delavallée dedfbd0c4f [IMP] crm: when unlink team, merge its pls frequencies with "no team" frequencies
PURPOSE

Purpose is to avoid loosing frequencies and also avoid rebuilding the whole
frequency table. We choose to merge frequencies from team about to be unlinked
with "no team" frequencies.

SPECIFICATIONS

Update PLS frequencies of "no team" leads when unlinking teams. Instead
of loosing those statistics merging them with "no team" is probably better even
if not completely right. Removing teams with a lot of PLS information is
something that is not a primary use case

LINKS

Task ID-2507750
COM PR odoo#70645
2021-06-23 08:56:40 +00:00
Thibault Delavallée c24ccef4fc [IMP] crm: better handle team deletion
PURPOSE

Make crm.team deletion effect explicit on main models (excluding wizards
or reports). Purpose is to ensure deleting a crm team has known side
effets.

SPECIFICATIONS

M2O on crm.team set to CASCADE

  * crm.lead.scoring.frequency: as we remove the team no need to keep the
    PLS data -> change to "cascade";
  * crm.team.member: when removing a team, remove its members as it prevents
    from unlinking the team;

M2O on crm.team set to SET NULL

  * account.move: void team_id field but track it to keep history;
  * crm.lead: void team_id field as it will be taken back into assign
    process (either manual or automatic), and will therefore be managed
    by other sales persons. In case of archived / lost leads setting to
    void has no real issue;
  * crm.stage: void team_id and set stage as shared to avoid loosing stage
    information for existing leads in that stage;
  * res.partner: void team_id taking care of this customer as this field
    is mainly informative anyway;
  * crm.iap.lead.mining.request: void team_id as it only impacts generated
    leads. Those will be created with a void team which is ok;
  * crm.reveal.rule: void team_id as it only impacts generated leads. Those
    will be created with a void team which is ok;
  * event.lead.rule: void lead_sales_team_id as this impact generated leads.
    Those will be created with a void team which is ok;
  * pos.config and pos.oser: void crm_team_id field. It is optional as it is
    not a core field of this model. Pos configurations and orders are still
    valid without team assigned on it;
  * sale.order: void team_id field but track it to keep history;
  * website: void salesteam_id field;

Prevent unlink when having more than 5 SO not canceled. If more than 5 active
SOs in the team, we consider this team to be actively used. 5 is some random
guess based on "user testing", aka more than testing CRM feature and less
than use it in real life use cases.

LINKS

Task ID-2507750
COM PR odoo/odoo#70645
ENT PR odoo/enterprise#18266
2021-06-23 08:36:18 +00:00
Thibault Delavallée 6a1cda64f8 [IMP] crm: remove duplicated field activity_deadline_my
Next to the addition of a generic field adding a compute to find
my next activity deadline there is no need to keep a custom field
on crm.lead model.

Task ID-2438822
COM PR odoo/odoo#72219

Related: odoo/upgrade#2566
Related: odoo/enterprise#19044
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-21 08:53:35 +00:00
Stéphane Debauche 5813242fe0 [FW][FIX] crm: dot not sync the phone / email from False to an empty string
Bug
===

1. Create a new database from the database selector
2. Do not select a country for your company
3. Install CRM
4. Create a new opportunity and select your company
5. The sync "warning" will be displayed, and it should not

The reason for that is the phone of the company is an empty string and the
phone of the lead is False. So we try to sync them and we show the warning
message even if for the user, nothing will happen.

This commit fixes that behavior by correctly checking that False / empty
strings are considered as equal.

UPDATE

In this commit we also display warnings about update only in edit mode to
avoid displaying irrelevant information to the user. Indeed email and phone
will be propagated at save, aka in edit mode.

TaskID-2499659

closes odoo/odoo#72286

X-original-commit: efea8fce6c7cb6e40b590cd827fe22e134cc3d13
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-17 12:38:34 +00:00
Thibault Francois 09e231e28e [FW][FIX] crm: always keep master lead probability when merging
Issue
-----

When a lead with an automated probability is merged with other leads and
if its probability is 0, it will be considered as null value and will be
erased by the value of the next lead with a probability > 0

The final lead gets a probability != automated_probability and is now
considered is_automated_probability = False. Therefore automated probability
computation will not be triggered anymore.

Expected behavior
-----------------

Possible use cases
  * if the probability is auto on the master keep the auto probability;
  * if the probability is manual on the master keep that manual value even if
    it is 0 as sales people know their pipe and gave an accurate probability;

In other words: never take the probability from the merged records and always
keep the master one.

Task-2526926
PR odoo#70270

X-Original-Commit: odoo/odoo@4e14997f92

closes odoo/odoo#70270

closes odoo/odoo#72073

X-original-commit: 8fa6c154b196ec5bebb37293e70f9009a56e7974
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-11 15:44:55 +00:00
da361f03fe [FW][FIX] crm: compute no team lead probability based on all lead
Before this commit, leads without any team_id set had their automated
proabbility computed based on the subset of all leads without team id.
Unless wrongly configured or strange pipeline use, all leads end up with
a team_id set. Therefore subset of leads without team is not really a
good set used to estimate probability of new leads.

After this commit, a lead with no team_id set yet will have its
automated probability computed based on the entire lead set.

Task-2526926
PR odoo/odoo#70270

X-original-commit: be1a55b305057803a67ec2b016e51325c992586f
Co-authored-by: David Beguin <dbe@odoo.com>
Co-authored-by: Thibault François <tfr@odoo.com>
2021-06-11 15:44:54 +00:00
dht-odoo 586ae4bcc4 [IMP] crm: improves description field type from text to html
Replace text fields to html fields as we have our own 'OdooEditor'.
Indeed, it gives more options to users in the way they format their
content without weighting too much on the UI
(tools appear on demand and not by default).

Models -> Fields

1) crm.lead -> description
2) event.event -> note

Task Id: 2499504

X-original-commit: 524e2f089a611d897b98d86001bda5d17263db66
2021-06-07 05:24:08 +00:00
dht-odoo e33ef69e7d [FIX] crm: fix UserError message while merging leads
This commit fixes the UserError message by properly displaying the
number of maximum leads that can be merged.

Apart from that, this commit also hides 'email_from' and 'phone' fields
on merge wizard to avoid scroll and to make sure that the 'x' icon is
always visible, which previously was far right and user had to scroll
a bit for removing the lines with that button.

TaskID-2542260

closes odoo/odoo#71523

X-original-commit: abbf3419767c149f338a4a48f15c2af7dfbed2bc
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-01 09:00:39 +00:00
Anjali a99d882c02 [IMP] crm,*_crm: better merge leads side documents
Purpose of this commit is to ensure side documents are redirected to the
master opportunity when merging leads. Those side documents include

  * communication history (mail.message);
  * attachments (ir.attachment);
  * visitors (website.visitor);

However some documents are currently not specifically handled :

  * meetings (calendar.event);
  * activities (mail.activity);
  * sale orders (sale.order);
  * attendees (event.registration);

In this commit we ensure all are attached to the final master opportunity.
That way we prevent loosing access to those documents and ensure we keep
the complete history of all merged leads.

Also tests are added to ensure the merging of leads and its contents.

A new field is added to have the o2m field between leads and calendar events.
In order to clarify naming, ``meeting_count`` is renamed to
``calendar_event_count`` to match naming.

Task Id-2457941
COM PR odoo/odoo#68884
UPG PR odoo/odoo#2494

Related: odoo/upgrade#2494
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-05-28 12:12:51 +00:00
Thibault Delavallée 962d8a443b [FIX] crm: set lost leads as last when sorting by confidence level
When sorting by confidence level, put lost (inactive) leads last. This should
not happen when using the merge tool that filter out inactive leads but may
happen in case of manual merge.

Task Id-2457941
COM PR odoo/odoo#68884
2021-05-28 11:49:02 +00:00
nounoubensebia d01e5c5cdb [IMP] calendar, crm, hr_holidays: move meeting stat button to calendar
Move the meeting stat button and kanban pill from CRM to Calendar, purpose is to
allow its usage even if CRM is not installed as this makes more sense since this
field is usually related to Calendar.

Increase query number limit in company leave test, in order to take into account
the newly introduced query in Calendar.

UPG-PR: https://github.com/odoo/upgrade/pull/2423

Task-2514473

closes odoo/odoo#69846

Related: odoo/upgrade#2423
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-04-28 14:05:07 +00:00
Thibault FrançoisandThibault Delavallée eca1b7aeaf [IMP] crm: ensure constant lead filling when assigning
PURPOSE

All unassigned leads should be assigned to teams as soon as possible to ease
lead analysis.

Purpose of assign thresholds is to ensure sales people receive at least this
amount of leads within 30 days, counting lost and won leads. Giving them leads
regularly is also one goal of automatic assign.

SPECIFICATIONS

Counting every lead whatever its state may lead to an inconvenient situation.
If a salesman always reaches its maximum every days he will always receive the
number of lead he got 30 days ago. For example if the salesman goes in holidays
for few days and set the max to 0 he receives no lead during his vacation.
Then after a few days of assign he reaches its maximum and receive 0 leads
for a few days. This leads to having windows of leads that repeat themselves
every 30 days.

   * Solution: do not limit at maximum capacity anymore. Compensation is voided
     if limit is achieved. However asked assignment is done. Salesman could
     receive more than its max capacity but 30 days window ensure old leads
     are regularly going out of count.

``assignment_max`` is now more a mean target of leads to be assigned during
a 30 days window than a real maximum capacity. Field is renamed accordingly.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: 3d1841f26ce64f0106122e48750d2c653ea9790f
Co-authored-by: Thibault François <tfr@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-05-12 14:23:55 +00:00
Thibault Francois fe8c5b9b01 [IMP] crm: change in assignation process and limit
PURPOSE

All unassigned leads should be assigned to teams as soon as possible to ease
lead analysis.

Purpose of assign thresholds is to ensure sales people receive at least this
amount of leads within 30 days, counting lost and won leads. Giving them leads
regularly is also one goal of automatic assign.

SPECIFICATIONS: TEAM ALLOCATION

Team assignment has to be updated as we may have team domains that overlap.
We therefore remove maximum number of leads to allocate to teams. Instead all
available unassigned leads are allocated within teams.

  - Solution: assign all available leads and not a count based on team's
    capacity. This notably reverts the main goal of odoo/odoo@6df2f0cfc0
    (see odoo/odoo#48422)

This assignment process is done proportionally to the team capacity. It is
computed as the sum of each member's maximum assignment counter. This means
that with a team having twice as much sale capacity than another team sharing
the same domain: first team should receive about 2/3 of leads while the second
one should receive the remaining 1/3.

  - Solution: assign lead one by one. Choose a team randomly using a weighted
    random algorithm, based on team's members capacity.

SPECIFICATIONS: MEMBER ASSIGN

Counting every lead whatever its state may lead to an inconvenient situation.
Moreover salespersons may opt-out from assign by setting their max capacity
to 0, for example when going on holidays.

When doing that lead assignment is not smooth and getting back to a full
pipe may take several days. To solve that issue a compensation is added in
assignment quota done to sales people. Salespersons having few leads will
get a boost in assign as soon as they get back in assign process. When being
near maximum compensation is nearing 0 and daily quota is given.

PERFORMANCE

During team assignation, assigning lead one by one may cause performance issue.
Since PLS is computed at each flush, so we want to flush after a bunch of lead.
To solve that we obviously need to not commit at each assignation but
also avoid to search for duplicate at each assignation, that why the
search for duplicates is done at the beginning of the process and stored
in memory.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: 83f72711e7affa8b0ad997b9ee262326e9577d54
2021-05-12 14:04:03 +00:00
Thibault François 74d6455cdb [IMP] crm: better support cron time configuration
When running the cron is should assign leads based on its frequency. If cron
runs once every day, work_days given to sub methods should be 1. If it runs
more than once day it should be less than 1. We therefore remove the *2
multiplier and support fraction of days.

As assign process will soon change, assigning more strictly compared to
salespersons capacity will not be an issue anymore. Assign process is best
designed to run every few hours (~4 times / day) or each few days. Code and
work_days are updated accordingly.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: c59ba43d1e9eb0c016b9a113c9475dec28fa413b
2021-05-12 14:02:23 +00:00
Thibault FrançoisandThibault Delavallée 05316742c0 [FIX] crm: correctly filter out won and lost leads for assignment
Automatic assignment is performed on leads that are unassigned and not won
nor lost. This commit fixes the condition that should be based only on
stage being set to a stage with ``is_won`` being True.

Current code fails with won unassigned leads that are assigned even if it
should not. This happens rarely as won leads have probably been taken care
of. However having the right condition ensure filtering won and lost leads
is not correctly done.

Followup of odoo/odoo@5016b47a06 (see odoo/odoo#48422)

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: d9fe86ec2ca6459a34b31e65c0702d8a80a7ec61
Co-authored-by: Thibault François <tfr@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-05-12 14:02:22 +00:00
Thibault FrançoisandThibault Delavallée 99bc9420a5 [REF] crm: use a duplicate cache when assigning to teams
PURPOSE

Purpose is to try to reduce friction between searches in loops, team assign
on leads and unlink during merge process that unlink leads and forces flush
/ cache reset, as well as PLS computation.

SPECIFICATIONS

During team assignment setting team on leads one lead at a time may cause
performance issue. As PLS is computed at each flush we want to flush after
a bunch of lead. For that purpose we need to avoid too much commits and
also avoid to search for duplicate at each assignation.

We therefore perform the search for duplicates before going into allocation
and use a cache through loops to ease using pre-fetched information.

Unlinking duplicates at each iteration is also sub efficient as it causes
recomputation or invalidation. We therefore aggregate all duplicates to
unlink and unlink them in the main team-based loop instead of the sub loop
that is lead-based.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: c5310102210fb9afc6ab786f4c8f6eaf5aee59bb
Co-authored-by: Thibault François <tfr@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-05-12 14:02:21 +00:00
Thibault François f2ff222fba [FIX] crm: keep team when assigning and deduplicating leads
New leads are automatically assigned to sales team and salesman during assign
process. Some of those leads are duplicates of existing opportunities. If a
new lead is merged into an existing opportunity, the opportunity is the master
data and the lead is duplicated. However the opportunity should keep its sales
team and not be assigned to the team being under automatic assign.

Before this commit, the merge was forcing the crm team to the 'current' team
during auto assignment and thus it was changing the team of the opportunity.
In this commit we now assign team to lead to merge before the merge and do
not force the crm team during merge process.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: 356a55053eb1cc49ae6eed0e58338cff08eddc42
2021-05-12 14:02:19 +00:00
Thibault François d92ca08fd7 [IMP] crm: count all leads in `lead_month_count` used in assign
PURPOSE

Goal of ``assignment_max`` is to make sure sales receives this amount of leads
within 30 days. Counting lost or won leads is therefore necessary to effectively
count all leads received those last 30 days.

SPECIFICATIONS

Change ``lead_month_count`` computation to take into account archived and won
leads. We consider now that goal of ``assignment_max`` is to make sure sales
people receive this amount of leads within the 30 days at max.

This allows to avoid archiving leads to get a new batch of leads to handle.
Also done leads should be counted as it is part of the month job.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: 23feb1a467e0a441eb775be26c96af697d74506f
2021-05-12 14:02:15 +00:00
Thibault François 6106642cb5 [IMP] crm: use stage instead of probability to exclude won duplicated leads
Change domain of ``_get_lead_duplicates``: lost and not win lead currently
means lead with a probability != 0 and != 100. This is not always accurate as
you may have a lead with 100% win probability but that is still not won.
Instead search for active lead and with stage_id.is_won = False .

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: 31e8d3cf03025085b5ae9db67536a1110bf3e484
2021-05-12 14:01:28 +00:00
2f829b0e28 [REF] crm: cleanup test environment to prepare changes in assignment process
This commit contains two main preparatory changes in tests

  * 1) lead_month_count will be changed to count lost lead as well. So
    archiving leads before running the test doesn't reset the counter.
    Lead needs to be unlinked in order to make tests reproducible;

  * 2) assertMemberAssign checked the validity of the team domain. Normally
    all lead assigned to the member should match the domain of its team.
    This assert is not always verified since we force the team after a
    merge of duplicated leads. Final merged lead may not match team domain
    anymore as final properties depend on all merged leads.

Some tests are also added :

  * add tests for master lead team_id and user_id values when merging leads
    in assign process;
  * add tests using email_normalized check in duplicate finding to ensure that
    normalized emails are used for duplicates and not only exact match;
  * add tests for won / lost inclusion in ``_get_lead_duplicates``, as well
    as different between probability=100 and stage.is_won = True . This is
    going to change in upcoming commits, hence some test to highlight it;
  * add tests counting existing leads for assignment purpose;
  * add tests for assignment_max maximum leads allocation as well as max=0
    meaning salesperson is opt-outed from assign;
  * add tests for default user / team / stage computation for leads;
  * add tests about leads taken into account in assign process (currently
    failing with won unassigned leads);

We also add some flush to ensure some fields notably related to probabilities
are flushed before counting queries.

LINKS

Task ID-2444908 (assign fixes)
Task ID-2489951 (assign process improvements)
COM PR odoo/odoo#70172

X-original-commit: bd3444085974f4e12287c2f5da4fb33308cd6180
Co-authored-by: Thibault François <tfr@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-05-12 14:00:58 +00:00
Thibault Delavallée a8fafbf02e [FIX] crm: correctly compute phone_sanitized without having crm_sms installed
Currently phone_sanitized computation on lead model works only if crm_sms
is installed. Indeed an override of ``_phone_get_number_fields`` is missing.
However ``_sms_get_number_fields`` coming with ``crm_sms`` and its ``sms``
dependency hides the issue as those modules are auto-install. However if
``crm_sms`` is uninstalled phone_sanitized is not correctly computed anymore.

Task ID-2528169
Oversight of odoo/odoo#45315

X-Original-Commit: odoo/odoo@45ae2922e5
2021-05-12 13:35:03 +00:00
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