Commit Graph
30 Commits
Author SHA1 Message Date
Rémy Voet (ryv) f9e75d19a9 [FIX] *: Fix bad usage of 'like'/'ilike' operator
The 'like'/'ilike' operators automatically add the wildcard character
(`%`) at the beginning and at the end of the value. This commit fixes
the incorrect usage.

closes odoo/odoo#136007

Related: odoo/enterprise#47886
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-09-27 09:11:44 +00:00
Thibault Delavallée 31150660ca [MOV] base, mail: regroup partner and mail tools tests
Move tests currently in mail about helpers defined in 'tools/mail.py' directly
into base. No need to test it in mail, there is no specific override or
behavior change compared to base.

Regroup partner related tests in base into 'test_res_partner'. This breaks
part of test history but it helps knowing which features are tested.

Task-2612945 (Mail: Defensive email formatting)

Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 459c085c19 [IMP] base, test_(mass_)mail(ing): add tests for multi / formatted email fields
PURPOSE

Be defensive when dealing with email fields, notably when having multi-emails
or email field containing an already-formatted email.

RATIONALE

Add tests related to not standard usage of email field. Two main use cases
are tested here

  * formatted emails: `"Full Name" <email@domain.com>` stored into the 'email'
    field;
  * multi emails: `email1@domain.com, email2@domain.com` stored into a single
    'email' field;

Additional tests: tests with unicode / ascii / case / wrong formatting are also
added to check the support in normalize and format methods.

IMPLICATION

Email field is generally managed as "containing a valid email". This means
it is sometimes used as it in 'formataddr' as well as to perform searches or
identification checks. Example of issue: partner 'Raoul' has a formatted email
like "Raoul" <raoul@raoul.fr>. Using 'formataddr' in email_from leads to

  from: "Raoul" <"Raoul" <raoul@raoul.fr>>
  -> which is incorrect (but often dynamically corrected by email servers);

Email field holding multi-emails are not normalized, as current normalize
is done only if the field holds a single email. It means

  * no easy finding based on 'email_normalized', e.g. various tools like
    '_mail_find_partner_from_emails' or 'find_or_create' do not find partners
    based on this email;
  * no exclusion list management;
  * issue with formatting, like

  to: "Raoul" <raoul@raoul.fr,raoul.other@raoul.fr>
  -> which is incorrect (but often dynamically corrected by email servers);

USAGE: OUTGOING EMAILS

Those use cases currently generate faulty outgoing emails. This is valid for
recipients ('email_cc', 'email_to') as well as author ('email_from').

For formatted emails: `email_to` is formatted again based on name and email
which leads to sending emails to `"Full Name" <"Other"<email@domain.com>>`.

Note that multi emails without formatting may work as it leads to email_to
`"Full name" <email1@domain.com,email2@domain.com>`. Some outgoing email
servers correctly send multiple emails. It depends on their fault
tolerance.

USAGE: FIND BASED ON EMAIL (NORMALIZED)

When searching for partners (e.g. using '_mail_find_partner_from_emails' or
'find_or_create') normalized version of input is used.

In case of multi emails sanitize is 'False', as normalization expects a single
email in the field. Therefore no partner is found. In processes that do a
"search or create" (e.g. using a template on a record) this leads to creating
a new partner (or several partners in case of multi emails) each time.

USAGE: OTHER FLOWS

Other flows are build on top of '_mail_find_partner_from_emails' / 'create'
of outgoing emails and are impacted by formatted email / multi email usage.
Those include notably

  * mass_mailing: '_message_get_default_recipients' should be defensive to
    give correct values when creating mailing emails;
  * mass_mailing: faulty emails is based on normalize and multi-emails are
    considered as faulty and ignored;
  * after post hook: '_message_post_after_hook' tries to link messages without
    author (but email_from) with newly-created partners, when partners are
    created from chatter. It is therefore impacted by those corner cases;
  * marketing_automation: built on top of mass_mailing and suffers from the
    same issues;

USAGE: UNICODE

Unicode in emails should be supported. 'formataddr' and IrMailServer notably
received fixes to support unicode. Some check performed on email addresses
fail when unicode is involved, which leads to some emails not being sent
while they could.

SPECIFICATIONS

Add tests related to those corner cases. Also add tests for computation of
`email_formatted` field of Partner model. It currently generates wrong email
values for the same corner cases (multi emails, formatted emails).

Tests are also added for the computation of `email_normalized` field used
notably for blacklists. It is not computed currently when being in multi
email mode which prevents from any blacklist mechanism as well as make
email finding harder. `_mail_find_partner_from_emails` tool method is also
tested with multi email as it uses the same heuristic as normalized email
field.

Tests are also added for mass mailing, when having to mail documents that
have a partner with formatted emails / multi-emails, or that have an email
field with formatted emails / multi-emails.

Also restore a test removed at odoo/odoo@afcb734908 while it should have been
updated to state that email addresses containing non-ascii characters are
supported.

Add some tests for tools methods used in various email processing flows.
Unicode tests are also added.

In future commits we will try to make email usage a bit more defensive to
try to lessen issues with that kind of use cases.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@fc8442f133
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Rémy Voet (ryv) cdebf336a5 [REF] core: _read_group for backend use
The `_read_group` was designed to be used by the web client to
efficiently compute aggregations grouped by one or more fields.
However, more and more developers have been using it from the backend
to make computations more efficient (avoid doing the aggregation
in Python). Unfortunately, the API was designed for the web client,
which added a lot of boilerplate when used in the Python (list of
dict with misleading key name choices).

`_read_group` was created to improve the performance of read_group
for backend use (4ef0c00b4b), but didn't
change the API and based the implementation on read_group itself.

Rewrite `_read_group` from scratch with a new API to make it easier
to use from the backend (see the method documentation). Also, split
the method to make it easy to override and add custom behavior.

Part-of: odoo/odoo#110737
2023-04-19 21:58:26 +02:00
Martin Trigaux d805349855 [FIX] base,mail: properly remove the user from an implied group
In mail, changing the setting "Restrict mail templates edition and
QWEB placeholders usage" to false should remove all users but admins
from the group, including the template user.
Before this commit, you could have weird behaviou such as

1. Disable the restrictiong (group_mail_template_editor in
   group_user.implied_ids)
2. Install mass_mailing (group_mail_template_editor in
   group_mass_mailing_user.implied_ids)
3. Create a user test with minimum employee roles (still has
   group_mail_template_editor as employee)
4. Check the box "Restrict mail templates edition and QWEB
   placeholders usage"

-> test still has the template group nothing implied it

The issue was a combinaison of recomputation of implied groups
https://github.com/odoo/odoo/blob/b2f760cae74201d1622e56a0027dae67dcff9e33/odoo/addons/base/models/res_users.py#L1292-L1295
that triggered the synchronisation of groups on template user
https://github.com/odoo/odoo/blob/b2f760cae74201d1622e56a0027dae67dcff9e33/odoo/addons/base/models/res_users.py#L611-L616

By removing the users already in a group, we avoid falling into the
condition added at 121cd0d608 where the default user gets a
group removed, readded, hence added for everybody.

closes odoo/odoo#115108

X-original-commit: 6398dd287f07641c85807f291d9fe078fcb8a231
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2023-03-16 13:07:52 +01:00
Alvaro Fuentes 27854c787a [IMP] test_base: test add/remove implied groups
Given a recordset R of (at least two) groups, and a group A.
We want to ensure that:
* `R._apply_group(A)` adds A to the list of implied groups of _all_
  groups in R.
* `R._remove_group(A)` removes A from the list of implied groups of
  _all_ groups in R

This is especially problematic for config settings of the form
```
class MyConfig(models.TransientModel):
    _inherit = 'res.config.settings'
    group_imply_A = fields.Boolean('x',implied_group='A',group='B1,B2')
```
since activating the implication via `group_imply_A=True` currently
fails in case only one of B1,B2 already implies A.

opw-2832741

closes odoo/odoo#96928

X-original-commit: 81dc64740ba46355462ed2169e57fc0ce694ccdb
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Signed-off-by: Alvaro Fuentes Suarez (afu) <afu@odoo.com>
2022-07-28 10:28:03 +02:00
Vincent Schippefilt 4ef0c00b4b [ADD] models: add _read_group method to avoid sorting on the names of many2one
The public read_group method is used by back-end code as well as RPC calls to receive grouped data.
 Most of the time, if the data isn't shown to the user, it doesn't need to be sorted on the names of
 the many2one, and can just be sorted on their ID instead, avoiding extra joins in the resulting queries

 This is a first commit that will reduce the features of _read_group to the strict minimum necessary
 to obtain correct grouped data that is never shown to a user

Task-id: 2479334
Part-of: odoo/odoo#84908
2022-03-02 17:10:47 +00:00
Vincent Schippefilt a5e21abdf5 [ADD] models: adds a test for read_group date:agg group
Adds a test that verifies that the grouping with a date aggregate
specifier (the only group specifier supported until now) is working correctly

Part-of: odoo/odoo#84908
2022-03-02 17:10:47 +00:00
Vincent Schippefilt 209249dcec [REF] base: modernize read_group tests
reshape a bit the read_group tests by ensuring that:
- creation of user is made in batch
- assertions are always assert(actual, expected)

Part-of: odoo/odoo#84908
2022-03-02 17:10:46 +00:00
oco-odoo e68873fe89 [FIX] base_vat: Don't always pass VAT check when validating the VAT of a partner without country_id
Before this, when making a partner without any country_id, any VAT could be set to it, which was inconsistent with the module's purpose.

closes odoo/odoo#68815

X-original-commit: 72606f14d0c1d86d7a205fd29aec8d66d3e98678
Related: odoo/enterprise#17505
Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
2021-04-07 09:46:58 +00:00
Damien Abeloos 162f3059d5 [IMP] base: modify some displayed texts for res_partner
* Add a new error message upon deleting the partner linked
  to an active user.

* Improve the error message wording upon archiving the partner
  linked to an active user. Add the linked users names at the end of
  the message.

* If the user has 'write' access on res.users, raise a RedirectWarning
  instead of a ValidationError, to offer an easy access to the related users :
    - If there are multiple Users, redirect to a list view.
    - If there is only one User, redirect to the form view.

* Adapt the test_access_deleted_records from test_orm.py to use a more
  basic model : `res.partner.category` (with less business logic), because the
  new unlink error message is dependent on a condition that will throw an error
  in case of multiple unlinks of the same record (MissingError).

* Force close the frontend archive confirmation Dialog since _toggleArchiveState
  may be interrupted by another Warning/Error Dialog. If the new Dialog was the
  redirectWarning, and the user chose to be redirected, the first Dialog would
  stay open even thought the context already changed.

* Modify the placeholders for a partner Name/Company
  -> placeholders will change according to an Individual or a Company.

* Adapt the main_flow tour to correctly select the partner name field on
  mobile (tested in enterprise).

Task ID : 2410217
PR : https://github.com/odoo/odoo/pull/63370
2021-03-03 12:12:47 +00:00
Julien Castiaux 90b52d144a [REF] base: Use Command helper for x2many
Task: 2366606
2020-11-30 10:16:09 +00:00
Thibault Delavallée 6e25a510b3 [REF] base, mail: improve partner creation from name / email
Rewrite code parsing name (_parse_partner_name) to make it easier to
understand. Tweak find_or_create to return directly a recordset with the
found partner / new partner instead of a name_get result.

Also inherit Partner.find_or_create() in mail in order to benefits from
email_normalized field, allowing to improve the search on matching emails
and avoid duplicates.

LINKS

Task ID 1963529
Community PR odoo/odoo#32397
2020-03-24 10:24:14 +00:00
Thibault Delavallée aa74a975d7 [IMP] base: add tests for partner find_or_create / name_create / _parse_partner_name
As find_or_create API and code will be slightly improved soon let us add some
tests to ensure behavior and avoid (too much) regressions. Notably about the
fallback on faulty emails support aka "name email@domain)" which in parsing
is considered as valid. This may happen when people copy-paste emails.

LINKS

Task ID 1963529
Community PR odoo/odoo#32397
2020-03-24 10:24:12 +00:00
Christophe Simonis 64e43808b7 [MERGE] forward port branch saas-12.5 up to 58a83d1222 2019-09-20 17:34:45 +02:00
Martin Trigaux f4d5a7fe8b [IMP] base: improve test coverage
The forbidden cases were not tested, making it harder to detect

closes odoo/odoo#36846

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-09-18 08:40:12 +00:00
Julien Castiaux 4f03a5f136 [FIX] *: remove old deprecated modules/functions
PEP-594 is deprecating a bunch of modules. As part of the cleanup, we
are also dealing with long deprecated modules, functions and aliases.

* `assert_` -> `assertTrue`
* `assertEquals` -> `assertEqual`
* `assertNotEquals` -> `assertNotEqual`
* `assertAlmostEquals` -> `assertAlmostEqual`
* `assertRaisesRegexp` -> `assertRaisesRegex`
* `assertRegexpMatches` -> `assertRegex`
* `base64.encodestring` -> `base64.encodebytes`
* `base64.decodestring` -> `base64.decodebytes`
* `inspect.getargspec` -> `inspect.signature`
* `inspect.formatargspec` -> `inspect.signature`
* `logging.warn` -> `logging.warning`

closes odoo/odoo#36863

Task: 2003936
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-09-17 11:36:42 +00:00
Nicolas Martinelli e1128c9387 [FIX] base: create partner from email
Call the method `find_or_create` with `email` equals to
`"Raoul Grosbedon <r.g@grosbedon.fr>"`

The partner created has the name `r.g@grosbedon.fr` instead of
`Raoul Grosbedon`.

The method `name_create` is capable of handling such a use case, so we
take advantage of it.

opw-2052997

closes odoo/odoo#35797

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2019-08-19 08:49:25 +00:00
Xavier-Do 95b4f2ab4b [IMP] core: improve test_tags
Add the support to be able to specify exlicitely module, class and method name in test_tags

Before this commit, there is no distinction between module tag and test tag. Meaning
that --test-tag module_name will replace the default +standard tag and execute all test
of the module.

This commit tries to keep the initial behaviour, while addind new features, like explicit
modules tag with /module_name, as well as class (:class) and method (.method)

Some usage examples:
--test_tags /module will execute all standard test of module
--test_tags :class will execute all standard test with class name 'class'
--test_tags .method will execute all standard test with method name 'method'
--test_tags external/module will execute all external test of module
--test_tags */module will execute all tests of module,
--test_tags */module,-standard will execute all non standard tests of module,
--test_tags -/website:TestUiTranslate.test_admin_tour_rte_translator will disable only rte translator test

closes odoo/odoo#34756

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-07-11 09:03:14 +00:00
Xavier Morel b4ae543098 [IMP] base: batching of _compute_commercial_partner
Should correctly handle / fallback to regular code when processing
non-stored partners.

Perf difference according to cprofile on my machine:

original python:
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     1    0.134    0.134  205.380  205.380 res_partner.py:277(_compute_commercial_partner)
SQLized
     1    0.118    0.118   67.239   67.239 res_partner.py:280(_compute_commercial_partner)

most of the time leftover seems to be in modified_draft
2019-04-02 09:57:49 +00:00
Raphael Collet 3a30391e9d [FIX] base: superuser cannot become active 2018-09-27 09:54:28 +02:00
William Henrotin c9735c75d6 [IMP] base: prevent to archive users linked to active partners.
An active user could not see messages in its inbox if his partner is
archived. With this commit, we cannot archiving a partner linked to an
active user anymore.

In the opposite way:

 -if we deactivate a user, warning message is given saying the related
  partner will stay active. A link to the related partner is also given
  if we really need to archive it;
 -if we activate a user, the related partner will be set as active;

This commit is linked to task ID 46158. Closes #24628.
2018-05-28 14:43:06 +02:00
Raphael Collet 80f1ac3599 [REF] never defer parent_store computation
Simplify the implementation of parent_left/parent_right by removing this
optimization.
2018-02-28 10:33:44 +01:00
Christophe Monniez b356b19033 [IMP] tests: Add the possibility to tag tests
Purpose: When running tests, all the tests for the installed/updated
files are done. This commit adds a 'tagged' decorator that can be used to
tag tests. Combined with a new 'test-tags' CLI option, it adds the ability
to filter which tests are executed. For example, @tagged('slow') will
add a tag 'slow' to the test. The CLI option 'test-tags="slow"' will
only run tests tagged 'slow'.

One can use prefixes to select cases with tags.
'+' or no prefix means that the tests tagged with this tag are selected
for execution. '-' prefix will exclude the tests tagged with this tag.
Exclusion takes precedence over inclusion.

Also, by default, all Odoo tests cases are tagged 'standard' and with
the technical name of the module.
This means that when selecting tests with the 'test-tags'
parameter, if '-standard' is not specified, all tests tags are
going to be executed.
When tagging tests, one can remove such automatic tag by prefixing the
tag name with '-'. E.g. @tagged('-standard') will remove the standard
tag from the test.

Another example, if one wants to test the 'sale' module alone,
even without adding any 'tagged' decorator thos tests can be selected
like that: --test-tags="sale"

Tests are selected or deselected using a TagsSelector. When instanciated,
 a string is passed with comma separated tests selectors like
'+slow,-standard'. When the 'check' method is called  with a test as argument,
it returns True or False if the test has to be executed or not.
2018-01-18 13:20:37 +01:00
Raphael Collet 2ed137af3e [REF] models: refactor code to update parent_left/parent_right
Put the code to update the MPTT in specific methods, and reduce the number of
queries being made (from 5-6 queries to 2-3 queries).  Add test on MPTT to
validate the refactoring.
2018-01-16 10:47:13 +01:00
Christophe Simonis bf51fe55a1 [MERGE] forward port branch saas-16 up to 0f2b2c4e2b 2017-07-07 14:30:30 +02:00
Nicolas Martinelli c61ae3a3ed [FIX] models: copy field with unique constrain
When a model contains a field translatable which has a unique
constrain, it is impossible to copy a record. Indeed, the unicity
constrain is always triggered, even if the model takes in charge the
overriding of the copy method to avoid duplication.

Introduced with commit ce7f31b0b0, with the goal to target only
XML/HTML translations. We apply this behavior in case of a callable
translate property, to target only the desired problematic use case.

opw-749481
2017-06-30 10:52:15 +02:00
Xavier Morel aaf8f3e37f [IMP] reorganise opcodes in categories 2017-06-26 16:45:03 +02:00
Raphael Collet 0783318f97 [FIX] adapt logger names 2016-09-02 17:28:13 +02:00
Raphael Collet 9e64f9f951 [REF] openerp: move openerp to odoo 2016-09-02 17:28:12 +02:00