From ac4a51436454f996509f23326d295a5777797f54 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Tue, 17 Sep 2024 10:28:29 +0200 Subject: [PATCH] [IMP] Avoid duplicate sendings in mass communications --- .../wizards/generate_communication_wizard.py | 10 ++++++++++ sbc_compassion/models/correspondence.py | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/partner_communication/wizards/generate_communication_wizard.py b/partner_communication/wizards/generate_communication_wizard.py index f5bc1e730..7a065858b 100644 --- a/partner_communication/wizards/generate_communication_wizard.py +++ b/partner_communication/wizards/generate_communication_wizard.py @@ -120,7 +120,17 @@ def close(self): def generate_communications(self, async_mode=True): """Create the communication records""" + processed_addresses = set() + send_mode = self.send_mode or self.model_id.send_mode for partner in self.partner_ids: + address = ( + partner.email + if "digital" in send_mode + else f"{partner.zip} {partner.city}" + ) + if address in processed_addresses: + continue + processed_addresses.add(address) vals = { "partner_id": partner.id, "object_ids": partner.id, diff --git a/sbc_compassion/models/correspondence.py b/sbc_compassion/models/correspondence.py index 2a9b2c73b..1b1106b31 100644 --- a/sbc_compassion/models/correspondence.py +++ b/sbc_compassion/models/correspondence.py @@ -234,8 +234,7 @@ class Correspondence(models.Model): # Letter remote access ###################### uuid = fields.Char( - required=True, default=lambda self: self._get_uuid(), - copy=False, index=True + required=True, default=lambda self: self._get_uuid(), copy=False, index=True ) read_url = fields.Char(compute="_compute_read_url", store=True)