Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] mass_mailing: make recipients unique by email #604

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion addons/mass_mailing/models/mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,27 @@ def _get_mass_mailing_context(self):

def _get_recipients(self):
mailing_domain = self._parse_mailing_domain()
res_ids = self.env[self.mailing_model_real].search(mailing_domain).ids
res_model = self.env[self.mailing_model_real]
if "email" in res_model._fields:
res_ids_grouped = res_model.read_group(
mailing_domain, ["__my_id:max(id)"], ["email"]
)
res_ids = [r["__my_id"] for r in res_ids_grouped]

elif "partner_id" in res_model._fields:
res_ids_grouped = res_model.read_group(
mailing_domain, ["__my_id:max(id)"], ["partner_id"], orderby="partner_id"
)
seen = set()
res_ids = []
for r in res_ids_grouped:
curr_email = self.env["res.partner"].browse(r["partner_id"][0]).email
if curr_email in seen:
continue
seen.add(curr_email)
res_ids.append(r["__my_id"])
else:
res_ids = res_model.search(mailing_domain).ids

# randomly choose a fragment
if self.ab_testing_enabled and self.ab_testing_pc < 100:
Expand Down