[FIX] whatsapp: check state of phone blacklist
When a customer sends a message to Odoo via WhatsApp, their number is saved in the `phone.blacklist` model, but the active state is set to False. If the customer sends 'STOP', it will be set to True, and if the customer sends a new message, it will again be set to False.
Before sending a message from Odoo to a customer via WhatsApp, we check if the number is in the `phone.blacklist` with this line in whatsapp_message.py
if self.env['phone.blacklist'].sudo().search([('number', 'ilike', number)]):
In SaaS 16.4, this line returns the following SQL request:
SELECT "phone_blacklist"."id" FROM "phone_blacklist" WHERE (("phone_blacklist"."active" = true) AND ("phone_blacklist"."number"::text ILIKE '%32491730941%')) ORDER BY "phone_blacklist"."id";
Here, we check if the Active state is True to block the message if necessary.
In 17, this same line returns this SQL request:
SELECT "phone_blacklist"."id" FROM "phone_blacklist" WHERE ("phone_blacklist"."number"::text ILIKE '%32491730941%') ORDER BY "phone_blacklist"."id";
I correct it in a PR https://github.com/odoo/enterprise/pull/55498
But if we go further we find that it's really because of the active_test = False of this line in thread.py
thread = request.env[thread_model].with_context(active_test=False).search([("id", "=", thread_id)])
from this commit
https://github.com/odoo-dev/odoo/commit/8b2605b99348b7707b3db3db46af880c17c7029c
with the fix of this PR, the discussion on Whatsapp is now possible and we keep the fix of the previous commit.
opw-3704136
closes odoo/odoo#152273
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -94,6 +94,7 @@ class ThreadController(http.Controller):
|
||||
'ids': canned_response_ids,
|
||||
})
|
||||
thread = request.env[thread_model].with_context(active_test=False).search([("id", "=", thread_id)])
|
||||
thread = thread.with_context(active_test=True)
|
||||
if not thread:
|
||||
raise NotFound()
|
||||
if "body" in post_data:
|
||||
|
||||
Reference in New Issue
Block a user