Commit Graph
64 Commits
Author SHA1 Message Date
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 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 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 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 709a65997d [LINT] mail, various: perform a quick code linting
Purpose is to try to have code easier to read and to update by having a
common way of sorting / writing code. Reorder some fields definitions and
dictionaries, update docstrings, ... in mail applications or when invoking
mail thread API.

Additional stuff worth noting here

  * add some tagged in tests helping debugging / choosing tests to execute;
  * in a test about mail generation with server action: correctly check
    body_html field, not body which comes from the mail.message inheritance
    (currently filled due to a side effect but actual field to check is the
    html one);
  * add same check on input for ``_render_template_qweb`` as done on other
    rendering methods (even if rendering on [False] should be supported);
  * move code translation update from specific tests into main test class
    (code update due to new translations, followup of odoo/odoo@f8c2b02abe);

Some test linting done here

  * reorder mail_render tests, remove some duplicated tests;
  * reorder mail_template tests, remove some duplicated tests;

Task-2710804 (Mail: Clean MailThread Posting API)

closes odoo/odoo#106025

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-11-18 14:00:30 +01:00
Renaud Thiry eaf905d55a [IMP] mass_mailing: hide mailing option on invalid
Currently when creating a composer in mass mode
the composer always shows the 'mass mailing name' option
even when a mailing cannot be created.

This silently creates a regular mass mail.

This hides that option when selecting records of models
that do not inherit from thread. So that users do not falsly
believe a mailing will be created.

task #2990447

closes odoo/odoo#102105

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-10-06 14:56:49 +02:00
Gorash 880954ebfc [IMP] *: remove _render from ir.ui.view and simplify report
There were inconsistencies in the calls to `_render`.
* the view context could contain information that misled developers.
Indeed, the context and value of the view are not supposed to be found
in the rendering. Thus by calling `ir.qweb` with the name of the
template, we ensure that there is no unwanted information and in
addition the cache key is that of the name of the template which saves
a query.
* the context used for rendering was modified by a method on
`ir.ui.view`, except this is not information used by this model. There
is now a `_prepare_environment` method residing on `ir.qweb`. This
method allows to modify the value dictionary as well as the context in
which the rendering will be done. This preparation of the data as well
as my security check is done only once per rendering. This also saves
some queries
* Freeze options for rendering were inconsistent. It could be that
options on which rendering depends were not part of the cache key. Thus,
depending on the user who generated the generation of the rendering
function, there was or was not information in the template. For example
for automatic branding. This is no longer possible, because it is the
context that is used. The options serving as a cache key are only
recorded for information (for the profiling system for example). A
simplification of the `ir.qweb.field` models could be made.

The report rendering and call `ir.qweb` instead of `ir.ui.view`.

Part-of: odoo/odoo#85110
2022-03-29 10:56:15 +02:00
Aurélien Warnon 1e25946a76 [IMP] utm: globally improve UTM records management across all apps
PURPOSE

This commit consolidates UTM usage across all applications.

Global purpose is to avoid having undesired side-effects, such as unlinking an
utm.source/utm.medium/utm.campaign and at the same time cascading the deletion
to various records without noticing.

SPECS

ALLOW MORE PEOPLE TO CLEAN UTM RECORDS

Currently, not even the system administrator can delete utm.mediums and
utm.sources (he can only delete campaigns).

These were considered as "technical records", but allowing some cleanup is
a good idea since these records are often automatically generated and can
create a lot of unnecessary noise in the database.

That's why we now allow the following groups to delete all UTM records
(sources, mediums and campaigns):
- group_system
- group_mass_mailing_user
- group_social_manager (enterprise)

PREVENT DELETION

For some use cases, removing an utm.source/utm.medium/utm.campaign would
cascade delete the related record, which was unintended / hidden side effect.

These combinations were secured by preventing to unlink:
- mailing.mailing source_id field
  Trying to delete the utm.source will throw an error message
- mailing.mailing medium_id field
  Trying to delete the utm.medium will throw an error message
- hr.recruitment.source source_id field
  Trying to delete the utm.source will throw an error message

ADDING CLEAN ERROR MESSAGES

When trying to delete an UTM record that is linked with ondelete="restrict", we
improved the error message to give a clear explication to the user, e.g:

"You can't delete these UTM sources as they are linked to the following
mailings in the Mass Mailing APP, and deleting the source would break the
statistics: Newsletter"

SPECIFY 'ondelete' strategy

For a lot of uses of sources/mediums/campaigns, the 'ondelete' strategy was not
specified, leading to the confusion of "is this really how we want to handle
this?".

A lot of ondelete="set null" have been added in various field definitions to
ensure that this is the desired and logical strategy we want for that
specific model.

PREVENT REMOVING HARDCODED UTM RECORDS

In some functional flows, UTM records are hardcoded using their direct
record reference.
This is notably the case for the recruitment process and its creation of
aliases, and for the Email / SMS Marketing flows.

As deleting them would break these flows, we prevent their deletion in a
"api.ondelete" method.

ENFORCE NEW RULES WITH TESTS

A lot of python tests have been added to make sure we enforce the decisions
taken here above.

LINKS

ENT PR odoo/enterprise#19048
Task-2459480

closes odoo/odoo#72239

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-11-23 11:12:04 +00:00
Julien Banken fbb9a25367 [IMP] mail: revamp the mail composer
On the CRM module, the user can send an email to all the contacts
associated to the leads matching some criteria by (1) displaying the
list view, (2) applying a search filter, (3) clicking on the "EMAIL"
button and (4) checking a checkbox on the mail composer to ask the
server to use the active search. To do the same thing, the user can
(1) display the list view, (2) apply a search filter, (3) select all
the records and (3) click on the "EMAIL" button.

To avoid redundancy and improve the usability of the composer, we will
remove the search domain passing from the mail composer. Note that it
will still be possible to pass a search domain programmatically.

To improve the guidance of the mail composer, we will add helper
messages, update the labels and move the options in a dedicated pane.
The wording of the buttons will also be updated dynamically based on
the selected options.

Example: When the user enters something in the `mass_mailing_name` field
to create a new mass mailing campaign from the new message, the label of
the "Send" button will be set to "Send Mass Mailing" which gives more
indication on what will happen when the user clicks on it.

task-2523036

Part-of: odoo/odoo#71413
2021-09-30 13:31:52 +00:00
Victor FeyensandThibault Delavallée f85387ef33 [IMP] mail(_*): limit usage of search
Purpose of this commit is to globally improve code performance by limiting
search impact by

  * adding limits when only first found record id used;
  * avoid unnecessary searches when record set can be filtered instead;
  * using cache when accessing ir.model;

Task-2638444
PR odoo/odoo#76005

Co-Authored-By: Thibault Delavallée <tde@odoo.com>
Co-Authored-By: Victor Feyens <vfe@odoo.com>
2021-09-08 07:56:04 +00:00
Thibault Delavallée 4e709ca3b7 [REF] mail, mass_mailing: stop using context for seen/optout list
Purpose of this commit is to keep blacklist and optout lists computation
at mailing level and correctly call it in composer. This allow to have
a clearer and more readable code as well as more robust.

Currently it is done by adding this information in context before invoking
the mail composer. It is now correctly done in composer: if a mailing is
linked to the composer, it calls both blacklist and optout lists methods.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
2021-08-18 13:38:17 +00:00
Thibault Delavallée 19ce266dbf [REF] mail: rename notification of mail.mail to is_notification
RATIONALE

Prepare code cleaning and optimization in mail, mass_mailing and SMS by
cleaning models for readability and code complexity and footprint reduction.

SPECIFICATIONS

Purpose is to prepare future changes by easing its grep. Notification is too
much heavily used through the codebase and finding it was quite hard among
other noise.

Rename ``notification`` field to ``is_notification``.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:38:17 +00:00
Thibault Delavallée 213d5d396c [MOV][REF] mail: add failure type on mail.mail model and move computation in mail
RATIONALE

Currently most of mail related failure types are computed in mass mailing.
This is mainly due to historical reasons. We could move some of this
computation directly at mail level and store failure information directly
in mail.mail records.

SPECIFICATIONS

Overall purpose is to get near SMS implementation where base composer prepare
more advanced pre computation: blacklist, optout, seen list.

Detect and store failure types directly on mail.mail: blacklist, optout,
duplicates, missing email, wrong email, ...

State computation is moved from mass mailing to mail. It is also improved as
currently everything is based on "first recipient found". This is globally
valid for mass mailing who uses default recipients (customer). However when
dealing with generic mailing this is not true anymore.

We choose to store and update status on mail.mail records only when having
a single recipient. When several recipients are defined on a given mail.mail
we cannot really decide a status prior to sending it and skip this computation.

Mass mailing override now uses information from mail.mail to update its linked
traces as computation is now delegated to base composer model.

LINKS

Task ID-2377974
Community PR odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:38:17 +00:00
Thibault Delavallée c178a7829f [REF] mail, mass_mailing: improve mail.notification / mailing.trace failure_type
PURPOSE

Clean mailing code and ease understanding by replacing some old selection
keys by new ones better highlighting their use and aligned with other keys
used notably in mass mailing or SMS.

SPECIFICATIONS

Use shorted and mail-related keys. Indeed we already have sms_ and sn_ for
sms and snailmail related failure type. We therefore update failure_type for
mail as

  * "UNKNOWN" -> "unknown", a generic unknown of uncategorized error;
  * "RECIPIENT" -> "mail_email_missing", indicates email address is
    invalid;
  * "SMTP" -> "mail_smtp", connection issue;

"BOUNCE" key is never used and removed. Actually we use a bounce state for
bounced emails / traces so this key has no use.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:38:17 +00:00
Thibault Delavallée bbf4783ac6 [REF] mass_mailing: improve traces state management
PURPOSE

Improve modeling and performances of mass mailing by manually updating trace
status instead of using complex computed fields and lessening fields usage.

Remove some fields and keep only relevant metrics to simplify and clean trace
model.

SPECIFICATIONS

In this commit we clean the way trace state is managed. Currently it is a
computed field based on several datetime fields. However this generates a
lot of noise in the table as well as unnecessary computation

  * there are several columns (one for each state) storing datetime at
    which status was reached. Generally only 2 or 3 contain relevant
    information;
  * state could be set in code directly to avoid a computed field based on
    many triggers;
  * recomputing it each time a date changes is not necessarily necessary;
  * state value can always be updated manually as this is main done through
    some automated server update (mailgateway, link clicks, ...);

As trace states and its triggers should not be updated manually it is better
to synchronize it in code flow. When there is an exception or update done
through sending or gateway status is updated as well accordingly. Various
datetime fields are also updated at the same time. In order to align with
notification model mail and sms trace status are updated to a classic field.
Only last status update is now kept as there is no need to store the entire
history of status change.

We keep only a datetime for relevant metrics: open, reply and click. Other
datetime bring no real value. Knowing when a trace was in error or bounced
is not necessary. Indeed exception generally indicates a server issue (at
sending), cancel indicates a data issue (at sending) and bounce depends on
customer email server.

Status update is removed as using write_date is sufficient. Once created
traces are updated only when an external event occurs (opened, replied, ...).
It allows to simplify trace model.

We also rename ignored field into canceled to match naming use through mail
and sms.

QUERY COUNTERS

This change has some positive update on query counters when sending mailings
as traces have less unnecessary status update compared to priori this change.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:38:08 +00:00
Thibault Delavallée d950b97dbf [REF] mass_mailing(_sms): improve mail/sms and traces failed/ignored state management
RATIONALE

Currently there are differences between mail and sms error management
especially when sending them in batch (mass mode). Moreover cancel
(ignored) and error (exception) states meaning is not clear. Finally
some failure types management between mail and sms can be cleaned.

SPECIFICATIONS

Meaning of ignored / error we want to enforce now is

  * error: there was something wrong at sending and user has an action to
    perform, i.e. server failed -> check its logs;
  * canceled: invalid recipients due to contact information or mailing
    configuration (blacklist, opt out, void or invalid email or phone number).
    In indicates issues linked to records themselves;

In this task we also add failure information granularity on mailing traces
linked to email like what is done currently on SMS. This can be related to
mailing (blacklist, optout, duplicates) or related to recipient (no recipient,
incorrectly formatted).

We also correctly distinguish optout from blacklist when sending SMS.

SPECIFIC USE CASES

  * recipient without email / number: mail / sms is set as canceled, trace is
    ignored;
  * recipient with invalid email (no @) / number (formatting impossible):
    mail / sms is set as canceled, trace is ignored;

    -> we now distinguish when possible a void email from a wrong email using
       a newly-added selection key (mail_email_missing);

  * recipient with email / number blacklisted: mail / sms is canceled, trace
    is ignored;
  * recipient with email / number that optouted from mailing: mail / sms is
    canceled, trace is ignored;
  * recipient with email that bounces: mail is sent and will be set as bounce
    when receiving bounce in gateway; trace follow same path;
  * recipient with number that bounces: not supported as currently no support
    of bounce through IAP;
  * mail server error, IAP error: mail / sms is set as exception / error,
    trace is set in exception;

This means we introduce new failure types on mailing.trace model to reflect
those failure types

  * ``mail_missing``: missing email (different from wrong value);
  * ``mail_bl``: blacklisted;
  * ``mail_optout``: optouted;
  * ``mail_dup``: duplicated email skipped during mass email send;

We introduce ``sms_optout`` on SMS and trace models as it was merged with
blacklist previously. Now both errors are distinguished.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:37:33 +00:00
Gorash 7df343dd1b [IMP] base: QWeb _render return Markup unicode instead of utf8 bytes
In order to limit encoding decoding, the _render method returns a
unicode string in the markup safe object instead of a MarkupSafeBytes

closes odoo/odoo#68299

Related: odoo/upgrade#2454
Related: odoo/enterprise#17270
Signed-off-by: Antony Lesuisse (al) <al@openerp.com>
2021-08-03 16:20:22 +00:00
Xavier Morel 34fbed3639 [FIX] mass_mailing: str/bytes confusion thing
qweb returns bytes, which would be stored in a dict's `body_html`,
which would then be stringified *but not decoded*.

Running with `-b` this gets flagged, it's probably better to fill the
dict with what's actually expected (text).
2021-04-29 05:34:21 +00:00
Thibault Delavallée c8aabac87d [IMP] mass mailing: update reply_to_mode keys
Propagate reply_to radio keys (update and new) to mass mailing in order to have
a coherent naming (was thread and email). This naming is also coherent with
gateway naming (message_update and message_new).

LINKS

Task ID-2117639
COM PR odoo/odoo#40931
ENT PR odoo/enterprise#17941
UPG PR odoo/upgrade#2419
2021-04-26 14:18:33 +00:00
shreya thakrar 59ce7d3969 [IMP] mail, mass_mailing: ease "reply to" fields understanding
PURPOSE

Right now, `reply_to` field on email template is misleading due to poor
explanation. This commit improves the placeholder and tooltip of the fields
to make the purpose of the field clearer especially for non technical users.

SPECIFICATIONS

Update reply-to field placeholder to "Preferred email address when sending
via mass mailing options".

Update reply-to field helper message to "Preferred email address when sending
via mass mailing options. <br> Only used when the answer is not added into
the original discussion.""

Update the no_auto_thread field label to "Reply to" in composer and introduce
a new radio button replacing the checkbox

  * The original discussion (thread)
  * Another email address (new)

Rename fields on mail_thread and wizard: ``no_auto_thread`` should be replaced
to ``reply_to_force_new`` to ease understanding and be prefixed by reply_to.

LINKS

Task ID-2117639
COM PR odoo/odoo#40931
ENT PR odoo/enterprise#17941
UPG PR odoo/upgrade#2419
2021-04-26 13:53:20 +00:00
Thibault Delavallée cbb911f530 [FIX] mass_mailing: keep invalid email on failed traces
SPECIFICATIONS

Traces are sent to normalized emails. If email is invalid email set on traces
is void as we cannot normalize it. In this commit we set it to the original
value of email, allowing to debug or at least understand what was wrong. It
also makes behavior coherent with SMS Marketing.

LINKS

Task ID-2508643
Prepares Task ID-27033 (support QWeb in templates)
Prepares Task ID-2377974 (clean trace and status management in mass mailing)
COM PR odoo/odoo#69461
ENT PR odoo/enterprise#17780

X-original-commit: af841ccece14ffee0291f761d5363eceded65dfc
2021-04-20 09:18:22 +00:00
Ivan Yelizariev defa46715e [IMP] mass_mailing: show attachments composer mailings
This improvement allows user to review mail attachments that were sent using
composer in mass mail mode while creating a mass mailing on the fly. This is
achieved via `Action > Send email` menu and setting a mailing name.

For example, you sent different mails to different set of partners and you want
to check that you sent correct attachments and didn't miss anything. This
behavior is doable in Email Marketing apps. Before this commit you would need
to open different partners in Contacts app and check messages in the chatter.
Now attachments are displayed in composer.

STEPS:
* Install mass_mailing
* Open Contacts menu
* Select any number of records
* Click `Action > Send email`
* Set **Mass Mailing Name**
* Attach a file
* Send
* Open ``Email Marketing`` app
* Open the created mailing
* Check ``[Settings]`` tab

BEFORE: Attachments field is empty
AFTER: You can see the attachments sent to the partners

WHY: In 2014 attachments were added to mailing.mailing, but not to composer
https://github.com/odoo/odoo/commit/7e1e475d89694d09e62c33d2529fa061c7983dff

---

Task ID-2418997
opw-2410938
closes #63065
closes #63470

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-05 08:04:30 +00:00
Martin Trigaux d9287caf94 [IMP] *: convert to private methods
render, render_template, load, activity_schedule_with_view,
get_website_pages should all be private:
It should not be possible to render an aribtrary template only with
its name or id

Still need to render some qweb views from js so the method
render_template is kept public.
This explains why the website editor still need read access on
ir.ui.view as we want to allow any snippet to be rendered.
2020-05-14 13:59:10 +02:00
jerome hanke (jhk) 19d00d668a [FIX] mass_mailing: mailing.mailing does not use template_id
Steps to reproduce:
- install crm and mass_mailing
- go to crm > configuration > settings > activate leads
- go to crm > leads > select at least 2 leads > action > send mail
- set a subject > set a mass mailing name > send

Previous behavior:
you get a traceback
ValueError: Invalid field 'template_id' on model 'mailing.mailing'

Current behavior:
the mass mail is sent

opw-2212605

closes odoo/odoo#48088

X-original-commit: c87db90d5dbab4d02a9378a1fc905c9b2935cbe2
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Signed-off-by: mightyjol <jhk-odoo@users.noreply.github.com>
2020-03-20 09:47:19 +00:00
qmo-odoo a661b00015 [REF] utm,mass_mailing: replace mass mailing campaign by utm campaign
PURPOSE

This commit removes the mass_mailing.campaign model. Instead of having a fully
fledged model, we will simply inherit utm.campaign. We will also add relevant
statistics on utm campaign model in order to use it in various applications.

SPECIFICATIONS

This commit removes the mass_mailing.campaign model. Instead of having a fully
fledged model, we will simply inherit utm.campaign. This change implies that
mass_mailing.tag and mass_mailing.stage have to move to the utm model along
their associated views/data.

These changes were made so that campaigns could be used in the future
by social, mass_mailing and mass_sms and available in the same view

This commit also removes the source_id and the medium_id
fields on the campaign.

This commit also moves the unique_ab_testing field from the mass_mailing_campaign
to the mass_mailing model

Task ID: 2002029
PR: #34015
2019-08-02 12:32:35 +00:00
Thibault Delavallée 49d2899fbd [REF] mass_mailing: rename mail.mass_mailing model
PURPOSE

Mass mailing is currently a bit messy. As SMS will be added as a way to notify
people in mass through SMS let us take this opportunity to somehow clean this
application: organization, light code cleaning, model renaming.

SPECIFICATIONS

Rename mail.mass_mailing model to mailing.mailing. Rationale :

  * mailing is now a prefix for mass mailing models;
  * mailing.mailing is easier to read / find / understand;

Note that mail.mass_mailing.campaign is not updated as it is likely to be
removed soon and replaced by simple utm.campaign model.

MIGRATION

mail.mass_mailing model -> mailing.mailing
mail_mass_mailing table -> mailing_mailing

LINKS

Task ID 2037906
Preparing task ID 1997464 (SMS addition in mass mailing)
PR #34938
2019-07-17 15:50:33 +00:00
Thibault Delavallée 772e1c0cc4 [REF] mass_mailing: rename mail.mass_mailing.{.contact{_rel}, list{.merge}} models
PURPOSE

Mass mailing is currently a bit messy. As SMS will be added as a way to notify
people in mass through SMS let us take this opportunity to somehow clean this
application: organization, light code cleaning, model renaming.

SPECIFICATIONS

Rename mail.mass_mailing.list and mail.mass_mailing.list to mailing.list
and mailing.list.merge. Rename mail.mass_mailing.contact to mailing.contact.
Rename mail.mailing_list.list_contact_rel to mailing.contact.subscription.
Rationale :

  * those new names are easier to understand: mailing.list and mailing.contact
    are less mail-related, especially taking into account that SMS will allow
    to be less mail-oriented;
  * those names are easier to read / find / understand;
  * align wizard and sub-models naming with the main naming;
  * have a mailing as first part of namespacing;

MIGRATION

mail.mass_mailing.list model -> mailing.list
mail.mass_mailing.list.merge model -> mailing.list.merge
mail.mass_mailing.contact model -> mailing.contact
mail.mass_mailing.list_contact_rel model -> mailing.contact.subscription
mail_mass_mailing_contact_list_rel table -> mailing_contact_list_rel (specific
case of a decorated m2m)

fields updated (no column change)
  * mailing.list: subscription_contact_ids -> subscription_ids

LINKS

Task ID 2037906
Preparing task ID 1997464 (SMS addition in mass mailing)
PR #34938
2019-07-17 15:50:33 +00:00
Thibault Delavallée 2896aad34e [REF] mass_mailing: rename mail.mail.statistics and reporting model
PURPOSE

Mass mailing is currently a bit messy. As SMS will be added as a way to notify
people in mass through SMS let us take this opportunity to somehow clean this
application: organization, light code cleaning, model renaming.

SPECIFICATIONS

Rename mail.mail.statistics to mailing.trace and mail.statistics.report
to mail.trace.report. Rationale :

  * mail.mail.statistics is linked to mail.mail model. Soon this model will
    hold data related to SMS sending. It makes sense to be broader in the
    naming;
  * mailing.trace is more inlined with marketing.trace model that is the
    marketing automation model using it in marketing automation (enterprise
    application);
  * mailing.trace is shorter to write;
  * mail.statistics.report model should sense to be updated at the same
    time;

MIGRATION

mail.mail.statistics model -> mailing.trace
mail_mail_statistics table -> mailing_trace
mail.statistics.report model -> mail.trace.report

fields updated (w column change)
  * link.tracker.click: mail_stat_id -> mailing_trace_id

fields updated (no column change)
  * mail.mail: statistics_ids -> mailing_trace_ids
  * mail.mass_mailing: statistics_ids -> mailing_trace_ids

LINKS

Task ID 2037906
Preparing task ID 1997464 (SMS addition in mass mailing)
PR #34938
2019-07-17 15:39:06 +00:00
Adrian Torres 4b38cc6590 [REM] *: calls to @api.multi
Multi is the default api for methods, it is not necessary to explicitly
decorate methods with it, adds clutter and most people use it because
they see that the rest of the code uses it.

Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
2019-07-17 14:13:12 +02:00
Christophe Simonis 6d4940675f [MERGE] forward port branch 12.0 up to ea1fc124ef 2019-04-09 11:11:48 +02:00
Thibault Delavallée b0491c4445 [FIX] mass_mailing: correctly find partner email in mass mailing
In mass mailing access to partners when performing a mass mailing has been
done in batch to speedup computation [1]. Emails are put into a dictionary
allowing to find back the email based on partner_id.

However the matching between the partner and its emails is done using a
shortcut using the current document ID as partner ID. It works when performing
a mass mailing on partners but fails when performing a mass mailing on models
having message_get_default_recipients not returning only emails. Currently
in saas-14 main models return only emails (crm, event, mailing contacts) but
other models may encounter issues (applicants, tickets).

This commit fixes it by correctly matching partner id and its found email.

Related to task ID 1924711
Linked to PR #32496

[1] See 65ed4553a5
2019-04-08 12:39:18 +00:00
David Beguin 1007df3dc3 [IMP] mass_mailing : apply email_normalized on _get_opt_out_list
To avoid sending mail to an opted-out mass_mailing_contact with email address
that is not strictly an email address (a <a@a.com> instead of a@a.com),
the the get_opt_out method must be adapted to use the email_normalized field,
as this method is only useful for that specific model.

Task ID : 1896677
2018-11-20 11:37:05 +00:00
David Beguin 4b3766e8eb [IMP] mass_mailing : include invalid emails into ignored state
If the email is invalid (incorrect pattern),
the mailing status is set to canceled and will be flaged as ignored
in the mail.mail.statistics
2018-08-10 17:46:08 +02:00
David Beguin a1d6064dcc [IMP] mail : auto-blacklist rule when too much email bounced
In order to avoid sending mail indefinitely to a wrong email address,
Take the mail statistics for the recipient of the last 3 month :
	if more than 5 mails bounced (with interval of more than 1 week)
		the email is blacklisted.
2018-08-10 17:46:08 +02:00
David Beguin 59b4836e8d [IMP] mail, mass_mailing : apply blacklist, opt_out per mailing list
Purpose
=======
- Apply the blacklist implementation to Improve mailing subscription to be more
  compliant with the European GDPR law. Keep a list of people who does not want
  to receive promotional emails (or mass mailing in general) anymore.
- Allows the recipient to update himself his mailing preferences

Specifications
===========
This commit is regrouping some main changes on mass mailing.
  Apply Blacklist for following models through blacklist.mixin :
    - crm.lead
    - res.partner
    - mail.mass_mailing.contact
    - mail.channel.partner
- Opt_out per mailing list instead of per mailing contact.
- Replace opt_out by blacklist in crm.lead + res.partner models
- Added 'ignored' state for mass_mailing. Ignored = blacklisted, opted-out
  Ignored email are not included into final statistics to avoid confusion.
- Unsubscribe(d) pages migrated from website_mass_mailing to mass_mailing module
  as thoses pages should work without having the website module installed

Detailed implementation
===================
Mass-mailing :
	- A blacklisted email is notified by the ban icon next to the email field.
	  (at the left of the email field for display purpose)
	- Renaming the '_get_blacklist' method that was actually
	  searching opt_out list into 'get_opt_out_list'
	- Opt out per mailing list : Add opt_out + related fields (for display and
	  ergonomy reasons) on the relational model
	- Display relational model tree view instead of mass_mailing.contact tree
	  view when clicking on mass_mailing_list in kanban view
	  -> In order to be align between contact_nbr displayed in kanban tile and
	     the content of the tree view
	  -> mass_mailing contact is accesible via the user icon in this tree view
	- Remove custom filters 'filter_contact_subscription' and
	  'filter_contact_unsubscription' as opt_out is not on mass_mailing.contact
	  model anymore
	- Add 'is_public' to mailing list
	    The name of this mailing list can be seen (or not) by recipient in
	    the unsubscription page
	    If the mailing lists used in the mass mailing are not public,
	    the user in only informed that he has been unsubscribed.
	    If the mailing lists are public, the user is informed that he has been
	    unsubscribed from the mailing lists
	    and he has the choice to modify his subscription to all the public
	    mailing list he is or was subscribed to.
	- Unsubscription Page :
		- mass_mailing_contact :
		  Opt_out per mailing list, done by email and not by id, as multiple
		  contact can have the same email
		  The recipient can add/remove himself to/from the blacklist
		  The recipient can send a feedback about why he unsubscribed
		- crm.lead + res.partner :
		  Once the recipient unsubscribe, he is automatically blacklisted
		  The recipient can 'Come back' and remove himself from the blacklist
		  if he changes his mind
		- Show blacklist button parameter added in config :
		  The idea is to enable/disable the fact that the recipient can add
		  himself to the blacklist by showing or not the 'blacklist me' button
		  Only applies for mass_mailing.contact. The recipient, once
		  blacklisted, can always, no matter the value of this parameter,
		  'come back' and unblacklist himself

crm.lead + res.partner :
	- Replace opt_out by blacklist in crm.lead + res.partner models.
	  As when a res.partner or crm.lead unsubcribe, we assume that the recipient
	  does not want to receive mass mailing anymore, at all, even if we adds him
	  to a mailing list afterwards. He is then blacklisted to avoid this.
	  With this behaviour, if a new lead is created with the same email address,
	  he won't be able to receive mail in mass_mode.
	  But he will still be able to receive '1 to 1' direct email.

Task ID 33224
Closes #25966
2018-08-10 17:46:08 +02:00
David Beguin 98ce81cac5 [IMP] mail - mail.blacklist: Not send mass_mail to recipient that does't want to
Purpose
=======
Improve mailing subscription to be more compliant with the European GDPR law.
Keep a list of people who does not want to receive promotional emails
(or mass mailing in general) anymore.

Specifications
===========
This commit is regrouping some main changes on mass mailing.
- Added blacklist : Avoid sending mass mailing to blacklisted recipient
  (blacklisted = email address that doens't want to receive mass mailing anymore)

Detailed implementation
===================
Mail :
- Add Blacklist mechanism in mail module (NOT in mass-mailing) :
  as we can send mass-mail without the mass-mailing module
- Unicity in email -> To avoid error in import, override the create and return
  the existing record if any, else, create the record normally.
- Blacklisting is done by email address and is cross model.
  Will apply to model that inherit the blacklist.mixin.
- field 'is_blacklisted' -> computed : check if email is in blacklist
  + search method to be able to filter on is_blacklisted
- When a email address is blacklisted, it will never get mass mailings anymore.
  Even if the email address is added to another mailing lists
- Avoid sending notification to blacklisted recipients when sending email
  in mass mail mode. If the recipient is blacklisted, we should not even send a
  notification in the recipient's chatter for an email that he won't even
  receive.
- When a email address is blacklisted, it can still get 'normal' mailings.
- The blacklist shoud be accessible in
  Mass Mailing / Configuration / Blacklist
  and Settings / Technical / Email / Blacklist
  -> Renaming Settings / Technical / White / Black List config menu item
     into Channel Moderation to avoid confusion with Mass Mail Blacklist
- Add indexes to the blacklist table (on email) to make it fast for access for
  the different use cases
- _primary_email : attribute that must be overriden to specify which field must
  be used as email in the blacklist mechanism.
- Filtering the blacklisted recipient in mail composer :
  done in mail._get mail value()
  In case of real mass mailing, we need the statistics to be computed in order
  to know how many recipients were ignored in the mail.
  So we cannot avoid sending mail but instead flag the mail as canceled.

Task ID 33224
2018-08-10 17:46:08 +02:00
Deep Patel 967d228a44 [IMP] mass_mailing, mail: added support for media queries in mass mail
- Email generated from mass mailing will have its own layout with internal css.
- strip_classes is removed from mail_message because mail client are now supporting
  internal stylesheet. we need it for make mail responsive.

mail: manually removed classes from incoming mail body

Because we removed strip_classes from mail message body field because we want to
allow classes in outgoing mail to make it responsive but classes are not removed
from incoming mails so here we manually removed classes from incoming mail.

opw-1836556
2018-08-06 16:06:45 +02:00
Kinjal Mehta d2b55d75a8 [IMP] mail,mass_mailing: changed duplicate field label in the same model 2018-01-04 17:56:54 +05:30
Raphael Collet c21fed6ea4 [FIX] performance: use IrModel._get instead of search 2017-09-21 16:10:13 +02:00
Yannick Tivisse 51b5ee7c3c [IMP] mass_mailing: choose model among all chatter models
This commit removes the strange selection box based on a magic flag and
some strange methods returning a string. Instead just allow to send mass
mailing on all models inheriting from mail.thread using the is mail
thread flag.

Various addons are updated to remove the _mail_mass_mailing class
attribute used to determine mass mailing capability.

We consider people could send a mass mailing on every model inheriting
from mail.thread. It makes no sense to limit it to a given set of addons.
2017-09-15 15:56:23 +02:00
Pierre Masereel 2c666af5d1 [FIX] mass_mailing: send mail to partner without email
When you send a mass mailing to muiltiple partner, if some of them have
no email adresse, it can lead to errors because of the variable 'recips'
is not set if the first occurence in the 'for loop' has no email.

To fix this, we always set the variable 'recips' by replacing the 'elif'
close by a 'else' one

introduced in rev: https://github.com/odoo/odoo/commit/65ed4553a50fdbefc986b7d21f87a81c42b743c7
2017-05-04 18:16:46 +02:00
Lucas Perais (lpe) 65ed4553a5 [FIX] mass_mailing: make blacklist and seenlist work with res_partner
Before this commit, the filtering brought by commit ca989b6 did not work when
no email_to was present. Which is the case for mass-mailings based on
res.partner records.

OPW 728321

Closes #16745
2017-05-03 14:54:55 +02:00
Olivier Dony ca989b6548 [FIX] mass_mailing: prevent duplicates and sending to opted-out
The mass-mailing App suffered from severe issues due to its inability
to detect and handle duplicates "at the email level", and the absence
of any global blacklist system, leading to lack of user trust.

Mailing-lists typically include multiple records with the same email,
and it is critical to avoid sending them the same email several times.
A related problem is the unsubscription of an email that is present
in other records (duplicates). Opting out the first email should
automatically blacklist it for other records as well.

Ideally we should have a global blacklist table in order to
share the unsubscription requests globally across models (Leads,
Partners, Mailing-list contacts). It would also allow importing
it from other blacklist systems. (TODO for master)

This commit introduces a partial solution, made of several
small changes:

- In mail.mail: double-check that an outgoing email has the
correct status (`outgoing`) before sending it. This allows
adding emails in the queue and cancelling them before they
actually get sent.
- In crm.lead: force predictable recipients for mass-mailing,
by always using the email of the lead rather than the email
of the linked partner when there is one. This simplifies the
computation of the blacklist and seen list. Other areas in
the codebase already assume as much.
- In mass.mailing:

 + Before sending out a mailing-list batch, compute the
   blacklist (all opted-out emails) and the seen_list
   (emails who previously received this mail) to make
   sure we only ever target valid recipients.
 + While delivering the mass-mailing, any email targeting
   an address that is in the blacklist or "seen list" is
   canceled before being sent. The corresponding statistics
   entry is considered "not delivered".
   Also updates the "seen list" continuously.
 + When a mass-mail belongs to a campaign with the
   "unique AB/B testing" flag, the "seen list" is
   common to the whole campaign, as an extra safety.
 + Auto-delete mass-mailing test messages sent with the
   test wizard, to avoid polluting the mail_mail table

Note: this fix uses a simple regex for efficiently extracting
the blacklist in pure SQL from different models, and doing so,
assumes that each record only holds a single email
(no comma-separated adresses). This should be sufficient for
most cases. The regex:

                   ([^ ,;<@]+@[^> ,;]+)
2017-03-27 18:47:59 +02:00
Keyur Gajjar bbca135410 [MIG] mass_mailing: code migration to new api
NB: A controller in website_mass_mailing has been migrated too. It's not a real issue
as this module will also be migrated in the days to come
2016-06-17 11:23:12 +02:00
Thibault Delavallée 4b122ad41d [MIGR] mail: migration to the new API 2015-04-27 10:36:15 +02:00
Julien De Coster d88c34d11e [IMP] Mass mailings send in cron
1. The merge of the "email_template" module into the "mail" module.
2. The send action of the mass mailing has been moved from the frontend to a cron, because it was too slow to send over 10,000 mails (the user's browser was blocked for 15 - 20 minutes). Mass mailings have now their own process in the kanban view.
3. Mails sent from the mail form are sent immediatly instead of from the mail queue (for instance, when you go to sales > customers > list view > select 2 -3 customers > More > Partner Mass Mailing).
4. Users have now the choice from which mailing list they want to unsubscribe when they click on the unsubscribe link at the bottom of the mail.
5. Mass mailings inherit from their campaign UTMs and mass mailing campaigns are linked to an UTM campaign.
6. Many little improvements
2015-01-07 18:01:58 +01:00
Bhavik Bagdiya ea6a3785bb [IMP] mass_mailing: option to keep sent emails 2014-10-02 09:34:29 +02:00
Olivier LAURENT ac9954d210 * [8.0][mass_mailing] some fixes
* [FIX] rename wrong mailing_type field and add missing fields when creating a mass mailing from the composer
* [FIX] coerce tooltip to an unicode string to avoid a json crash when locale produces a non unicode string for strftime(%B)
* [FIX] repair wrong sql statement computing statistics
2014-08-21 11:07:00 +02:00
Thibault Delavallée cbdf7830b1 [FIX] mass_mailing: fixes:
- fixed keeping the original message for routing, only when choosing to reply in the
original thread (notification=True)
- auto delete sent emails explicitely
- mail_thread: routing: fixed replies always choosen even when replying to emails
with a specified reply_to (using ref_match in the algorithm)
- mail_thread: routing: instead of exclusive routing heuristics, use each case
as a fallback of the previous.
2014-06-02 13:52:27 +02:00
Thibault Delavallée 3eaeae55a0 [IMP] mail, mass_mailing: better recipientsz computation
for mass mailing, composer and template. This allows to have one method computing recipints
and avoid repetiting myself.

bzr revid: tde@openerp.com-20140415154700-zu2izvxfjq1k4h4a
2014-04-15 17:47:00 +02:00