Commit Graph
434 Commits
Author SHA1 Message Date
miad-odoo f608bce9b8 [IMP] mail: prevent saving template when no model
With this commit, we now raise a UserError if a user tries to save a template
with a composer that has no attached model.

Task-2504439

Part-of: odoo/odoo#126049
2023-09-29 13:11:50 +00:00
miad-odoo 39dd2fc2ab [IMP] mail: allow users to manage own templates
Before this commit, all mail templates were shared, which was cluttering the UI
for everyone.

Now, each user can have their own templates that they can edit and save. Access
is done through the mail composer wizard, where users can only access their own
templates and templates that don't belong to anyone.

Some groups are considered as admins and can access all templates in
Settings/Technical/Email/Email Templates:

- Sales Admin
- Project Admins
- Helpdesk Admins
- Accountants
- Event Admins
- Recruitment Admins

Task-2504439

Part-of: odoo/odoo#126049
2023-09-29 13:11:50 +00:00
Renaud Thiry 79e9665a49 [IMP] mail: improve Composer duplicates check
Only duplicate emails used to be checked when sending a mass mail.

However it is possible (e.g. using templates) to send a mass mail
to the same person containing different information.

The existing functions to allow models to specify emails
processed in the past by some other means are kept.

A new check is added in the processing that checks the full contents
of the message, subject and attachment ids.

The strings are not hashed as most situations are:
- Sending the exact same mail to everyone
  -> Only need to check against one message
   -> Same complexity as hashing

- Sending all different emails
  -> Checking inequality of str is usually very fast

For attachments, as we cannot compare them easily.
They are ignored for the purpose of equating emails
whenever there are the same number of attachments
in the email values as there are on the composer.

This is because each email should receive its own copy
of the composer attachments. If they have a different
number of attachments, they were generated dynamically
through reports and we assume they are all different.

We can thus remove the 'document based' information
as it is implicitly infered from this check.

-------------------------

Test utils are also updated for two purposes:

1. Add optional body and attachment_name discriminents
assertMailMail assumed all emails could at least be
differentiated by subject. Our test breaks that
assumption, so we use body and attachment to find the
best-fitting email based on the data passed in.

2. Check email_formatted on recipients
When using assertMailMailWEmails, we first find the
email using the non-formatted email of the recipient.
This does not match assertSentMail which checks against
the raw email_to value, which would often be formatted.

Task-2826811

closes odoo/odoo#99541

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-09-18 22:16:56 +00:00
Thibault Delavallée e0207d1551 [IMP] tools, base, mail: better support non-ascii / IDNA when normalizing
PURPOSE

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

SPECIFICATIONS

As of rfc5322 section 3.4.1 local-part is case-sensitive. However most main
providers do consider the local-part as case insensitive. With the introduction
of smtp-utf8 within odoo, this assumption is certain to fall short for
international emails. We now consider that

  * if local part is ascii: normalize still 'lower' ;
  * else: use as it, SMTP-UF8 is made for non-ascii local parts;

Concerning domain part of the address, as of v14 international domain (IDNA)
are handled fine. The domain is always lowercase, lowering it is fine as it
is probably an error. With the introduction of IDNA, there is an encoding
that allow non-ascii characters to be encoded to ascii ones, using 'idna.encode'.

Also remove usage of 'email_re' in mailing email check. It is too restrictive
compared to real formatting we support (or try to). Valid outgoing emails
were directly canceled, notably when containing unicode.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@3ce5fb3072
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 59652b25e0 [IMP] various: support multi-emails in mailings
PURPOSE

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

SPECIFICATIONS: MAIL COMPOSER IN MAILING

When using the composer with a mailing, it currently skips recipients whose
email is a multi-email due to the strict usage of 'email_normalize'.

We can improve multi-email support by effectively checking for the first
email found, using the "less strict" mode of normalize. It means more emails
are detected as valid, and therefore sent.

Due to lower support of multi-emails when sending emails, this even allows
to send multiple emails as all emails are mailed.

SPECIFICATIONS: DEFAULT RECIPIENTS

Mailings are generally done using default recipients, aka using a model method
that returns the people to mail: customers ('partner_id'), customer emails
('email_from'), specific implementation, ...

This is implementation using '_message_get_default_recipients' that returns
'partner_ids', 'email_to' and 'email_cc' that are then used in the mail
composer to generate final recipients.

In this commit we better handle the content of email fields to avoid issues
with multi-emails. For that purpose we correctly split the content of those
fields. We now have several 'email_to' for records having multi-emails instead
of a single badly-formatted 'email_to'.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@4a0d87d44f
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 20d0357df7 [FIX] mail: make mail_to computation of mailing traces deterministic
When having several possible emails to contact the first one is saved on the
trace model. Indeed a trace is normally linked to a unique recipient but
in case of multi-emails in an email field, several emails are available.

This commit ensure computation keeps the original mail_to when making emails
adresses uniques before sending mails and creating traces.

Followup of odoo/odoo@213d5d396c

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@b9b6fae9c5
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Yannick Tivisse b1f7e56f79 [IMP] base: Remove private res.partner type
- Improve performances, as the ir.rule restricting private partners
  visibility is also applied on res.users by inheritance, on each
  prefetch.
- Solve the issue of partners set as followers on records (eg: application
  form) and then made private, making them impossible to contact via the
  chatter.
- Solve the multiple access issues when trying to access the bank
  account, or the private address for non HR people like the accountants
  forcing the usage of sudo in the business code.

TaskID: 3101400
2023-07-05 14:21:28 +02:00
Renaud Thiry 39f14ca2c9 [IMP] mail: add auto_comment message type
Currently some auto_reply templates are internal as a means to prevent
notifying users everytime we send a reply to somebody.

This raises the issue that since responses to internal notifications
are themselves internal notifications, often nobody will be notified of
responses to these automated messages.

We fix this by marking these messages as auto_comments, which will
ensure responses to these messages are
considered non-internal (and thus 'discussions', by default).

task-2834304

closes odoo/odoo#94018

Related: odoo/enterprise#35466
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-05-05 09:25:42 +02:00
Pierre-Yves Dufays ed8a101a08 [FIX] test_mass_mailing, {test_}mail: always apply blacklist for mass mailing
Always apply the blacklist in mass_mail composition mode regardless of the
recipient model implementing mail.thread.blacklist or not.

This solves the problem of mail sent to black listed address for model not
inheriting from mail.thread.blacklist.

Technical notes:
- it has been done in mail.compose.message _get_blacklist_record_ids ignoring
the mixin mail.thread.blacklist to avoid model change in stable.
- some tests have one added query because the blacklist is now queried for each
batch mail sends even if the model of the recipient doesn't implement
mail.thread.blacklist.

Task-2834862

closes odoo/odoo#118497

X-original-commit: 263e86114c60650f421354e165364afcd4122461
Signed-off-by: Dufays Pierre-Yves (pydu) <pydu@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-04-13 17:57:56 +02:00
Mahamadasif Ansari 5ad9686b2f [FIX] mail: composer non-thread _compute_subject
When using the composer on a non-thread model a notification is sent instead
of posting a message, as the model does not support the posting process.
However there is currently a crash due to the default subject computation
which is solved in this commit.

Task-3254379

Part-of: odoo/odoo#117763
2023-04-05 15:11:33 +02:00
Thibault Delavallée c2f8b03e3f [IMP] mail: support layouting in composer mailing mode
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 to post on a 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 and translated if
    matching template content -> ok;

Email layout situation when posting / mailing

  * comment: layout translated based on recipient lang or fallback on template
    'lang' field definition, or current user's lang;
  * mailing: no layout supported;

PURPOSE

Make those the two composer modes less different by supporting layouting in
mailing mode of composer. Consider it a bit experimental.

SPECIFICATIONS

When using the composer in mailing mode, render email layout if given. This
layout is used to encapsulate body.

To simplify rendering and sending, consider all recipients to be 'customer'
as defined in '_notify_get_recipients'. This means all recipients receive the
same basic layouting currently as a first attempt to improve this situation.
Considered lang is the one coming from the template 'lang' field, or fallback
on current user's lang.

Task-3186426 (Mail: Support notification layout in template / email composer)

Part-of: odoo/odoo#106177
2023-03-09 15:54:15 +01:00
Thibault Delavallée 9887bd0c7b [IMP] mail: correctly propagate language when posting from composer
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 to post on a 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 and translated if
    matching template content -> ok;

Email layout situation when posting / mailing

  * comment, monorecord model, using a template from UX: layout is partly
    translated based on template 'lang' field to match the content translation.
    Part of the layout still uses the current user lang;
  * other comment use cases: layout is translated based on current user lang;
  * mailing mode: layout not supported;

PURPOSE

Correctly propagate lang from template in all situations whenever a template
is used, and translate all layout parts.

SPECIFICATIONS

When using the composer to post messages (either as comment or in batch) the
language coming from the template is not propagated until the notification
process.

A hack has been done to try to guess the language inside the notification
process, based on context keys at odoo/odoo@9e71d228ed. This was done to partly fix
the bug in stable.

Since odoo/odoo@3eb9680602 it is possible to propagate a lang from 'message_post' or
'message_notify' calls until the notification process. We can therefore call
the posting methods using the rendered lang (in both mono and multi record
modes) and remove that hack.

When a lang is propagated using the 'force_email_lang' it is used to choose
the language of the layout (content, buttons). Currently all recipients
receives the same language for layouting. We plan to soon use the recipient
language when possible, then fallback on that forced lang. This will offer
more granularity and a better user experience.

When using scheduled messages (creating message but delaying the sending of
notifications) it is also working as notification parameters are saved when
creating the scheduling record, see odoo/odoo@9b11a9d82b.

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);
  * layout is translated into spanish (customer's lang);

Both recipients (customer and follower) receive the content in spanish.

LINKS

Task-3046371 (Mail: Better Language Support in Composer)
Task-2555155 (Mail: Translate notification action/access buttons)

Part-of: odoo/odoo#106177
2023-03-09 15:54:14 +01: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 2b9e288e1f [IMP] mail: support email_layout_xmlid on template
RATIONALE

Currently email layout choice is done in code and is not controllable through
any user interface. In this commit we prepare improvements in template
management by allowing to choose the email layout directly from a given
mail template. As number of layouts is going to grow better be able to
choose the right one.

SPECIFICATIONS

Add a field on template to propagate email layout choice directly on
template and propagate it to the composer, then post/notify process.

We can now choose directly on a template which notification layout should be
used in conjunction with this template. Composer model already holds a field
'email_layout_xmlid', used in various places in code to give a specific
layout to use when sending notifications emails e.g. SO email layout. This
can now be specified directly from the template itself. It allows to
customize the look and feel of notifications without having to do it
explicitly in a given code flow.

Computation is coming either from template, either reset. When having a
template with a value set, set it on composer. When removing the template
reset it.

Currently no standard template uses it as this task targets mainly a code
cleaning that began with the composer code cleaning. It targets the near
freeze to have the base code updated once, then functional templates will
make use of it (hopefully).

Note that currently notification layout is still not supported at composer
level for mailings. It is simply ignored when generating outgoing mail
records. This will be improved soon.

Global followup of odoo/odoo#107356 / Task-2088884 (Mail: Use editable
computed stored fields in composer).

Prepares code for Task-3046371 (Mail: Better Language Support in Composer)
see odoo/odoo#106177 .

Task-3186426 (Mail: Support notification layout in template / email composer)

closes odoo/odoo#114462

Related: odoo/upgrade#4404
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-03-07 02:56:46 +01:00
Raphael Collet 6ef3772847 [IMP] *: optimize code with search_fetch() and fetch()
closes odoo/odoo#112126

Related: odoo/enterprise#36782
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-03-05 15:12:57 +01:00
Thibault Delavallée 3121454e9d [IMP] mail: move composer 'email_add_signature' 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 ``email_add_signature`` in
compute method.

When having a template, consider it defines completely body and do not add
signature. Without template, add signature by default in comment due to post
processing for notification emails. Mailing mode does not handle signature.

Followup of odoo/odoo#107356

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

closes odoo/odoo#113522

Related: odoo/enterprise#37478
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-02-23 18:28:59 +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 65470cf180 [REF] mail: move composer 'force_send' 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 ``force_send`` in compute method.
It is currently computed in a default_get override.

It is set to True in mass mailing mode (send directly by default) and in
monorecord comment mode (send notifications right now). Batch comment delays
notification to use the email queue.

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 2c1bb88644 [REF] mail: move composer 'model' and 'res_ids' 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 ``model`` and ``res_ids`` in
compute methods.

Model can be set from parent or using 'active_model' context key frequently
used as the composer is most invoked from list or form views.

Res Ids computation may come from parent in comment mode, if set. It takes
the parent message's res_id. Otherwise the composer uses the 'active_ids'
context key, unless it is too big to be stored in database. Indeed when
invoked for big mailings, 'active_ids' may be a very big list. Support of
'active_ids' when sending is granted in order to not always rely on 'res_ids'
field. When 'active_ids' is not present, fallback on 'active_id'.

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 69209ae4bf [MOV] (mass_)mail(_ing): move 'model_is_thread' field to mail
This field will be used to remove low-level asserts using existence of
'message_post' on a given model instead of correctly checking the
inheritance on mail.thread.

This is going to increase a bit query counters but those queries should
be fast and have no real impact on performances.

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 b77af1760b [FIX] mail: fix 'res_domain' usage in composer
Using 'res_domain' should always activate the batch mode, either in mailing
or comment mode. In this commit we fix some glitches linked to the usage
of this new mode recently introduced.

Followup of odoo/odoo#99482

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

Part-of: odoo/odoo#107356
2023-01-27 19:56:01 +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
Thibault Delavallée e08854093e [FIX] account, mail: better batch mode support
Mail composer does not support direct assignment of res_ids for rendering
using active_ids context key anymore when res_ids or res_domain are present.
With this commit we allow to force the rendering on some specific IDs in the
composer using a temporarily 'composer_force_res_ids' context key.

This will be removed once languages are better supported in the mail composer
which is the source of that small hack in the invoice composer.

Followup of odoo/odoo#99482

Task-3149286 (Account: cleanup account.invoice.send wizard
Task-3046371 (Mail: Better Language Support in Composer)

Part-of: odoo/odoo#110919
2023-01-26 22:09:46 +01:00
Thibault Delavallée 6876a19cb9 [FIX] mail: fix 'composition_batch' composer triggers
'res_domain' field is used but was missing in triggers.

Followup of odoo/odoo#99482

closes odoo/odoo#110293

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-01-18 17:38:35 +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 55bcb62131 [REM] mail: remove mass post option from mail 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

Remove deprecated "mass_post" option from composer. It is either a comment
(using message_post) either a mass mail (creating emails). Mass post was
anyway nor used nor really supported. It will be replaced by supporting
having a comment on several IDs (batch comment mode, posting a message
on several records instead of being limited to one as currently).

This cleaning also allows to remove the 'notify' field that was an option
used for mass_post. All this should be supported through subtypes and
correct choice of post / mass mailing.

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

Part-of: odoo/odoo#99482
2023-01-17 20:58:39 +01:00
Thibault Delavallée 7973960784 [FIX] mail: pre-raise when trying to post on no record
RATIONALE

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

SPECIFICATIONS

When trying to use the composer without related records in comment mode
message_post raises, as record is mandatory (ensure_one). In this commit
we make this raise explicit in the composer itself, in order to be able
to assert the behavior.

In mass mail mode, having no record to mail is possible and the composer
simply skips the mail creation. Indeed when doing mass mailing, notably
with crons, records might have been updated / removed and the composer
should not crash, just produce nothing.

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 26f1f7c433 [MOV] mail: reorganize composer values generation code
Purpose of this commit is to move methods to better prepare future changes.
Currently onchange code, value generation and tools for email management
are mixed, which leads to the file being quite messy.

Separate methods generating mail or message values, from methods doing
data marshmalling.

Task-2710804 (Mail: Clean MailThread Posting API)

Part-of: odoo/odoo#99482
2023-01-17 20:58:37 +01:00