Commit Graph
64 Commits
Author SHA1 Message Date
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
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 1af84e28ee [IMP] mail: introduce 'mail.alias.mixin.optional' with optional aliases
Some models would like to use the 'mail.alias.mixin' but it creates an alias
for each record in the parent model. This leads to a lot of unused aliases
if only a subset of those records really use aliases i.e. a lot of aliases
with 'alias_name' being 'False'.

In this commit we introduce a new mixin 'mail.alias.mixin.optional' that
behaves like the old 'mail.alias.mixin' but without having the 'alias_id'
field required i.e. without the "inherits". When creating a record without
giving an 'alias_name' no alias is created.

In future commit, we plan to use it notably to remove custom code in account
journal model and make it more standard. Using it in more models will be done
later, but it is a candidate to cleanup unused aliases related to discuss
channel model.

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 e130289ebe [IMP] mail: add a default heuristic to find a partner on a document
RATIONALE

Simplify field management for mail / phone / sms flows. Make it working out
of the box, easier to use and tweak.

SPECIFICATIONS

In addition to finding the customer, sometimes we just want any partner on
a record, notably for VOIP. For that purpose we improve heuristic for
finding partner (fields or records). It introspects the model to find any
relational field towards res.partner. Note that as it is generic it does
not ensure the partner is a customer, just some partner.

Task-3422449 (Mail, Phone: Move and improve field helpers)
Prepares Task-36879 (Mail: Support MultiCompany Aliases)

Part-of: odoo/odoo#130468
2023-08-02 18:50:17 +02:00
miad-odoo d31b3ecb84 [IMP] mail: add mixin to compute many2one duration
This commit implements a mixin, `MailTrackingDurationMixin`, that can be added
to a model with a `many2one` field. It computes the time a record spends in each
value the many2one field takes and stores it in a JSON field
(`duration_tracking`).

The primary use is with the StatusBarDurationField
(`widget='statusbar_duration'`), to compute and display the time a record has
spent in each stage in the form view statusbar.

To specify on what field the computation has to be done, the model that inherits
from this mixin has to specify  `_track_duration_field`.  (e.g.
_track_duration_field = 'stage_id')

Computation is based on `mail.tracking.value` messages, so tracking has to be
activated for that field.

Task-3032773

Part-of: odoo/odoo#108554
2023-07-18 13:07:41 +02:00
Sébastien Theys a3260cfcd7 [FIX] mail: apply multi-company when feching systray activities
A raw query is not necessary to produce the desired result, found
activities need to be kept only if the corresponding record can be found
with standard search (which includes multi-company check).

Part of task-3266643

closes odoo/odoo#123070

X-original-commit: 9dd7ae942aebe2cfd3e2dcd52e10b3bff5c8e0a9
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-05-31 14:23:48 +02:00
std-odoo 09095db293 [IMP] web, mail: open the chat window when clicking on an avatar property
Purpose
=======
Like standard avatar widget, we want to open the chat window of a user
when clicking on a many2many / many2one avatar property.

Task-3208449

Part-of: odoo/odoo#114200
2023-05-17 13:37:37 +02:00
Pierre-Yves Dufays a0cb558048 [IMP] test_mail: add unfollow record test
Add tests that check the behavior of unfollowing a record from the inbox and
the unfollow link in email.

To support unfollowing a document in the inbox no matter the current company,
we have modified message_unsubscribe in mail_thread to allow internal user to
unsubscribe themself without checking any rights. Indeed, some document have
record rule that prevents reading it if the user is not in the right company
(ex. crm.lead) and then was preventing the user to unfollow the document using
that method. We also add a test checking that internal user can unsubscribe a
record without any read and write rights. And that a portal user can't in the
same circumstance.

Task-3061864

Part-of: odoo/odoo#107978
2023-05-10 13:21:07 +02:00
Thibault Delavallée 110d86f504 [IMP] mail: allow composer to translate from template
RATIONALE

Naming conventions
  * content = core message / subject (+ other fields);
  * email layout = layouting applied to messages when sent to recipients who
    receive notifications by email e.g. access button, ...;
  * comment mode / mailing mode: composer main composition mode: posting on
    record(s) / sending a mailing on records;

Content situation when using a template on the composer

  * comment, monorecord mode: choose a template, content is rendered directly
    from template side according to 'lang' field definition -> ok;
  * comment, multirecord mode / mailing mode: choose a template, content is
    the raw content. At post / send, content is rendered on composer side.
    As composer is not translated -> no translation -> ko;

PURPOSE

Take translations from template when composer content is the same as the
template one to benefits from their translations.

SPECIFICATIONS

When rendering some fields fetching translations can be complicated. Indeed
when using a template the translation is stored on template model while the
rendering is done on composer model. Translations are therefore not fetched
as fields of the composer record itself are not translated. It is a transient
record, not something people translate manually like templates.

As translations are not stored in a table anymore we can't really fetch
translations, except from using directly the template field. In this commit
we therefore do the rendering based on template value instead of composer
value when they are considered as equal and if a translation is asked either
through 'compute_lang' of 'force_lang'. This allows to fetch template
translations instead of composer translations.

If the composer content has been modified compared to the template we keep
the old behavior, which means probably no translations. Let us hope editor
does not mess too much with html content.

EXAMPLE

A user in english uses a template on a lead whose customer is in spanish
with a follower being in german. Template lang is customer's lang:

  * content is translated into spanish (customer's lang);

Concerning layout (to be fixed in next commits):

  * layout is partly translated into spanish (customer's lang) if coming from
    form view, otherwise is in english (current user's lang);

LINKS

Task-3046371 (Mail: Better Language Support in Composer)

Part-of: odoo/odoo#106177
2023-03-09 15:54:14 +01:00
Thibault Delavallée c088d5423e [IMP] mail: cleanup _notify_get_recipients code bits
This commit contains mainly code cleaning, docstrings and a small split
for notification tool methods. In this commit we

  * make some notification groups variable explicit;
  * move the filler of groups into its own submethod to ease being called
    from other code (to be used soon);
  * fix some strange overrides or code manipulation;
  * propagate some additional parameters to ease future commits that will
    improve rendering of groups-based notification emails;
  * cleanup, fixup and improve docstrings;

This does not change anything from functional point of view, just preparing
further work.

Task-3046371 (Mail: Better Language Support in Composer)

Part-of: odoo/odoo#106177
2023-03-09 15:54:12 +01:00
Pierre-Yves Dufays 0a527ace82 [IMP] test_mail: add tests to justify sudo when writing attachment
Add message post with attachment test on record of another company than the
user company but for which the user has readonly access on. The goal is to
justify the sudo added in mail_thread:

  - in '_message_post_process_attachments' method to create attachment linked
    to the record (the creation of attachment linked to a record verify the
    right to write to the record, so in readonly we need a sudo);
  - in '_message_set_main_attachment_id' method to link the main attachment to
    the record. Here we write directly on the record for which we only have
    readonly access, so a sudo is needed. Here the attachment is already linked
    to the model and we only "tag" it has main attachment (see odoo/odoo#30659)

Task-3178885 (Mail: fix 'readonly' post support)

X-original-commit: odoo/odoo@8486c7ee05
Part-of: odoo/odoo#114511
2023-03-07 18:03:02 +01:00
Thibault Delavallée 248e0e495b [IMP] test_mail: add composer tests for email layout support and translation
Purpose is to add some tests about email layout support in both comment and
email mode, as well as language support in those two modes. They are added
in a test targeting a complete template usage, testing globally the results
(outgoing notifications or emails, buttons, language, recipients, ...).
Posting in multi-languages environment with notification layout is also
tested. Finally a test about reply-to is moved into its own subtest to
avoid polluting core template tests. Other low level details should already
sufficiently tested. Normally.

Main observations

  * translations are quite broken in mass mode (either batch comment either
    mass mailing). Indeed translations are fetched based on <mail.compose.
    message> body and subject fields, which are probably not translated
    as they are linked to a transient model. Real translations are stored
    at <mail.template> level when users translate their templates;
  * layout translation is partly supported in comment mode, due to a small
    context-based hack. However access buttons are not translated and some
    use case (like using a 'res_domain') are not supported;
  * mass_mail mode does not support layouting at all;
  * when posting manually ('message_post') current users' language determines
    the language of notification email layout e.g. a user using Odoo in French
    will send a french layout to all followers, whatever their language and
    whatever the language of the post (which is not known as user input);

Most of those use cases will be fixed soon.

Also update some query counters while passing by.

Task-3046371 (Mail: Better Language Support in Composer)

Part-of: odoo/odoo#114511
2023-03-07 18:03:01 +01:00
Pierre-Yves Dufays 4991dbc9a8 [REF] mail: adapt test using new main attachment mixin
Task-2648976

Part-of: odoo/odoo#110734
2023-03-02 12:32:11 +01:00
Pierre-Yves Dufays 1018c72571 [IMP] mail, test_mail: allow model to provide partner default values
Allow model to provide default values for auto creation of related res_partner
such as name, title, company_id, ...

It is used when claling 'Partner._find_or_create_from_emails()' that now
accepts custom data when creating partners based on a given email_normalized.
This allows notably to flatten a loop due to multi-company when creating
partners from emails in template management. It is now done using this email
based dict allowing to create all partners at once.

Task-3024050

Part-of: odoo/odoo#105111
2023-02-23 14:53:56 +01:00
Thibault Delavallée c70662b6c6 [IMP] test_mail_full: add tests for portal inheritance of thread features
Purpose is to add tests as there are some broken overrides in mail.thread
inheritance mechanism.

We see notably that bad override in portal make some override not being
called correctly.

Task-3175768 (Mail: check inheritances / overrides)

Part-of: odoo/odoo#112573
2023-02-13 22:46:41 +01:00
Thibault Delavallée 041e9924c7 [REF] mail: improve default record-based data in composer
Purpose is to ease understanding of those default values and prepare move
towards editable stored computed fields by rewriting a bit the code to better
understand its purpose.

While being at it, some tests introduced recently are moved at their right
place now that everything is ready to rewrite the posting API and the
composer. Some tests are added to ensure notification-specific methods are
called along with the newly-introduced '_message_compute_subject', aka methods
to add custom header and custom mail values.

Task-2710804 (Mail: Clean MailThread Posting API)
Prepares Task-2088884 (Mail: Use editable computed stored fields in compo

Part-of: odoo/odoo#99482
2023-01-17 20:58:38 +01:00
Thibault Delavallée 418761e344 [LINT] mail, various: use explicit subtype in message_post_{with_...}
RATIONALE

Purpose of this commit is to be explicit in subtype chosen when invoking the
message composer / calling message_post. As default value may not always be
clear, better be explicit in case the composer default value changes.

SPECIFICATIONS

Add explicit references to subtype when it is not obvious what will be the
final subtype, notably when using helpers (post_with_view or template which
uses the composer that is not crystal clear in its subtype management).

In this commit we also add support of XMLID-based subtype when invoking the
composer. A ``default_subtype_xmlid`` context key is transformed into a
``default_subtype_id``, to be used notably in JS where we cannot easily
use a ``ref``-like statement. Post API now also supports 'subytpe_xmlid'
argument allowing to give the xml id and ease calling the methods.

Use ``_xmlid_to_res_id`` to get directly the ID of subtypes in order to
avoid useless queries from ``ref`` that does an exists.

Also remove useless values given to post API, notably author_id that is by
default the current users' partner.

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:33 +01:00
Thibault Delavallée 1394903873 [IMP] test_mail: add tests for exclusion list and duplicates in composer
Purpose of this commit is to add tests for exclusion list and duplicates
management in composer.

When being in email mode (mass_mail) state of emails is pre-processed in
order to already flag emails that should not be sent or will bounce back.
Notably emails in exclusion list or duplicates emails are set as cancel
with the right failure type.

Some tests already exist at higher level in mass mailing but having tests
at composer level is better when trying to improve code and add tests for
corner cases.

Task-3132710 (Mail: Configurable composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:32 +01:00
Renaud Thiry f039f57eb8 [IMP] Add more detailed default email subjects from chatter
All emails sent from the chatter start with "Re:" followed
by the name of the record. The name of the record alone is sometimes not enough for
the followers to understand what the mail is about.
Additionally, "Re:" does not make sense when starting a conversation.

This commit gives better default subject
for event registrations and allows thread models
to override the default subject of messages.

This also removes "Re:" from default mail subjects.

Task-2833215

closes odoo/odoo#95817

Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
2023-01-05 15:36:53 +01:00
Thibault Delavallée 902cda0a1b [IMP] test_mail: add some tests on content translation
Purpose of this commit is to add tests on translations when using templates
and composer, on both email content (body, subject) and email layouting
content (view content, groups-based buttons, ...). This better highlights
some missing part of translation support, notably

  * when being in mass mode: as content is taken from the composer and rendered
    dynamically, it does not take the original translation from the template
    even if it matches template content exactly;
  * access button title is not translated as it is added during a separate
    part of the process;

We also improve tests for ``mail.composer.mixin``. The wizard used in test
(mail.test.composer.mixin) is improve to behave more like a real invite
wizard: it runs on records (mail.test.composer.source) which are records
on which dynamic content is rendered. This highlights one issue with
translations: translations are fetched on current model (aka: composer
body and subject fields). However when using templates, translations are
stored on template model (aka: mail.template). This will be improved soon
by trying to fetch template translations when composer content matches
content from template.

Task-3046371 (Mail: Improve language propagation in mail and layouting)

Part-of: odoo/odoo#106072
2022-11-21 19:55:13 +01:00
Thibault Delavallée 94208cb8b4 [IMP] test_mail: improve coverage of post helpers
Purpose of this commit is to add some test about MailThread helpers built on
top of ``message_post`` / ``composer`` (log, post with view, ...). Some tests
about batch are also added.

Some performance tests are also added for those helpers.

Counters are updated. Note that they did not change, it is just an update
based on current master counters.

Task-2710804 (MailThread Api Cleaning)

closes odoo/odoo#100184

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-09-14 23:38:05 +02:00
diagnoza cb07db6e41 [FIX] mail: allow tracking values not loaded into registry
Use dict.get() instead of a subscriptable call. This way we let through
selection values that are not loaded into the registry, instead
of raising an error.

This is especially useful in the upgrade environment
where such values may be unavailable (because of being
lambda-defined in a custom module for instance).

closes odoo/odoo#94530

X-original-commit: 36a6943740f9b4fbd9a78986bee4cd84bb8469c7
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-24 18:33:05 +02:00
Fabio Barbero dc66b7aec3 [IMP] mail, various: use overridden method in message_notify
Purpose
=======

In message_notify, when called on a recordset, call model methods instead of
base one defined on MailThread. This allows to use internal methods overrides.

Also perform some linting on calls to ``message_notify`` in order to better
spot calls, parameters, ...

Task-2852908

closes odoo/odoo#92868

Related: odoo/enterprise#28038
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-18 10:23:03 +02:00
Thibault Delavallée 4193b1ee64 [FW][IMP] test_mail: test gateway with multiple references
Purpose is to test behavior when having multiple references in mail headers.
We have to check that parent_id is correctly taken (as it impacts internal
flag), and that flattening is performance when posting the message (always
attaching to the thread first message being the default behavior).

Note that tests highlighted that flattening is currently a bit broken as it
does not go up until the first ancestor, which is the expected behavior for
business documents having ``_mail_flat_thread``. Next commit will fix that.

Task-2822652 (Mail: fix parent message fetch / flattening)
Task-2643114 (Mail: Message-Id in references to ease thread formation)

X-original-commit: f7d4f1d29213c71e76564c485db2bbecf0bbf37c
Part-of: odoo/odoo#89328
2022-04-22 12:04:33 +02:00
Thibault Delavallée bf508a808e [IMP] test_mail: add multicompany test models
PURPOSE

Purpose of this commit is to add a company field on test mail models used to
replicate ticket / project behavior (``mail.test.ticket`` and ``mail.test.
container``).

SPECIFICATIONS

To avoid messing with existing tests and ease comparison through all Odoo
versions (notably performance) this is done by adding new models inheriting
from current mail models. A company_id field is added as well as MC rules.

Those models will be used to add tests for mail thread behavior in a multi
company environment (aliases management, performance, emails and notification
layouts, ...).

In this commit we also update ACLs for ticket-like models to add rules for
portal users, based on followers. This mimics classic rules from Odoo used
notably in a light project-like environment. This allows to test a bit more
in details recipients, access tokens, links in emails, ...

Task-2673913 (TestMail: Cleanup and improve test coverage)

Part-of: odoo/odoo#86393
2022-03-24 13:57:35 +01:00
Thibault Delavallée c2fd9a4965 [IMP] (test_)mail: allow attachment propagation in all activity feedback methods
Activity-level feedback method accepts attachment_ids but not its mixin-level
counterpart. This commit fixes that by adding the parameter. The activity-level
action_feedback_schedule_next method now also accepts attachments in addition
to the feedback, making the API coherent through all entry points.

At activity level ``action_done`` now goes through ``action_feedback``. This
means it now has two main methods
  * ``action_feedback``;
  * ``action_feedback_schedule_next``;

All methods finally end up calling ``_action_done`` and correctly propagate
feedback and attachments. We have a bit less entry points with possible API
changes.

Test mail models are updated to be able to use this small addition.

Task-2710804 (Mail: Clean MailThread API)

Part-of: odoo/odoo#86393
2022-03-24 13:57:34 +01:00
tsm-odoo 1e828a14ec [IMP] mail: get closer from python model definition in test setup
*: hr, hr_holidays, im_livechat, mail, snailmail, test_mail, website_livechat,
website_slides.

This commit will remove the need to duplicate models definition for
test purposes. Indeed, for now, we need to mock the model definitions
on the client side. Those models definitions are often very different
from the ones found on the server.

This approach will allow us :
	- to ease model definitions during tests
	- to get closer from the real models

task-2767820

closes odoo/odoo#84828

Related: odoo/enterprise#24486
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-10 18:19:59 +00:00
Thibault Delavallée bc9943f188 [FIX] test_mail: re-add groups for notification, allowing bw tests
To ease comparisons for query counters let us try to keep the same test flow
through v15+. We therefore now also compute recipient groups for portal users
for some test models, like before odoo/odoo@faeb5e7fee .

Part-of: odoo/odoo#83832
2022-02-02 18:14:54 +00:00
Thibault Delavallée a62927e7e2 [REF] mail: improve recipients computation
Purpose of this commit is to improve notification recipients computation.

Code cleaning

  * make it batch enabled. Currently it works only for a single record. It
    should evolve towards real multi computation, allowing to prepare post
    and notification in batch;
  * better manage multi users. Now when several users are linked to the same
    partner, we try to find an internal user or fallback on share user. This
    is cleaned compared to a distinct done previously;
  * support recipients without subtype (pids + records) as a new case to
    include follower computation;

Improvements

  * include follower status if linked to records (is_follower can be used
    notably in link computation to redirect to the portal);
  * fetch partner lang directly in the SQL query. While fetching partner data
    let us add its lang. That way it will be easier to improve lang support
    in layouts;

Task-2739294 (Mail: Batch recipients fetch and improve its usage)

Part-of: odoo/odoo#82167
2022-01-31 17:47:34 +00:00
Thibault Delavallée 75979fccdf [REF] mail, *: improve 'pay now' notification template
* = sale, purchase

PURPOSE

Purpose of this commit is to improve the 'Pay Now' notification template
used notably when using the "Send by email" button on

  * invoices
  * sale orders
  * RFQ and purchase orders

SPECIFICATIONS

Global specifications

  * remove gray background that is around the white content (aka have an
    email with an uniform white background);
  * move button on top of email like other notification templates (top-left
    and company logo is top-right);
  * fix various small wording issues;
  * fix signature usage;

Technical specifications

Remove custom definition of access links and labels in 'Pay Now' notification
template (``mail_notification_paynow``). It is now done at model level through
the ``_notify_get_groups`` that is generic to notification emails. This allows
to remove QWeb override in purchase and sale notably. Displaying access links
is now controller by the ``has_button_access`` value. Model computes links,
access and labels while view only displays what is requested. That way any
template can use those values instead of being defined in a template subject
to user changes.

Sale / Purchase

Overrides of those modules is not necessary anymore since button labelling
and URLs are managed at model level.

Purchase "specific" buttons for Accept / Update dates are now email layout
actions, like used in other modules like HR or Project.

Continuation of odoo/odoo#76418 .

Task-2712450 (Mail/Sale: Improve 'Pay Now' notification template)

Part-of: odoo/odoo#82167
2022-01-31 17:47:33 +00:00
Thibault Delavallée 86db4f56c8 [IMP] (test_)mail: add tests for translation of notification layout
Purpose of this commit is to add tests for language-based tweaks of email
notification layouts and composer usage. Purpose is to assess current
behavior before going into some cleaning or refactoring. Notably

  * check layout content is translated;
  * check "view document" button is translated;
  * check action buttons are translated;
  * check content based on templates is translated;

This is currently mainly available through the "lang" context key being
correctly set. Partial support of translations when posting based on template
is tested (content and model description but not notification layout).
Failing support in mass mail mode is tested. Future improvements will be
done in order to improve language support.

Note that ``MailTemplate.send_mail()`` email sending method language support
is tested in ``test_mail_template`` file. Those tests are updated to share
a common base with new tests about language setup.

Task-2712450 (Mail/Sale: Improve 'Pay Now' notification template)

Part-of: odoo/odoo#82167
2022-01-31 17:47:30 +00:00
roen-odoo fef39f82ac [FIX] mail : Remove double signature on invoice email
Current behavior :
When sending an invoice by email there was 2 signature in the mail

Steps to reproduce :
Create an invoice
Send it by email
Check the mail, there are 2 signatures

opw-2703272

closes odoo/odoo#82347

X-original-commit: 00965df4be591b952b339038c324d7e92596e3d5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-01-06 19:30:53 +00:00
Nicolas Bayet 4813f42997 [IMP] mail,*: replace jinja with qweb
Jinja as a templating engine was problematic in differents respect:
- introduce external dependency to Odoo (less controll)
- add another templating mechanism in the stack
- specific feature in qweb cannot be reused
- difficulty in rendering easily editable templates
- more knowledge required with no betterment

By replacing jinja with qweb we can now build tools to edit a qweb
that will work with the previously jinja encoded document
(essentially `mail.template` records).

There is a catch however. Some email fields (eg. email_to) used jinja
syntax for rendering dynamic variables (ie. ${object.something} and
${object.something_that_should_not_be_escaped | safe}).

We still want user to use dynamic variables for some char fields (eg.
subject, from, to, ...). We made a new rendering engine called
"inline_template" that will render an expression enclosed by `{{` and
`}}`.

To be able to edit the templates from the backend interface, a
plugin to the Odoo editor has been made for seamlessly edit the
document.

This qweb plugin includes:
- make dynamic variables (eg. `<t t-out="variable"/>`) not editable
  (for preventing the user to shoot himself in the foot)
- group and hide related logical branching (ie. t-if, t-elif, and t-else)
  in order to see only one at once
- a floating select input to switch visibility of a particular logical
  branching

Task-27033

X-original-commit: odoo/odoo@68182baff4
Part-of: odoo/odoo#77377
2021-09-28 23:42:54 +00:00
Jairo LlopisandThibault Delavallee 1efeffd297 [FW][IMP] test_mail: test models with type do not mess with attachment types
Purpose of this commit is to highlight an issue that may happens easily with
`crm` that is made generic here within `test_mail`.

`crm` alters the context when creating a new record adding in this case
`default_type` to it][1]. The returned record contains that altered context.
his results in other records created from it trying to assign that same default
value for `type`. This is a very common name for fields, and happens to exist
in `ir.attachment` too.

If you create an alias for incoming leads in your DB with default values
`{"type": "lead"}` (something very common) and then an email comes to that
alias that contains an inlined base64 image, the attachment creation process
would simply fail.

Obtained error is ``ValueError: Wrong value for ir.attachment.type: 'lead'`` .

[1]: https://github.com/odoo/odoo/blob/272602193f5647f7f2270ed6ec68777625a139dd/addons/crm/models/crm_lead.py#L310-L311

X-original-commit: 99434b2e8528c10fcc9cb6860765e0ddcaa364c8
Part-of: odoo/odoo#77005
Co-authored-by: Thibault Delavallee <tde@odoo.com>
2021-09-22 19:25:55 +00:00
Thibault Delavallée bc7dbfea63 [IMP] test_mail: improve tests for template translations
Extract translations and preparation to setup of TestTemplate class. That
way those are usable in other tests.

Create a new model to test language computation. It holds both a string
and a partner field, allowing to test a bit jinja-based language computation.

Task-2643750

X-original-commit: 7896cbc4f2256122b5cf6c5506921398f2ebc931
Part-of: odoo/odoo#76458
2021-09-14 07:10:57 +00:00
Ivan YelizarievandNicolas Seinlet a88a912bd4 [FIX] mail: speed up read_progress_bar
This commit fixes the performance issue in getting statistics for
``activity_state`` (colored clock icon for overdue/today/planned) in
CRM.  The query has been tested for several years on a large database
(Odoo's own production database).

Performance test on 29 K crm.lead records (activity_state):

With a filter for 10 records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |     25 |     5 |
| query time, ms     |     12 |    95 | (*)
| remaining time, ms |     32 |     7 |
```

All records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |   1326 |     5 |
| query time, ms     |   1739 |   129 |
| remaining time, ms |  47934 |    17 |
```

As we can see in the last results, the time went from almost 50 seconds
(not responsive at all) to 150 milliseconds (responsive).  The time
increase in (*) may be caused by imperfect measurements, which are raw
and not averaged measures.

---

opw-2346901
task-1915411

X-original-commit: 1088e73c9a897902f9d2d70df980fe2a5ed23492
Co-authored-by: Nicolas Seinlet <nse@odoo.com>
2021-07-16 11:16:34 +00:00
Thibault Delavallée 69dfaf4ca5 [IMP] mail: experimentally support QWeb rendering
Purpose of this commit is to prepare ground for future improvements by already
supporting QWeb rendering in ``mail.render.mixin``.

We temporarily support new field parameters allowing to tune the rendering
directly from field. Notaby choosing engine (jinja or qweb) can be done
from field directly. This is considered as experimental, used mainly to
prepare QWeb support.

Task ID-2534550 (Template usage improvement)
Task ID-2477164 (Composer mixin)
Prepares Task ID-27033 (QWeb in templates)
COM PR odoo/odoo#70889
ENT PR odoo/enterprise#18352
2021-06-01 09:24:26 +00:00
Stéphane DebaucheandThibault Delavallée b19fe6dea5 [IMP] mail: introduce a composer mixin for invite / send email wizards
This commits introduces a new mixin ``mail.composer.mixin`` used when sending
emails or notifications based on a mail template.

Main current purpose is to hide details related to subject and body computation
and rendering based on a mail.template. It also give the base tools to control
who is allowed to edit body, notably when dealing with templating language
like jinja or qweb.

It is meant to evolve in a near future with upcoming support of qweb and fine
grain control of rendering access.

Task ID-2534550 (Template usage improvement)
Task ID-2477164 (Composer mixin)
COM PR odoo/odoo#70889
ENT PR odoo/enterprise#18352

Co-Authored-By: Stéphane Debauche <std@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
2021-06-01 09:06:07 +00:00
Jérémy Hennecart 3a398dc9d9 [IMP] mail: improve monetary tracking field
Add the currency symbol for the monetary tracking field to better
represent the change of a monetary field.
The currency will be fetch from the currency defined in the
monetary field or on the record's company in case there is not.

For example, if we have a record with a monetary field displaying
"$ 500". If we modify the currency and the value to have "450 €",
the message containing the tracking values will display:
"500 € -> 450 €".

We only use one field to track the currency of a monetary field.
Indeed, in the case where the currency is changed with the value
of a monetary field, only the new currency is tracked. We focus
on the fact that the more important thing is the new value.

Furthermore, when modifying a currency of a monetary field, the
user can already see the new currency before saving the changes.
This allows him to adapt the value of the field if he needs it.
(N.B. we assume that this case will happen very rarely)

Using only one field takes also into account that there are
millions of record for this model and adding a new field would
take a lot of memory.

odoo/odoo#61999
odoo/upgrade#2060
task-2387268
2021-02-01 16:19:30 +00:00
Thibault Delavallée 7c3a0daaa1 [REF] test_mail: sun is shining, no more umbrellas
PURPOSE

Have a cleaner test_mail addons

SPECIFICATIONS

Umbrella -> Container, easier to understand that we target a ticket / project
like model using mail.test.ticket and mail.test.container .

LINKS

Prepares Task ID 2238597 (clean notification models)
Prepares Task ID 2083854 (improve mass mailing technical flows)
PR #49891
2020-04-22 08:40:03 +00:00
Thibault Delavallée ba068ee728 [REF] test_mail: rename test models to ease understanding
PURPOSE

Have a cleaner test_mail addons

SPECIFICATIONS

Keep only mail-related tests, move odoobot in test mail full, send "update
notification" tests in mail (specific to mail). Merge some test files to
lessen number of files, perform light file renaming.

Split test mail models file to prepare some cleaning in those models and tests.

LINKS

Prepares Task ID 2238597 (clean notification models)
Prepares Task ID 2083854 (improve mass mailing technical flows)
PR #49891
2020-04-22 08:39:46 +00:00
Thibault Delavallée 6e347b196d [MOV] (test_)mail(_full): redispatch some tests and split test mail models file
PURPOSE

Have a cleaner test_mail addons

SPECIFICATIONS

Keep only mail-related tests, move odoobot in test mail full, send "update
notification" tests in mail (specific to mail). Merge some test files to
lessen number of files, perform light file renaming.

Split test mail models file to prepare some cleaning in those models and tests.

LINKS

Prepares Task ID 2238597 (clean notification models)
Prepares Task ID 2083854 (improve mass mailing technical flows)
PR #49891
2020-04-22 08:00:29 +00:00
Thibault DelavalléeandRémy Voet 7cfd364db5 [REF] mail, various: clean usage of mail alias
Clean the usage of mail aliases and more specifically its associated mixin
`mail.alias.mixin` .

Stop using context for model of aliases, and correctly give model_id and
parent_model_id to the call chain through a cleaned code easier to override.

We also merge methods get_alias_model_name and get_alias_values in single one
called before record creation (alias first values) and right after (to have
values depending on actual record).

LINKS

Task ID 1919277
Community PR odoo/odoo#41160
Enterprise PR odoo/enterprise#6983
Upgrade PR odoo/upgrade#872

Co-Authored-By: Rémy Voet <ryv@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
2020-04-17 06:51:46 +00:00
Raphael Collet 020e2a5e85 [IMP] mail: add tracking on computed stored fields
Also delay the tracking until pre-commit, so that several updates on a
record generate a single tracking message.
2020-02-05 15:14:58 +00:00
Kevin Baptiste 2c6cd81f30 [IMP] mail: track fields based on ir_model_fields
The tracked field is now a relation to the corresponding ir.model.field.
This prevents potential privacy issues should the field be deleted or renamed.

closes odoo/odoo#39232

Taskid: 2088634
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-11-19 07:50:34 +00:00
Martin Trigaux 35a9150d79 [FIX] *: add missing model description
Some models did not specified a _description
2019-09-24 07:33:09 +00:00
Yannick Tivisse 1cdbeeca55 [IMP] test_mail: Add multi company test from _redirect_to_record 2019-05-29 08:33:18 +00:00
Thibault Delavallée dbd4aab6c3 [REF] mail: make blacklist a mixin built upon mail.thread and add message_bounce
* mail.blacklist.mixin now clearly make inheritance on mail.thread. Indeed
    we consider models using the blacklist mechanism as being used in mailing
    features, meaning they will anyway inherit form mail.thread. In standard
    Odoo it is the case for the 3 models using it (Lead/Opportunity, Contact
    and Mailing Contact);
  * define message_bounce directly in mail.blacklist.mixin. Bounce counter
    is indeed linked to the blacklist and mailing mechanism;
  * rename mail.blacklist.mixin to mail.thread.blacklist to ensure coherency
    with mail.thread and mail.thread.cc (another mixin build on mailL.thread);

Inherit declarations in various addons are updated accordingly.

Related to task ID 1911679
Linked to PR #29483
2019-05-13 15:18:40 +00:00
Thibault Delavallée e87189222d [IMP] test_mail: add tests for mail gateway and perform light cleaning
This commit add some tests related to the mail gateway: more bounce management
tests and some additional thread formation tests. Some test asserts about
bounce / blacklist management are commented as they are not completely working
currently. This will be improved in master soon.

Some cleaning in also done in all mail gateway tests. Notably some call to
tool methods are cleaned / simplified, duplicate tests are removed. Some
low-level checks are removed.

A new test model is added for mail gateway: mail.test.gateway. It is a
chatter model with blacklist enabled on it. It allows to tests the
various blacklist-related overrides and features as well as all basic
mail gateway features.

Sub-part of task 1853147 (pre-cleaning before implementing mail gateway
improvements)
Linked to PR #32974
2019-04-26 10:28:09 +00:00
XavierDo 92e9e84b63 [IMP] mail, *: don't track fields at create
*: project, crm, maintenance, helpdesk,

It is useless to track fields during create since they
have no initial value and future tracking message will
show changes on tracked field.

We can log a default creation message instead
(as it is now if there is no mail_create_nolog context key)

This change will implies
- less queries when creating record
- cleaner creation messages
- less occurence of mail_create_nolog ctx key

Removing tracking at create could break the creation subtypes
mechanism (example: following task creation subtype on project)
Instead of using _track_subtype to give a subtype at create,
a new _creation_subtype method can be override. If a creation
subtype is set on a specific modlel, creation messages will be
create by message_post instead of _message_log.

We also need to adapt the message_track_post_template in order to
keep this feature whithout tracking.

Task: #1916916

closes odoo/odoo#31945

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-03-29 15:28:43 +00:00