Commit Graph
730 Commits
Author SHA1 Message Date
Yannick Tivisse fda7ec5f1f [FIX] mail: Fix truncated template field on mail.composer
TaskID: 3101400
2023-07-05 14:21:28 +02: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
Maryam Kia 896a69cc30 [IMP] mail: disable escape on composer wizard
task #2793003
- rename Cancel to Discard on composer wizard
- disable escape on composer wizard to prevent closing the composer accidentally

closes odoo/odoo#120427

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-06-21 00:13:46 +02:00
amdi-odoo 02ec80445b [IMP] mail,mass_mailing_sms,*: improve UI
*: phone_validation

- Add sample data in the mass_mailing_sms blacklist phone
numbers tree view.
- Update the mass_mailing_sms demo data so that, instead of
the sms being stuck due to a lack of credits, they are
all sent.
- Swap the mass_mailing_sms list view with the kanban view
so that the list view is the main one like in Email Marketing.
- Rename the reset mail template confirm button from "Proceed"
to "Reset Template" to make the action more explicit.

Task-3280602

closes odoo/odoo#119321

Related: odoo/enterprise#40120
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-05-05 17:06:23 +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
Renaud Thiry 5c146ec219 [FIX] mail: compute resource_ref
Before this, the resource_ref field is computed once in the default_get.
This means if the cache is invalidated, its value is unrecoverable.

Notably, the cache is invalidated when an attachment is generated
(triggering a commit).

So calling _generate_template could invalidate resource_ref,
which we use as a key to retrieve its result.

This results in a traceback for the user when trying to preview
a template where the first record hasn't yet generated its attachment.

As an example, trying to preview `Sales: Send Quotation`
on fresh installs.

task-3162320

X-original-commit: b4bd93c9b61736a7f41d70afe5db977a6e4b35e0
Part-of: odoo/odoo#118710
2023-04-17 11:47:11 +02:00
Renaud Thiry 20fe457377 [FIX] mail: set error_msg in template_preview
If the preview wizard was used to preview a template on a model that
has no record, error_msg would not be set.

This means the field is never set in that case and creating the wizard
results in a cache miss on that field.

The fix is to simply set it, and we add a test to cover that flow of
the wizard.

task-3162320

X-original-commit: 0976ce53e0a97a1f49dc2a262cf66355242fde25
Part-of: odoo/odoo#118710
2023-04-17 11:47:11 +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
Pierre-Yves Dufays b245b8cb6f [FIX] mail: fix error while previewing a template without record
To reproduce the problem:
- Install project
- Remove all tasks
- Go to settings -> Technical -> Email Templates
- Select the template "Project: Task Rating Request"
- Click on Preview
Without the fix, a stack trace is displayed. With the fix, the preview is
displayed with the message "No record for this model" for the field "Test
record".

Technical note: the error happens because error_msg was not assigned in the
compute method of that field when the reference to the record is missing or
incomplete.

Task-3196081

closes odoo/odoo#116431

X-original-commit: 1f296539210a07e0b1aed0d9d3cd736c5cb33375
Signed-off-by: Dufays Pierre-Yves (pydu) <pydu@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-03-24 10:04:46 +01: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
Victor Feyens 24ccf7d9b0 [CLN] *: useless type info for actions
The type fields of actions already defaults to
the model name in the base model definition.

Therefore, specifying `ir.actions.server`, `ir.actions.act_window`
& so on as type is useless (and adds noise since it's the same as
the action model).

closes odoo/odoo#114539

Related: odoo/enterprise#37855
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
2023-03-08 17:33:37 +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
std-odoo 97ca45e4f3 [IMP] mail, mass_mailing: store the bounce email and allow the user to read it
Purpose
=======
The bounce emails aren't stored in Odoo, which can complicate the
debugging of the email sending.

Now, we store this bounce email, and we allow the user to read it from
the interface, so he can easily find the issue when an email sending
fail.

Specifications
==============
The bounce email is stored on the mail notification for standard emails
sending, and on the mailing traces when using mass mailing.

For some email providers (e.g. Yahoo), the "Final-Recipient" header is
not present. Normally, it allows us to retrieve the original recipient
of the email which bounced and then the partner. So if this header is
not there in a bounce email, we take the first recipient of the parent
<mail.message>.

Change the way that we parse the email body, for the bounce email.
For most email providers, the first mail body is the one that contains
the error and the next one contains the parent email body. So, the
current logic might ignore this body for Outlook and Yahoo.

Task-2116296

closes odoo/odoo#105923

Related: odoo/enterprise#34051
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
2023-03-06 17:47:29 +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 c712998f00 [FIX] mail: be more defensive when previewing fields
Sometimes due to new ids / not existing records for previewing crash may
happen when rendering the preview of templates. In this commit we rewrite
a bit the computation to try to be more resistant.

Task-3093257 (Mail: The Composer Update)

Part-of: odoo/odoo#107356
2023-01-27 19:56:02 +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
Pierre-Yves Dufays a556b54c89 [IMP] mail: standardize template preview form
Small refactor of the template preview form to use regular group and field tags
instead of custom layout using bootstrap.

Technical note: we weren't able to keep the model name in the label of
resource_ref so we have replaced the label with a static one: "Test Record:".
The reasons why we weren't able to keep the dynamic label are:
- a div instead a label tag is rendered with a style of width:50% which breaks
the layout (even when adding class="o_form_label"). Here we can keep the
dynamic part but we get a broken layout.
- when using a label tag for the label, the system forces us to use a "for"
attribute. But the "for" attribute replace the text content of the label by the
standard field label (here "Record"). Here we have a good layout but the label
is “Record”.
- we can override the standard field label with the attribute "string" but in
that case it is not possible to make it dynamic with the model name (field
model_id). Here it is the best we can get: a good layout and a decent label.
Unfortunately, we can't have the dynamic part of the label (the model name
here).

Task-3098782

closes odoo/odoo#109560

Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
2023-01-20 20:58:15 +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