diff --git a/whatsapp_mail_messaging/__init__.py b/whatsapp_mail_messaging/__init__.py index fbc778978..ed5fac8d4 100644 --- a/whatsapp_mail_messaging/__init__.py +++ b/whatsapp_mail_messaging/__init__.py @@ -19,5 +19,6 @@ # If not, see . # ############################################################################# +from . import controllers from . import model from . import wizard diff --git a/whatsapp_mail_messaging/__manifest__.py b/whatsapp_mail_messaging/__manifest__.py index 8144a9098..c16530eef 100644 --- a/whatsapp_mail_messaging/__manifest__.py +++ b/whatsapp_mail_messaging/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Odoo Whatsapp Connector', - 'version': '16.0.1.1.0', + 'version': '16.0.1.1.2', 'category': 'Extra Tools', 'summary': """Odoo Whatsapp Connector For Sales, Invoice, and Floating button in Website""", 'description': """Added options for sending Whatsapp messages and Mails in systray bar,sale order, invoices, @@ -38,6 +38,7 @@ 'views/sale_order_inherited.xml', 'views/account_move_inherited.xml', 'views/website_inherited.xml', + 'views/selection_message_views.xml', 'views/res_config_settings_views.xml', 'views/res_company_views.xml', 'wizard/wh_message_wizard.xml', diff --git a/whatsapp_mail_messaging/controllers/__init__.py b/whatsapp_mail_messaging/controllers/__init__.py new file mode 100644 index 000000000..c51c0ecba --- /dev/null +++ b/whatsapp_mail_messaging/controllers/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import whatsapp_mail_messaging diff --git a/whatsapp_mail_messaging/controllers/whatsapp_mail_messaging.py b/whatsapp_mail_messaging/controllers/whatsapp_mail_messaging.py new file mode 100644 index 000000000..8a530a602 --- /dev/null +++ b/whatsapp_mail_messaging/controllers/whatsapp_mail_messaging.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import http +from odoo.http import request + + +class SendMessage(http.Controller): + """ Controller for getting whatsapp message templates """ + @http.route('/whatsapp_message', type='json', auth='public') + def whatsapp_message(self, **kwargs): + """ Whatsapp message templates """ + messages = request.env['selection.message'].sudo().search_read( + fields=['name', 'message']) + return {'messages': messages} + + @http.route('/mobile_number', type='json', auth='public') + def mobile_number(self, **kwargs): + """ Mobile number of website """ + mobile_number = request.env['website'].sudo().search_read( + fields=['mobile_number'] + ) + return {'mobile': mobile_number} diff --git a/whatsapp_mail_messaging/doc/changelog.md b/whatsapp_mail_messaging/doc/changelog.md index 3a9c8935c..0f5fd7723 100644 --- a/whatsapp_mail_messaging/doc/changelog.md +++ b/whatsapp_mail_messaging/doc/changelog.md @@ -12,6 +12,11 @@ - Added Default Message functionality where users can save message templates and use these templates for sending Whatsapp Message. #### 20.05.2024 -#### Version 16.0.1.1.0 +#### Version 16.0.1.1.1 #### UPDT -- Added new message template feature. \ No newline at end of file +- Added new message template feature. + +#### 02.09.2024 +#### Version 16.0.1.1.2 +##### UPDT +- Fixed bugs in sending messages from public users. \ No newline at end of file diff --git a/whatsapp_mail_messaging/model/__init__.py b/whatsapp_mail_messaging/model/__init__.py index 16780b68b..2a511de7f 100644 --- a/whatsapp_mail_messaging/model/__init__.py +++ b/whatsapp_mail_messaging/model/__init__.py @@ -24,3 +24,4 @@ from . import sale_order from . import account_move from . import res_config_settings from . import res_company +from . import selection_message diff --git a/whatsapp_mail_messaging/model/selection_message.py b/whatsapp_mail_messaging/model/selection_message.py new file mode 100644 index 000000000..1e3d05f95 --- /dev/null +++ b/whatsapp_mail_messaging/model/selection_message.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2021-TODAY Cybrosys Technologies() +# Author: Cybrosys Techno Solutions() +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +from odoo import api, fields, models + + +class SelectionMessage(models.Model): + """ Message Templates """ + _name = 'selection.message' + _description = 'Selection Message' + + name = fields.Char(string="Name", + help="Name of message template") + message = fields.Text(string="Message", required=True, + help="The message to send") diff --git a/whatsapp_mail_messaging/security/ir.model.access.csv b/whatsapp_mail_messaging/security/ir.model.access.csv index 245c7ddc6..bc0bd180d 100644 --- a/whatsapp_mail_messaging/security/ir.model.access.csv +++ b/whatsapp_mail_messaging/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_whatsapp_message_wizard,access.whatsapp.message.wizard,model_whatsapp_message_wizard,base.group_user,1,1,1,1 +access_selection_message_user,access.selection.message.user,model_selection_message,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/whatsapp_mail_messaging/static/src/js/whatsapp_icon_website.js b/whatsapp_mail_messaging/static/src/js/whatsapp_icon_website.js index 5b56bd32d..89dfac603 100644 --- a/whatsapp_mail_messaging/static/src/js/whatsapp_icon_website.js +++ b/whatsapp_mail_messaging/static/src/js/whatsapp_icon_website.js @@ -14,7 +14,7 @@ odoo.define('whatsapp_mail_messaging.whatsapp_icon_website.js', function (requir this._super.apply(this, arguments); }, _onClickWhatsappIcon: function (ev) { - $('#ModalWhatsapp').css('display', 'block'); + $('#ModalWhatsapp').css('display', 'block'); }, }); }); \ No newline at end of file diff --git a/whatsapp_mail_messaging/static/src/js/whatsapp_modal.js b/whatsapp_mail_messaging/static/src/js/whatsapp_modal.js index 6d2c3c86e..01182f6c8 100644 --- a/whatsapp_mail_messaging/static/src/js/whatsapp_modal.js +++ b/whatsapp_mail_messaging/static/src/js/whatsapp_modal.js @@ -3,6 +3,7 @@ odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { var publicWidget = require('web.public.widget'); var ajax = require('web.ajax'); + var rpc = require('web.rpc'); publicWidget.registry.deliveryDateToggl = publicWidget.Widget.extend({ selector: '#ModalWhatsapp', @@ -17,77 +18,64 @@ odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { this._super.apply(this, arguments); }, onclickCustomRadio: function () { - document.getElementById("myFormControl").style.display = "none"; + document.getElementById("myFormControl").style.display = "none"; }, onclickDefaultRadio: function () { - document.getElementById("myFormControl").style.display = "block"; - var self = this; - this._rpc({ - model: 'selection.messages', // Your Odoo model - method: 'search_read', // Use search_read to retrieve data - fields: ['name', 'message'], // Specify the fields you want to retrieve - }).then(function (data) { - // Process the data received from the server - - self.updateUI(data); - }); + document.getElementById("myFormControl").style.display = "block"; + let data = ajax.jsonRpc('/whatsapp_message', {data:'data'}) + this.updateUI(data); }, - updateUI: function (data) { - - // Clear existing options - var selectElement = document.getElementById("myFormControl"); - selectElement.innerHTML = ''; - - // Add default option - var defaultOption = document.createElement('option'); - defaultOption.textContent = 'Select the Template'; - selectElement.appendChild(defaultOption); - - // Add options from the data - data.forEach(function (record) { - var option = document.createElement('option'); - option.value = record.id; - option.textContent = record.name; - option.setAttribute('data-message', record.message); // Save the message as a data attribute - selectElement.appendChild(option); - }); - }, - onSelectChange: function () { - var selectElement = document.getElementById("myFormControl"); - var textareaElement = document.getElementById("exampleFormControlTextarea1"); - var selectedOption = selectElement.options[selectElement.selectedIndex]; - var selectedMessage = selectedOption.getAttribute('data-message'); - // Update the textarea with the message from the selected option - textareaElement.value = selectedMessage; - }, - onCloseButtonClick: function () { - //Closing the Modal - document.getElementById("ModalWhatsapp").style.display = "none"; - }, -onSendMessageClick: function () { - // Send Message to Whatsapp - var textareaElement = document.getElementById("exampleFormControlTextarea1"); - var messageString = textareaElement.value; - this._rpc({ - model: 'website', - method: 'search_read', - fields: ['mobile_number'], - }).then(function (data) { - // Process the data received from the server -if (data && data.length > 0 && 'mobile_number' in data[0] && data[0].mobile_number) { - // Check if 'mobile_number' is present in the first item of the 'data' array and is not falsy - var mobileNumber = data[0].mobile_number; - // Construct the WhatsApp URL using the mobile number and messageString - var whatsappUrl = 'https://api.whatsapp.com/send?phone=' + mobileNumber + '&text=' + encodeURIComponent(messageString); - // Open the WhatsApp URL in a new tab or window - window.open(whatsappUrl, '_blank'); -} else { - // If mobile number is not available or falsy, hide the element with id "phoneMessage" - document.getElementById("phoneMessage").style.display = "block"; - // You might want to display a user-friendly error message on the UI -} -}) -}, + updateUI: function (data) { + // Clear existing options + var selectElement = document.getElementById("myFormControl"); + selectElement.innerHTML = ''; + // Add default option + var defaultOption = document.createElement('option'); + defaultOption.textContent = 'Select the Template'; + selectElement.appendChild(defaultOption); + // Add options from the data + data.then((result) => { + const messages = result.messages; + messages.forEach((message) => { + var option = document.createElement('option'); + option.value = message.id; + option.textContent = message.name; + option.setAttribute('data-message', message.message); + selectElement.appendChild(option); + }); + }) + }, + onSelectChange: function () { + var selectElement = document.getElementById("myFormControl"); + var textareaElement = document.getElementById("exampleFormControlTextarea1"); + var selectedOption = selectElement.options[selectElement.selectedIndex]; + var selectedMessage = selectedOption.getAttribute('data-message'); + // Update the textarea with the message from the selected option + textareaElement.value = selectedMessage; + }, + onCloseButtonClick: function () { + //Closing the Modal + document.getElementById("ModalWhatsapp").style.display = "none"; + }, + onSendMessageClick: function () { + // Send Message to Whatsapp + var textareaElement = document.getElementById("exampleFormControlTextarea1"); + var messageString = textareaElement.value; + let data = ajax.jsonRpc('/mobile_number', {data:'data'}) + data.then((result) => { + const mobile_num = result.mobile; + mobile_num.forEach((mobile) => { + if (mobile_num && mobile_num.length > 0 && 'mobile_number' in mobile_num[0] && mobile_num[0].mobile_number) { + var mobileNumber = mobile_num[0].mobile_number; + // Construct the WhatsApp URL using the mobile number and messageString + var whatsappUrl = 'https://api.whatsapp.com/send?phone=' + mobileNumber + '&text=' + encodeURIComponent(messageString); + window.open(whatsappUrl, '_blank'); + } else { + document.querySelector("#phoneMessage").style.display = "block"; + } + }); + }) + }, }); }); \ No newline at end of file diff --git a/whatsapp_mail_messaging/views/portal_whatsapp_view.xml b/whatsapp_mail_messaging/views/portal_whatsapp_view.xml index d6e2fd97a..cddde0cb9 100644 --- a/whatsapp_mail_messaging/views/portal_whatsapp_view.xml +++ b/whatsapp_mail_messaging/views/portal_whatsapp_view.xml @@ -73,6 +73,5 @@ - \ No newline at end of file diff --git a/whatsapp_mail_messaging/views/selection_message_views.xml b/whatsapp_mail_messaging/views/selection_message_views.xml new file mode 100644 index 000000000..d23af3569 --- /dev/null +++ b/whatsapp_mail_messaging/views/selection_message_views.xml @@ -0,0 +1,54 @@ + + + + + selection.message.view.tree + selection.message + + + + + + + + + + selection.message.view.form + selection.message + +
+ + + + + + + + + + + + + + +
+
+
+ + + Selection Message + selection.message + ir.actions.act_window + tree,form + + + + +