Maintainers
+Maintainers
This module is maintained by the OCA.
@@ -510,6 +505,5 @@ diff --git a/mail_gateway_whatsapp/README.rst b/mail_gateway_whatsapp/README.rst index 13d3b85db4..e137810160 100644 --- a/mail_gateway_whatsapp/README.rst +++ b/mail_gateway_whatsapp/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ===================== Mail Whatsapp Gateway ===================== @@ -17,7 +13,7 @@ Mail Whatsapp Gateway .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github diff --git a/mail_gateway_whatsapp/__manifest__.py b/mail_gateway_whatsapp/__manifest__.py index 5f8cc8bb83..86e7edc534 100644 --- a/mail_gateway_whatsapp/__manifest__.py +++ b/mail_gateway_whatsapp/__manifest__.py @@ -3,8 +3,7 @@ { "name": "Mail Whatsapp Gateway", - "summary": """ - Set a gateway for whatsapp""", + "summary": "Set a gateway for WhatsApp", "version": "18.0.1.0.0", "license": "AGPL-3", "author": "Creu Blanca, Dixmit, Odoo Community Association (OCA)", @@ -14,6 +13,7 @@ "data": [ "security/security.xml", "security/ir.model.access.csv", + "views/ir_actions_server_views.xml", "wizards/whatsapp_composer.xml", "wizards/mail_compose_gateway_message.xml", "views/mail_whatsapp_template_views.xml", diff --git a/mail_gateway_whatsapp/models/__init__.py b/mail_gateway_whatsapp/models/__init__.py index 6be3802ded..4b39010d9d 100644 --- a/mail_gateway_whatsapp/models/__init__.py +++ b/mail_gateway_whatsapp/models/__init__.py @@ -1,3 +1,4 @@ +from . import ir_actions_server from . import mail_gateway from . import mail_thread from . import mail_gateway_whatsapp diff --git a/mail_gateway_whatsapp/models/ir_actions_server.py b/mail_gateway_whatsapp/models/ir_actions_server.py new file mode 100644 index 0000000000..b282e3da11 --- /dev/null +++ b/mail_gateway_whatsapp/models/ir_actions_server.py @@ -0,0 +1,90 @@ +# Copyright 2025 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import markupsafe + +from odoo import api, exceptions, fields, models + + +class IrServerAction(models.Model): + _inherit = "ir.actions.server" + + state = fields.Selection( + selection_add=[("whatsapp", "WhatsApp message")], + ondelete={"whatsapp": "cascade"}, + ) + whatsapp_gateway_id = fields.Many2one( + comodel_name="mail.gateway", domain=[("gateway_type", "=", "whatsapp")] + ) + whatsapp_partner = fields.Char() + whatsapp_template_id = fields.Many2one( + comodel_name="mail.whatsapp.template", + domain="[('gateway_id', '=', whatsapp_gateway_id),('model_id', '=', model_id)]", + ) + + @api.depends("state") + def _compute_available_model_ids(self): + gateway_based = self.filtered(lambda action: action.state == "whatsapp") + if gateway_based: + mail_models = self.env["ir.model"].search( + [("is_mail_thread", "=", True), ("transient", "=", False)] + ) + gateway_based.available_model_ids = mail_models.ids + return super( + IrServerAction, self - gateway_based + )._compute_available_model_ids() + + @api.constrains("state", "model_id") + def _check_whatsapp_model_coherency(self): + for action in self: + if action.state == "whatsapp" and ( + action.model_id.transient or not action.model_id.is_mail_thread + ): + raise exceptions.ValidationError( + self.env._( + "Sending WhatsApp message can only be done on a non transient " + "mail.thread model" + ) + ) + + def _run_action_whatsapp_multi(self, eval_context=None): + # Method called by upstream in ir.actions~_get_runner() using naming convention + context = self.env.context + if ( + not self.whatsapp_template_id + or (not context.get("active_ids") and not context.get("active_id")) + or self._is_recompute() + ): + return False + res_ids = context.get("active_ids", [context.get("active_id")]) + for record in self.env[self.model_id.model].browse(res_ids): + partner_id = int( + self.env["mail.render.mixin"]._render_template( + self.whatsapp_partner, record._name, [record.id] + )[record.id] + ) + partner = self.env["res.partner"].browse(partner_id) + partner._whatsapp_get_channel("mobile", self.whatsapp_gateway_id) + gateway_channel = partner.gateway_channel_ids.filtered( + lambda x: x.gateway_id == self.whatsapp_gateway_id + ) + body = markupsafe.Markup( + self.whatsapp_template_id.with_context( + default_res_id=record.id + ).render_body_message() + ) + # pylint: disable=translation-required + record.with_context( + whatsapp_template_id=self.whatsapp_template_id.id, res_id=record.id + ).message_post( + body=body, + subtype_xmlid="mail.mt_comment", + message_type="comment", + gateway_notifications=[ + { + "channel_type": "gateway", + "gateway_channel_id": gateway_channel.id, + "partner_id": partner_id, + } + ], + ) + return False diff --git a/mail_gateway_whatsapp/static/description/index.html b/mail_gateway_whatsapp/static/description/index.html index 517190b8e5..dc3642eedc 100644 --- a/mail_gateway_whatsapp/static/description/index.html +++ b/mail_gateway_whatsapp/static/description/index.html @@ -3,7 +3,7 @@
-This module allows to respond whatsapp chats.
This way, a group of users can respond customers or any other set of partners in an integrated way.
@@ -399,9 +394,9 @@You need to create a WhatsApp Business Account (WABA), a Meta App and define a phone number. You can follow this steps.
@@ -410,7 +405,7 @@In order to make the webhook accessible, the system must be public.
Once you have created the Meta App, you need to add the gateway and webhook. In order to make it you must follow this steps:
WhatsApp templates
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -467,16 +462,16 @@
Do not contact contributors directly about support or help with technical issues.
Olga Marco <olga.marco@creublanca.es>
This work has been funded by AEOdoo (Asociación Española de Odoo - https://www.aeodoo.org)