Commit Graph
639 Commits
Author SHA1 Message Date
std-odoo dab3d0a282 [FIX] mail: revert the unlink in batch of the <mail.mail>
Bug
===
The unlink of the <mail.mail> in the CRON is problematic because we
accumulate a lot of records, and the CRON timeout.

In particular, when we sent a mailing, we receive the "opened" event
(blank image in the email), and so we need to update the mailing trace.
But, if we unlink the mail at the same time, it locked the mailing trace
table and we couldn't write the new value.

The reason for that is that before, the unlink took more queries, but
it was done one record at a time, so we could commit the change and
release the lock between each unlink.

Task-3179157
See odoo/odoo/pull/73271

closes odoo/odoo#112703

X-original-commit: 57ae1b9b8b61f5f4719a8a81e9d0d21fab58cfda
Related: odoo/enterprise#37069
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
2023-02-15 10:14:53 +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 8a66cc7db0 [IMP] mail: display scheduled_datetime of delayed notify in chatter
Followup of odoo/odoo#95623 (introduce scheduled message notification) as well
as odoo/odoo#99482 (support scheduled datetime from template to composer in
both comment and mailing modes).

Task-3093257 (Mail: The Composer Update)

Part-of: odoo/odoo#107356
2023-01-27 19:56:09 +01:00
Thibault Delavallée 6218d84f04 [IMP] various: update query counters
Update query counters now that fields are editable computed fields. Some
counters are higher as the usage of composer in code is now closer to the
usage in view, with fields being correctly computed. Some other counters
are a bit lessened, but it globally stays the same.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:08 +01:00
Thibault Delavallée 300ae603d1 [REF] mail: remove composer onchange, now unnecessary
PURPOSE

Purpose of this task is to remove the _onchange_template_id method on composer
model. Split it into editable computed stored fields. It gives a better control
of value generation and avoid having to call the onchange when composer is
invoked in code.

SPECIFICATIONS

Remove onchange as it is not used anymore. All fields have been converted.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:08 +01:00
Thibault Delavallée 29f14327cd [REF] mail: move composer 'subtype_id' field to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute field ``subtype_id`` in compute method.

It is currently always set to be a 'comment' subtype. However in mass mailing
mode it is not used, as we do not use the value. Better void it directly.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:07 +01:00
Thibault Delavallée bfc583fcf3 [REF] mail: move composer 'attachment_ids' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute fields ``attachment_ids`` and reports
(``report_template_ids`` on template that generates reports) in compute method.

Computation is based on template and composition mode. In monorecord comment
mode, template is used to generate attachments based on both attachment_ids
of template, and reports coming from report_template_ids. Those are generated
based on the current record to display. As template generation returns a list
of tuples, new attachments are created on the fly during the compute.

In batch or email mode, only attachment_ids from template are used on the
composer. Reports will be generated at sending time.

When template is removed, attachments are reset.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:07 +01:00
Thibault Delavallée 6a78ed2cad [REF] mail: move composer 'partner_ids' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute fields ``partner_ids`` in compute
method.

Computation is coming either from template, either from context. When having
a template it uses its 3 fields 'email_cc', 'email_to' and 'partner_to' in
monorecord comment mode. Emails are converted into partners, creating new
ones when the email does not match any existing partner. Composer does not
deal with emails but only with partners.

When having a template in other modes, no recipients are computed as it is
done at sending time. When removing the template, reset it.

When not having a template, recipients may come from the parent in comment
mode, to be sure to notify the same people.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:07 +01:00
Thibault Delavallée c656703874 [REF] mail: move composer 'scheduled_date' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute fields ``scheduled_date`` in compute
method.

Scheduled_date computation is coming either from template, either reset. When
having a template with a value set, copy it (in batch mode) or render it (in
monorecord comment mode) on the composer. When removing the template, reset it.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:06 +01:00
Thibault Delavallée 05f45043da [REF] mail: move composer 'mail_server_id' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute field ``mail_server_id`` in compute
method. Copy value from template when updating it, if set on template. When
removing the template, reset it.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:06 +01:00
Thibault Delavallée 5cfe750a83 [REF] mail: move composer 'body' and 'subject' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute fields ``body`` and ``subject`` in
compute methods.

Subject computation is coming either form template, either from context.
When having a template with a value set, copy it (in batch mode) or render
it (in monorecord comment mode) on the composer. Otherwise it comes from
the parent (if set), or computed based on the generic '_message_compute_
subject' method in monorecord comment mode, or set to False. When removing
the template, reset it.

Body computation is coming either from template, either reset. When having
a template with a value set, copy it (in batch mode) or render it (in
monorecord comment mode) on the composer. When removing the template, reset it.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:06 +01:00
Thibault Delavallée 2436ddf141 [REF] mail: move composer 'reply_to_*' fields from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONSS

Improve composer to correctly compute fields ``reply_to(_force_new)`` in
compute methods.

Reply_to computation is coming either from template, either reset. When having
a template with a value set, copy it (in batch mode) or render it (in
monorecord comment mode) on the composer. When removing the template reset it.

Reply_to_force_new computation depends on model. If it does not inherit from
MailThread, avoid replies to be considered as thread updates, they will instead
follow the routing rules (alias, ...).

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:05 +01:00
Thibault Delavallée 4924df5743 [REF] mail: move composer 'author_id' / 'email_from' fields from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute fields ``email_from`` and ``author_id``
in compute methods.

Email_from computation is coming either from template, either from context.
When having a template with a value set, copy it (in batch mode) or render it
(in monorecord comment mode) on the composer. Otherwise try to take current
user's email. When removing the template, fallback on default thread behavior
(which is current user's email).

Author computation is not controllable from the template currently. We therefore
try to synchronize it with the given email_from (in rendered mode to avoid
trying to find partner based on qweb expressions), or fallback on current user.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:05 +01:00
Thibault Delavallée 7ee2e2d5d3 [REF] mail: move composer 'auto_delete_*' fields from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute field ``auto_delete(_keep_log)`` in
compute methods.

For auto_delete, computation is coming either from template, either from
composition mode. When having a template, its value copied. Without template
it is True in comment mode to remove notification emails by default. In email
mode we keep emails (backward compatibility mode).

For auto_delete_keep_log, it is used only in email mode. It is used to keep
the core message when unlinking sent emails. It allows to keep the message as
a trace in the record's chatter. In other modes it has no use and can be set
to False. When auto_delete is turned off it has no usage.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:05 +01:00
Thibault Delavallée c349e8d929 [REF] mail: move composer 'record_name' field from onchange to computed
RATIONALE

Remove _onchange_template_id / defaults usage for composer fields. It
lacks control and make value computation hard to understand and predict.

PURPOSE

Split _onchange_template_id + default_get + get_record_data usage into editable
computed stored fields. Each field should have its own method with its triggers
(template, composition mode, ...).

SPECIFICATIONS

Improve composer to correctly compute field ``record_name`` in compute method.
Computation is coming either from parent message, either from the record's
display name in monorecord comment mode. In batch mode it makes no sense to
compute a single record name. In email mode it is not used anyway.

Computing it in composer allows to benefit from its computation to give it to
the message created afterwards during message_post.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:04 +01:00
Thibault Delavallée b7d23e981b [FIX] mail: better support using composer on no thread record
When using the mail composer in comment mode on models that do not inherit
from mail.thread, the post is transformed into notification process. Instead
of calling 'message_post' on the records (which would crash) 'message_notify'
is called, using MailThread as abstract class (which creates notifications
without having to inherit from mail.thread).

However some parameters from the composer are not supported when calling
'message_notify'. This commit fixes it and adds tests accordingly.

Followup of odoo/odoo#99482

Task-2710804 (Mail: Clean MailThread API)

Part-of: odoo/odoo#107356
2023-01-27 19:56:04 +01:00
Thibault Delavallée 8fb59b55d9 [IMP] mail: improve 'real author' detection when posting a message
When posting a message, author is added in followers in order to receive
answers. They also do not receive its own messages, to avoid being notified
of something they just posted.

However the real author is not always the message author. In this commit
we better define this author
  * when current user is active, real author is the current user. It means
    posting on behalf of someone will send answers to you, not to the
    spoofed partner;
  * when current user is inactive, real author is the message author. An
    inactive current user means the post was probably done as sudo, aka
    in the mailgateway or frontend. In that case we don't want to add
    odoobot in followers, but the actual message author;

Task-3093257 (Mail: The Composer Update)

Part-of: odoo/odoo#107356
2023-01-27 19:56:03 +01:00
Thibault Delavallée 17e6cd1e14 [IMP] mail: add a notification parameter to allow notifying the author
Currently notification process called notably by message_{post,notify} does
not notify message's author by default. Rationale is that as he typed the
message he is already aware of it.

However in some cases we want to skip this step, notably when messages are
generated in the name of the author and when we want him to be notified if
he should.

This is currently controllable through a context key 'mail_notify_author'.
In this commit we add an explicit parameter propagated through the notify
process, allowing to remove some context key usage and instead use real
parameters.

Note that all context keys usage cannot be removed as it is not always
possible to propagate this parameter.

Followup of odoo#99482

Task-2710804 (Mail: Clean MailThread API)

Part-of: odoo/odoo#107356
2023-01-27 19:56:03 +01:00
Thibault Delavallée 5b8f9341a1 [IMP] test_mail: remove __system__ performance tests
Replace them by admin, which should globally be the same as employee. Testing
with system is a remaining of old times, when bichons were running freely in
the court.

Task-3093257 (Mail: The Composer Update)

Part-of: odoo/odoo#107356
2023-01-27 19:56:03 +01:00
Thibault Delavallée 2c87910f2c [IMP] test_mail: add some additional asserts about authorship
As this matter is a bit complicated due to synchronization / desynchronization
of author and email, some asserts are added to help understanding the changes.
To ease converting field into an editable stored field, some additional
checks are added in tests to ease debugging and avoid regressions.

Task-2088884 (Mail: Use editable computed stored fields in composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:02 +01:00
Thibault Delavallée 587555d558 [IMP] test_mail: add composer tests for res_domain usage
Purpose of this commit is to add some tests about 'res_domain' usage in
the composer. As it takes over 'res_ids' when being set, being sure all
use cases are covered is better, especially in batch comment mode that
has been recently added.

Followup of odoo/odoo#99482

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#107356
2023-01-27 19:56:02 +01:00
Thibault Delavallée 74b59bab26 [FIX] mail: improve 'subtype_is_log' composer computation
As subtype has no usage in mail mode, let us consider subtype_is_log as being
True in mail mode, as it eases display of buttons. This is its main usage
aka display "Log" instead of "Send" on composer. In mail mode it should
always be send.

Followup of odoo/odoo#99482

Task-2710804 (Mail: Clean MailThread API)

Part-of: odoo/odoo#107356
2023-01-27 19:56:01 +01:00
Rémy Voet (ryv) 5a870462e0 [REM] base: remove _patch_method and _revert_method
There is only one legitimate usage of `_patch_method` (base_automation)
and none of `_revert_method`. The other uses are in tests and they are
all wrong: if the test crashes between the `_patch_method` and the
`_revert_method`, the method will not be reverted.

For the only proper usage of `_patch_method`, move the code to this
place. Correct tests using `_patch_method`/`_revert_method` by calling
the `patch` method of `BaseCase`.

Also, remove the `api.returns` from the `create` method of `BaseModel`
as it is useless and confusing. In fact, we never use it because we
have a special treatment at the RPC level for the `create` method
(see `_call_kw_model_create`).

closes odoo/odoo#110370

Signed-off-by: Raphael Collet <rco@odoo.com>
2023-01-25 16:36:53 +01:00
Julien CastiauxandBaptiste Vergote 37ca7770a6 [FIX] mail: bad CTE/QP decoding of rfc822-headers
Based on RFC3462, a Content-Type text/rfc822-headers
exists and provide a mechanism to label and return
only the RFC 822 headers of a failed message (bounce)

These are only the headers and not the full message.

The Content-Type-Encoding should be either 7-bit(US-ASCII)
or Quoted-Printable (QP) as in the section 2 of the RFC.

Spawn the error:
After getting reported by a customer, I had to reproduce
by spamming wrong outlook addresses and add logging
in a sh database on the message_process of mail_thread.py
and logged the `message` variable.

After few retry, I got one of the part that was defined
as followed:
Content-Description: Undelivered Message Headers
Content-Type: text/rfc822-headers
Content-Transfer-Encoding: quoted-printable

The `get_payload()`function used was only assuming
that there is a full email on that part and that
it could only be encoded as an email, which was not
the case in this situation (quoted-printable:
76 characters per line, character `=` used
as the end of line character).

opw-3064589
task-3131561

closes odoo/odoo#110901

X-original-commit: f86f4b671696178f8fa42b81d8753d2591578431
Signed-off-by: Julien Castiaux <juc@odoo.com>
Co-authored-by: Baptiste Vergote <bve@odoo.com>
2023-01-24 23:21:57 +01:00
Romain Estievenart a10967214b [FIX] mail, test_mail: h-scroll broken on small screen
This commit add the missing `o_action_delegate_scroll` on the activity
view controller on small screen device to scroll the activity view
content only instead of the whole controller (i.e. control panel
included).

Steps to reproduce:

1. Open Project on small screen device like a smartphone
2. Open a Project like 'Office Design'
3. Switch to the Activity view and try to scroll horizontally
 => The whole activity controller currently scroll => bug

closes odoo/odoo#110531

X-original-commit: e4d6a8ad14abee72d61fd01d8b601acc6bfa2c49
Signed-off-by: Pierre Paridans (app) <app@odoo.com>
Signed-off-by: Romain Estievenart (res) <res@odoo.com>
2023-01-20 21:56:48 +01:00
Thibault Delavallée 0039c326f4 [FIX] test_mail, various: update query counters
Update counters now that all changes in this PR are validated.

Main observations

  * batch mode is improved: few tests effectively run on a real batch of
    records but in those use cases there are more gains due to better batch
    management of values rendering and recipients management;
  * posting using a view does not call the composer anymore in all situations
    allowing to gain a lot of queries by not creating a composer and calling
    a dummy onchange on it;
  * various small gains in various tests, notably linked to usage of low-level
    reference fetch and various small code tweaks;

Task-2710804 (Mail: Clean MailThread API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:42 +01:00
Thibault Delavallée c298e1309d [REF] mail: allow to control composer exclusion list usage
Currently when using the composer excluded emails are computed when the target
model inherits from the blacklist mixin. This behavior can now be deactivated
through a new field 'use_exclusion_list', like what has been done in SMS
composer.

Task-3132710 (Mail: Configurable composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:42 +01:00
Thibault Delavallée 360d9ce201 [REF] mail: add 'force_send' field on composer to control email queue usage
Currently when using the composer to create a mass mailing emails are sent
directly, unless scheduled date is in the future.

With this commit it is now controllable through a field like what has been
done on SMS composer. Its default behavior is the same as before

  * posting on a monorecord: force send notification emails;
  * posting on multirecords: use the queue (force_send=False parameter given
    to message_post and propagated to _notify_thread);
  * mass mailing: use force send to send emails directly;

Usage of mail_notify_force_send context key is also removed when possible
as it is a standard parameter of posting API.

Task-3132710 (Mail: Configurable composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:41 +01:00
Thibault Delavallée 35762204a6 [REF] mail: better use and update 'auto_delete' composer field
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Correctly update 'auto_delete' field

  * add missing update in onchange, to either take value from template, either
    fallback on default_get values as other fields;
  * in comment mode, actual value for 'auto_delete' is True by default. Composer
    value was not used and bypassed by a context value being True by default.
    Context key support is removed, correctly replaced by the composer field
    value itself;

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:41 +01:00
Thibault Delavallée 9140ce06c3 [REF] mail: better define 'keep log' fields of composer
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Change 'auto_delete_message' into 'auto_delete_keep_log' that has the inverse
meaning. Indeed it is unclear what 'auto_delete_message' really does. It is
used when automatically removing emails sent through mass mailing, to know
if message created through inherits are kept or not. Purpose of keeping them
is to have a log on the document. Deleting the message therefore removes the
log.

In this commit we change the meaning to something positive, keeping logs being
clearer when choosing which option to activate. Functional usage of the field
itself does not change with this commit.

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:41 +01:00
Thibault Delavallée 629ba0c392 [REF] mail: replace 'is_log' on composer by posting a note
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Remove 'is_log' field on mail composer. Indeed its usage can be globally
replaced by using the 'note' subtype when posting. It is now better matching
the result of using the log a note mode of chatter.

Posting with a False subtype_id already automatically converts it into a
note subtype in 'message_post'. It is now done directly at composer level
to lessen magic and have more control on final output.

In case of outgoing emails subtype has no usage, as notification process is
not called. It is therefore forced to False when creating the mail records.

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:40 +01:00
Thibault Delavallée 28b4ba4049 [IMP] mail, various: allow to link multiple reports to templates
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Update report_template field on template model to be a many2many field instead
of a many2one. It allows to attach multiple dynamic reports to a given template
instead of being limited to a single one.

Name should now come from the report itself, which should be considered as
complete by itself. Template cannot override report naming anymore.

Task-2868153 (Mail: Allow multi reports in mail templates)

Part-of: odoo/odoo#99482
2023-01-17 20:58:40 +01:00
Thibault Delavallée fbcc1bf4c0 [IMP] mail: support 'scheduled_date' from template on composer
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Purpose of this task is to correctly support scheduled_date from template on
both comment and mass mode in the composer.

It is currently mainly supported at template level, when using a template
to directly send emails. In this commit we add a field on composer that
takes the value from the template, and propagate it to the mail or messages
created when validating it.

As most template fields it can contain inline template code to be rendered
dynamically on target records, hence using a char field. Its rendering
is done using template that calls _parse_scheduled_datetime. It allows
to have an UTC and timezone agnostic value.

SCHEDULED_DATE SUPPORT

When posting a comment, scheduled posts uses the 'mail.message.schedule'
mechanism that creates the message but send notifications later.

When sending a mailing, emails have a scheduled_date set. As the 'send'
method does not check for scheduled_date (only the cron queue) we have
to filter emails scheduled in the future before calling the 'send'
method.

Task-2993872 (Mail: Support scheduled date in all composer flows)

Part-of: odoo/odoo#99482
2023-01-17 20:58:40 +01:00
Thibault Delavallée 1a1acabd7b [REF] mail: cleanup mono/multi record composer behavior
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Support a real res_ids field on mail.compose.message model. Instead of relying
on active_ids from context, store it once for all at composer level and use
it in code. Active_ids usage is still done at default_get level, using it to
populate the field.

Improve usage of domain, renamed to res_domain to match other document related
fields naming. Add support of a res_domain_user_id field allowing to set the
user from which the domain should be evaluated.

Composer now runs on a list of IDs. Mass mail mode and comment mode are now
distinct from running on a singleton or on more records. Rendered or raw
mode is not triggered by

  * mass mailing mode: always display raw mode, whatever the number of records;
  * comment mode: display rendered mode when having a single record (like the
    previous comment mode). Display raw mode when having either no records
    either at least two records.

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:39 +01:00
Thibault Delavallée 5b332e2d28 [REF] mail: cleanup context usage in composer
Purpose of this commit is to cleanup context usage in composer

  * remove now dead 'custom_layout' context keys that was present mainly for
    compatibility until Odoo v15. You should now correctly use default value
    for 'email_layout_xmlid' field like every field;
  * remove 'mail_auto_delete' context key, not used anywhere in codebase.
    Auto-delete field of composer will be improved soon so that setting it
    as every field will replace the context usage;
  * remove usage of self._context, to use self.env.context;

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:38 +01:00
Thibault Delavallée df6171ac38 [REF] mail: rewrite values generation in composer
Purpose is to rewrite value generation as code is messy with a lot of dict
updates, rewriting key on top of existing keys until reaching the final value.

In this commit we better split computation, to have computation that is static
(currently, posting a comment as composer holds final code) separated from
dynamic computation (posting a mass mailing, as rendering is done based on
qweb or inline template value).

It allows to better understand how composer and template fields are used when
sending emails or posting messages. This commit should not change anything
functionally, even if some values are weirdly computed. Future commits will
improve support of composer / template fields, notably through computed field
and less cross computation.

Also split sending methods: do a mailing in batch in case of mass mailing
(allowing commit per batch), and simply loop on records to post a message
in case of comment (or mass post).

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

Part-of: odoo/odoo#99482
2023-01-17 20:58:38 +01:00
Thibault Delavallée 09a1647c64 [REF] mail: improve composer call to template values generation
Now that template generation methods have been cleaned we can cleanup calls
done in composer. We notably

  * make methods private, improve their naming and docstrings;
  * better support input / output of asked fields;
  * be more coherent with composer fields and template fields usage;

Task-2710804 (Mail: Clean MailThread Posting API)
Prepares Task-2088884 (Mail: Composer Onchange to Editable Computed Stored)

Part-of: odoo/odoo#99482
2023-01-17 20:58:38 +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 9bbb276c42 [REF] mail: cleanup message_{notify, log} wrappers
RATIONALE

Purpose of this commit is to cleanup main post helpers and have a more easy
and understandable way of calling them.

SPECIFICATIONS

Update methods parameters to look more like 'message_post' definition. Add
docstrings to explain parameter usage. Cleanup some parameter we do not
want. Add a api.returns on message_notify to wrap the value in case of external
call, as this method is public, like message_post.

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:35 +01:00
Thibault Delavallée 4775bd93a2 [REF] mail: cleanup post with {view, template} wrappers
RATIONALE

Purpose of this commit is to cleanup main post helpers and have a more easy
and understandable way of calling them.

SUMMARY

We now have two main API methods, based on business flow: either posting
on documents, either sending a mass mailing. Indeed those two flows are
different

  * post: create message, then launch notification process by taking into
    account subtype, followers, ...
  * mail: create mails in batch with recipients being based on template or
    given partners. No notifications is involved, only maybe traces if a
    mass mailing is linked

Delegate QWeb rendering to the render mixin (i.e. _render_template_qweb_view)
in order to have a single point to forge evaluation context and re-use
existing rendering code.

SPECIFICATIONS

Main API helpers are now

  * ``message_post_with_source``: (batch) post on records, using an ir.ui.view
    (given a record or its xml id) or a mail.template record (given a record or
    its xml id). When using a template, a composer is called to post on each
    record (as batch post is not yet supported). When using a view, a direct
    call to message_post using the rendered bodies is done, one record at a
    time.
  * ``message_mail_with_source``: send a mass mailing on records, acting like
    invoking the mail composer in mass mode. Same arguments are valid, either
    a reference to a view, either a reference to a mail template.

Other helpers are

  * ``_message_log_with_view``: (batch) log on records, using an ir.ui.view
    to render the body using QWeb (no notification process);
  * ``_message_log(_batch)``: (batch) log on records (no notification process);
  * ``message_notify``: notify partners on records (creating notifications
    specifically for some people while message itself is not displayed in
    chatter);

Code migration

  * ``message_post_with_template`` in "mass mode": use ``message_mail_with_source``
    and set the template record as source;
  * ``message_post_with_template`` in "comment" mode: use ``message_post_with_source``
    and set the template record as source;
  * ``message_post_with_view``: its main usage was to post on a document, in which
    case it generally can be replaced by ``message_mail_with_source`` using
    the view reference as source;

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:34 +01:00
Thibault Delavallée 2175bde607 [IMP] mail: add sanity checks for message_post and its helpers
Purpose of this commit is to clearly check input of ``message_post`` method
and its main helpers in order to prevent wrong usage of message post API.

Some values used to populate message fields should not be set directly when
posting or logging messages. Indeed they may be part of other process (like
notification process managed by ``_notify_thread``, or could be setup by
custom routes like 'reaction_ids', or custom usage of 'model' and 'res_id'
that could conflicts with record on which methods are called).

We therefore add checks and cleanup in those methods to be sure the API
is used as intended and avoid unwanted side effects.

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:34 +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 d6aa0050da [FIX] mail: stop spamming CCs of outgoing emails
Fix usage of CCs when sending emails. Currently CCs are added to all outgoing
emails, which leads to unnecessary spam. Recipients are currently computed like

  * create an outgoing email based on 'email_to';
  * create one outgoing email / partner in 'recipient_ids';
  * add CCs to all outgoing emails;

They are now sent only once, either with the email_to if given, either as
standalone. That way partners receive specific emails (due to tracking and
partner specific links management), email_to / email_cc are sent on their own.

Task-3093268 (Mail: Stop spamming CCs)
Prepares Task-2684479 (Mail: Better report errors when sending emails)

Part-of: odoo/odoo#99482
2023-01-17 20:58:33 +01:00
Thibault Delavallée 91672b1cab [IMP] mail: log a warning when having invalid headers on mail.mail
In this commit we add some logs when we fail to evaluate the 'headers' field
on a 'mail.mail' record, used to populate the headers of outgoing emails.

Some tests are added to ensure we do not crash if headers is malformed, and
to cover the feature itself as it was still not really done.

Task-2710804 (Mail: Clean MailThread Posting API)
Task-3093268 (Mail: Stop spamming CCs)
Prepares Task-2684479 (Mail: Better report errors when sending emails)

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
Thibault Delavallée c98f259736 [IMP] mail: improve tests tooling methods
In this commit we add a method to check MailMail, based on a given record.
When having duplicates to differentiate in a given mailing, having just
recipients is not sufficient as multiple emails may match a given recipients
list. Checking model / res_id is another method for finding emails.

This will be used notably to add tests for exclusion list and duplicates
management in standard mail composer, outside of mass mailing context.

While being at it, use subTests when having loops checking values. That
way it is easier to fix tests that have several failing values in the same
global assertMailMail_* .

Task-3132710 (Mail: Configurable composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:31 +01:00
Thibault Delavallée 0fcd089a3d [IMP] test_mail: improve composer tests, yet again
Some additional changes in mail composer tests before going into some rewriting
and improvements

  * some improved messages in asserts;
  * additional tests for attachments in mass mailing mode, using sub tests;
  * additional tests for configuration (auto_delete_* fields, email fields,
    subtype, ...);
  * removed some wrong tests not failing due to current code: when testing
    template values, do not give a creation value at the same time as it
    will fail when moving to editable stored fields;

Task-2710804 (Mail: Clean MailThread Posting API)

closes odoo/odoo#109522

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-01-10 14:40:59 +01:00
Thibault DelavalléeandRobin Engels a45afdd830 [IMP] mail: add tests for private partners in composer
Add tests showing current behavior of partner_ids fields on composer when
dealing with private partners. Some use cases are added as unit tests

  * default_partner_ids: coming notably from suggested recipients;
  * template usage adding a partner (e.g. partner_to);
  * when not having the rights to see private partners, access error should
    be raised;
  * mail gateway when a private partner sends an email;

X-original-commit: 2153eec790b730761fe50d6bea5cd4bacedce97a
Part-of: odoo/odoo#109522
Co-authored-by: Robin Engels <roen@odoo.com>
2023-01-10 14:40:58 +01:00
fdardenne e602a55503 [FIX] mail: activity view: luxon in rendering context
Since the refactoring of the activity view, luxon is not in the
rendering context. Resulting in crashing in some activity views
that used luxon in their template.

- Go to Appraisal
- Switch to the activity view
- Create a record in this view -> crash

Now, luxon is in the rendering context.

closes odoo/odoo#109153

Signed-off-by: Luca Vitali <luvi@odoo.com>
2023-01-10 10:16:51 +01:00
fdardenne ca80a60199 [IMP] mail: activity view: allow to filter columns
Before, in activity view, it was not possible for users to hide
never used columns.

Now it is possible for users to hide and show columns in the
activity view.

task-3039919

Part-of: odoo/odoo#109153
2023-01-10 10:16:51 +01:00