Browse Source

Aug 30 [UPDT] Updated 'whatsapp_mail_messaging'

pull/332/merge
AjmalCybro 8 months ago
parent
commit
ebc950afa7
  1. 1
      whatsapp_mail_messaging/__init__.py
  2. 3
      whatsapp_mail_messaging/__manifest__.py
  3. 22
      whatsapp_mail_messaging/controllers/__init__.py
  4. 41
      whatsapp_mail_messaging/controllers/whatsapp_mail_messaging.py
  5. 9
      whatsapp_mail_messaging/doc/changelog.md
  6. 1
      whatsapp_mail_messaging/model/__init__.py
  7. 33
      whatsapp_mail_messaging/model/selection_message.py
  8. 1
      whatsapp_mail_messaging/security/ir.model.access.csv
  9. 2
      whatsapp_mail_messaging/static/src/js/whatsapp_icon_website.js
  10. 124
      whatsapp_mail_messaging/static/src/js/whatsapp_modal.js
  11. 1
      whatsapp_mail_messaging/views/portal_whatsapp_view.xml
  12. 54
      whatsapp_mail_messaging/views/selection_message_views.xml

1
whatsapp_mail_messaging/__init__.py

@ -19,5 +19,6 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import controllers
from . import model
from . import wizard

3
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',

22
whatsapp_mail_messaging/controllers/__init__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# 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 <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import whatsapp_mail_messaging

41
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(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# 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 <http://www.gnu.org/licenses/>.
#
#############################################################################
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}

9
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.
- Added new message template feature.
#### 02.09.2024
#### Version 16.0.1.1.2
##### UPDT
- Fixed bugs in sending messages from public users.

1
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

33
whatsapp_mail_messaging/model/selection_message.py

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2021-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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")

1
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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_whatsapp_message_wizard access.whatsapp.message.wizard model_whatsapp_message_wizard base.group_user 1 1 1 1
3 access_selection_message_user access.selection.message.user model_selection_message base.group_user 1 1 1 1

2
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');
},
});
});

124
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";
}
});
})
},
});
});

1
whatsapp_mail_messaging/views/portal_whatsapp_view.xml

@ -73,6 +73,5 @@
</div>
</div>
</xpath>
</template>
</odoo>

54
whatsapp_mail_messaging/views/selection_message_views.xml

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Tree View -->
<record id="selection_message_view_tree" model="ir.ui.view">
<field name="name">selection.message.view.tree</field>
<field name="model">selection.message</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="message"/>
</tree>
</field>
</record>
<!-- Form View-->
<record id="selection_message_view_form" model="ir.ui.view">
<field name="name">selection.message.view.form</field>
<field name="model">selection.message</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<group>
<field name="name"/>
</group>
</group>
<notebook>
<page string="Message">
<group>
<field colspan="2" name="message" widget="text_emojis"
nolabel="1"
placeholder="Write Message here...."
/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<!-- Action of Menu item -->
<record id="selection_message_action" model="ir.actions.act_window">
<field name="name">Selection Message</field>
<field name="res_model">selection.message</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="selection_message_view_tree"/>
</record>
<!-- Menu item for message templates -->
<menuitem name="Whatsapp Messages"
id="menu_website_selection_message"
action="selection_message_action"
parent="website.menu_website_global_configuration"
sequence="50"/>
</odoo>
Loading…
Cancel
Save