Browse Source

Merge remote changes for whatsapp_web

odoo 1 month ago
parent
commit
18a377b2c9
1 changed files with 19 additions and 0 deletions
  1. 19 0
      models/discuss_channel.py

+ 19 - 0
models/discuss_channel.py

@@ -1,3 +1,4 @@
+from datetime import datetime, timedelta
 from odoo import models, api, fields
 from odoo import models, api, fields
 from odoo.addons.mail.tools.discuss import Store
 from odoo.addons.mail.tools.discuss import Store
 from odoo.exceptions import ValidationError
 from odoo.exceptions import ValidationError
@@ -8,6 +9,24 @@ class DiscussChannel(models.Model):
 
 
     is_whatsapp_web = fields.Boolean(compute="_compute_is_whatsapp_web")
     is_whatsapp_web = fields.Boolean(compute="_compute_is_whatsapp_web")
 
 
+    def write(self, vals):
+        """
+        Override write to debounce 'last_interest_dt' updates.
+        If the channel was updated less than 10 seconds ago, skip updating last_interest_dt.
+        This prevents 'concurrent update' errors during high traffic (e.g. active WhatsApp groups).
+        """
+        if "last_interest_dt" in vals and len(self) == 1:
+            # Check if we have a recent update
+            if self.last_interest_dt:
+                # Calculate time since last update
+                # Note: last_interest_dt is usually UTC
+                time_since_last = datetime.now() - self.last_interest_dt
+                if time_since_last < timedelta(seconds=10):
+                    # Skip updating this field
+                    del vals["last_interest_dt"]
+
+        return super().write(vals)
+
     @api.depends("channel_type", "wa_account_id.whatsapp_web_url")
     @api.depends("channel_type", "wa_account_id.whatsapp_web_url")
     def _compute_is_whatsapp_web(self):
     def _compute_is_whatsapp_web(self):
         for record in self:
         for record in self: