Removal of SMS Settings and SMS Parameters from ERPNext (#10033)
* Removal of SMS Settings and SMS Parameter from ERPNext. * [DOCS]Documentation for Two Factor Authentication * [Patch]Point SMS module to frappe core * Rearrange doc help index.txt to fit * [DOCS]Update Documentation for Two Factor Authentication
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-1.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-2.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-3.png
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-4.png
Normal file
After Width: | Height: | Size: 182 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-5.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-6.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor-8.png
Normal file
After Width: | Height: | Size: 430 KiB |
BIN
erpnext/docs/assets/img/articles/twofactor/twofactor_app.jpeg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
erpnext/docs/assets/img/setup-wizard/twofactor.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
erpnext/docs/assets/img/setup/settings/twofactor-settings.png
Normal file
After Width: | Height: | Size: 71 KiB |
@ -9,4 +9,5 @@ managing-tree-structure-masters
|
||||
naming-series-current-value
|
||||
overwriting-data-from-data-import-tool
|
||||
rename-user
|
||||
using-custom-domain-on-erpnext
|
||||
using-custom-domain-on-erpnext
|
||||
setup-two-factor-authentication
|
@ -0,0 +1,41 @@
|
||||
#Setup Two Factor Authentication
|
||||
|
||||
##Enable Two Factor Authentication (2FA)
|
||||
|
||||
Activate two factor authentication by running the command.
|
||||
|
||||
`bench --site [sitename] enable_two_factor_auth true`
|
||||
|
||||
Specify the following in System Settings
|
||||
|
||||
* The method of OTP validation (OTP App = TOTP using Soft or Hard Token while Email/SMS = HOTP using Email or SMS
|
||||
* The expiry time for the QR Code on the server if OTP App is specified
|
||||
* The OTP Issuer Name.
|
||||
|
||||
<img alt="Enable Two Factor Auth" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-1.png">
|
||||
|
||||
|
||||
On activation of 2FA from setup, it is also activated for the Role "All". In this way, all users including the Administrator have to perform a 2nd level authentication with a token. By unchecking the "Two Factor Authentication" checkbox in the "All" role and enabling it in other roles, the need to login with a token can be limited to specific roles. 2FA does not apply to login by Web Users and API login
|
||||
|
||||
<img alt="Role Enable Two Factor Auth" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-2.png">
|
||||
|
||||
If using SMS authentication, please make sure that your SMS settings are updated
|
||||
|
||||
<img alt="SMS Settings" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-3.png">
|
||||
|
||||
If using Email, make sure that your outgoing Email account settings are updated
|
||||
|
||||
<img alt="Email Settings" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-4.png">
|
||||
|
||||
When the new user tries to log in for the first time in a system that has two-factor authentication enabled and which has the authentication option as OTP App, an email is sent containing a link to the QR Code.
|
||||
|
||||
<img alt="Email Notify Two Factor" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-5.png">
|
||||
<img alt="QR Code Page" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-6.png">
|
||||
|
||||
Scanning the QR Code with an authentication app like Google Authenticator registers the access for the user and automatically starts to generate tokens that can be used to login
|
||||
|
||||
<img alt="Two Factor Scan App" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor_app.jpeg">
|
||||
|
||||
If either of Email/SMS is used as the authentication method, you get notifications also
|
||||
|
||||
<img alt="Email and SMS" class="screenshot" src="/docs/assets/img/articles/twofactor/twofactor-8.png">
|
@ -10,4 +10,14 @@ To open System Settings, go to:
|
||||
|
||||
<img class="screenshot" alt="System Settings" src="/docs/assets/img/setup/settings/system-settings.png">
|
||||
|
||||
####Two Factor Authentication.
|
||||
Settings for Two Factor Authentication can be configured here.
|
||||
|
||||
* Select the authentication method to be used
|
||||
* Expiry time for QRCode image if "OTP App" is selected in method
|
||||
* Issuer name of the One Time Password
|
||||
|
||||
<img class="screenshot" alt="Two Factor Auth" src="/docs/assets/img/setup/settings/twofactor-settings.png">
|
||||
|
||||
|
||||
{next}
|
||||
|
@ -1,10 +1,11 @@
|
||||
step-1-language
|
||||
step-2-currency-and-timezone
|
||||
step-3-user-details
|
||||
step-4-company-details
|
||||
step-5-letterhead-and-logo
|
||||
step-6-add-users
|
||||
step-7-tax-details
|
||||
step-8-customer-names
|
||||
step-9-suppliers
|
||||
step-10-item
|
||||
step-4-two-factor-authentication
|
||||
step-5-company-details
|
||||
step-6-letterhead-and-logo
|
||||
step-7-add-users
|
||||
step-8-tax-details
|
||||
step-9-customer-names
|
||||
step-10-suppliers
|
||||
step-11-item
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Step 8: Suppliers
|
||||
# Step 10: Suppliers
|
||||
|
||||
Enter a few of your Suppliers' names.
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Step 9: Item Names
|
||||
# Step 11: Item Names
|
||||
|
||||
In this final step, please enter the names of the Items you buy or sell.
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
Enter Users Profile Details like Name, User ID and preferred password.
|
||||
|
||||
<img alt="User" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-3.png">
|
||||
<img alt="User" class="screenshot" src="/docs/assets/img/setup-wizard/step-3.png">
|
||||
|
||||
---
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
# Step 4: Two Factor Authentication
|
||||
|
||||
Enable Two Factor Athentication
|
||||
|
||||
<img alt="TwoFactor" class="screenshot" src="/docs/assets/img/setup-wizard/twofactor.png">
|
||||
|
||||
---
|
||||
###Authentication Method
|
||||
Whenevever each user logs in, based on the role set for that user,
|
||||
they will be asked for a **One Time Password** after they input
|
||||
their login details.
|
||||
|
||||
{next}
|
@ -1,9 +1,8 @@
|
||||
# Step 4: Company Details
|
||||
# Step 5: Company Details
|
||||
|
||||
Enter Company Details like Name, Abbreviation and Financial Year Details.
|
||||
|
||||
<img alt="Company Details" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-4.png">
|
||||
<img alt="Company Details" class="screenshot" src="/docs/assets/img/setup-wizard/step-4.png">
|
||||
|
||||
---
|
||||
|
@ -1,8 +0,0 @@
|
||||
# Step 6: Add Users
|
||||
|
||||
Add other users and assign them roles based on their job responsibilities.
|
||||
|
||||
<img alt="Users" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-6.png">
|
||||
|
||||
{next}
|
@ -1,9 +1,8 @@
|
||||
# Step 5: Letterhead and Logo
|
||||
# Step 6: Letterhead and Logo
|
||||
|
||||
Attach Company Letterhead and Company Logo.
|
||||
|
||||
<img alt="Company Logo and Letterhead" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-5.png">
|
||||
<img alt="Company Logo and Letterhead" class="screenshot" src="/docs/assets/img/setup-wizard/step-5.png">
|
||||
|
||||
---
|
||||
|
@ -0,0 +1,7 @@
|
||||
# Step 7: Add Users
|
||||
|
||||
Add other users and assign them roles based on their job responsibilities.
|
||||
|
||||
<img alt="Users" class="screenshot" src="/docs/assets/img/setup-wizard/step-6.png">
|
||||
|
||||
{next}
|
@ -1,9 +1,8 @@
|
||||
# Step 6: Tax Details
|
||||
# Step 8: Tax Details
|
||||
|
||||
Enter any three types of taxes which you regularly pay. This wizard will create a tax master which will calculate the taxes as per the tax-type.
|
||||
|
||||
<img alt="Tax Details" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-7.png">
|
||||
<img alt="Tax Details" class="screenshot" src="/docs/assets/img/setup-wizard/step-7.png">
|
||||
|
||||
Just set the tax name and the standard percentage levied.
|
||||
|
@ -1,10 +1,9 @@
|
||||
# Step 7: Customers
|
||||
# Step 9: Customers
|
||||
|
||||
Enter your Customer names and the contact person from that organisation.
|
||||
|
||||
|
||||
<img alt="Customers" class="screenshot"
|
||||
src="/docs/assets/img/setup-wizard/step-8.png">
|
||||
<img alt="Customers" class="screenshot" src="/docs/assets/img/setup-wizard/step-8.png">
|
||||
|
||||
---
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2017, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
frappe.db.sql('''UPDATE `tabDocType` SET module="Core"
|
||||
WHERE name IN ("SMS Parameter", "SMS Settings");''')
|
@ -35,7 +35,7 @@ erpnext.SMSManager = function SMSManager(doc) {
|
||||
|
||||
this.get_contact_number = function(contact, ref_doctype, ref_name) {
|
||||
frappe.call({
|
||||
method: "erpnext.setup.doctype.sms_settings.sms_settings.get_contact_number",
|
||||
method: "frappe.core.doctype.sms_settings.sms_settings.get_contact_number",
|
||||
args: {
|
||||
contact_name: contact,
|
||||
ref_doctype: ref_doctype,
|
||||
@ -85,7 +85,7 @@ erpnext.SMSManager = function SMSManager(doc) {
|
||||
if(v) {
|
||||
$(btn).set_working();
|
||||
frappe.call({
|
||||
method: "erpnext.setup.doctype.sms_settings.sms_settings.send_sms",
|
||||
method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
|
||||
args: {
|
||||
receiver_list: [v.number],
|
||||
msg: v.message
|
||||
|
@ -9,7 +9,7 @@ from frappe import msgprint, _
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
|
||||
from frappe.core.doctype.sms_settings.sms_settings import send_sms
|
||||
|
||||
class SMSCenter(Document):
|
||||
def create_receiver_list(self):
|
||||
|
@ -1 +0,0 @@
|
||||
SMS query parameter for SMS Settings.
|
@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
@ -1,85 +0,0 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2013-02-22 01:27:58",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "parameter",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Parameter",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": "150px",
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "value",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Value",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": "150px",
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0,
|
||||
"width": "150px"
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 1,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-07-11 03:28:08.624783",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "SMS Parameter",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"track_seen": 0
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SMSParameter(Document):
|
||||
pass
|
@ -1 +0,0 @@
|
||||
Settings for automatically sending SMS from the system.
|
@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
@ -1,202 +0,0 @@
|
||||
{
|
||||
"allow_copy": 1,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"creation": "2013-01-10 16:34:24",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "column_break0",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Eg. smsgateway.com/api/send_sms.cgi",
|
||||
"fieldname": "sms_gateway_url",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "SMS Gateway URL",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Enter url parameter for message",
|
||||
"fieldname": "message_parameter",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Message Parameter",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Enter url parameter for receiver nos",
|
||||
"fieldname": "receiver_parameter",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Receiver Parameter",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "sms_sender_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "SMS Sender Name",
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "static_parameters_section",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Enter static url parameters here (Eg. sender=ERPNext, username=ERPNext, password=1234 etc.)",
|
||||
"fieldname": "parameters",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Static Parameters",
|
||||
"no_copy": 0,
|
||||
"options": "SMS Parameter",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"icon": "fa fa-cog",
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"modified": "2015-03-02 02:24:19.692599",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "SMS Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 0,
|
||||
"email": 0,
|
||||
"export": 0,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 0,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe import _, throw, msgprint
|
||||
from frappe.utils import nowdate
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SMSSettings(Document):
|
||||
pass
|
||||
|
||||
def validate_receiver_nos(receiver_list):
|
||||
validated_receiver_list = []
|
||||
for d in receiver_list:
|
||||
# remove invalid character
|
||||
for x in [' ', '+', '-', '(', ')']:
|
||||
d = d.replace(x, '')
|
||||
|
||||
validated_receiver_list.append(d)
|
||||
|
||||
if not validated_receiver_list:
|
||||
throw(_("Please enter valid mobile nos"))
|
||||
|
||||
return validated_receiver_list
|
||||
|
||||
|
||||
def get_sender_name():
|
||||
"returns name as SMS sender"
|
||||
sender_name = frappe.db.get_single_value('SMS Settings', 'sms_sender_name') or \
|
||||
'ERPNXT'
|
||||
if len(sender_name) > 6 and \
|
||||
frappe.db.get_default("country") == "India":
|
||||
throw("""As per TRAI rule, sender name must be exactly 6 characters.
|
||||
Kindly change sender name in Setup --> Global Defaults.
|
||||
Note: Hyphen, space, numeric digit, special characters are not allowed.""")
|
||||
return sender_name
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_contact_number(contact_name, ref_doctype, ref_name):
|
||||
"returns mobile number of the contact"
|
||||
number = frappe.db.sql("""select mobile_no, phone from tabContact
|
||||
where name=%s
|
||||
and exists(
|
||||
select name from `tabDynamic Link` where link_doctype=%s and link_name=%s
|
||||
)
|
||||
""", (contact_name, ref_doctype, ref_name))
|
||||
|
||||
return number and (number[0][0] or number[0][1]) or ''
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_sms(receiver_list, msg, sender_name = '', success_msg = True):
|
||||
|
||||
import json
|
||||
if isinstance(receiver_list, basestring):
|
||||
receiver_list = json.loads(receiver_list)
|
||||
if not isinstance(receiver_list, list):
|
||||
receiver_list = [receiver_list]
|
||||
|
||||
receiver_list = validate_receiver_nos(receiver_list)
|
||||
|
||||
arg = {
|
||||
'receiver_list' : receiver_list,
|
||||
'message' : unicode(msg).encode('utf-8'),
|
||||
'sender_name' : sender_name or get_sender_name(),
|
||||
'success_msg' : success_msg
|
||||
}
|
||||
|
||||
if frappe.db.get_value('SMS Settings', None, 'sms_gateway_url'):
|
||||
send_via_gateway(arg)
|
||||
else:
|
||||
msgprint(_("Please Update SMS Settings"))
|
||||
|
||||
def send_via_gateway(arg):
|
||||
ss = frappe.get_doc('SMS Settings', 'SMS Settings')
|
||||
args = {ss.message_parameter: arg.get('message')}
|
||||
for d in ss.get("parameters"):
|
||||
args[d.parameter] = d.value
|
||||
|
||||
success_list = []
|
||||
for d in arg.get('receiver_list'):
|
||||
args[ss.receiver_parameter] = d
|
||||
status = send_request(ss.sms_gateway_url, args)
|
||||
|
||||
if 200 <= status < 300:
|
||||
success_list.append(d)
|
||||
|
||||
if len(success_list) > 0:
|
||||
args.update(arg)
|
||||
create_sms_log(args, success_list)
|
||||
if arg.get('success_msg'):
|
||||
frappe.msgprint(_("SMS sent to following numbers: {0}").format("\n" + "\n".join(success_list)))
|
||||
|
||||
|
||||
def send_request(gateway_url, params):
|
||||
import requests
|
||||
response = requests.get(gateway_url, params = params, headers={'Accept': "text/plain, text/html, */*"})
|
||||
response.raise_for_status()
|
||||
return response.status_code
|
||||
|
||||
|
||||
# Create SMS Log
|
||||
# =========================================================
|
||||
def create_sms_log(args, sent_to):
|
||||
sl = frappe.new_doc('SMS Log')
|
||||
sl.sender_name = args['sender_name']
|
||||
sl.sent_on = nowdate()
|
||||
sl.message = args['message'].decode('utf-8')
|
||||
sl.no_of_requested_sms = len(args['receiver_list'])
|
||||
sl.requested_numbers = "\n".join(args['receiver_list'])
|
||||
sl.no_of_sent_sms = len(sent_to)
|
||||
sl.sent_to = "\n".join(sent_to)
|
||||
sl.flags.ignore_permissions = True
|
||||
sl.save()
|