Commit Graph
221 Commits
Author SHA1 Message Date
Gorash cdaa761ced [REF] base: Update modifier syntax (invisible, required, readonly)
Goal:
* Simplified modifiers to only have one way to define modifiers;
* Remove states attributes on python field;
* Use python expression in view `required`, `readonly`, `invisible`;
* More accurate validation of xml views.

This commit change the syntax to python expression. The next commit
will update/convert all xml views.

Before this commit:
* the `required`, `readonly` and `invisible` attributes can only have
values of `True`, `False`, 1, 0 or a python expression to use the
context;
* the `attrs` attribute define a dict. The key of this dict was
`required`, `readonly` and `invisible` and the values are the domain or
a string representing a domain to be evaluate as python expression.
This python expressions was evaluate by the javascript with view fields
and other contextual values as: context, uid, parent, active_id,
active_ids, active_model, allowed_company_ids, current_company_id.
* the `states` attribute in the view was a comma separated list of the
state. This list was combined with the `invisible` attribute;
* the `invisible` attribute on python field is used as default value;
* the `states` attribute on python field was dictionnary with state as
key and list of tuple. This structure was combined with `readonly` view
attribute.
* After combining, the resulting domains of the different attributes
`required`, `readonly` and `invisible` are evaluated with the values of
the fields. The `invisible` attributes is splitted into two use:
`invisible` and `column_invisible`.

After this commit:
* The attributes `required`, `readonly`, `invisible` and
`column_invisible` define python expression. This python expressions
are evaluate by the javascript with view fields and other contextual
values as: context, uid, parent, active_id, active_ids, active_model,
allowed_company_ids, current_company_id.

The domains can contains contextual value and will be evaluate by the
javascript.

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'readonly': [('field_b', '!=', False), ('field_c', '=', parent.c)]}"/>
    <field name="field_b" states="draft"/>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a') or field_b and field_c == parent.c"/>
    <field name="field_b" invisible="state != 'draft'"/>
```

Some inherited views will be modified differently in order to maintain
the previous behavior:

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'invisible': [('field_b', '!=', False)]}">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="attrs">{'readonly': [('field_c', '=', False)], 'invisible': [('field_d', '!=', '3')]}<attribute>
    </field>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a')" invisible="field_b">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="readonly" add="(not field_c)" separator=" or "/>
        <attribute name="invisible">field_d != 3<attribute>
    </field>
```

Validation:
A stricter control is made on the level of the attributes (modifiers)
and the fields necessary for these. The use of the previous attributes
'attr' and 'states' triggers an error (these no longer exist after the
application of the migration script)

task-2495504

Part-of: odoo/odoo#104741
2023-08-18 09:49:08 +02:00
Thibault Delavallée 638e0f658d [REF] mail, various: cleanup alias usage
Cleanup alias usage and definition. Prepare code to ease future changes and
improvements. Notably

  * add a 'alias_email' computed field on the mixin allowing to have the
    complete alias email when set, and False in case it is inactive or linked
    to an inactive alias domain;
  * remove unnecessary alias_id field definition when just the help differs
    from the standard definition coming from the 'mail.alias.mixin';
  * use fields coming from 'inherits' instead of using alias_id and its sub-
    fields; notably use 'alias_display_name' and 'alias_email' fields;
  * remove useless custom code and management;
  * improve alias parameters support code in configuration parameters;

Task-3453343 (Mail: Cleanup Alias Usage)
Prepares Task-36879 (Mail: Support MultiCompany Aliases)

Part-of: odoo/odoo#130632
2023-08-09 17:04:26 +02:00
Thibault Delavallée b5949d1672 [REF] test_mail, various: prepare gateway / alias tests
Rename alias domain and aliases used a test data. This allows to make
them easier to read, follow, grep and understand.

Activate multi-company on alias and gateway tests, ensuring it currently
has few impact on tests.

Task-3453577 (TestMail: Update Alias/Gateway tests for MC)
Prepares Task-36879 (Mail: Support MultiCompany Aliases)

Part-of: odoo/odoo#130768
2023-08-03 21:56:56 +02:00
Krzysztof Magusiak ad74ef3870 [FIX] crm: lead probability too close to 100%
If you have some leads which are nearly always won or lost, you may
end with a probability which is either 0% or 100%.
These values indicate that the lead is lost or won, therefore we must
check the limit values.

opw-3413206

closes odoo/odoo#130109

X-original-commit: 49166f3c291c44d6635d30687ec8d439de145d01
Signed-off-by: Jérémy Hennecart (jeh) <jeh@odoo.com>
2023-07-28 23:16:26 +02:00
Thibault Delavallée 2fc8a324d1 [FIX] phone_validation: use international formatting in onchange
International formatting ease reading the value, which is handy in onchange.
This partially reverts odoo/odoo@51d571fab4 .

closes odoo/odoo#129851

X-original-commit: dab802a939c97603f70c504e98ecc92b0ac552f9
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-07-27 07:00:08 +02:00
william-andre 0479b2b594 [IMP] account,*: manage subsidiary companies
Allow sharing records between company
* accounts
* taxes
* fiscal positions
* products
* ...and some related models

These records can be read and used in children companies.

This can be used to
* have different branding for different businesses
* allow more complex security rules
* consolidate branches differently
* manage different tax reports with different tax ids in the same
  country

task-3371677

closes odoo/odoo#125642

Related: odoo/enterprise#43215
Signed-off-by: Quentin De Paoli <qdp@odoo.com>
2023-07-20 11:49:06 +02:00
Romeo Fragomeli 73e7c20573 [IMP] *,test_mail,test_mail_full: update query count
* = crm,hr_work_entry_holidays

This commit changes the value of the "QueryCount" as `mail_enterprise`
executes a new query to search for devices associated with the partner.

Task ID: 3123678

closes odoo/odoo#127198

Related: odoo/enterprise#43577
Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
2023-07-19 18:24:10 +02:00
miad-odoo d6274a9e10 [IMP] crm,project: add duration tracking mixin
This commit implements the `mail.tracking.duration.mixin` with the
`statusbar_duration` widget for `crm.lead` and `project.task`.

The goal is to compute and display how long a record has spent in each stage in
the statusbar of their form view.

Task-3032773

Part-of: odoo/odoo#108554
2023-07-18 13:07:41 +02:00
Thibault Delavallée 0f26b490e1 [FIX] crm, phone_validation: format numbers using E164 standard
Most number formatting is done using E164 standard, see notably
'phone_get_sanitized_number' method in mail.thread.phone.

Some calls are still done using INTERNATIONAL format. Notably on 'partner'
and 'lead' model, an onchange is implemented that formats numbers according
to INTL format. However this leads to inconsistent computation where sanitize
is done using E164, and format using INTL. This makes some computation and
comparisons harders without much real added value.

In this commit we choose to make the onchange on those models use the same
E164 format as the sanitized one. This eases comparisons and usage of phone
numbers through Odoo.

Task-3342820

X-original-commit: 51d571fab4871fd62ce154b6fc1ed573407c7f86
Part-of: odoo/odoo#128118
2023-07-12 12:38:47 +02:00
adda-odoo a81a6e994e [FIX] crm: add minimum of return value to _get_assignment_quota
The method _assign_and_convert_leads() gets called when the CRM: Assign Leads cron is called.
The values in the list `weights` gets caluclated in a way that memebers with a lower
`lead_month`count` value gets a higher weight when randomizing assignement of a new lead. Assuming that the
max assignment per member is consistent (or default = 30).
Assume that each sale member belonging to any team has around 500 leads assigned to them the previous
month(`lead_month_count`) and `work_days` is set to `0.2`. The return value of the method
`_get_assignement_quota()` in this case would be 0 for every member, which causes the list `weights`
to get populated with just zeros. This raises a `ValueError: Total of weights must be greater than zero`.

Fix:

Make sure the minimum weight for each member is at least 1 and not 0.

opw-3171085

closes odoo/odoo#121908

X-original-commit: 15e2a1ebe2e64b752fb1c1d6bc422beb7d548b78
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-05-22 15:09:08 +02:00
Renaud Thiry 1a25988101 [IMP] crm: replace context with explicit default
Prior to this we used the context active_ids directly to determine
which leads to mark as lost in the lost reason wizard.

We now use a m2m field to store that value to make the behavior more
obvious and predictable, and to ease debugging.

task-3272955

Part-of: odoo/odoo#118494
2023-05-10 10:18:46 +02:00
Raphael Collet 58bd33ccde [IMP] core: make onchange2() work with properties fields
The issue with properties fields is that the value in the record
snapshot is not correct.  This is caused by convert_to_record()
combining the values with the definition, and in the case of onchange(),
the values don't match the definition, which causes the method to return
the empty list [].

We fix the root cause by changing convert_to_record() to return the dict
itself.  The combination of the values with the definition is now only
done in convert_to_read().  Method convert_to_onchange() has only one
hack to retrieve the current definition record from the record snapshot,
as because of cache invalidation, its value is no longer available.

closes odoo/odoo#120457

Signed-off-by: Raphael Collet <rco@odoo.com>
2023-05-05 18:08:10 +02:00
std-odoo df9e9ec261 [IMP] digest, *: compute the KPI in batch
*: account, crm, hr_recruitement, im_livechat, point_of_sale,
   project, sale_management, website_sale

Purpose
=======
Now, the KPI are computed based on their `company_id` and not based
on the current company. If no company is set on the digest, we compute
it based on the current company.

The KPIs are computed based on their company. Most of the time, they
will all belong to the same company so we can improve the performance
by computing them in batch.

Task-2827996
See odoo/enterprise/pull/27658

Part-of: odoo/odoo#91945
2023-04-05 15:11:06 +02:00
Louis Wicket (wil) 9afe7c74c9 [IMP] *: remove "French spacing" 👺
According to Wiktionary, French spacing is "the archaic practice (though
still current in French) of inserting a space around colons, semicolons,
question marks, and exclamation marks". This is not standard practice in
English and most languages of the world.

The purpose of this commit is to start purging the code from this typo,
as it may reflect poorly on the software for some people.

closes odoo/odoo#114533

Related: odoo/enterprise#37853
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-03-14 15:52:10 +01:00
Thibault Delavallée b1695201b8 [PERF] crm: rewrite duplicates computation
RATIONALE

Duplicates computation on leads is slow when having a lot of leads. We can
simplify the heuristic to keep only relevant terms and use tailored fields
to find duplicates based on email and phone, to speedup the computation while
loosing few duplicates or avoiding false duplicates.

SPECIFICATIONS

We remove
  * an ilike on email_normalized (slow and exact matches are what really
    matters);
  * an ilike based on partner_name and contact_name (as lead is a contact
    oriented record, better optimize email and phone / mobile than names that
    are weak criterions);
  * an ilike on phone_mobile_search, which was searching on both fields
    phone and mobile;

Criterions are now

  * email domain exact match;
  * phone_sanitized exact match;
  * same commercial entity;

Main change is that only phone_sanitized is used for exact match. Partial
matching based on phone and mobile number is lost. That should not be an
issue as real duplicates should come with a complete phone or mobile number
and not partial numbers. First found in phone / mobile populates the phone
sanitized field, meaning if we have two different numbers, only one is used
for duplicate finding. This is considered acceptable.

Other main change is the removal of partner name / contact name search. Those
are weak criterions and did not return any explicit result when used internally.

Task-3142659 (Crm: Fix duplicate leads computation performances)

Part-of: odoo/odoo#112535
2023-03-09 10:51:37 +01:00
Pierre-Yves Dufays 31811ba89f [IMP] base, crm, mail: prefill partner creation form with current record data
Selecting a recipient for which there exists no partner trigger a partner form
dialog creation. For some model (ex.: crm.lead), some default values can be
prefilled from the current record. This is what we do here by calling a generic
mechanism that allows each model to define default value for related partner.

Note that we don't provide a more detailed form to the user because some will
otherwise feel obligated to fill it out entirely.

Technical note: As there is no need for a custom form per model from which the
data are extracted to populate the related partner, the simplified partner form
(view_partner_simple_form) is just augmented with additional invisible field by
modules that add fields to partner and need to populate them automatically from
values of another model.

Technical note: In TestCRMLead.test_message_recipient_partner_auto_creation, we
test that the _message_get_suggested_recipients returns the correct default
values to copy some fields from the lead to the partner to avoid the user to
reenter them. But we don't test specifically that it also work when using mail
composer and template (which generate the partner) because it has already been
tested when introducing the mechanism. Although, we verify that it should
behave the same because we verify that the default values returned by
_get_customer_information, that is used in mail template when using the
composer, are the same as the ones returned by _message_get_suggested_recipients
which is tested here.

Task-3024050

Part-of: odoo/odoo#105111
2023-02-23 14:53:56 +01:00
Pierre-Yves Dufays a1d508f7ba [IMP] crm: provide crm_lead values for related res_partner creation
Define information taken from the lead when a partner is automatically
created from it. It avoids the user to enter the information twice and
automated partner creation now correctly takes information when possible.

Task-3024050

Part-of: odoo/odoo#105111
2023-02-23 14:53:56 +01:00
wan 5125748616 [REF] account: remove chart template
Rewrite the whole chart template mechanism, removing the templates
stored in the database. The new format will mainly use CSV.

Speed up install time
---------------------

* About half of the time of installing a localization for the first time is
  taken by creating the template records. This new in code format gets
  completely rid of this.
* Creating the template records could often not be done in batch because
  of parent/children relations.
* The instanciation of the accounts on the company has been entirely
  reworked too, by
  - optimizing the order of creation of records to avoid UPDATE queries
  - using precomputed fields to avoid UPDATE queries
  - updating the translation in batch
  - deactivating logging in the chatter
  - avoiding access rights checks by checking the rights at the start

Overall, when installing a chart template for the first time, it is 4
times faster because half of the time spent on saving the template in
the database is not done at all anymore, and the instanciation on the
company is more than twice as fast.

Reduce technical debt
---------------------

There is no need to synchronize the templates with the real records
anymore. No need to use hooks to copy the data from one to the other.

It is easier to change a template in a stable version, which can often
be necessary due to legal reasons (i.e. a change of tax rates, reporting
tags,...)

Two modules have been removed:
* `l10n_generic_coa`: since there is nothing left datawise in this
  module, it can be integrated in `account` for free. It is just code
  and CSV.
* `l10n_multilang`: the fields that this module modified to be
  translatable are now always translatable:
  - there was an issue when updating modules that deleted all the
    translations because the fields were not translatable at some point
    during the loading of the registry, then they because translatable
    again but lost all translations because of the column type change.
  - most devs are not able to understand all the languages needed for
    all the localization available. Therefore, english has been added in
    the sources in most localization to understand better issues while
    debugging.
  - no need to call post init hooks anymore, doing the sync with the
    templates.
  - more: see "Translations" section

Because most of the data is now in CSV, it is also easier for product
owners to edit, audit, modify files themselves, removing one layer
during trivial development processes when only data should be changed.

More flexibility for declaration
--------------------------------

The data declaration can now be done easily in python or CSV.
A nice feature is that you can declare everything at once, even for some
more complex chart of accounts:
* if you have to set default taxes on accounts, would need to
  - declare the accounts because accounts are required on the taxes
  - declare the taxes
  - declare the taxes to put on the accounts
  This would lead to scatter information in multiple files. Now,
  everything can be declared in the same place and the loading of the
  chart of accounts will do the 3 steps automatically.
* if you have a relation of child/parent, you would first need to
  declare the parents then the children, and the loading would not be
  efficient because done one by one. Now, everything is done in batch
  automatically without having to think about it.

It is also easier to update fields on records where there was no field
for that on the templates, like
* setting a restriction for journals on accounts
* setting specific values on the company
* modifying journals and linking them easily by using the xml_id instead
  of having to compute it manually

Translations
------------

Some countries have multiple languages (i.e. Belgium uses officially
French, Dutch and German, and the CoA also has an official English
version) and we must support the languages in all these countries.
All these translations are known, and hard coded without using out
translation platform (Transifex). We also like to have the English
version (even if an official one doesn't exist) so that support can be
done more easily in databases using chart templates in other languages
(especially using a non roman alphabet).

Because the translations were not on Transifex for these records, it was
really hard to maintain: the translation templates (`.pot` files) were
not easy to extract as the automatic export would give values mixing
both the CoA and the menuitmes, the fields' strings,... But we don't
want to translate the CoA as we already know the value.
Managing the translations in the `.po` files was also annoying:
- it is easy to forget that the translations need an update too
- it requires a special editor, special terminal commands that everyone
  is not familiar with
- it is easy to make mistakes in the source string

The new format is the following: `field@en_US` where `field` is the
translatable field (usually `name`) and `en_US` is the locale code.
This allows to have the whole declaration on one line, everything in one
file. It also makes the process easier when debugging: instead of
searching for the translation in the `.po` files, it directly appears
next to the configuration of the account/tax/... .

Update of the code
------------------

The code can be updated using this script
https://github.com/william-andre/transform_coa
Forward ports can be managed too by stashing/resetting/checkout the new
modules or the changes in the modules updated in the same PR.

task-2687567

Part-of: odoo/odoo#110016
2023-02-17 19:30:40 +01:00
Thibault Delavallée 04a6b74d09 [FIX] mail, various: update query counters
Update counters according to latest runbot counters. It allows to better spot
side effects of upcoming changes.

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:30 +01:00
Denis Ledoux 3752b3166e [REF] base: set USD as default currency for the main company
There are three rationales behind this change to set USD as default
currency and to enable it in the demo data, from the beginning.
With a demo database, before this revision:
1. On runbot, with all modules installed, it's already USD the default
   company currency. It's only when you install a module not depending
   on account that it's EUR the company currency by default (e.g. CRM)
2. in the base demo data,
   the company is set in the United States but with the currency EUR,
3. before installing account, the company currency is EUR,
   after installing account, the company currency is USD,
   this is due to the fact as the company is in the United States,
   the US Chart Of Account is installed, switching the company currency
   to USD.
4. when you install a demo database with a module not depending on
   account, you are left with a database without any active currency,
   and the monetary fields therefore do not show any currency.
   For instance, install only CRM with demo,
   you have no currency symbol before or after the expected revenue,
   which is not the best user friendly experience.
   On runbot you do not feel it because all modules are installed,
   therefore with account installed, which activated the USD currency.

Additional weird thing with point 2.:
- Unit tests in modules not dependent on account with the
  post-install tag had to handle this sudden change of currency change
  before and after installing account.
  For instance, when running their unit tests with only their module,
  but not account, the company currency is EUR,
  but when executing the same unit test with all modules installed,
  the company currency is USD.
  The unit tests had to handle this sudden change within the unit test,
  for instance by setting a 1.0 rate for their own company currency,
  which shouldn't be the case: the rate of your own currency should
  always be 1.0.

closes odoo/odoo#107113

Related: odoo/enterprise#34613
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-12-13 11:47:49 +01:00
Pierre-Yves Dufays 33d23cc246 [IMP] crm: improve lead searching and duplicate detection
Accelerate duplicate lead detection by adding indexes on field involved in the
search.

In this commit we add trigram indexes on email_normalized, partner_name and
contact_name that are used a lot for searching and finding leads.

Task-3007714

Part-of: odoo/odoo#105873
2022-12-12 13:18:46 +01:00
Aurélien Warnon f43b9e01c2 [FIX] sales_team: allow creating team in mono-company mode
Currently, adding members in a sales.team without the multi-company group is
not possible, the selection does not show any users.

This is because the domain field for the users search ("member_company_ids") is
not computed as none of its triggers are present in the view.

To fix this, we add the 'name' field as a fake trigger to force the
computation.

Side-note: the tour was added into the CRM module as we require this module to
have entry menus into crm.team form views.

Task-3088861

closes odoo/odoo#107352

X-original-commit: 11d24d8757a74cdf4af433bdc735460e68ba6cd2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-12-06 19:09:39 +01:00
Thibault Delavallée 9a5046ba0a [FIX] phone_validation: correctly support phone/mobile search parameters
Currently the search method defined on 'phone_mobile_search' supports either
a boolean (is set / is not set) search, either considers all searches to be
"like TERM". This is coming from the main usage that is the search view
that sends domains like "[('phone_mobile_search', 'ilike', term)]".

In this commit we improve the method to correctly support

  * direct check (=)
  * negative operators (not (i)like)
  * like / ilike (previously like were considered as ilike)

Idea is: a positive operator check that any of the phone fields respects the
domain (phone or mobile is TERM). A negative operator checks that all phone
fields respects the negative domain (both phone and mobile do not contain TERM).

Tests are added.

Task-3012789

X-original-commit: 8e905343f38a4dae828ccaddc62ce5c6a2f754db
Part-of: odoo/odoo#104111
2022-10-26 00:55:05 +02:00
Denis Ledoux 59a78b344a [FIX] base, crm: format address mixin _get_view override
The same override of `_get_view` was done in `res.partner` and `crm.lead`
in order to call `_view_get_address`, to change the address format
of the partner and lead form.

The definition of `_view_get_address` was already shared between these
two models through the `format.address.mixin` mixin.
So, why not share the override of `_get_view` also in this mixin,
so only one override needs to be written, instead of two.

In addition to merge the code of the `_get_view` override
in `format.address.mixin`, also set the `_get_view_cache_key`,
so the partner and lead form are correctly cached by company,
in case multiple companies in a same db use different address views.

Before this revision, this wasn't the case for `crm.lead`,
which therefore leaded to a bug when two companies where
using different address view, and one company accessed the lead
form before the other, therefore caching its own view version
in the cache, re-used later by the second company when fetching
its own lead form.

This revision takes the opportunity to add a unit test for crm.lead,
to assert the expected form according to the company address.
There was already a test for res.partner, but not for crm.lead.
To avoid copy/pasting the unit for both models,
a common test class is created, re-used to test both res.partner
and crm.lead.

closes odoo/odoo#103438

X-original-commit: 7e4a8b77024af663c5555c6d56557e2c6136b24b
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-10-19 20:47:51 +02:00
Xavier-Do 503ed05029 [IMP] tests: add generic Basecase.start for patch
Using patcher.start() can easily lead to incorrect cleanup.
-> after a copy paste, patcher is working, but stop is forgotten
-> stop is present, but won't be called if something fails during the
test

This commit add an utility `start(patcher)` to always have the add
cleanup.

Using a standard way to start the patcher with an automated addCleanup
should prevent this kind of mistake. This is why this commit also
replaces all valid patch.start() (followed immediately by a addCleanup)

closes odoo/odoo#102873

X-original-commit: 7d5a193d86316965a0908c65cfacfb607dc3f3ad
Related: odoo/enterprise#32618
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2022-10-10 16:11:01 +02:00
std-odoo 17335f13fd [IMP] crm: add a properties field on lead
Purpose
=======
To be able to customize the working flow on the lead, based on their
team, we add a properties field on leads, whose definition is stored
on their team.

Include the properties value in the merge message to keep the history
of the properties value if they have been overwritten during the merge
process.

Task-2965523

X-original-commit: 4722cc4b1fb027b7b9d731c3b206656588071360
Part-of: odoo/odoo#101487
2022-09-28 19:31:49 +02:00
Xavier Morel 5afcd06168 [REM] *: incorrect taggings which break tests when applied
Not entirely sure about TestAllocationRights. For TestEsEdiCommon
issue is quite obviously that it's inherited by tests which are
external, so when the `post_install_l10n` tag gets applied those tests
get run during "normal" l10n and they break.

closes odoo/odoo#98814

Related: odoo/enterprise#30825
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2022-09-05 08:33:13 +02:00
Xavier-Do 6de39178a5 [FIX] crm: update counter for `test_assign_perf_duplicates`
The test is currently disabled on runbot and breaks every night. Update the
counter to check if it is still random.

Task-2925606

closes odoo/odoo#99305

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-08-31 21:12:05 +02:00
Pratik Raval bb24757d08 [IMP] crm: detect leads based on similar phone/mobile number
Currently, the 'similar lead detection' mechanism only considers email,
contact name, and partner name while finding duplicate leads in CRM.

After this commit, it will also consider the mobile/phone number for
the same. Note that the mobile numbers and phone numbers both will be
matched with each other while finding duplicate leads.

Task-2817884

closes odoo/odoo#88372

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-08-25 19:56:48 +02:00
bve-odooandXavier Alt 9d1cb826c7 [FIX] crm: missing company on default crm team on incoming emails
Commit 0edc854a84 introduces a company check on the salesperson, partner
& team on the lead model.

However 184334a97d1ccd19b9a7266a13ff51531d22cff4 was not able to find the expected company on a lead
created by email when the team did not have a company set. Which is the case by
default for the following crm.team:

  - Sales (3ad1867ea4)
  - Pre-Sales
  - Website (3ad1867ea4)
  - PoS

Having added the company check introduce an unexpected error:
  "Incompatible companies on records:\n-
  '[header subject of email]'
  belongs to company False and 'Customer'
  (partner_id: '[name in header from of email]')
  belongs to another company."

Error was hard to spot as the db logs are reporting that the routing of the
email was correctly done. But script to send eml using xmlrpc showed the error.

In this commit we fix the issue by removing the custom code trying to set
a company in ``message_new`` method of crm.lead. Indeed as it is a computed
field with a complete heuristic it is easier to let the ORM do its job and
remove that wrong value. It is now correctly computed as with any other
lead.

opw-2862509
opw-2783249
opw-2832435
opw-2881841

closes odoo/odoo#98746

X-original-commit: 2fec9c53314ef3f7c7e3305a6ee2417018d70ce5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Xavier Alt <alt@odoo.com>
2022-08-24 09:29:27 +02:00
Denis Ledoux 0501bbd62e [IMP] base: uniform "groups" in back-end view
This revision is to make uniform the behavior of the `groups` attribute
on the Python model fields
and on the node in the view architecture.
In both cases, remove the node from the view completely.

Before this revision,

in a back-end view:
 - In the Python model, if a field has the `groups` attribute set
   and the user is not part of
   the groups, the field is removed, completely, from the view.
 - In the view architecture, if a node has the `groups` attribute set
   and the user is not part of
   the groups, the node is made invisible (not completely removed, just
   made invisible).

in a front-end view:
 - if a node has a "groups" or "t-groups" set and the user
   is not part of the groups, the node is removed from the view.

So it's 2/3 cases removing nodes restricted to a group.
and 1/3 case making invisible nodes restricted to a group.
It's simpler to have a uniform behavior for the 3 cases,
simpler to understandard for developers.

In addition, this will help for the goal to cache back-end views.
It makes possible to convert views using the `groups_id` field
by moving the content of these views directly
in the view to which they add content which is suppose to be completely
removed when the user has not the according group.
By getting rid of the `groups_id` many2many field on `ir.ui.view`,
it makes possible to cache the view architecture without
requiring to use the groups in the cache key.
Currently, if we want to cache the view architecture,
it would be required to use the intersection of the user
groups with the `groups_id` groups of the view,
making it costly to compute the cache key,
therefore altering the performance point to cache the view
architectures.

closes odoo/odoo#95729

Related: odoo/enterprise#29592
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-08-19 19:10:39 +02:00
Thibault Delavallée edb4cb6f8c [REF][IMP] crm, event, test_mail(_full): make performance tests post-install
PURPOSE

Have more reliable tests.
Better spot side effects coming from sub addons.
Lessen non deterministic counters due to local db.

SPECIFICATIONS

Make crm, event and mail performance tests post install.

Update query counters with
  * local values (install module only with enterprise activated);
  * community / enterprise runbots (if value is different);
  * some notes on non deterministic issue if known;

Task-2925606

closes odoo/odoo#96446

Related: odoo/enterprise#29726
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-08-18 21:08:50 +02:00
Florian CharlierandFabio Barbero 6f81b5e0a8 [FIX/IMP] crm: allow more specific lead default company
# Purpose

Take into account the current company when creating a new lead if not defined
earlier.

# Specifications

If there is no company provided by the sales team and the user belongs
to several companies and several companies are allowed by context,
we preferentially take the current company over the user's company if allowed.

# Additional considerations

This commit
* builds on the multi-company fix brought by e5f35a60 avoiding the restricted
access error when setting to the user's base company if not allowed by context,
but will also allow to first preferentially use the current company instead of None.
* Complete tests

Task-2824913

X-original-commit: ce62780153183545ba423a7a8d945d9665cdc50e
Part-of: odoo/odoo#97136
Co-authored-by: Florian Charlier <flch@odoo.com>
Co-authored-by: Fabio Barbero <faba@odoo.com>
2022-08-16 09:18:56 +02:00
william-andre d8d47f9ff8 [REF] accounting v16. Yeeeeaah
TLDR:
* invoices are implemented using computed methods instead of onchange
* the synchronization only happens when switching tabs in the Form view
  to improve perfs.

_______________________________________________________________________

The whole engine of the synchronization of Invoices to the Journal
Entries has been refactored
* by using computed fields instead of onchange functions
* by synchronizing only from invoice to journal entry in `create` and
  `write`
* by saving when switching tabs on the Invoice form, to synchronize
  before showing the values

This comes with numerous advantages:
* no need to call the onchange methods manually
* no need to use the Form emulator to build invoices (i.e. EDI, OCR,
  intercompany, ...)
* the performance for invoices with many lines improves drastically, going
  from 2 minutes to 4 seconds to create an invoice with 500 lines
* the model is more declarative, we can now see how the values are computed
  instead of having the values being copied from various places.
* remove the hack in `onchange` that disabled the recursivity of it,
  which was unexpected and needed to be managed manually in all the
  onchange methods

This means that:
* Some fields need to be exclusively computed on journal entries values
  or invoice values, more specifically the Tax Summary widget.
  It is now
    - computed from entry lines, when opening the view
    - computed from invoice lines when changing those, because the tax lines
      will need to be recomputed anyways, erasing previously set values
    - set with an inverse function when saving; after the sync has been done
* Some possible operations previously possible have been dropped.
  (i.e. look at the removed test test_in_invoice_line_onchange_accounting_fields_1)
  This is because such a behavior was undefined (how is changing the balance going
  to affect the unit price? How is the amount currency going to affect it?)

_______________________________________________________________________

Implementation Details
----------------------

The "dynamic lines", meaning the payment terms and the tax lines are now
only created in the `create` and `write` functions.
In order to reduce code duplication, it has been implemented using
context managers used in both `account.move` and `account.move.line`
These context managers help comparing the values before/after, acting
like a local `onchange`, but getting benefit from the dirty flags from
the `compute` dependences.
This is relying on computed fields on the move (`needed_terms`) and on
the lines (`compute_all_tax`) which contain the values needed for the
related move.
Depending on the needed values and the existing values (`term_key` and
`tax_key`, respectively) the context manager will determine what needs
to be created/updated/deleted.

Some related changes are to produce a `dict` instead of a `str` for the
`tax_totals` (previously `tax_totals_json`) fields, by simplicity to
reduce the complexity of IO, and simplicity of debugging, because the
logic of the field needed to change (cannot be computed at the same time
anymore since it needed the lines to be synced)

By simplicity, and also because it makes more sense, some boolean fields
have been merged into `display_type`:
* `is_rounding_line`
* `exclude_from_invoice_tab`
* `is_anglo_saxon_line`

The `price_unit`, `quantity` and other "invoice fields" are now not set
anymore on lines that are not product lines since it didn't make any
sense to have it.

Performances
------------

You have to keep in mind that a simple `create` didn't compute a lot of
fields, for instance not taxes were set, no payment terms,...
Now it does.

```python
import random
from timeit import timeit
from odoo import Command
domain = [('company_id', 'in', (False, self.env.company.id))]
products = self.env['product.product'].search(domain).ids
partners = self.env['res.partner'].search(domain).ids
taxes = self.env['account.tax'].search(domain).ids
def create(nmove, nline):
    self.env['account.move'].create([
        {
            'move_type': 'out_invoice',
            'partner_id': random.choice(partners),
            'invoice_line_ids': [
                Command.create({
                    'name': f'line{i}',
                    'product_id': random.choice(products),
                    'tax_ids': [Command.set([random.choice(taxes)])],
                })
                for i in range(nline)
            ]
        }
        for j in range(nmove)
    ])
                                                             # After  | Before
print(timeit("create(1, 1)", globals=globals(), number=1))   # 0.11   | 0.09
print(timeit("create(100, 1)", globals=globals(), number=1)) # 2.76   | 2.50
print(timeit("create(500, 1)", globals=globals(), number=1)) # 14.56  | 12.34
print(timeit("create(1, 100)", globals=globals(), number=1)) # 1.03   | 5.52
print(timeit("create(1, 500)", globals=globals(), number=1)) # 3.99   | 125.02
print(timeit("create(50, 50)", globals=globals(), number=1)) # 19.44  | 79.55
```

Another metric that can be used is running the test suite with
`--test-tags=/account` (only `account` installed)
* before: 404s, 267127 queries (366 tests)
* after: 318s, 232125 queries (362 tests)

Why this commit title?
----------------------

Someone told me that this was the perfect way of naming your commits.
c04065abd8

task-2711317

closes odoo/odoo#96134

Related: odoo/upgrade#3715
Related: odoo/enterprise#29758
Signed-off-by: Laurent Smet <las@odoo.com>
2022-08-03 13:44:49 +02:00
Thibault Delavallée f4d2a12b26 [FIX] crm: fix crashing nightly test
closes odoo/odoo#96283

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-07-19 18:00:24 +02:00
KareemAbuzaid 205df4df9c [FW][FIX] crm: remove res_model/res_id from meetings when unlinking leads
With Calendar and CRM installed:
- Create a lead and a meeting related to that lead.
- Delete the lead.
- Go to the meeting form view from the calendar App.
- Click the Document action button and nothing will take place.

After this commit if you delete the lead, you will no longer be able to the
see the button as document information is correctly reset.

Task-2917174
Closes odoo/odoo#42450
Closes odoo/odoo#47497

closes odoo/odoo#96190

X-original-commit: 71ccb7dae43a13521f2a290ce76cafd8fb5b963f
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-07-18 19:55:39 +02:00
Thibault Delavallée 9cd840f25b [FW][FIX] crm: correctly reset date_closed when going out of won stage
Probability is not always given to write, hence date_closed is currently not
always reset. Indeed as it is a computed field it can be updated after stage
update, without being explicitly in values.

In this fix we consider that going out of won stage without any other hints
on probability is like being not won anymore, therefore resetting date closed.

Task-2917116
Closes odoo/odoo#93704
Closes odoo/odoo#93704

X-original-commit: 1cf1b572b10bfbd02581c12f89824a028c4f23e6
Part-of: odoo/odoo#96190
2022-07-18 19:55:38 +02:00
Thibault Delavallée 2f7fe3b016 [FIX] lead: fix and quickly reorganize some tests
Followup of odoo/odoo@6e46d4cd07 and odoo/odoo@1f81d60de6

Also fix a test failing with python 3.8. Message-ID is formatted using chevrons.

Task-2917174

X-original-commit: 26c88387f24b8515dc74c24594f203e3953b8a39
Part-of: odoo/odoo#96190
2022-07-18 19:55:38 +02:00
Lorenzo Ciciotti e0898fd4d8 [FW][FIX] crm: update lead language based on partner
Onchange could also populate the lang field of the lead when updating the
customer.

Partial backport of odoo/odoo@65bb3a5710

Task-2917174
Closes odoo/odoo#78715

X-original-commit: e0e1e402a6c40ed89bc5a11671e364a67e93a176
Part-of: odoo/odoo#96190
2022-07-18 19:55:38 +02:00
Thibault Delavallée 40f4ea486b [UPD] various: update query counters
closes odoo/odoo#95556

Related: odoo/enterprise#29247
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-07-08 14:34:04 +02:00
Denis Ledoux 5ccc32fcf7 [IMP] tests: common.Form, can't write on invisible fields
In the web client, in a real use case, it's not possible
to write on fields which are invisible,
as it's not possible to write on fields which are readonly.

This is a first step in the goal to change the behavior
of the `groups=` attribute in the back-end views,
to remove them for the view instead of making them invisible.

This is mainly to reduce the diff of the revision that will introduce
the mentioned above behavior change.

As nodes with `groups=` will be removed from the view
when the user doesn't have the group, it's no longer possible
to set a value on a field having a `groups=` the user doesn't have
in the `Form` test class, as the field will no longer be at all in the
view.
However, these unit tests shouldn't have been able to set values
on invisible fields in the first place.
This revision therefore aims to correct the unit tests setting value
on fields which were invisible because the user executing the
test was not part of the required group(s) for these fields
to be visible in the view.

closes odoo/odoo#94337

Related: odoo/enterprise#28936
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-07-08 14:33:47 +02:00
Abdelouahab (abla) c91797a41d [FIX] crm : set default value to company_currency
To reproduce
============

Have two companies with different currencies,
Create a lead in the first compnay => the expected revenue has the company's currency
Create a lead in the second company => the expected revenue doesn't have the currency

Purpose
=======

in v15 the `company_id` has became computed, but the compute method in some scenarios
doesn't set the `company_id`.
`company_currency` is related to `company_id`, so when `company_id` is not set `company_currency`
is also not set which occures this issue.

Specification
=============
To solve the issue, the field `company_currency` is computed now, and we give it the value of the active
company if `company_id` is not set.

opw-2862410

closes odoo/odoo#95484

X-original-commit: de59391caede72624fddcb01ba3565884c4e5574
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-07-07 10:15:59 +02:00
Raphael ColletandVincent Schippefilt eb67feb590 [FIX] *: cache consistency
In module mail, invalidating 'message_ids' on a mail thread also
invalidates its inverse field 'res_id' on messages.  If you haven't
flushed it before, your cache will be inconsistent, as shown by the test
/mail:TestMailgateway.test_message_process_bounce_records_channel.

In module purchase_stock, add depends on report.stock.quantity.  This
ensures that when the model is queried after changes in other models,
the data on which the SQL view depends is flushed to the database before
querying that model's table.

closes odoo/odoo#66938

Related: odoo/enterprise#16722
Signed-off-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
2022-07-05 11:35:01 +02:00
Thibault Francois e26d3e1166 [FIX] crm: sale user should be able to convert and merge lead
Use case
--------

A sale user convert a lead to an opportunity, this lead has duplicates.

The wizard will convert and merge the lead. At the end of the process
the duplicated lead are delete.

Issue
-----

Before this commit the user get an access error because he cannot delete
leads

Since they can merge lead using the action "Merge" it's not consistent
and sales user should be able to merge lead during the conversion
as well

closes odoo/odoo#94699

X-original-commit: 3b79867460d9a407fba094fe1cd719d8d52011ef
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Thibault Francois <tfr@odoo.com>
2022-06-27 17:35:22 +02:00
Mitul Shah f0b7600314 [IMP] base, crm: set salesperson and team on partner from parent
This commit does below improvements:

1/ If salesperson and sales team are set on an individual partner, we propagate
   those to parent company being created from m2o of the form view.
2/ If the existing parent company is manually linked to an individual partner
   being created, and salesperson and sales team are not set on the individual,
   we set those values from the linked parent (if set on the parent).

Task-2636290

closes odoo/odoo#78696

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-24 13:49:07 +02:00
Laurent Desausoi 6762590b9d [IMP] crm: add tests for MC computation on lead with partner company
Currently using a customer with a company set on a lead without company
crashes, as it keep a void company on the lead. This is not compatible
with the company set on the partner itself.

OPW-2805181
Task-2888330

X-original-commit: 51be6cab5c4437ef56de5d1b25c0ba8486d25291
Part-of: odoo/odoo#94493
2022-06-24 10:30:05 +02:00
Thibault Delavallée b71455c328 [UPD] various: update query counters
Update to latest runbot state, at least for tests known to be
deterministic.

Notably mail tests are lower than before, probably due to odoo/odoo#73271

closes odoo/odoo#93470

X-original-commit: 6118ecba8d807ac5ebc69ae4877e1f202b0daeb1
Related: odoo/enterprise#28308
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-13 19:10:58 +02:00
mafo-odoo 28b41a3246 [FIX] crm: no date_closed update between 2 won stages
Steps to reproduce:
	install crm and change a lead between two won
	stages

Expected behavior:
The date_closed does not change

Current behavior:
The date_closed changes

opw-2839298

closes odoo/odoo#92534

X-original-commit: 0c55c0d31021abe966c453c4827d5873a7af485c
Signed-off-by: Fockedey Martin (mafo) <mafo@odoo.com>
2022-06-01 08:51:46 +02:00
Raphael Collet 6cf8db906f [REF] *: adapt code to new flush API
closes odoo/odoo#87527

Related: odoo/upgrade#3497
Related: odoo/enterprise#26939
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-05-25 18:00:47 +02:00
Fabio Barbero fc79bd1e0e [IMP] sm modules: "neutralise" genders
Purpose
=======
Change all masculine nouns in Odoo's code to neutral nouns (when
possible), making sure that demo data is correctly handled. This is
particularly important since our code is open source, and nowadays lots
of machine learning models are trained on open source repositories.

With this small change we contribute to training more "fair" models, and
teaching models that "employee" or "user" != "he".

This also affects some text visible by the user, hence making it more
inclusive for Odoo users.

Task-2853046

closes odoo/odoo#91292

Related: odoo/enterprise#27302
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-05-16 10:09:32 +02:00